4545#include "blk-wbt.h"
4646#include "blk-cgroup.h"
4747
48+ /* Holding context data for changing elevator */
49+ struct elv_change_ctx {
50+ const char * name ;
51+ bool no_uevent ;
52+ };
53+
4854static DEFINE_SPINLOCK (elv_list_lock );
4955static LIST_HEAD (elv_list );
5056
@@ -621,16 +627,16 @@ void elevator_init_mq(struct request_queue *q)
621627 * If switching fails, we are most likely running out of memory and not able
622628 * to restore the old io scheduler, so leaving the io scheduler being none.
623629 */
624- static int elevator_switch (struct request_queue * q , const char * name )
630+ static int elevator_switch (struct request_queue * q , struct elv_change_ctx * ctx )
625631{
626632 struct elevator_type * new_e = NULL ;
627633 int ret = 0 ;
628634
629635 WARN_ON_ONCE (q -> mq_freeze_depth == 0 );
630636 lockdep_assert_held (& q -> elevator_lock );
631637
632- if (strncmp (name , "none" , 4 )) {
633- new_e = elevator_find_get (name );
638+ if (strncmp (ctx -> name , "none" , 4 )) {
639+ new_e = elevator_find_get (ctx -> name );
634640 if (!new_e )
635641 return - EINVAL ;
636642 }
@@ -646,7 +652,7 @@ static int elevator_switch(struct request_queue *q, const char *name)
646652 ret = blk_mq_init_sched (q , new_e );
647653 if (ret )
648654 goto out_unfreeze ;
649- ret = elv_register_queue (q , true );
655+ ret = elv_register_queue (q , ! ctx -> no_uevent );
650656 if (ret ) {
651657 elevator_exit (q );
652658 goto out_unfreeze ;
@@ -656,7 +662,7 @@ static int elevator_switch(struct request_queue *q, const char *name)
656662 q -> elevator = NULL ;
657663 q -> nr_requests = q -> tag_set -> queue_depth ;
658664 }
659- blk_add_trace_msg (q , "elv switch: %s" , name );
665+ blk_add_trace_msg (q , "elv switch: %s" , ctx -> name );
660666
661667out_unfreeze :
662668 blk_mq_unquiesce_queue (q );
@@ -674,7 +680,7 @@ static int elevator_switch(struct request_queue *q, const char *name)
674680/*
675681 * Switch this queue to the given IO scheduler.
676682 */
677- static int elevator_change (struct request_queue * q , const char * elevator_name )
683+ static int elevator_change (struct request_queue * q , struct elv_change_ctx * ctx )
678684{
679685 unsigned int memflags ;
680686 int ret = 0 ;
@@ -683,9 +689,8 @@ static int elevator_change(struct request_queue *q, const char *elevator_name)
683689
684690 memflags = blk_mq_freeze_queue (q );
685691 mutex_lock (& q -> elevator_lock );
686- if (!(q -> elevator && elevator_match (q -> elevator -> type ,
687- elevator_name )))
688- ret = elevator_switch (q , elevator_name );
692+ if (!(q -> elevator && elevator_match (q -> elevator -> type , ctx -> name )))
693+ ret = elevator_switch (q , ctx );
689694 mutex_unlock (& q -> elevator_lock );
690695 blk_mq_unfreeze_queue (q , memflags );
691696 return ret ;
@@ -701,15 +706,17 @@ void elv_update_nr_hw_queues(struct request_queue *q)
701706
702707 mutex_lock (& q -> elevator_lock );
703708 if (q -> elevator && !blk_queue_dying (q ) && !blk_queue_registered (q )) {
704- const char * name = q -> elevator -> type -> elevator_name ;
709+ struct elv_change_ctx ctx = {
710+ .name = q -> elevator -> type -> elevator_name ,
711+ };
705712
706713 /* force to reattach elevator after nr_hw_queue is updated */
707- elevator_switch (q , name );
714+ elevator_switch (q , & ctx );
708715 }
709716 mutex_unlock (& q -> elevator_lock );
710717}
711718
712- static void elv_iosched_load_module (char * elevator_name )
719+ static void elv_iosched_load_module (const char * elevator_name )
713720{
714721 struct elevator_type * found ;
715722
@@ -725,7 +732,7 @@ ssize_t elv_iosched_store(struct gendisk *disk, const char *buf,
725732 size_t count )
726733{
727734 char elevator_name [ELV_NAME_MAX ];
728- char * name ;
735+ struct elv_change_ctx ctx = {} ;
729736 int ret ;
730737 struct request_queue * q = disk -> queue ;
731738 struct blk_mq_tag_set * set = q -> tag_set ;
@@ -740,12 +747,12 @@ ssize_t elv_iosched_store(struct gendisk *disk, const char *buf,
740747 * queue is the one for the device storing the module file.
741748 */
742749 strscpy (elevator_name , buf , sizeof (elevator_name ));
743- name = strstrip (elevator_name );
750+ ctx . name = strstrip (elevator_name );
744751
745- elv_iosched_load_module (name );
752+ elv_iosched_load_module (ctx . name );
746753
747754 down_read (& set -> update_nr_hwq_lock );
748- ret = elevator_change (q , name );
755+ ret = elevator_change (q , & ctx );
749756 if (!ret )
750757 ret = count ;
751758 up_read (& set -> update_nr_hwq_lock );
0 commit comments