From: Matteo Croce <mcr...@microsoft.com>

Add a new sysfs handle to export the new diskseq value.
Place it in <sysfs>/block/<disk>/diskseq and document it.

Signed-off-by: Matteo Croce <mcr...@microsoft.com>
---
 Documentation/ABI/testing/sysfs-block | 12 ++++++++++++
 block/genhd.c                         | 11 +++++++++++
 2 files changed, 23 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-block 
b/Documentation/ABI/testing/sysfs-block
index e34cdeeeb9d4..a0ed87386639 100644
--- a/Documentation/ABI/testing/sysfs-block
+++ b/Documentation/ABI/testing/sysfs-block
@@ -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 <mcr...@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 <jmarc...@redhat.com>
diff --git a/block/genhd.c b/block/genhd.c
index a59a35cf452c..1aedd4fab6f3 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -1975,6 +1975,7 @@ static void disk_check_events(struct disk_events *ev,
  * events_async                : list of events which can be detected w/o 
polling
  *                       (always empty, only for backwards compatibility)
  * events_poll_msecs   : polling interval, 0: disable, -1: system default
+ * diskseq             : disk sequence number, since boot
  */
 static ssize_t __disk_events_show(unsigned int events, char *buf)
 {
@@ -2045,16 +2046,26 @@ static ssize_t disk_events_poll_msecs_store(struct 
device *dev,
        return count;
 }
 
+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 const DEVICE_ATTR(events, 0444, disk_events_show, NULL);
 static const DEVICE_ATTR(events_async, 0444, disk_events_async_show, NULL);
 static const DEVICE_ATTR(events_poll_msecs, 0644,
                         disk_events_poll_msecs_show,
                         disk_events_poll_msecs_store);
+static const DEVICE_ATTR(diskseq, 0444, diskseq_show, NULL);
 
 static const struct attribute *disk_sysfs_attrs[] = {
        &dev_attr_events.attr,
        &dev_attr_events_async.attr,
        &dev_attr_events_poll_msecs.attr,
+       &dev_attr_diskseq.attr,
        NULL,
 };
 
-- 
2.29.2

Reply via email to