From cf5c55fba82dc8471cc7c631d12ac7d88f2bedc1 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Wed, 2 Nov 2016 02:06:13 +0100 Subject: [PATCH 1/1] btrfs-progs: dump-tree: print dev stats Signed-off-by: David Sterba --- print-tree.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/print-tree.c b/print-tree.c index 24710db..03d7714 100644 --- a/print-tree.c +++ b/print-tree.c @@ -1009,6 +1009,31 @@ static void print_balance_item(struct extent_buffer *eb, print_disk_balance_args(btrfs_balance_item_sys(eb, bi)); } +static void print_dev_stats(struct extent_buffer *eb, + struct btrfs_dev_stats_item *stats, u32 size) +{ + int i; + u32 known = BTRFS_DEV_STAT_VALUES_MAX * sizeof(__le64); + __le64 *values = btrfs_dev_stats_values(eb, stats); + + printf("\t\tdevice stats\n"); + printf("\t\twrite_errs %llu read_errs %llu flush_errs %llu corruption_errs %llu generation %llu\n", + (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_WRITE_ERRS]), + (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_READ_ERRS]), + (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_FLUSH_ERRS]), + (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_CORRUPTION_ERRS]), + (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_GENERATION_ERRS])); + + if (known < size) { + printf("\t\tunknown stats item bytes %u", size - known); + for (i = BTRFS_DEV_STAT_VALUES_MAX; i * sizeof(__le64) < size; i++) { + printf("\t\tunknown item %u offset %lu value %llu\n", + i, i * sizeof(__le64), + (unsigned long long)le64_to_cpu(values[i])); + } + } +} + void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l) { int i; @@ -1264,7 +1289,9 @@ void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l) printf(" offset %llu\n", (unsigned long long)offset); switch (objectid) { case BTRFS_DEV_STATS_OBJECTID: - printf("\t\tdevice stats\n"); + print_dev_stats(l, btrfs_item_ptr(l, i, + struct btrfs_dev_stats_item), + btrfs_item_size(l, item)); break; default: printf("\t\tunknown persistent item objectid %llu\n", -- 2.7.4