[RFC,1/2] elevator: add a helper for applying scheduler to request_queue

Message ID 5abfd81ae73b4e86ff260475b28a218e78eaad4a.1668772991.git.nickyc975@zju.edu.cn
State New
Headers
Series elevator: restore old io scheduler on failure in elevator_switch |

Commit Message

Jinlong Chen Nov. 18, 2022, 12:09 p.m. UTC
  Prepare for supporting fallback in elevator_switch.

Signed-off-by: Jinlong Chen <nickyc975@zju.edu.cn>
---
 block/elevator.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)
  

Patch

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: