]> git.hungrycats.org Git - linux/commitdiff
btrfs: export dev_item.type in /sys/fs/btrfs/<uuid>/devinfo/<devid>/type (v8)
authorGoffredo Baroncelli <kreijack@inwind.it>
Sun, 24 Oct 2021 15:31:05 +0000 (17:31 +0200)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Sun, 5 Dec 2021 08:11:07 +0000 (03:11 -0500)
Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
(cherry picked from commit d4315910dfc1e8b28875220c1a4a25b67943b96f)
(cherry picked from commit d71e3b5d41e9fbee5d33785b02c0918226804ab6)
(cherry picked from commit 576c9c72d46b861f2a8d05201dc56af9a20c0b0d)

fs/btrfs/sysfs.c

index d4998fb8e406eeb0266409416f48fc42d5956f2d..a9d234d08bf26f4c287534b8b5f68b371cb54fdf 100644 (file)
@@ -1445,12 +1445,56 @@ static ssize_t btrfs_devinfo_writeable_show(struct kobject *kobj,
 }
 BTRFS_ATTR(devid, writeable, btrfs_devinfo_writeable_show);
 
+static ssize_t btrfs_devinfo_error_stats_show(struct kobject *kobj,
+               struct kobj_attribute *a, char *buf)
+{
+       struct btrfs_device *device = container_of(kobj, struct btrfs_device,
+                                                  devid_kobj);
+
+       if (!device->dev_stats_valid)
+               return scnprintf(buf, PAGE_SIZE, "invalid\n");
+
+       /*
+        * Print all at once so we get a snapshot of all values from the same
+        * time. Keep them in sync and in order of definition of
+        * btrfs_dev_stat_values.
+        */
+       return scnprintf(buf, PAGE_SIZE,
+               "write_errs %d\n"
+               "read_errs %d\n"
+               "flush_errs %d\n"
+               "corruption_errs %d\n"
+               "generation_errs %d\n",
+               btrfs_dev_stat_read(device, BTRFS_DEV_STAT_WRITE_ERRS),
+               btrfs_dev_stat_read(device, BTRFS_DEV_STAT_READ_ERRS),
+               btrfs_dev_stat_read(device, BTRFS_DEV_STAT_FLUSH_ERRS),
+               btrfs_dev_stat_read(device, BTRFS_DEV_STAT_CORRUPTION_ERRS),
+               btrfs_dev_stat_read(device, BTRFS_DEV_STAT_GENERATION_ERRS));
+}
+BTRFS_ATTR(devid, error_stats, btrfs_devinfo_error_stats_show);
+
+static ssize_t btrfs_devinfo_type_show(struct kobject *kobj,
+                                           struct kobj_attribute *a, char *buf)
+{
+       struct btrfs_device *device = container_of(kobj, struct btrfs_device,
+                                                  devid_kobj);
+
+       return scnprintf(buf, PAGE_SIZE, "0x%08llx\n", device->type);
+}
+BTRFS_ATTR(devid, type, btrfs_devinfo_type_show);
+
+/*
+ * Information about one device.
+ *
+ * Path: /sys/fs/btrfs/<uuid>/devinfo/<devid>/
+ */
 static struct attribute *devid_attrs[] = {
        BTRFS_ATTR_PTR(devid, in_fs_metadata),
        BTRFS_ATTR_PTR(devid, missing),
        BTRFS_ATTR_PTR(devid, replace_target),
        BTRFS_ATTR_PTR(devid, scrub_speed_max),
        BTRFS_ATTR_PTR(devid, writeable),
+       BTRFS_ATTR_PTR(devid, type),
        NULL
 };
 ATTRIBUTE_GROUPS(devid);