Skip to content

Commit f76af42

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: move the nowait flag to queue_limits
Move the nowait flag into the queue_limits feature field so that it can be set atomically with the queue frozen. Stacking drivers are simplified in that they now can simply set the flag, and blk_stack_limits will clear it when the features is not supported by any of the underlying devices. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Damien Le Moal <dlemoal@kernel.org> Reviewed-by: Hannes Reinecke <hare@suse.de> Link: https://lore.kernel.org/r/20240617060532.127975-20-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent aadd5c5 commit f76af42

File tree

8 files changed

+22
-42
lines changed

8 files changed

+22
-42
lines changed

block/blk-mq-debugfs.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ static const char *const blk_queue_flag_name[] = {
9696
QUEUE_FLAG_NAME(ZONE_RESETALL),
9797
QUEUE_FLAG_NAME(RQ_ALLOC_TIME),
9898
QUEUE_FLAG_NAME(HCTX_ACTIVE),
99-
QUEUE_FLAG_NAME(NOWAIT),
10099
QUEUE_FLAG_NAME(SQ_SCHED),
101100
QUEUE_FLAG_NAME(SKIP_TAGSET_QUIESCE),
102101
};

block/blk-mq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4118,7 +4118,7 @@ struct request_queue *blk_mq_alloc_queue(struct blk_mq_tag_set *set,
41184118

41194119
if (!lim)
41204120
lim = &default_lim;
4121-
lim->features |= BLK_FEAT_IO_STAT;
4121+
lim->features |= BLK_FEAT_IO_STAT | BLK_FEAT_NOWAIT;
41224122

41234123
q = blk_alloc_queue(lim, set->numa_node);
41244124
if (IS_ERR(q))

block/blk-settings.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,15 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
459459

460460
t->features |= (b->features & BLK_FEAT_INHERIT_MASK);
461461

462+
/*
463+
* BLK_FEAT_NOWAIT needs to be supported both by the stacking driver
464+
* and all underlying devices. The stacking driver sets the flag
465+
* before stacking the limits, and this will clear the flag if any
466+
* of the underlying devices does not support it.
467+
*/
468+
if (!(b->features & BLK_FEAT_NOWAIT))
469+
t->features &= ~BLK_FEAT_NOWAIT;
470+
462471
t->max_sectors = min_not_zero(t->max_sectors, b->max_sectors);
463472
t->max_user_sectors = min_not_zero(t->max_user_sectors,
464473
b->max_user_sectors);

drivers/block/brd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,8 @@ static int brd_alloc(int i)
335335
.max_hw_discard_sectors = UINT_MAX,
336336
.max_discard_segments = 1,
337337
.discard_granularity = PAGE_SIZE,
338-
.features = BLK_FEAT_SYNCHRONOUS,
338+
.features = BLK_FEAT_SYNCHRONOUS |
339+
BLK_FEAT_NOWAIT,
339340
};
340341

341342
list_for_each_entry(brd, &brd_devices, brd_list)
@@ -367,7 +368,6 @@ static int brd_alloc(int i)
367368
strscpy(disk->disk_name, buf, DISK_NAME_LEN);
368369
set_capacity(disk, rd_size * 2);
369370

370-
blk_queue_flag_set(QUEUE_FLAG_NOWAIT, disk->queue);
371371
err = add_disk(disk);
372372
if (err)
373373
goto out_cleanup_disk;

drivers/md/dm-table.c

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ int dm_split_args(int *argc, char ***argvp, char *input)
582582
static void dm_set_stacking_limits(struct queue_limits *limits)
583583
{
584584
blk_set_stacking_limits(limits);
585-
limits->features |= BLK_FEAT_IO_STAT;
585+
limits->features |= BLK_FEAT_IO_STAT | BLK_FEAT_NOWAIT;
586586
}
587587

