[PATCH -next 7/8] md: use new helper to stop sync_thread in __md_stop_writes()

From: Yu Kuai
Date: Fri Nov 10 2023 - 13:07:57 EST


From: Yu Kuai <yukuai3@xxxxxxxxxx>

md_reap_sync_thread() should only be called when md_do_sync() is done,
for example, holding 'reconfig_mutex' to wait for md_do_sync() to be
done can deadlock(see details in commit 130443d60b1b ("md: refactor
idle/frozen_sync_thread() to fix deadlock")). Hence use new helper to
stop sync_thread.

Signed-off-by: Yu Kuai <yukuai3@xxxxxxxxxx>
Signed-off-by: Yu Kuai <yukuai1@xxxxxxxxxxxxxxx>
---
drivers/md/md.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index 7252fae0c989..35f3dd7db369 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -6325,12 +6325,11 @@ static void md_clean(struct mddev *mddev)

static void __md_stop_writes(struct mddev *mddev)
{
- set_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
- if (work_pending(&mddev->sync_work))
- flush_workqueue(md_misc_wq);
- if (mddev->sync_thread) {
- set_bit(MD_RECOVERY_INTR, &mddev->recovery);
- md_reap_sync_thread(mddev);
+ if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) {
+ stop_sync_thread(mddev, true, false);
+ mddev_lock_nointr(mddev);
+ } else {
+ set_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
}

del_timer_sync(&mddev->safemode_timer);
--
2.39.2