block: export diskseq in sysfs
authorMatteo Croce <mcroce@microsoft.com>
Mon, 12 Jul 2021 23:05:28 +0000 (01:05 +0200)
committerJens Axboe <axboe@kernel.dk>
Mon, 2 Aug 2021 19:37:28 +0000 (13:37 -0600)
Add a new sysfs handle to export the new diskseq value.
Place it in <sysfs>/block/<disk>/diskseq and document it.

    $ grep . /sys/class/block/*/diskseq
    /sys/class/block/loop0/diskseq:13
    /sys/class/block/loop1/diskseq:14
    /sys/class/block/loop2/diskseq:5
    /sys/class/block/loop3/diskseq:6
    /sys/class/block/ram0/diskseq:1
    /sys/class/block/ram1/diskseq:2
    /sys/class/block/vda/diskseq:7

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Matteo Croce <mcroce@microsoft.com>
Tested-by: Luca Boccassi <bluca@debian.org>
Link: https://lore.kernel.org/r/20210712230530.29323-5-mcroce@linux.microsoft.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Documentation/ABI/testing/sysfs-block
block/genhd.c

index e34cdee..a0ed873 100644 (file)
@@ -28,6 +28,18 @@ Description:
                For more details refer Documentation/admin-guide/iostats.rst
 
 
+What:          /sys/block/<disk>/diskseq
+Date:          February 2021
+Contact:       Matteo Croce <mcroce@microsoft.com>
+Description:
+               The /sys/block/<disk>/diskseq files reports the disk
+               sequence number, which is a monotonically increasing
+               number assigned to every drive.
+               Some devices, like the loop device, refresh such number
+               every time the backing file is changed.
+               The value type is 64 bit unsigned.
+
+
 What:          /sys/block/<disk>/<part>/stat
 Date:          February 2008
 Contact:       Jerome Marchand <jmarchan@redhat.com>
index e1b2f89..a4817e4 100644 (file)
@@ -977,6 +977,14 @@ static ssize_t disk_discard_alignment_show(struct device *dev,
        return sprintf(buf, "%d\n", queue_discard_alignment(disk->queue));
 }
 
+static ssize_t diskseq_show(struct device *dev,
+                           struct device_attribute *attr, char *buf)
+{
+       struct gendisk *disk = dev_to_disk(dev);
+
+       return sprintf(buf, "%llu\n", disk->diskseq);
+}
+
 static DEVICE_ATTR(range, 0444, disk_range_show, NULL);
 static DEVICE_ATTR(ext_range, 0444, disk_ext_range_show, NULL);
 static DEVICE_ATTR(removable, 0444, disk_removable_show, NULL);
@@ -989,6 +997,7 @@ static DEVICE_ATTR(capability, 0444, disk_capability_show, NULL);
 static DEVICE_ATTR(stat, 0444, part_stat_show, NULL);
 static DEVICE_ATTR(inflight, 0444, part_inflight_show, NULL);
 static DEVICE_ATTR(badblocks, 0644, disk_badblocks_show, disk_badblocks_store);
+static DEVICE_ATTR(diskseq, 0444, diskseq_show, NULL);
 
 #ifdef CONFIG_FAIL_MAKE_REQUEST
 ssize_t part_fail_show(struct device *dev,
@@ -1034,6 +1043,7 @@ static struct attribute *disk_attrs[] = {
        &dev_attr_events.attr,
        &dev_attr_events_async.attr,
        &dev_attr_events_poll_msecs.attr,
+       &dev_attr_diskseq.attr,
 #ifdef CONFIG_FAIL_MAKE_REQUEST
        &dev_attr_fail.attr,
 #endif