diff options
| author | Christoph Hellwig <hch@lst.de> | 2025-05-05 22:17:48 +0800 |
|---|---|---|
| committer | Jens Axboe <axboe@kernel.dk> | 2025-05-06 07:43:43 -0600 |
| commit | a11abb98388e23188f3915780f3a193fdc1e4ff0 (patch) | |
| tree | 5b2e26804d432f63cacacf792543626c2ca9d162 /block/elevator.c | |
| parent | b126d9d7475e3a35155f31418e54d9221b971ca1 (diff) | |
block: look up the elevator type in elevator_switch
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>
Diffstat (limited to 'block/elevator.c')
| -rw-r--r-- | block/elevator.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/block/elevator.c b/block/elevator.c index 2e18513dcd73..286d240a3aef 100644 --- a/block/elevator.c +++ b/block/elevator.c @@ -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) |
