diff mbox series

[06/11] block: Introduce BLKGETZONESZ ioctl

Message ID 20181010015239.24930-7-damien.lemoal@wdc.com (mailing list archive)
State New, archived
Headers show
Series Zoned block device support improvements | expand

Commit Message

Damien Le Moal Oct. 10, 2018, 1:52 a.m. UTC
Get a zoned block device zone size in number of 512 B sectors.
The zone size is always 0 for regular block devices.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
 block/ioctl.c                 | 2 ++
 include/uapi/linux/blkzoned.h | 2 ++
 2 files changed, 4 insertions(+)

Comments

Christoph Hellwig Oct. 10, 2018, 1:27 p.m. UTC | #1
On Wed, Oct 10, 2018 at 10:52:34AM +0900, Damien Le Moal wrote:
> Get a zoned block device zone size in number of 512 B sectors.
> The zone size is always 0 for regular block devices.

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>
Bart Van Assche Oct. 10, 2018, 4:53 p.m. UTC | #2
On Wed, 2018-10-10 at 10:52 +0900, Damien Le Moal wrote:
>  #define BLKREPORTZONE	_IOWR(0x12, 130, struct blk_zone_report)
>  #define BLKRESETZONE	_IOW(0x12, 131, struct blk_zone_range)
> +#define BLKGETZONESZ	_IOW(0x12, 132, unsigned int)

From Documentation/ioctl/botching-up-ioctls.txt, a collection of lessons learned
the hard way about ioctls:

 * Only use fixed sized integers. To avoid conflicts with typedefs in userspace
   the kernel has special types like __u32, __s64. Use them.

Please follow that advice.

Thanks,

Bart.
diff mbox series

Patch

diff --git a/block/ioctl.c b/block/ioctl.c
index 3884d810efd2..f6d2c6f1f050 100644
--- a/block/ioctl.c
+++ b/block/ioctl.c
@@ -532,6 +532,8 @@  int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
 		return blkdev_report_zones_ioctl(bdev, mode, cmd, arg);
 	case BLKRESETZONE:
 		return blkdev_reset_zones_ioctl(bdev, mode, cmd, arg);
+	case BLKGETZONESZ:
+		return put_uint(arg, bdev_zone_sectors(bdev));
 	case HDIO_GETGEO:
 		return blkdev_getgeo(bdev, argp);
 	case BLKRAGET:
diff --git a/include/uapi/linux/blkzoned.h b/include/uapi/linux/blkzoned.h
index ff5a5db8906a..daf47351d519 100644
--- a/include/uapi/linux/blkzoned.h
+++ b/include/uapi/linux/blkzoned.h
@@ -137,8 +137,10 @@  struct blk_zone_range {
  *                 sector specified in the report request structure.
  * @BLKRESETZONE: Reset the write pointer of the zones in the specified
  *                sector range. The sector range must be zone aligned.
+ * @BLKGETZONESZ: Get the device zone size in number of 512 B sectors.
  */
 #define BLKREPORTZONE	_IOWR(0x12, 130, struct blk_zone_report)
 #define BLKRESETZONE	_IOW(0x12, 131, struct blk_zone_range)
+#define BLKGETZONESZ	_IOW(0x12, 132, unsigned int)
 
 #endif /* _UAPI_BLKZONED_H */