block: look up the elevator type in elevator_switch
authorChristoph Hellwig <hch@lst.de>
Mon, 5 May 2025 14:17:48 +0000 (22:17 +0800)
committerJens Axboe <axboe@kernel.dk>
Tue, 6 May 2025 13:43:43 +0000 (07:43 -0600)
That makes the function nicely self-contained and can be used
to avoid code duplication.

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

index 74f4b1d37376044c5f88820e53dfdb46f8ef570b..84395cc3c01239c94a16d72bbd6e3cd34e301531 100644 (file)
@@ -5058,7 +5058,7 @@ static void blk_mq_elv_switch_back(struct list_head *head,
        kfree(qe);
 
        mutex_lock(&q->elevator_lock);
-       elevator_switch(q, t);
+       elevator_switch(q, t->elevator_name);
        /* drop the reference acquired in blk_mq_elv_switch_none */
        elevator_put(t);
        mutex_unlock(&q->elevator_lock);
index ff21f234b62f65b158cb9525b08d26d4f46975d1..678308c8a78fc60cc80031160159d1e2ce0f1ba4 100644 (file)
@@ -322,7 +322,7 @@ bool blk_bio_list_merge(struct request_queue *q, struct list_head *list,
 
 bool blk_insert_flush(struct request *rq);
 
-int elevator_switch(struct request_queue *q, struct elevator_type *new_e);
+int elevator_switch(struct request_queue *q, const char *name);
 void elevator_disable(struct request_queue *q);
 void elevator_exit(struct request_queue *q);
 int elv_register_queue(struct request_queue *q, bool uevent);
index 2e18513dcd739196b7eb7b02bb0400dbd719acad..286d240a3aefe7516060b2eb67dcce5c2e461f85 100644 (file)
@@ -621,13 +621,18 @@ void elevator_init_mq(struct request_queue *q)
  * If switching fails, we are most likely running out of memory and not able
  * to restore the old io scheduler, so leaving the io scheduler being none.
  */
-int elevator_switch(struct request_queue *q, struct elevator_type *new_e)
+int elevator_switch(struct request_queue *q, const char *name)
 {
+       struct elevator_type *new_e;
        int ret;
 
        WARN_ON_ONCE(q->mq_freeze_depth == 0);
        lockdep_assert_held(&q->elevator_lock);
 
+       new_e = elevator_find_get(name);
+       if (!new_e)
+               return -EINVAL;
+
        blk_mq_quiesce_queue(q);
 
        if (q->elevator) {
@@ -654,6 +659,7 @@ out_unfreeze:
                        new_e->elevator_name);
        }
 
+       elevator_put(new_e);
        return ret;
 }
 
@@ -679,9 +685,6 @@ void elevator_disable(struct request_queue *q)
  */
 static int elevator_change(struct request_queue *q, const char *elevator_name)
 {
-       struct elevator_type *e;
-       int ret;
-
        /* Make sure queue is not in the middle of being removed */
        if (!blk_queue_registered(q))
                return -ENOENT;
@@ -695,12 +698,7 @@ static int elevator_change(struct request_queue *q, const char *elevator_name)
        if (q->elevator && elevator_match(q->elevator->type, elevator_name))
                return 0;
 
-       e = elevator_find_get(elevator_name);
-       if (!e)
-               return -EINVAL;
-       ret = elevator_switch(q, e);
-       elevator_put(e);
-       return ret;
+       return elevator_switch(q, elevator_name);
 }
 
 static void elv_iosched_load_module(char *elevator_name)