Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit 776687b

Browse files
htejunaxboe
authored andcommitted
block, blk-mq: draining can't be skipped even if bypass_depth was non-zero
Currently, both blk_queue_bypass_start() and blk_mq_freeze_queue() skip queue draining if bypass_depth was already above zero. The assumption is that the one which bumped the bypass_depth should have performed draining already; however, there's nothing which prevents a new instance of bypassing/freezing from starting before the previous one finishes draining. The current code may allow the later bypassing/freezing instances to complete while there still are in-flight requests which haven't finished draining. Fix it by draining regardless of bypass_depth. We still skip draining from blk_queue_bypass_start() while the queue is initializing to avoid introducing excessive delays during boot. INIT_DONE setting is moved above the initial blk_queue_bypass_end() so that bypassing attempts can't slip inbetween. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Jens Axboe <axboe@kernel.dk> Cc: Nicholas A. Bellinger <nab@linux-iscsi.org> Signed-off-by: Jens Axboe <axboe@fb.com>
1 parent 531ed62 commit 776687b

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

block/blk-core.c

+7-4
Original file line numberDiff line numberDiff line change
@@ -438,14 +438,17 @@ static void __blk_drain_queue(struct request_queue *q, bool drain_all)
438438
*/
439439
void blk_queue_bypass_start(struct request_queue *q)
440440
{
441-
bool drain;
442-
443441
spin_lock_irq(q->queue_lock);
444-
drain = !q->bypass_depth++;
442+
q->bypass_depth++;
445443
queue_flag_set(QUEUE_FLAG_BYPASS, q);
446444
spin_unlock_irq(q->queue_lock);
447445

448-
if (drain) {
446+
/*
447+
* Queues start drained. Skip actual draining till init is
448+
* complete. This avoids lenghty delays during queue init which
449+
* can happen many times during boot.
450+
*/
451+
if (blk_queue_init_done(q)) {
449452
spin_lock_irq(q->queue_lock);
450453
__blk_drain_queue(q, false);
451454
spin_unlock_irq(q->queue_lock);

block/blk-mq.c

+2-5
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,12 @@ void blk_mq_drain_queue(struct request_queue *q)
131131
*/
132132
static void blk_mq_freeze_queue(struct request_queue *q)
133133
{
134-
bool drain;
135-
136134
spin_lock_irq(q->queue_lock);
137-
drain = !q->bypass_depth++;
135+
q->bypass_depth++;
138136
queue_flag_set(QUEUE_FLAG_BYPASS, q);
139137
spin_unlock_irq(q->queue_lock);
140138

141-
if (drain)
142-
blk_mq_drain_queue(q);
139+
blk_mq_drain_queue(q);
143140
}
144141

145142
static void blk_mq_unfreeze_queue(struct request_queue *q)

block/blk-sysfs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,8 @@ int blk_register_queue(struct gendisk *disk)
554554
* Initialization must be complete by now. Finish the initial
555555
* bypass from queue allocation.
556556
*/
557-
blk_queue_bypass_end(q);
558557
queue_flag_set_unlocked(QUEUE_FLAG_INIT_DONE, q);
558+
blk_queue_bypass_end(q);
559559

560560
ret = blk_trace_init_sysfs(dev);
561561
if (ret)

0 commit comments

Comments
 (0)