Skip to content

Commit da658b5

Browse files
committed
btrfs: sysfs: export dev stats in devinfo directory
The device stats can be read by ioctl, wrapped by command 'btrfs device stats'. Provide another source where to read the information in /sys/fs/btrfs/FSID/devinfo/DEVID/error_stats . The format is a list of 'key value' pairs one per line, which is common in other stat files. The names are the same as used in other device stat outputs. The stats are all in one file as it's the snapshot of all available stats. The 'one value per file' format is not very suitable here. The stats should be valid right after the stats item is read from disk, shortly after initializing the device. In case the stats are not yet valid, print just 'invalid' as the file contents. Reviewed-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 1a9fd41 commit da658b5

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

fs/btrfs/sysfs.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,7 +1495,36 @@ static ssize_t btrfs_devinfo_writeable_show(struct kobject *kobj,
14951495
}
14961496
BTRFS_ATTR(devid, writeable, btrfs_devinfo_writeable_show);
14971497

1498+
static ssize_t btrfs_devinfo_error_stats_show(struct kobject *kobj,
1499+
struct kobj_attribute *a, char *buf)
1500+
{
1501+
struct btrfs_device *device = container_of(kobj, struct btrfs_device,
1502+
devid_kobj);
1503+
1504+
if (!device->dev_stats_valid)
1505+
return scnprintf(buf, PAGE_SIZE, "invalid\n");
1506+
1507+
/*
1508+
* Print all at once so we get a snapshot of all values from the same
1509+
* time. Keep them in sync and in order of definition of
1510+
* btrfs_dev_stat_values.
1511+
*/
1512+
return scnprintf(buf, PAGE_SIZE,
1513+
"write_errs %d\n"
1514+
"read_errs %d\n"
1515+
"flush_errs %d\n"
1516+
"corruption_errs %d\n"
1517+
"generation_errs %d\n",
1518+
btrfs_dev_stat_read(device, BTRFS_DEV_STAT_WRITE_ERRS),
1519+
btrfs_dev_stat_read(device, BTRFS_DEV_STAT_READ_ERRS),
1520+
btrfs_dev_stat_read(device, BTRFS_DEV_STAT_FLUSH_ERRS),
1521+
btrfs_dev_stat_read(device, BTRFS_DEV_STAT_CORRUPTION_ERRS),
1522+
btrfs_dev_stat_read(device, BTRFS_DEV_STAT_GENERATION_ERRS));
1523+
}
1524+
BTRFS_ATTR(devid, error_stats, btrfs_devinfo_error_stats_show);
1525+
14981526
static struct attribute *devid_attrs[] = {
1527+
BTRFS_ATTR_PTR(devid, error_stats),
14991528
BTRFS_ATTR_PTR(devid, in_fs_metadata),
15001529
BTRFS_ATTR_PTR(devid, missing),
15011530
BTRFS_ATTR_PTR(devid, replace_target),

0 commit comments

Comments
 (0)