Skip to content

Commit e876df1

Browse files
ajaysjoshiaxboe
authored andcommitted
block: add zone open, close and finish ioctl support
Introduce three new ioctl commands BLKOPENZONE, BLKCLOSEZONE and BLKFINISHZONE to allow applications to control the condition of zones on a zoned block device through the execution of the REQ_OP_ZONE_OPEN, REQ_OP_ZONE_CLOSE and REQ_OP_ZONE_FINISH operations. Contains contributions from Matias Bjorling, Hans Holmberg, Dmitry Fomichev, Keith Busch, Damien Le Moal and Christoph Hellwig. Reviewed-by: Javier González <javier@javigon.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Ajay Joshi <ajay.joshi@wdc.com> Signed-off-by: Matias Bjorling <matias.bjorling@wdc.com> Signed-off-by: Hans Holmberg <hans.holmberg@wdc.com> Signed-off-by: Dmitry Fomichev <dmitry.fomichev@wdc.com> Signed-off-by: Keith Busch <kbusch@kernel.org> Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 6c1b1da commit e876df1

4 files changed

Lines changed: 46 additions & 14 deletions

File tree

‎block/blk-zoned.c‎

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -357,15 +357,16 @@ int blkdev_report_zones_ioctl(struct block_device *bdev, fmode_t mode,
357357
}
358358

359359
/*
360-
* BLKRESETZONE ioctl processing.
360+
* BLKRESETZONE, BLKOPENZONE, BLKCLOSEZONE and BLKFINISHZONE ioctl processing.
361361
* Called from blkdev_ioctl.
362362
*/
363-
int blkdev_reset_zones_ioctl(struct block_device *bdev, fmode_t mode,
364-
unsigned int cmd, unsigned long arg)
363+
int blkdev_zone_mgmt_ioctl(struct block_device *bdev, fmode_t mode,
364+
unsigned int cmd, unsigned long arg)
365365
{
366366
void __user *argp = (void __user *)arg;
367367
struct request_queue *q;
368368
struct blk_zone_range zrange;
369+
enum req_opf op;
369370

370371
if (!argp)
371372
return -EINVAL;
@@ -386,8 +387,25 @@ int blkdev_reset_zones_ioctl(struct block_device *bdev, fmode_t mode,
386387
if (copy_from_user(&zrange, argp, sizeof(struct blk_zone_range)))
387388
return -EFAULT;
388389

389-
return blkdev_zone_mgmt(bdev, REQ_OP_ZONE_RESET,
390-
zrange.sector, zrange.nr_sectors, GFP_KERNEL);
390+
switch (cmd) {
391+
case BLKRESETZONE:
392+
op = REQ_OP_ZONE_RESET;
393+
break;
394+
case BLKOPENZONE:
395+
op = REQ_OP_ZONE_OPEN;
396+
break;
397+
case BLKCLOSEZONE:
398+
op = REQ_OP_ZONE_CLOSE;
399+
break;
400+
case BLKFINISHZONE:
401+
op = REQ_OP_ZONE_FINISH;
402+
break;
403+
default:
404+
return -ENOTTY;
405+
}
406+
407+
return blkdev_zone_mgmt(bdev, op, zrange.sector, zrange.nr_sectors,
408+
GFP_KERNEL);
391409
}
392410

393411
static inline unsigned long *blk_alloc_zone_bitmap(int node,

‎block/ioctl.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,10 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
532532
case BLKREPORTZONE:
533533
return blkdev_report_zones_ioctl(bdev, mode, cmd, arg);
534534
case BLKRESETZONE:
535-
return blkdev_reset_zones_ioctl(bdev, mode, cmd, arg);
535+
case BLKOPENZONE:
536+
case BLKCLOSEZONE:
537+
case BLKFINISHZONE:
538+
return blkdev_zone_mgmt_ioctl(bdev, mode, cmd, arg);
536539
case BLKGETZONESZ:
537540
return put_uint(arg, bdev_zone_sectors(bdev));
538541
case BLKGETNRZONES:

‎include/linux/blkdev.h‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,8 @@ extern int blk_revalidate_disk_zones(struct gendisk *disk);
367367

368368
extern int blkdev_report_zones_ioctl(struct block_device *bdev, fmode_t mode,
369369
unsigned int cmd, unsigned long arg);
370-
extern int blkdev_reset_zones_ioctl(struct block_device *bdev, fmode_t mode,
371-
unsigned int cmd, unsigned long arg);
370+
extern int blkdev_zone_mgmt_ioctl(struct block_device *bdev, fmode_t mode,
371+
unsigned int cmd, unsigned long arg);
372372

373373
#else /* CONFIG_BLK_DEV_ZONED */
374374

@@ -389,9 +389,9 @@ static inline int blkdev_report_zones_ioctl(struct block_device *bdev,
389389
return -ENOTTY;
390390
}
391391

392-
static inline int blkdev_reset_zones_ioctl(struct block_device *bdev,
393-
fmode_t mode, unsigned int cmd,
394-
unsigned long arg)
392+
static inline int blkdev_zone_mgmt_ioctl(struct block_device *bdev,
393+
fmode_t mode, unsigned int cmd,
394+
unsigned long arg)
395395
{
396396
return -ENOTTY;
397397
}

‎include/uapi/linux/blkzoned.h‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,11 @@ struct blk_zone_report {
120120
};
121121

122122
/**
123-
* struct blk_zone_range - BLKRESETZONE ioctl request
124-
* @sector: starting sector of the first zone to issue reset write pointer
125-
* @nr_sectors: Total number of sectors of 1 or more zones to reset
123+
* struct blk_zone_range - BLKRESETZONE/BLKOPENZONE/
124+
* BLKCLOSEZONE/BLKFINISHZONE ioctl
125+
* requests
126+
* @sector: Starting sector of the first zone to operate on.
127+
* @nr_sectors: Total number of sectors of all zones to operate on.
126128
*/
127129
struct blk_zone_range {
128130
__u64 sector;
@@ -139,10 +141,19 @@ struct blk_zone_range {
139141
* sector range. The sector range must be zone aligned.
140142
* @BLKGETZONESZ: Get the device zone size in number of 512 B sectors.
141143
* @BLKGETNRZONES: Get the total number of zones of the device.
144+
* @BLKOPENZONE: Open the zones in the specified sector range.
145+
* The 512 B sector range must be zone aligned.
146+
* @BLKCLOSEZONE: Close the zones in the specified sector range.
147+
* The 512 B sector range must be zone aligned.
148+
* @BLKFINISHZONE: Mark the zones as full in the specified sector range.
149+
* The 512 B sector range must be zone aligned.
142150
*/
143151
#define BLKREPORTZONE _IOWR(0x12, 130, struct blk_zone_report)
144152
#define BLKRESETZONE _IOW(0x12, 131, struct blk_zone_range)
145153
#define BLKGETZONESZ _IOR(0x12, 132, __u32)
146154
#define BLKGETNRZONES _IOR(0x12, 133, __u32)
155+
#define BLKOPENZONE _IOW(0x12, 134, struct blk_zone_range)
156+
#define BLKCLOSEZONE _IOW(0x12, 135, struct blk_zone_range)
157+
#define BLKFINISHZONE _IOW(0x12, 136, struct blk_zone_range)
147158

148159
#endif /* _UAPI_BLKZONED_H */

0 commit comments

Comments
 (0)