588588
/*
@@ -1746,23 +1746,13 @@ static bool dm_table_supports_write_zeroes(struct dm_table *t)
17461746
return true;
17471747
}
17481748

1749-
static int device_not_nowait_capable(struct dm_target *ti, struct dm_dev *dev,
1750-
sector_t start, sector_t len, void *data)
1751-
{
1752-
return !bdev_nowait(dev->bdev);
1753-
}
1754-
17551749
static bool dm_table_supports_nowait(struct dm_table *t)
17561750
{
17571751
for (unsigned int i = 0; i < t->num_targets; i++) {
17581752
struct dm_target *ti = dm_table_get_target(t, i);
17591753

17601754
if (!dm_target_supports_nowait(ti->type))
17611755
return false;
1762-
1763-
if (!ti->type->iterate_devices ||
1764-
ti->type->iterate_devices(ti, device_not_nowait_capable, NULL))
1765-
return false;
17661756
}
17671757

17681758
return true;
@@ -1824,10 +1814,8 @@ int dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
18241814
{
18251815
int r;
18261816

1827-
if (dm_table_supports_nowait(t))
1828-
blk_queue_flag_set(QUEUE_FLAG_NOWAIT, q);
1829-
else
1830-
blk_queue_flag_clear(QUEUE_FLAG_NOWAIT, q);
1817+
if (!dm_table_supports_nowait(t))
1818+
limits->features &= ~BLK_FEAT_NOWAIT;
18311819

18321820
if (!dm_table_supports_discards(t)) {
18331821
limits->max_hw_discard_sectors = 0;

drivers/md/md.c

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5788,7 +5788,7 @@ struct mddev *md_alloc(dev_t dev, char *name)
57885788
int error;
57895789
struct queue_limits lim = {
57905790
.features = BLK_FEAT_WRITE_CACHE | BLK_FEAT_FUA |
5791-
BLK_FEAT_IO_STAT,
5791+
BLK_FEAT_IO_STAT | BLK_FEAT_NOWAIT,
57925792
};
57935793

57945794
/*
@@ -6150,13 +6150,6 @@ int md_run(struct mddev *mddev)
61506150
}
61516151
}
61526152

6153-
if (!mddev_is_dm(mddev)) {
6154-
struct request_queue *q = mddev->gendisk->queue;
6155-
6156-
/* Set the NOWAIT flags if all underlying devices support it */
6157-
if (nowait)
6158-
blk_queue_flag_set(QUEUE_FLAG_NOWAIT, q);
6159-
}
61606153
if (pers->sync_request) {
61616154
if (mddev->kobj.sd &&
61626155
sysfs_create_group(&mddev->kobj, &md_redundancy_group))
@@ -7115,15 +7108,6 @@ static int hot_add_disk(struct mddev *mddev, dev_t dev)
71157108
set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags);
71167109
if (!mddev->thread)
71177110
md_update_sb(mddev, 1);
7118-
/*
7119-
* If the new disk does not support REQ_NOWAIT,
7120-
* disable on the whole MD.
7121-
*/
7122-
if (!bdev_nowait(rdev->bdev)) {
7123-
pr_info("%s: Disabling nowait because %pg does not support nowait\n",
7124-
mdname(mddev), rdev->bdev);
7125-
blk_queue_flag_clear(QUEUE_FLAG_NOWAIT, mddev->gendisk->queue);
7126-
}
71277111
/*
71287112
* Kick recovery, maybe this spare has to be added to the
71297113
* array immediately.

drivers/nvme/host/multipath.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl, struct nvme_ns_head *head)
538538

539539
blk_set_stacking_limits(&lim);
540540
lim.dma_alignment = 3;
541-
lim.features |= BLK_FEAT_IO_STAT;
541+
lim.features |= BLK_FEAT_IO_STAT | BLK_FEAT_NOWAIT;
542542
if (head->ids.csi != NVME_CSI_ZNS)
543543
lim.max_zone_append_sectors = 0;
544544

@@ -550,7 +550,6 @@ int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl, struct nvme_ns_head *head)
550550
sprintf(head->disk->disk_name, "nvme%dn%d",
551551
ctrl->subsys->instance, head->instance);
552552

553-
blk_queue_flag_set(QUEUE_FLAG_NOWAIT, head->disk->queue);
554553
/*
555554
* This assumes all controllers that refer to a namespace either
556555
* support poll queues or not. That is not a strict guarantee,

include/linux/blkdev.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,9 @@ enum {
304304

305305
/* always completes in submit context */
306306
BLK_FEAT_SYNCHRONOUS = (1u << 6),
307+
308+
/* supports REQ_NOWAIT */
309+
BLK_FEAT_NOWAIT = (1u << 7),
307310
};
308311

309312
/*
@@ -580,12 +583,10 @@ struct request_queue {
580583
#define QUEUE_FLAG_ZONE_RESETALL 26 /* supports Zone Reset All */
581584
#define QUEUE_FLAG_RQ_ALLOC_TIME 27 /* record rq->alloc_time_ns */
582585
#define QUEUE_FLAG_HCTX_ACTIVE 28 /* at least one blk-mq hctx is active */
583-
#define QUEUE_FLAG_NOWAIT 29 /* device supports NOWAIT */
584586
#define QUEUE_FLAG_SQ_SCHED 30 /* single queue style io dispatch */
585587
#define QUEUE_FLAG_SKIP_TAGSET_QUIESCE 31 /* quiesce_tagset skip the queue*/
586588

587-
#define QUEUE_FLAG_MQ_DEFAULT ((1UL << QUEUE_FLAG_SAME_COMP) | \
588-
(1UL << QUEUE_FLAG_NOWAIT))
589+
#define QUEUE_FLAG_MQ_DEFAULT (1UL << QUEUE_FLAG_SAME_COMP)
589590

590591
void blk_queue_flag_set(unsigned int flag, struct request_queue *q);
591592
void blk_queue_flag_clear(unsigned int flag, struct request_queue *q);
@@ -1348,7 +1349,7 @@ static inline bool bdev_fua(struct block_device *bdev)
13481349

13491350
static inline bool bdev_nowait(struct block_device *bdev)
13501351
{
1351-
return test_bit(QUEUE_FLAG_NOWAIT, &bdev_get_queue(bdev)->queue_flags);
1352+
return bdev->bd_disk->queue->limits.features & BLK_FEAT_NOWAIT;
13521353
}
13531354

13541355
static inline bool bdev_is_zoned(struct block_device *bdev)

0 commit comments

Comments
 (0)