Skip to content

Commit 00ed996

Browse files
author
Ming Lei
committed
block: look up the elevator type in elevator_switch
JIRA: https://issues.redhat.com/browse/RHEL-106845 commit a11abb9 Author: Christoph Hellwig <hch@lst.de> Date: Mon May 5 22:17:48 2025 +0800 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> Signed-off-by: Ming Lei <ming.lei@redhat.com>
1 parent 6b39994 commit 00ed996

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

block/blk-mq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5058,7 +5058,7 @@ static void blk_mq_elv_switch_back(struct list_head *head,
50585058
kfree(qe);
50595059

50605060
mutex_lock(&q->elevator_lock);
5061-
elevator_switch(q, t);
5061+
elevator_switch(q, t->elevator_name);
50625062
/* drop the reference acquired in blk_mq_elv_switch_none */
50635063
elevator_put(t);
50645064
mutex_unlock(&q->elevator_lock);

block/blk.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ bool blk_bio_list_merge(struct request_queue *q, struct list_head *list,
322322

323323
bool blk_insert_flush(struct request *rq);
324324

325-
int elevator_switch(struct request_queue *q, struct elevator_type *new_e);
325+
int elevator_switch(struct request_queue *q, const char *name);
326326
void elevator_disable(struct request_queue *q);
327327
void elevator_exit(struct request_queue *q);
328328
int elv_register_queue(struct request_queue *q, bool uevent);

block/elevator.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -621,13 +621,18 @@ void elevator_init_mq(struct request_queue *q)
621621
* If switching fails, we are most likely running out of memory and not able
622622
* to restore the old io scheduler, so leaving the io scheduler being none.
623623
*/
624-
int elevator_switch(struct request_queue *q, struct elevator_type *new_e)
624+
int elevator_switch(struct request_queue *q, const char *name)
625625
{
626+
struct elevator_type *new_e;
626627
int ret;
627628

628629
WARN_ON_ONCE(q->mq_freeze_depth == 0);
629630
lockdep_assert_held(&q->elevator_lock);
630631

632+
new_e = elevator_find_get(name);
633+
if (!new_e)
634+
return -EINVAL;
635+
631636
blk_mq_quiesce_queue(q);
632637

633638
if (q->elevator) {
@@ -654,6 +659,7 @@ int elevator_switch(struct request_queue *q, struct elevator_type *new_e)
654659
new_e->elevator_name);
655660
}
656661

662+
elevator_put(new_e);
657663
return ret;
658664
}
659665

@@ -679,9 +685,6 @@ void elevator_disable(struct request_queue *q)
679685
*/
680686
static int elevator_change(struct request_queue *q, const char *elevator_name)
681687
{
682-
struct elevator_type *e;
683-
int ret;
684-
685688
/* Make sure queue is not in the middle of being removed */
686689
if (!blk_queue_registered(q))
687690
return -ENOENT;
@@ -695,12 +698,7 @@ static int elevator_change(struct request_queue *q, const char *elevator_name)
695698
if (q->elevator && elevator_match(q->elevator->type, elevator_name))
696699
return 0;
697700

698-
e = elevator_find_get(elevator_name);
699-
if (!e)
700-
return -EINVAL;
701-
ret = elevator_switch(q, e);
702-
elevator_put(e);
703-
return ret;
701+
return elevator_switch(q, elevator_name);
704702
}
705703

706704
static void elv_iosched_load_module(char *elevator_name)

0 commit comments

Comments
 (0)