Prepare for supporting fallback in elevator_switch. Signed-off-by: Jinlong Chen <nickyc975@xxxxxxxxxx> --- block/elevator.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/block/elevator.c b/block/elevator.c index a5bdc3b1e7e5..517857a9a68f 100644 --- a/block/elevator.c +++ b/block/elevator.c @@ -649,6 +649,21 @@ void elevator_init_mq(struct request_queue *q) elevator_put(e); } +static int __elevator_apply(struct request_queue *q, struct elevator_type *e) +{ + int ret; + + ret = blk_mq_init_sched(q, e); + if (ret) + return ret; + + ret = elv_register_queue(q, true); + if (ret) + elevator_exit(q); + + return ret; +} + /* * switch to new_e io scheduler. be careful not to introduce deadlocks - * we don't free the old io scheduler, before we have allocated what we @@ -669,15 +684,10 @@ int elevator_switch(struct request_queue *q, struct elevator_type *new_e) elevator_exit(q); } - ret = blk_mq_init_sched(q, new_e); + ret = __elevator_apply(q, new_e); if (ret) goto out_unfreeze; - ret = elv_register_queue(q, true); - if (ret) { - elevator_exit(q); - goto out_unfreeze; - } blk_add_trace_msg(q, "elv switch: %s", new_e->elevator_name); out_unfreeze: -- 2.31.1