diff options
author | Yu Kuai <yukuai3@huawei.com> | 2023-05-29 15:20:37 +0200 |
---|---|---|
committer | Song Liu <song@kernel.org> | 2023-07-27 09:13:29 +0200 |
commit | f71209b1f21c838a973d858d9f6f76cd39227733 (patch) | |
tree | 1a10f042ff871ffc2ff52774cd289b3f223ab51b /drivers/md/md.c | |
parent | md: wake up 'resync_wait' at last in md_reap_sync_thread() (diff) | |
download | linux-f71209b1f21c838a973d858d9f6f76cd39227733.tar.xz linux-f71209b1f21c838a973d858d9f6f76cd39227733.zip |
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 <yukuai3@huawei.com>
Reviewed-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230529132037.2124527-7-yukuai1@huaweicloud.com
Diffstat (limited to '')
-rw-r--r-- | drivers/md/md.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/drivers/md/md.c b/drivers/md/md.c index e0d8e751a782..320d71537359 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -9388,16 +9388,24 @@ void md_check_recovery(struct mddev *mddev) if (mddev->sb_flags) md_update_sb(mddev, 0); - if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) && - !test_bit(MD_RECOVERY_DONE, &mddev->recovery)) { - /* resync/recovery still happening */ - clear_bit(MD_RECOVERY_NEEDED, &mddev->recovery); - goto unlock; - } - if (mddev->sync_thread) { + /* + * Never start a new sync thread if MD_RECOVERY_RUNNING is + * still set. + */ + if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) { + if (!test_bit(MD_RECOVERY_DONE, &mddev->recovery)) { + /* resync/recovery still happening */ + clear_bit(MD_RECOVERY_NEEDED, &mddev->recovery); + goto unlock; + } + + if (WARN_ON_ONCE(!mddev->sync_thread)) + goto unlock; + md_reap_sync_thread(mddev); goto unlock; } + /* Set RUNNING before clearing NEEDED to avoid * any transients in the value of "sync_action". */ |