-
- canonical_path = canonicalize_path((char *)path);
-
- if (args.nr_items >= BTRFS_DEV_STAT_WRITE_ERRS + 1)
- printf("[%s].write_io_errs %llu\n",
- canonical_path,
- (unsigned long long) args.values[
- BTRFS_DEV_STAT_WRITE_ERRS]);
- if (args.nr_items >= BTRFS_DEV_STAT_READ_ERRS + 1)
- printf("[%s].read_io_errs %llu\n",
- canonical_path,
- (unsigned long long) args.values[
- BTRFS_DEV_STAT_READ_ERRS]);
- if (args.nr_items >= BTRFS_DEV_STAT_FLUSH_ERRS + 1)
- printf("[%s].flush_io_errs %llu\n",
- canonical_path,
- (unsigned long long) args.values[
- BTRFS_DEV_STAT_FLUSH_ERRS]);
- if (args.nr_items >= BTRFS_DEV_STAT_CORRUPTION_ERRS + 1)
- printf("[%s].corruption_errs %llu\n",
- canonical_path,
- (unsigned long long) args.values[
- BTRFS_DEV_STAT_CORRUPTION_ERRS]);
- if (args.nr_items >= BTRFS_DEV_STAT_GENERATION_ERRS + 1)
- printf("[%s].generation_errs %llu\n",
- canonical_path,
- (unsigned long long) args.values[
- BTRFS_DEV_STAT_GENERATION_ERRS]);
+ int j;
+ static const struct {
+ const char name[32];
+ u64 num;
+ } dev_stats[] = {
+ { "write_io_errs", BTRFS_DEV_STAT_WRITE_ERRS },
+ { "read_io_errs", BTRFS_DEV_STAT_READ_ERRS },
+ { "flush_io_errs", BTRFS_DEV_STAT_FLUSH_ERRS },
+ { "corruption_errs",
+ BTRFS_DEV_STAT_CORRUPTION_ERRS },
+ { "generation_errs",
+ BTRFS_DEV_STAT_GENERATION_ERRS },
+ };
+
+ canonical_path = canonicalize_path(path);
+
+ /* No path when device is missing. */
+ if (!canonical_path) {
+ canonical_path = malloc(32);
+ if (!canonical_path) {
+ error("not enough memory for path buffer");
+ goto out;
+ }
+ snprintf(canonical_path, 32,
+ "devid:%llu", args.devid);
+ }
+
+ for (j = 0; j < ARRAY_SIZE(dev_stats); j++) {
+ /* We got fewer items than we know */
+ if (args.nr_items < dev_stats[j].num + 1)
+ continue;
+ printf("[%s].%-16s %llu\n", canonical_path,
+ dev_stats[j].name,
+ (unsigned long long)
+ args.values[dev_stats[j].num]);
+ if ((check == 1)
+ && (args.values[dev_stats[j].num] > 0))
+ err |= 64;
+ }