diff mbox series

[v4,3/5] block: add ioctl to read the disk sequence number

Message ID 20210711175415.80173-4-mcroce@linux.microsoft.com (mailing list archive)
State New, archived
Headers show
Series block: add a sequence number to disks | expand

Commit Message

Matteo Croce July 11, 2021, 5:54 p.m. UTC
From: Matteo Croce <mcroce@microsoft.com>

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

Signed-off-by: Matteo Croce <mcroce@microsoft.com>
---
 block/ioctl.c           | 2 ++
 include/uapi/linux/fs.h | 1 +
 2 files changed, 3 insertions(+)

Comments

Christoph Hellwig July 12, 2021, 6:28 a.m. UTC | #1
Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>
Elliott, Robert (Servers) July 12, 2021, 7:22 p.m. UTC | #2
> -----Original Message-----
> From: Matteo Croce <mcroce@linux.microsoft.com>
> Sent: Sunday, July 11, 2021 12:54 PM
...
> Subject: [PATCH v4 3/5] block: add ioctl to read the disk sequence number
> 
> From: Matteo Croce <mcroce@microsoft.com>
> 
> Add a new BLKGETDISKSEQ ioctl which retrieves the disk sequence number
> from the genhd structure.
...


Given:
    static int put_u64(u64 __user *argp, u64 val)
    {
        return put_user(val, argp);
    }

> diff --git a/block/ioctl.c b/block/ioctl.c
> index 24beec9ca9c9..0c3a4a53fa11 100644
> --- a/block/ioctl.c
> +++ b/block/ioctl.c
> @@ -469,6 +469,8 @@ static int blkdev_common_ioctl(struct block_device
> *bdev, fmode_t mode,
>  				BLKDEV_DISCARD_SECURE);
...

> +	case BLKGETDISKSEQ:
> +		return put_u64(argp, bdev->bd_disk->diskseq);

How does that work on a system in which int is 32 bits?
Matteo Croce July 12, 2021, 11:25 p.m. UTC | #3
On Mon, 12 Jul 2021 19:22:43 +0000
"Elliott, Robert (Servers)" <elliott@hpe.com> wrote:

> 
> 
> > -----Original Message-----
> > From: Matteo Croce <mcroce@linux.microsoft.com>
> > Sent: Sunday, July 11, 2021 12:54 PM
> ...
> > Subject: [PATCH v4 3/5] block: add ioctl to read the disk sequence
> > number
> > 
> > From: Matteo Croce <mcroce@microsoft.com>
> > 
> > Add a new BLKGETDISKSEQ ioctl which retrieves the disk sequence
> > number from the genhd structure.
> ...
> 
> 
> Given:
>     static int put_u64(u64 __user *argp, u64 val)
>     {
>         return put_user(val, argp);
>     }
> 
> > diff --git a/block/ioctl.c b/block/ioctl.c
> > index 24beec9ca9c9..0c3a4a53fa11 100644
> > --- a/block/ioctl.c
> > +++ b/block/ioctl.c
> > @@ -469,6 +469,8 @@ static int blkdev_common_ioctl(struct
> > block_device *bdev, fmode_t mode,
> >  				BLKDEV_DISCARD_SECURE);
> ...
> 
> > +	case BLKGETDISKSEQ:
> > +		return put_u64(argp, bdev->bd_disk->diskseq);
> 
> How does that work on a system in which int is 32 bits?
> 
> 

Hi,

what's the difference with this?

	case BLKGETSIZE64:
		return put_u64(argp, i_size_read(bdev->bd_inode));

The returned int is an error code, not the diskseq value itself, e.g.

	case BLKFRAGET:
		if (!argp)
			return -EINVAL;

Regards,
Christoph Hellwig July 13, 2021, 5:59 a.m. UTC | #4
On Mon, Jul 12, 2021 at 07:22:43PM +0000, Elliott, Robert (Servers) wrote:
>     static int put_u64(u64 __user *argp, u64 val)
>     {
>         return put_user(val, argp);
>     }
> 
> > diff --git a/block/ioctl.c b/block/ioctl.c
> > index 24beec9ca9c9..0c3a4a53fa11 100644
> > --- a/block/ioctl.c
> > +++ b/block/ioctl.c
> > @@ -469,6 +469,8 @@ static int blkdev_common_ioctl(struct block_device
> > *bdev, fmode_t mode,
> >  				BLKDEV_DISCARD_SECURE);
> ...
> 
> > +	case BLKGETDISKSEQ:
> > +		return put_u64(argp, bdev->bd_disk->diskseq);
> 
> How does that work on a system in which int is 32 bits?

Why would it not work?  put_user is a magic macro that works on all
scalar value.
diff mbox series

Patch

diff --git a/block/ioctl.c b/block/ioctl.c
index 24beec9ca9c9..0c3a4a53fa11 100644
--- a/block/ioctl.c
+++ b/block/ioctl.c
@@ -469,6 +469,8 @@  static int blkdev_common_ioctl(struct block_device *bdev, fmode_t mode,
 				BLKDEV_DISCARD_SECURE);
 	case BLKZEROOUT:
 		return blk_ioctl_zeroout(bdev, mode, arg);
+	case BLKGETDISKSEQ:
+		return put_u64(argp, bdev->bd_disk->diskseq);
 	case BLKREPORTZONE:
 		return blkdev_report_zones_ioctl(bdev, mode, cmd, arg);
 	case BLKRESETZONE:
diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h
index 4c32e97dcdf0..bdf7b404b3e7 100644
--- a/include/uapi/linux/fs.h
+++ b/include/uapi/linux/fs.h
@@ -184,6 +184,7 @@  struct fsxattr {
 #define BLKSECDISCARD _IO(0x12,125)
 #define BLKROTATIONAL _IO(0x12,126)
 #define BLKZEROOUT _IO(0x12,127)
+#define BLKGETDISKSEQ _IOR(0x12,128,__u64)
 /*
  * A jump here: 130-136 are reserved for zoned block devices
  * (see uapi/linux/blkzoned.h)