Skip to content

Commit dc4d137

Browse files
Niklas Casselaxboe
authored andcommitted
null_blk: add support for max open/active zone limit for zoned devices
Add support for user space to set a max open zone and a max active zone limit via configfs. By default, the default values are 0 == no limit. Call the block layer API functions used for exposing the configured limits to sysfs. Add accounting in null_blk_zoned so that these new limits are respected. Performing an operation that would exceed these limits results in a standard I/O error. A max open zone limit exists in the ZBC standard. While null_blk_zoned is used to test the Zoned Block Device model in Linux, when it comes to differences between ZBC and ZNS, null_blk_zoned mostly follows ZBC. Therefore, implement the manage open zone resources function from ZBC, but additionally add support for max active zones. This enables user space not only to test against a device with an open zone limit, but also to test against a device with an active zone limit. Signed-off-by: Niklas Cassel <niklas.cassel@wdc.com> Reviewed-by: Damien Le Moal <damien.lemoal@wdc.com> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 1ed4211 commit dc4d137

3 files changed

Lines changed: 282 additions & 58 deletions

File tree

‎drivers/block/null_blk.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ struct nullb_device {
4242
struct badblocks badblocks;
4343

4444
unsigned int nr_zones;
45+
unsigned int nr_zones_imp_open;
46+
unsigned int nr_zones_exp_open;
47+
unsigned int nr_zones_closed;
4548
struct blk_zone *zones;
4649
sector_t zone_size_sects;
4750

@@ -51,6 +54,8 @@ struct nullb_device {
5154
unsigned long zone_size; /* zone size in MB if device is zoned */
5255
unsigned long zone_capacity; /* zone capacity in MB if device is zoned */
5356
unsigned int zone_nr_conv; /* number of conventional zones */
57+
unsigned int zone_max_open; /* max number of open zones */
58+
unsigned int zone_max_active; /* max number of active zones */
5459
unsigned int submit_queues; /* number of submission queues */
5560
unsigned int home_node; /* home node for the device */
5661
unsigned int queue_mode; /* block interface */

‎drivers/block/null_blk_main.c‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,14 @@ static unsigned int g_zone_nr_conv;
212212
module_param_named(zone_nr_conv, g_zone_nr_conv, uint, 0444);
213213
MODULE_PARM_DESC(zone_nr_conv, "Number of conventional zones when block device is zoned. Default: 0");
214214

215+
static unsigned int g_zone_max_open;
216+
module_param_named(zone_max_open, g_zone_max_open, uint, 0444);
217+
MODULE_PARM_DESC(zone_max_open, "Maximum number of open zones when block device is zoned. Default: 0 (no limit)");
218+
219+
static unsigned int g_zone_max_active;
220+
module_param_named(zone_max_active, g_zone_max_active, uint, 0444);
221+
MODULE_PARM_DESC(zone_max_active, "Maximum number of active zones when block device is zoned. Default: 0 (no limit)");
222+
215223
static struct nullb_device *null_alloc_dev(void);
216224
static void null_free_dev(struct nullb_device *dev);
217225
static void null_del_dev(struct nullb *nullb);
@@ -351,6 +359,8 @@ NULLB_DEVICE_ATTR(zoned, bool, NULL);
351359
NULLB_DEVICE_ATTR(zone_size, ulong, NULL);
352360
NULLB_DEVICE_ATTR(zone_capacity, ulong, NULL);
353361
NULLB_DEVICE_ATTR(zone_nr_conv, uint, NULL);
362+
NULLB_DEVICE_ATTR(zone_max_open, uint, NULL);
363+
NULLB_DEVICE_ATTR(zone_max_active, uint, NULL);
354364

355365
static ssize_t nullb_device_power_show(struct config_item *item, char *page)
356366
{
@@ -468,6 +478,8 @@ static struct configfs_attribute *nullb_device_attrs[] = {
468478
&nullb_device_attr_zone_size,
469479
&nullb_device_attr_zone_capacity,
470480
&nullb_device_attr_zone_nr_conv,
481+
&nullb_device_attr_zone_max_open,
482+
&nullb_device_attr_zone_max_active,
471483
NULL,
472484
};
473485

@@ -521,7 +533,7 @@ nullb_group_drop_item(struct config_group *group, struct config_item *item)
521533
static ssize_t memb_group_features_show(struct config_item *item, char *page)
522534
{
523535
return snprintf(page, PAGE_SIZE,
524-
"memory_backed,discard,bandwidth,cache,badblocks,zoned,zone_size,zone_capacity,zone_nr_conv\n");
536+
"memory_backed,discard,bandwidth,cache,badblocks,zoned,zone_size,zone_capacity,zone_nr_conv,zone_max_open,zone_max_active\n");
525537
}
526538

527539
CONFIGFS_ATTR_RO(memb_group_, features);
@@ -584,6 +596,8 @@ static struct nullb_device *null_alloc_dev(void)
584596
dev->zone_size = g_zone_size;
585597
dev->zone_capacity = g_zone_capacity;
586598
dev->zone_nr_conv = g_zone_nr_conv;
599+
dev->zone_max_open = g_zone_max_open;
600+
dev->zone_max_active = g_zone_max_active;
587601
return dev;
588602
}
589603

0 commit comments

Comments
 (0)