Skip to content

Commit 997a1f0

Browse files
damien-lemoalaxboe
authored andcommitted
null_blk: Introduce zone_append_max_sectors attribute
Add the zone_append_max_sectors configfs attribute and module parameter to allow configuring the maximum number of 512B sectors of zone append operations. This attribute is meaningful only for zoned null block devices. If not specified, the default is unchanged and the zoned device max append sectors limit is set to the device max sectors limit. If a non 0 value is used for this attribute, which is the default, then native support for zone append operations is enabled. Setting a 0 value disables native zone append operations support to instead use the block layer emulation. Signed-off-by: Damien Le Moal <dlemoal@kernel.org> Reviewed-by: Hannes Reinecke <hare@suse.de> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com> Reviewed-by: Bart Van Assche <bvanassche@acm.org> Tested-by: Hans Holmberg <hans.holmberg@wdc.com> Tested-by: Dennis Maisenbacher <dennis.maisenbacher@wdc.com> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com> Link: https://lore.kernel.org/r/20240408014128.205141-17-dlemoal@kernel.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent b66f79b commit 997a1f0

3 files changed

Lines changed: 27 additions & 4 deletions

File tree

drivers/block/null_blk/main.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,11 @@ static unsigned int g_zone_max_active;
253253
module_param_named(zone_max_active, g_zone_max_active, uint, 0444);
254254
MODULE_PARM_DESC(zone_max_active, "Maximum number of active zones when block device is zoned. Default: 0 (no limit)");
255255

256+
static int g_zone_append_max_sectors = INT_MAX;
257+
module_param_named(zone_append_max_sectors, g_zone_append_max_sectors, int, 0444);
258+
MODULE_PARM_DESC(zone_append_max_sectors,
259+
"Maximum size of a zone append command (in 512B sectors). Specify 0 for zone append emulation");
260+
256261
static struct nullb_device *null_alloc_dev(void);
257262
static void null_free_dev(struct nullb_device *dev);
258263
static void null_del_dev(struct nullb *nullb);
@@ -436,6 +441,7 @@ NULLB_DEVICE_ATTR(zone_capacity, ulong, NULL);
436441
NULLB_DEVICE_ATTR(zone_nr_conv, uint, NULL);
437442
NULLB_DEVICE_ATTR(zone_max_open, uint, NULL);
438443
NULLB_DEVICE_ATTR(zone_max_active, uint, NULL);
444+
NULLB_DEVICE_ATTR(zone_append_max_sectors, uint, NULL);
439445
NULLB_DEVICE_ATTR(virt_boundary, bool, NULL);
440446
NULLB_DEVICE_ATTR(no_sched, bool, NULL);
441447
NULLB_DEVICE_ATTR(shared_tags, bool, NULL);
@@ -580,6 +586,7 @@ static struct configfs_attribute *nullb_device_attrs[] = {
580586
&nullb_device_attr_zone_nr_conv,
581587
&nullb_device_attr_zone_max_open,
582588
&nullb_device_attr_zone_max_active,
589+
&nullb_device_attr_zone_append_max_sectors,
583590
&nullb_device_attr_zone_readonly,
584591
&nullb_device_attr_zone_offline,
585592
&nullb_device_attr_virt_boundary,
@@ -671,7 +678,7 @@ static ssize_t memb_group_features_show(struct config_item *item, char *page)
671678
"shared_tags,size,submit_queues,use_per_node_hctx,"
672679
"virt_boundary,zoned,zone_capacity,zone_max_active,"
673680
"zone_max_open,zone_nr_conv,zone_offline,zone_readonly,"
674-
"zone_size\n");
681+
"zone_size,zone_append_max_sectors\n");
675682
}
676683

677684
CONFIGFS_ATTR_RO(memb_group_, features);
@@ -751,6 +758,7 @@ static struct nullb_device *null_alloc_dev(void)
751758
dev->zone_nr_conv = g_zone_nr_conv;
752759
dev->zone_max_open = g_zone_max_open;
753760
dev->zone_max_active = g_zone_max_active;
761+
dev->zone_append_max_sectors = g_zone_append_max_sectors;
754762
dev->virt_boundary = g_virt_boundary;
755763
dev->no_sched = g_no_sched;
756764
dev->shared_tags = g_shared_tags;

drivers/block/null_blk/null_blk.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ struct nullb_device {
8282
unsigned int zone_nr_conv; /* number of conventional zones */
8383
unsigned int zone_max_open; /* max number of open zones */
8484
unsigned int zone_max_active; /* max number of active zones */
85+
unsigned int zone_append_max_sectors; /* Max sectors per zone append command */
8586
unsigned int submit_queues; /* number of submission queues */
8687
unsigned int prev_submit_queues; /* number of submission queues before change */
8788
unsigned int poll_queues; /* number of IOPOLL submission queues */

drivers/block/null_blk/zoned.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ int null_init_zoned_dev(struct nullb_device *dev,
103103
dev->zone_nr_conv);
104104
}
105105

106+
dev->zone_append_max_sectors =
107+
min(ALIGN_DOWN(dev->zone_append_max_sectors,
108+
dev->blocksize >> SECTOR_SHIFT),
109+
zone_capacity_sects);
110+
106111
/* Max active zones has to be < nbr of seq zones in order to be enforceable */
107112
if (dev->zone_max_active >= dev->nr_zones - dev->zone_nr_conv) {
108113
dev->zone_max_active = 0;
@@ -154,7 +159,7 @@ int null_init_zoned_dev(struct nullb_device *dev,
154159

155160
lim->zoned = true;
156161
lim->chunk_sectors = dev->zone_size_sects;
157-
lim->max_zone_append_sectors = dev->zone_size_sects;
162+
lim->max_zone_append_sectors = dev->zone_append_max_sectors;
158163
lim->max_open_zones = dev->zone_max_open;
159164
lim->max_active_zones = dev->zone_max_active;
160165
return 0;
@@ -163,10 +168,16 @@ int null_init_zoned_dev(struct nullb_device *dev,
163168
int null_register_zoned_dev(struct nullb *nullb)
164169
{
165170
struct request_queue *q = nullb->q;
171+
struct gendisk *disk = nullb->disk;
166172

167173
blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, q);
168-
nullb->disk->nr_zones = bdev_nr_zones(nullb->disk->part0);
169-
return blk_revalidate_disk_zones(nullb->disk, NULL);
174+
disk->nr_zones = bdev_nr_zones(disk->part0);
175+
176+
pr_info("%s: using %s zone append\n",
177+
disk->disk_name,
178+
queue_emulates_zone_append(q) ? "emulated" : "native");
179+
180+
return blk_revalidate_disk_zones(disk, NULL);
170181
}
171182

172183
void null_free_zoned_dev(struct nullb_device *dev)
@@ -365,6 +376,9 @@ static blk_status_t null_zone_write(struct nullb_cmd *cmd, sector_t sector,
365376

366377
trace_nullb_zone_op(cmd, zno, zone->cond);
367378

379+
if (WARN_ON_ONCE(append && !dev->zone_append_max_sectors))
380+
return BLK_STS_IOERR;
381+
368382
if (zone->type == BLK_ZONE_TYPE_CONVENTIONAL) {
369383
if (append)
370384
return BLK_STS_IOERR;

0 commit comments

Comments
 (0)