Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

block: add ioctl to read the disk sequence number

Add a new BLKGETDISKSEQ ioctl which retrieves the disk sequence number
from the genhd structure.

# ./getdiskseq /dev/loop*
/dev/loop0: 13
/dev/loop0p1: 13
/dev/loop0p2: 13
/dev/loop0p3: 13
/dev/loop1: 14
/dev/loop1p1: 14
/dev/loop1p2: 14
/dev/loop2: 5
/dev/loop3: 6

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-4-mcroce@linux.microsoft.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Matteo Croce and committed by
Jens Axboe
7957d93b 87eb7107

+3
+2
block/ioctl.c
··· 469 469 BLKDEV_DISCARD_SECURE); 470 470 case BLKZEROOUT: 471 471 return blk_ioctl_zeroout(bdev, mode, arg); 472 + case BLKGETDISKSEQ: 473 + return put_u64(argp, bdev->bd_disk->diskseq); 472 474 case BLKREPORTZONE: 473 475 return blkdev_report_zones_ioctl(bdev, mode, cmd, arg); 474 476 case BLKRESETZONE:
+1
include/uapi/linux/fs.h
··· 184 184 #define BLKSECDISCARD _IO(0x12,125) 185 185 #define BLKROTATIONAL _IO(0x12,126) 186 186 #define BLKZEROOUT _IO(0x12,127) 187 + #define BLKGETDISKSEQ _IOR(0x12,128,__u64) 187 188 /* 188 189 * A jump here: 130-136 are reserved for zoned block devices 189 190 * (see uapi/linux/blkzoned.h)