Skip to content

Commit 089565f

Browse files
aravind-wdcChristoph Hellwig
authored andcommitted
null_blk: introduce zone capacity for zoned device
Allow emulation of a zoned device with a per zone capacity smaller than the zone size as as defined in the Zoned Namespace (ZNS) Command Set specification. The zone capacity defaults to the zone size if not specified and must be smaller than the zone size otherwise. Reviewed-by: Matias Bjørling <matias.bjorling@wdc.com> Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com> Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com> Reviewed-by: Hannes Reinecke <hare@suse.de> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Reviewed-by: Daniel Wagner <dwagner@suse.de> Signed-off-by: Aravind Ramesh <aravind.ramesh@wdc.com> Signed-off-by: Christoph Hellwig <hch@lst.de>
1 parent 82394db commit 089565f

3 files changed

Lines changed: 24 additions & 3 deletions

File tree

‎drivers/block/null_blk.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ struct nullb_device {
4949
unsigned long completion_nsec; /* time in ns to complete a request */
5050
unsigned long cache_size; /* disk cache size in MB */
5151
unsigned long zone_size; /* zone size in MB if device is zoned */
52+
unsigned long zone_capacity; /* zone capacity in MB if device is zoned */
5253
unsigned int zone_nr_conv; /* number of conventional zones */
5354
unsigned int submit_queues; /* number of submission queues */
5455
unsigned int home_node; /* home node for the device */

‎drivers/block/null_blk_main.c‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ static unsigned long g_zone_size = 256;
200200
module_param_named(zone_size, g_zone_size, ulong, S_IRUGO);
201201
MODULE_PARM_DESC(zone_size, "Zone size in MB when block device is zoned. Must be power-of-two: Default: 256");
202202

203+
static unsigned long g_zone_capacity;
204+
module_param_named(zone_capacity, g_zone_capacity, ulong, 0444);
205+
MODULE_PARM_DESC(zone_capacity, "Zone capacity in MB when block device is zoned. Can be less than or equal to zone size. Default: Zone size");
206+
203207
static unsigned int g_zone_nr_conv;
204208
module_param_named(zone_nr_conv, g_zone_nr_conv, uint, 0444);
205209
MODULE_PARM_DESC(zone_nr_conv, "Number of conventional zones when block device is zoned. Default: 0");
@@ -341,6 +345,7 @@ NULLB_DEVICE_ATTR(mbps, uint, NULL);
341345
NULLB_DEVICE_ATTR(cache_size, ulong, NULL);
342346
NULLB_DEVICE_ATTR(zoned, bool, NULL);
343347
NULLB_DEVICE_ATTR(zone_size, ulong, NULL);
348+
NULLB_DEVICE_ATTR(zone_capacity, ulong, NULL);
344349
NULLB_DEVICE_ATTR(zone_nr_conv, uint, NULL);
345350

346351
static ssize_t nullb_device_power_show(struct config_item *item, char *page)
@@ -457,6 +462,7 @@ static struct configfs_attribute *nullb_device_attrs[] = {
457462
&nullb_device_attr_badblocks,
458463
&nullb_device_attr_zoned,
459464
&nullb_device_attr_zone_size,
465+
&nullb_device_attr_zone_capacity,
460466
&nullb_device_attr_zone_nr_conv,
461467
NULL,
462468
};
@@ -510,7 +516,8 @@ nullb_group_drop_item(struct config_group *group, struct config_item *item)
510516

511517
static ssize_t memb_group_features_show(struct config_item *item, char *page)
512518
{
513-
return snprintf(page, PAGE_SIZE, "memory_backed,discard,bandwidth,cache,badblocks,zoned,zone_size,zone_nr_conv\n");
519+
return snprintf(page, PAGE_SIZE,
520+
"memory_backed,discard,bandwidth,cache,badblocks,zoned,zone_size,zone_capacity,zone_nr_conv\n");
514521
}
515522

516523
CONFIGFS_ATTR_RO(memb_group_, features);
@@ -571,6 +578,7 @@ static struct nullb_device *null_alloc_dev(void)
571578
dev->use_per_node_hctx = g_use_per_node_hctx;
572579
dev->zoned = g_zoned;
573580
dev->zone_size = g_zone_size;
581+
dev->zone_capacity = g_zone_capacity;
574582
dev->zone_nr_conv = g_zone_nr_conv;
575583
return dev;
576584
}

‎drivers/block/null_blk_zoned.c‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ int null_init_zoned_dev(struct nullb_device *dev, struct request_queue *q)
2828
return -EINVAL;
2929
}
3030

31+
if (!dev->zone_capacity)
32+
dev->zone_capacity = dev->zone_size;
33+
34+
if (dev->zone_capacity > dev->zone_size) {
35+
pr_err("null_blk: zone capacity (%lu MB) larger than zone size (%lu MB)\n",
36+
dev->zone_capacity, dev->zone_size);
37+
return -EINVAL;
38+
}
39+
3140
dev->zone_size_sects = dev->zone_size << ZONE_SIZE_SHIFT;
3241
dev->nr_zones = dev_size >>
3342
(SECTOR_SHIFT + ilog2(dev->zone_size_sects));
@@ -60,7 +69,7 @@ int null_init_zoned_dev(struct nullb_device *dev, struct request_queue *q)
6069

6170
zone->start = zone->wp = sector;
6271
zone->len = dev->zone_size_sects;
63-
zone->capacity = zone->len;
72+
zone->capacity = dev->zone_capacity << ZONE_SIZE_SHIFT;
6473
zone->type = BLK_ZONE_TYPE_SEQWRITE_REQ;
6574
zone->cond = BLK_ZONE_COND_EMPTY;
6675

@@ -187,6 +196,9 @@ static blk_status_t null_zone_write(struct nullb_cmd *cmd, sector_t sector,
187196
return BLK_STS_IOERR;
188197
}
189198

199+
if (zone->wp + nr_sectors > zone->start + zone->capacity)
200+
return BLK_STS_IOERR;
201+
190202
if (zone->cond != BLK_ZONE_COND_EXP_OPEN)
191203
zone->cond = BLK_ZONE_COND_IMP_OPEN;
192204

@@ -195,7 +207,7 @@ static blk_status_t null_zone_write(struct nullb_cmd *cmd, sector_t sector,
195207
return ret;
196208

197209
zone->wp += nr_sectors;
198-
if (zone->wp == zone->start + zone->len)
210+
if (zone->wp == zone->start + zone->capacity)
199211
zone->cond = BLK_ZONE_COND_FULL;
200212
return BLK_STS_OK;
201213
default:

0 commit comments

Comments
 (0)