@@ -7767,6 +7767,33 @@ static int remove_and_add_spares(struct mddev *mddev,
77677767 return spares ;
77687768}
77697769
7770+ static void md_start_sync (struct work_struct * ws )
7771+ {
7772+ struct mddev * mddev = container_of (ws , struct mddev , del_work );
7773+
7774+ mddev -> sync_thread = md_register_thread (md_do_sync ,
7775+ mddev ,
7776+ "resync" );
7777+ if (!mddev -> sync_thread ) {
7778+ printk (KERN_ERR "%s: could not start resync"
7779+ " thread...\n" ,
7780+ mdname (mddev ));
7781+ /* leave the spares where they are, it shouldn't hurt */
7782+ clear_bit (MD_RECOVERY_SYNC , & mddev -> recovery );
7783+ clear_bit (MD_RECOVERY_RESHAPE , & mddev -> recovery );
7784+ clear_bit (MD_RECOVERY_REQUESTED , & mddev -> recovery );
7785+ clear_bit (MD_RECOVERY_CHECK , & mddev -> recovery );
7786+ clear_bit (MD_RECOVERY_RUNNING , & mddev -> recovery );
7787+ if (test_and_clear_bit (MD_RECOVERY_RECOVER ,
7788+ & mddev -> recovery ))
7789+ if (mddev -> sysfs_action )
7790+ sysfs_notify_dirent_safe (mddev -> sysfs_action );
7791+ } else
7792+ md_wakeup_thread (mddev -> sync_thread );
7793+ sysfs_notify_dirent_safe (mddev -> sysfs_action );
7794+ md_new_event (mddev );
7795+ }
7796+
77707797/*
77717798 * This routine is regularly called by all per-raid-array threads to
77727799 * deal with generic issues like resync and super-block update.
@@ -7883,7 +7910,7 @@ void md_check_recovery(struct mddev *mddev)
78837910
78847911 if (!test_and_clear_bit (MD_RECOVERY_NEEDED , & mddev -> recovery ) ||
78857912 test_bit (MD_RECOVERY_FROZEN , & mddev -> recovery ))
7886- goto unlock ;
7913+ goto not_running ;
78877914 /* no recovery is running.
78887915 * remove any failed drives, then
78897916 * add spares if possible.
@@ -7895,7 +7922,7 @@ void md_check_recovery(struct mddev *mddev)
78957922 if (mddev -> pers -> check_reshape == NULL ||
78967923 mddev -> pers -> check_reshape (mddev ) != 0 )
78977924 /* Cannot proceed */
7898- goto unlock ;
7925+ goto not_running ;
78997926 set_bit (MD_RECOVERY_RESHAPE , & mddev -> recovery );
79007927 clear_bit (MD_RECOVERY_RECOVER , & mddev -> recovery );
79017928 } else if ((spares = remove_and_add_spares (mddev , NULL ))) {
@@ -7908,7 +7935,7 @@ void md_check_recovery(struct mddev *mddev)
79087935 clear_bit (MD_RECOVERY_RECOVER , & mddev -> recovery );
79097936 } else if (!test_bit (MD_RECOVERY_SYNC , & mddev -> recovery ))
79107937 /* nothing to be done ... */
7911- goto unlock ;
7938+ goto not_running ;
79127939
79137940 if (mddev -> pers -> sync_request ) {
79147941 if (spares ) {
@@ -7918,34 +7945,20 @@ void md_check_recovery(struct mddev *mddev)
79187945 */
79197946 bitmap_write_all (mddev -> bitmap );
79207947 }
7921- mddev -> sync_thread = md_register_thread (md_do_sync ,
7922- mddev ,
7923- "resync" );
7924- if (!mddev -> sync_thread ) {
7925- printk (KERN_ERR "%s: could not start resync"
7926- " thread...\n" ,
7927- mdname (mddev ));
7928- /* leave the spares where they are, it shouldn't hurt */
7929- clear_bit (MD_RECOVERY_RUNNING , & mddev -> recovery );
7930- clear_bit (MD_RECOVERY_SYNC , & mddev -> recovery );
7931- clear_bit (MD_RECOVERY_RESHAPE , & mddev -> recovery );
7932- clear_bit (MD_RECOVERY_REQUESTED , & mddev -> recovery );
7933- clear_bit (MD_RECOVERY_CHECK , & mddev -> recovery );
7934- } else
7935- md_wakeup_thread (mddev -> sync_thread );
7936- sysfs_notify_dirent_safe (mddev -> sysfs_action );
7937- md_new_event (mddev );
7948+ INIT_WORK (& mddev -> del_work , md_start_sync );
7949+ queue_work (md_misc_wq , & mddev -> del_work );
7950+ goto unlock ;
79387951 }
7939- unlock :
7940- wake_up (& mddev -> sb_wait );
7941-
7952+ not_running :
79427953 if (!mddev -> sync_thread ) {
79437954 clear_bit (MD_RECOVERY_RUNNING , & mddev -> recovery );
79447955 if (test_and_clear_bit (MD_RECOVERY_RECOVER ,
79457956 & mddev -> recovery ))
79467957 if (mddev -> sysfs_action )
79477958 sysfs_notify_dirent_safe (mddev -> sysfs_action );
79487959 }
7960+ unlock :
7961+ wake_up (& mddev -> sb_wait );
79497962 mddev_unlock (mddev );
79507963 }
79517964}
0 commit comments