block: don't call freeze queue in elevator_switch() and elevator_disable()
authorMing Lei <ming.lei@redhat.com>
Mon, 5 May 2025 14:17:41 +0000 (22:17 +0800)
committerJens Axboe <axboe@kernel.dk>
Tue, 6 May 2025 13:43:42 +0000 (07:43 -0600)
Both elevator_switch() and elevator_disable() are only called from the
two code paths, in which queue is guaranteed to be frozen.

So don't call freeze queue in the two functions, also add asserts for
queue freeze.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Nilay Shroff <nilay@linux.ibm.com>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Reviewed-by: Yu Kuai <yukuai3@huawei.com>
Link: https://lore.kernel.org/r/20250505141805.2751237-4-ming.lei@redhat.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/elevator.c

index b4d08026b02cef8c0c573f3b921eb9e585fc516a..5051a98dc08c209ba78a9252bc11a188898b8e50 100644 (file)
@@ -615,12 +615,11 @@ void elevator_init_mq(struct request_queue *q)
  */
 int elevator_switch(struct request_queue *q, struct elevator_type *new_e)
 {
-       unsigned int memflags;
        int ret;
 
+       WARN_ON_ONCE(q->mq_freeze_depth == 0);
        lockdep_assert_held(&q->elevator_lock);
 
-       memflags = blk_mq_freeze_queue(q);
        blk_mq_quiesce_queue(q);
 
        if (q->elevator) {
@@ -641,7 +640,6 @@ int elevator_switch(struct request_queue *q, struct elevator_type *new_e)
 
 out_unfreeze:
        blk_mq_unquiesce_queue(q);
-       blk_mq_unfreeze_queue(q, memflags);
 
        if (ret) {
                pr_warn("elv: switch to \"%s\" failed, falling back to \"none\"\n",
@@ -653,11 +651,9 @@ out_unfreeze:
 
 void elevator_disable(struct request_queue *q)
 {
-       unsigned int memflags;
-
+       WARN_ON_ONCE(q->mq_freeze_depth == 0);
        lockdep_assert_held(&q->elevator_lock);
 
-       memflags = blk_mq_freeze_queue(q);
        blk_mq_quiesce_queue(q);
 
        elv_unregister_queue(q);
@@ -668,7 +664,6 @@ void elevator_disable(struct request_queue *q)
        blk_add_trace_msg(q, "elv switch: none");
 
        blk_mq_unquiesce_queue(q);
-       blk_mq_unfreeze_queue(q, memflags);
 }
 
 /*