Skip to content

Commit e15864f

Browse files
Niklas Casselaxboe
authored andcommitted
block: add max_open_zones to blk-sysfs
Add a new max_open_zones definition in the sysfs documentation. This definition will be common for all devices utilizing the zoned block device support in the kernel. Export max open zones according to this new definition for NVMe Zoned Namespace devices, ZAC ATA devices (which are treated as SCSI devices by the kernel), and ZBC SCSI devices. Add the new max_open_zones member to struct request_queue, rather than as a queue limit, since this property cannot be split across stacking drivers. Signed-off-by: Niklas Cassel <niklas.cassel@wdc.com> Reviewed-by: Javier González <javier@javigon.com> Reviewed-by: Damien Le Moal <damien.lemoal@wdc.com> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent b1d37e5 commit e15864f

6 files changed

Lines changed: 61 additions & 0 deletions

File tree

‎Documentation/ABI/testing/sysfs-block‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,15 @@ Description:
273273
device ("host-aware" or "host-managed" zone model). For regular
274274
block devices, the value is always 0.
275275

276+
What: /sys/block/<disk>/queue/max_open_zones
277+
Date: July 2020
278+
Contact: Niklas Cassel <niklas.cassel@wdc.com>
279+
Description:
280+
For zoned block devices (zoned attribute indicating
281+
"host-managed" or "host-aware"), the sum of zones belonging to
282+
any of the zone states: EXPLICIT OPEN or IMPLICIT OPEN,
283+
is limited by this value. If this value is 0, there is no limit.
284+
276285
What: /sys/block/<disk>/queue/chunk_sectors
277286
Date: September 2016
278287
Contact: Hannes Reinecke <hare@suse.com>

‎Documentation/block/queue-sysfs.rst‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ Maximum number of elements in a DMA scatter/gather list with integrity
117117
data that will be submitted by the block layer core to the associated
118118
block driver.
119119

120+
max_open_zones (RO)
121+
-------------------
122+
For zoned block devices (zoned attribute indicating "host-managed" or
123+
"host-aware"), the sum of zones belonging to any of the zone states:
124+
EXPLICIT OPEN or IMPLICIT OPEN, is limited by this value.
125+
If this value is 0, there is no limit.
126+
120127
max_sectors_kb (RW)
121128
-------------------
122129
This is the maximum number of kilobytes that the block layer will allow

‎block/blk-sysfs.c‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,11 @@ static ssize_t queue_nr_zones_show(struct request_queue *q, char *page)
306306
return queue_var_show(blk_queue_nr_zones(q), page);
307307
}
308308

309+
static ssize_t queue_max_open_zones_show(struct request_queue *q, char *page)
310+
{
311+
return queue_var_show(queue_max_open_zones(q), page);
312+
}
313+
309314
static ssize_t queue_nomerges_show(struct request_queue *q, char *page)
310315
{
311316
return queue_var_show((blk_queue_nomerges(q) << 1) |
@@ -668,6 +673,11 @@ static struct queue_sysfs_entry queue_nr_zones_entry = {
668673
.show = queue_nr_zones_show,
669674
};
670675

676+
static struct queue_sysfs_entry queue_max_open_zones_entry = {
677+
.attr = {.name = "max_open_zones", .mode = 0444 },
678+
.show = queue_max_open_zones_show,
679+
};
680+
671681
static struct queue_sysfs_entry queue_nomerges_entry = {
672682
.attr = {.name = "nomerges", .mode = 0644 },
673683
.show = queue_nomerges_show,
@@ -766,6 +776,7 @@ static struct attribute *queue_attrs[] = {
766776
&queue_nonrot_entry.attr,
767777
&queue_zoned_entry.attr,
768778
&queue_nr_zones_entry.attr,
779+
&queue_max_open_zones_entry.attr,
769780
&queue_nomerges_entry.attr,
770781
&queue_rq_affinity_entry.attr,
771782
&queue_iostats_entry.attr,
@@ -793,6 +804,10 @@ static umode_t queue_attr_visible(struct kobject *kobj, struct attribute *attr,
793804
(!q->mq_ops || !q->mq_ops->timeout))
794805
return 0;
795806

807+
if (attr == &queue_max_open_zones_entry.attr &&
808+
!blk_queue_is_zoned(q))
809+
return 0;
810+
796811
return attr->mode;
797812
}
798813

‎drivers/nvme/host/zns.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ int nvme_update_zone_info(struct gendisk *disk, struct nvme_ns *ns,
9696

9797
q->limits.zoned = BLK_ZONED_HM;
9898
blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, q);
99+
blk_queue_max_open_zones(q, le32_to_cpu(id->mor) + 1);
99100
free_data:
100101
kfree(id);
101102
return status;

‎drivers/scsi/sd_zbc.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,10 @@ int sd_zbc_read_zones(struct scsi_disk *sdkp, unsigned char *buf)
717717
/* The drive satisfies the kernel restrictions: set it up */
718718
blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, q);
719719
blk_queue_required_elevator_features(q, ELEVATOR_F_ZBD_SEQ_WRITE);
720+
if (sdkp->zones_max_open == U32_MAX)
721+
blk_queue_max_open_zones(q, 0);
722+
else
723+
blk_queue_max_open_zones(q, sdkp->zones_max_open);
720724
nr_zones = round_up(sdkp->capacity, zone_blocks) >> ilog2(zone_blocks);
721725

722726
/* READ16/WRITE16 is mandatory for ZBC disks */

‎include/linux/blkdev.h‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ struct request_queue {
513513
unsigned int nr_zones;
514514
unsigned long *conv_zones_bitmap;
515515
unsigned long *seq_zones_wlock;
516+
unsigned int max_open_zones;
516517
#endif /* CONFIG_BLK_DEV_ZONED */
517518

518519
/*
@@ -722,6 +723,17 @@ static inline bool blk_queue_zone_is_seq(struct request_queue *q,
722723
return true;
723724
return !test_bit(blk_queue_zone_no(q, sector), q->conv_zones_bitmap);
724725
}
726+
727+
static inline void blk_queue_max_open_zones(struct request_queue *q,
728+
unsigned int max_open_zones)
729+
{
730+
q->max_open_zones = max_open_zones;
731+
}
732+
733+
static inline unsigned int queue_max_open_zones(const struct request_queue *q)
734+
{
735+
return q->max_open_zones;
736+
}
725737
#else /* CONFIG_BLK_DEV_ZONED */
726738
static inline unsigned int blk_queue_nr_zones(struct request_queue *q)
727739
{
@@ -737,6 +749,10 @@ static inline unsigned int blk_queue_zone_no(struct request_queue *q,
737749
{
738750
return 0;
739751
}
752+
static inline unsigned int queue_max_open_zones(const struct request_queue *q)
753+
{
754+
return 0;
755+
}
740756
#endif /* CONFIG_BLK_DEV_ZONED */
741757

742758
static inline bool rq_is_sync(struct request *rq)
@@ -1519,6 +1535,15 @@ static inline sector_t bdev_zone_sectors(struct block_device *bdev)
15191535
return 0;
15201536
}
15211537

1538+
static inline unsigned int bdev_max_open_zones(struct block_device *bdev)
1539+
{
1540+
struct request_queue *q = bdev_get_queue(bdev);
1541+
1542+
if (q)
1543+
return queue_max_open_zones(q);
1544+
return 0;
1545+
}
1546+
15221547
static inline int queue_dma_alignment(const struct request_queue *q)
15231548
{
15241549
return q ? q->dma_alignment : 511;

0 commit comments

Comments
 (0)