Skip to content

Commit f71209b

Browse files
YuKuai-huaweiliu-song-6
authored andcommitted
md: enhance checking in md_check_recovery()
For md_check_recovery(): 1) if 'MD_RECOVERY_RUNING' is not set, register new sync_thread. 2) if 'MD_RECOVERY_RUNING' is set: a) if 'MD_RECOVERY_DONE' is not set, don't do anything, wait for md_do_sync() to be done. b) if 'MD_RECOVERY_DONE' is set, unregister sync_thread. Current code expects that sync_thread is not NULL, otherwise new sync_thread will be registered, which will corrupt the array. Make sure md_check_recovery() won't register new sync_thread if 'MD_RECOVERY_RUNING' is still set, and a new WARN_ON_ONCE() is added for the above corruption, Signed-off-by: Yu Kuai <[email protected]> Reviewed-by: Xiao Ni <[email protected]> Signed-off-by: Song Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 753260e commit f71209b

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

drivers/md/md.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9388,16 +9388,24 @@ void md_check_recovery(struct mddev *mddev)
93889388
if (mddev->sb_flags)
93899389
md_update_sb(mddev, 0);
93909390

9391-
if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) &&
9392-
!test_bit(MD_RECOVERY_DONE, &mddev->recovery)) {
9393-
/* resync/recovery still happening */
9394-
clear_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
9395-
goto unlock;
9396-
}
9397-
if (mddev->sync_thread) {
9391+
/*
9392+
* Never start a new sync thread if MD_RECOVERY_RUNNING is
9393+
* still set.
9394+
*/
9395+
if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) {
9396+
if (!test_bit(MD_RECOVERY_DONE, &mddev->recovery)) {
9397+
/* resync/recovery still happening */
9398+
clear_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
9399+
goto unlock;
9400+
}
9401+
9402+
if (WARN_ON_ONCE(!mddev->sync_thread))
9403+
goto unlock;
9404+
93989405
md_reap_sync_thread(mddev);
93999406
goto unlock;
94009407
}
9408+
94019409
/* Set RUNNING before clearing NEEDED to avoid
94029410
* any transients in the value of "sync_action".
94039411
*/

0 commit comments

Comments
 (0)