Skip to content

Commit 797476b

Browse files
hgstaxboe
authored andcommitted
block: Add 'zoned' queue limit
Add the zoned queue limit to indicate the zoning model of a block device. Defined values are 0 (BLK_ZONED_NONE) for regular block devices, 1 (BLK_ZONED_HA) for host-aware zone block devices and 2 (BLK_ZONED_HM) for host-managed zone block devices. The standards defined drive managed model is not defined here since these block devices do not provide any command for accessing zone information. Drive managed model devices will be reported as BLK_ZONED_NONE. The helper functions blk_queue_zoned_model and bdev_zoned_model return the zoned limit and the functions blk_queue_is_zoned and bdev_is_zoned return a boolean for callers to test if a block device is zoned. The zoned attribute is also exported as a string to applications via sysfs. BLK_ZONED_NONE shows as "none", BLK_ZONED_HA as "host-aware" and BLK_ZONED_HM as "host-managed". Signed-off-by: Damien Le Moal <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Martin K. Petersen <[email protected]> Reviewed-by: Shaun Tancheff <[email protected]> Tested-by: Shaun Tancheff <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 14155ca commit 797476b

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed

Documentation/ABI/testing/sysfs-block

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,19 @@ Description:
235235
write_same_max_bytes is 0, write same is not supported
236236
by the device.
237237

238+
What: /sys/block/<disk>/queue/zoned
239+
Date: September 2016
240+
Contact: Damien Le Moal <[email protected]>
241+
Description:
242+
zoned indicates if the device is a zoned block device
243+
and the zone model of the device if it is indeed zoned.
244+
The possible values indicated by zoned are "none" for
245+
regular block devices and "host-aware" or "host-managed"
246+
for zoned block devices. The characteristics of
247+
host-aware and host-managed zoned block devices are
248+
described in the ZBC (Zoned Block Commands) and ZAC
249+
(Zoned Device ATA Command Set) standards. These standards
250+
also define the "drive-managed" zone model. However,
251+
since drive-managed zoned block devices do not support
252+
zone commands, they will be treated as regular block
253+
devices and zoned will report "none".

block/blk-settings.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ void blk_set_default_limits(struct queue_limits *lim)
107107
lim->io_opt = 0;
108108
lim->misaligned = 0;
109109
lim->cluster = 1;
110+
lim->zoned = BLK_ZONED_NONE;
110111
}
111112
EXPORT_SYMBOL(blk_set_default_limits);
112113

block/blk-sysfs.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,18 @@ QUEUE_SYSFS_BIT_FNS(random, ADD_RANDOM, 0);
257257
QUEUE_SYSFS_BIT_FNS(iostats, IO_STAT, 0);
258258
#undef QUEUE_SYSFS_BIT_FNS
259259

260+
static ssize_t queue_zoned_show(struct request_queue *q, char *page)
261+
{
262+
switch (blk_queue_zoned_model(q)) {
263+
case BLK_ZONED_HA:
264+
return sprintf(page, "host-aware\n");
265+
case BLK_ZONED_HM:
266+
return sprintf(page, "host-managed\n");
267+
default:
268+
return sprintf(page, "none\n");
269+
}
270+
}
271+
260272
static ssize_t queue_nomerges_show(struct request_queue *q, char *page)
261273
{
262274
return queue_var_show((blk_queue_nomerges(q) << 1) |
@@ -485,6 +497,11 @@ static struct queue_sysfs_entry queue_nonrot_entry = {
485497
.store = queue_store_nonrot,
486498
};
487499

500+
static struct queue_sysfs_entry queue_zoned_entry = {
501+
.attr = {.name = "zoned", .mode = S_IRUGO },
502+
.show = queue_zoned_show,
503+
};
504+
488505
static struct queue_sysfs_entry queue_nomerges_entry = {
489506
.attr = {.name = "nomerges", .mode = S_IRUGO | S_IWUSR },
490507
.show = queue_nomerges_show,
@@ -546,6 +563,7 @@ static struct attribute *default_attrs[] = {
546563
&queue_discard_zeroes_data_entry.attr,
547564
&queue_write_same_max_entry.attr,
548565
&queue_nonrot_entry.attr,
566+
&queue_zoned_entry.attr,
549567
&queue_nomerges_entry.attr,
550568
&queue_rq_affinity_entry.attr,
551569
&queue_iostats_entry.attr,

include/linux/blkdev.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,15 @@ struct blk_queue_tag {
261261
#define BLK_SCSI_MAX_CMDS (256)
262262
#define BLK_SCSI_CMD_PER_LONG (BLK_SCSI_MAX_CMDS / (sizeof(long) * 8))
263263

264+
/*
265+
* Zoned block device models (zoned limit).
266+
*/
267+
enum blk_zoned_model {
268+
BLK_ZONED_NONE, /* Regular block device */
269+
BLK_ZONED_HA, /* Host-aware zoned block device */
270+
BLK_ZONED_HM, /* Host-managed zoned block device */
271+
};
272+
264273
struct queue_limits {
265274
unsigned long bounce_pfn;
266275
unsigned long seg_boundary_mask;
@@ -290,6 +299,7 @@ struct queue_limits {
290299
unsigned char cluster;
291300
unsigned char discard_zeroes_data;
292301
unsigned char raid_partial_stripes_expensive;
302+
enum blk_zoned_model zoned;
293303
};
294304

295305
struct request_queue {
@@ -627,6 +637,23 @@ static inline unsigned int blk_queue_cluster(struct request_queue *q)
627637
return q->limits.cluster;
628638
}
629639

640+
static inline enum blk_zoned_model
641+
blk_queue_zoned_model(struct request_queue *q)
642+
{
643+
return q->limits.zoned;
644+
}
645+
646+
static inline bool blk_queue_is_zoned(struct request_queue *q)
647+
{
648+
switch (blk_queue_zoned_model(q)) {
649+
case BLK_ZONED_HA:
650+
case BLK_ZONED_HM:
651+
return true;
652+
default:
653+
return false;
654+
}
655+
}
656+
630657
/*
631658
* We regard a request as sync, if either a read or a sync write
632659
*/
@@ -1354,6 +1381,26 @@ static inline unsigned int bdev_write_same(struct block_device *bdev)
13541381
return 0;
13551382
}
13561383

1384+
static inline enum blk_zoned_model bdev_zoned_model(struct block_device *bdev)
1385+
{
1386+
struct request_queue *q = bdev_get_queue(bdev);
1387+
1388+
if (q)
1389+
return blk_queue_zoned_model(q);
1390+
1391+
return BLK_ZONED_NONE;
1392+
}
1393+
1394+
static inline bool bdev_is_zoned(struct block_device *bdev)
1395+
{
1396+
struct request_queue *q = bdev_get_queue(bdev);
1397+
1398+
if (q)
1399+
return blk_queue_is_zoned(q);
1400+
1401+
return false;
1402+
}
1403+
13571404
static inline int queue_dma_alignment(struct request_queue *q)
13581405
{
13591406
return q ? q->dma_alignment : 511;

0 commit comments

Comments
 (0)