Skip to content

Commit c48dac1

Browse files
Ming Leiaxboe
authored andcommitted
block: don't hold q->sysfs_lock in elevator_init_mq
The original comment says: q->sysfs_lock must be held to provide mutual exclusion between elevator_switch() and here. Which is simply wrong. elevator_init_mq() is only called from blk_mq_init_allocated_queue, which is always called before the request queue is registered via blk_register_queue(), for dm-rq or normal rq based driver. However, queue's kobject is only exposed and added to sysfs in blk_register_queue(). So there isn't such race between elevator_switch() and elevator_init_mq(). So avoid to hold q->sysfs_lock in elevator_init_mq(). Cc: Christoph Hellwig <[email protected]> Cc: Hannes Reinecke <[email protected]> Cc: Greg KH <[email protected]> Cc: Mike Snitzer <[email protected]> Cc: Bart Van Assche <[email protected]> Cc: Damien Le Moal <[email protected]> Reviewed-by: Bart Van Assche <[email protected]> Signed-off-by: Ming Lei <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 9685b22 commit c48dac1

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

block/elevator.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -607,23 +607,19 @@ int elevator_init_mq(struct request_queue *q)
607607
if (q->nr_hw_queues != 1)
608608
return 0;
609609

610-
/*
611-
* q->sysfs_lock must be held to provide mutual exclusion between
612-
* elevator_switch() and here.
613-
*/
614-
mutex_lock(&q->sysfs_lock);
610+
WARN_ON_ONCE(test_bit(QUEUE_FLAG_REGISTERED, &q->queue_flags));
611+
615612
if (unlikely(q->elevator))
616-
goto out_unlock;
613+
goto out;
617614

618615
e = elevator_get(q, "mq-deadline", false);
619616
if (!e)
620-
goto out_unlock;
617+
goto out;
621618

622619
err = blk_mq_init_sched(q, e);
623620
if (err)
624621
elevator_put(e);
625-
out_unlock:
626-
mutex_unlock(&q->sysfs_lock);
622+
out:
627623
return err;
628624
}
629625

0 commit comments

Comments
 (0)