From: Yu Kuai <[email protected]>
Hi, Song! this patchset is rebased from mainline tree, because I
didn't found commit f52f5c71f3d4 ("md: fix stopping sync thread") in
md-next or for-6.8/block branch.
Yu Kuai (3):
md: remove redundant check of 'mddev->sync_thread'
md: remove redundant md_wakeup_thread()
md: use interruptible apis in idle/frozen_sync_thread()
drivers/md/md.c | 139 ++++++++++++++++++++++++---------------------
drivers/md/raid5.c | 6 +-
2 files changed, 75 insertions(+), 70 deletions(-)
--
2.39.2
From: Yu Kuai <[email protected]>
On the one hand, mddev_unlock() will call md_wakeup_thread()
unconditionally; on the other hand, md_check_recovery() can't make
progress if 'reconfig_mutex' can't be grabbed. Hence, it really doesn't
make sense to wake up daemon thread while 'reconfig_mutex' is still
grabbed.
Remove all the md_wakup_thread() for 'mddev->thread' while
'reconfig_mtuex' is still grabbed.
Signed-off-by: Yu Kuai <[email protected]>
---
drivers/md/md.c | 20 ++------------------
1 file changed, 2 insertions(+), 18 deletions(-)
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 2208eed3baac..60f99768a1a9 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -2904,7 +2904,6 @@ static int add_bound_rdev(struct md_rdev *rdev)
set_bit(MD_RECOVERY_RECOVER, &mddev->recovery);
set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
md_new_event();
- md_wakeup_thread(mddev->thread);
return 0;
}
@@ -3019,10 +3018,8 @@ state_store(struct md_rdev *rdev, const char *buf, size_t len)
if (err == 0) {
md_kick_rdev_from_array(rdev);
- if (mddev->pers) {
+ if (mddev->pers)
set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags);
- md_wakeup_thread(mddev->thread);
- }
md_new_event();
}
}
@@ -3052,7 +3049,6 @@ state_store(struct md_rdev *rdev, const char *buf, size_t len)
clear_bit(BlockedBadBlocks, &rdev->flags);
wake_up(&rdev->blocked_wait);
set_bit(MD_RECOVERY_NEEDED, &rdev->mddev->recovery);
- md_wakeup_thread(rdev->mddev->thread);
err = 0;
} else if (cmd_match(buf, "insync") && rdev->raid_disk == -1) {
@@ -3090,7 +3086,6 @@ state_store(struct md_rdev *rdev, const char *buf, size_t len)
!test_bit(Replacement, &rdev->flags))
set_bit(WantReplacement, &rdev->flags);
set_bit(MD_RECOVERY_NEEDED, &rdev->mddev->recovery);
- md_wakeup_thread(rdev->mddev->thread);
err = 0;
} else if (cmd_match(buf, "-want_replacement")) {
/* Clearing 'want_replacement' is always allowed.
@@ -3220,7 +3215,6 @@ slot_store(struct md_rdev *rdev, const char *buf, size_t len)
if (rdev->raid_disk >= 0)
return -EBUSY;
set_bit(MD_RECOVERY_NEEDED, &rdev->mddev->recovery);
- md_wakeup_thread(rdev->mddev->thread);
} else if (rdev->mddev->pers) {
/* Activating a spare .. or possibly reactivating
* if we ever get bitmaps working here.
@@ -6166,7 +6160,6 @@ int do_md_run(struct mddev *mddev)
/* run start up tasks that require md_thread */
md_start(mddev);
- md_wakeup_thread(mddev->thread);
md_wakeup_thread(mddev->sync_thread); /* possibly kick off a reshape */
set_capacity_and_notify(mddev->gendisk, mddev->array_sectors);
@@ -6187,7 +6180,6 @@ int md_start(struct mddev *mddev)
if (mddev->pers->start) {
set_bit(MD_RECOVERY_WAIT, &mddev->recovery);
- md_wakeup_thread(mddev->thread);
ret = mddev->pers->start(mddev);
clear_bit(MD_RECOVERY_WAIT, &mddev->recovery);
md_wakeup_thread(mddev->sync_thread);
@@ -6232,7 +6224,6 @@ static int restart_array(struct mddev *mddev)
pr_debug("md: %s switched to read-write mode.\n", mdname(mddev));
/* Kick recovery or resync if necessary */
set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
- md_wakeup_thread(mddev->thread);
md_wakeup_thread(mddev->sync_thread);
sysfs_notify_dirent_safe(mddev->sysfs_state);
return 0;
@@ -6376,7 +6367,6 @@ static int md_set_readonly(struct mddev *mddev, struct block_device *bdev)
if (!test_bit(MD_RECOVERY_FROZEN, &mddev->recovery)) {
did_freeze = 1;
set_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
- md_wakeup_thread(mddev->thread);
}
stop_sync_thread(mddev, false, false);
@@ -6408,7 +6398,6 @@ static int md_set_readonly(struct mddev *mddev, struct block_device *bdev)
if ((mddev->pers && !err) || did_freeze) {
clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
- md_wakeup_thread(mddev->thread);
sysfs_notify_dirent_safe(mddev->sysfs_state);
}
@@ -6430,7 +6419,6 @@ static int do_md_stop(struct mddev *mddev, int mode,
if (!test_bit(MD_RECOVERY_FROZEN, &mddev->recovery)) {
did_freeze = 1;
set_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
- md_wakeup_thread(mddev->thread);
}
stop_sync_thread(mddev, true, false);
@@ -6444,7 +6432,6 @@ static int do_md_stop(struct mddev *mddev, int mode,
if (did_freeze) {
clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
- md_wakeup_thread(mddev->thread);
}
return -EBUSY;
}
@@ -6985,9 +6972,7 @@ static int hot_remove_disk(struct mddev *mddev, dev_t dev)
md_kick_rdev_from_array(rdev);
set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags);
- if (mddev->thread)
- md_wakeup_thread(mddev->thread);
- else
+ if (!mddev->thread)
md_update_sb(mddev, 1);
md_new_event();
@@ -7069,7 +7054,6 @@ static int hot_add_disk(struct mddev *mddev, dev_t dev)
* array immediately.
*/
set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
- md_wakeup_thread(mddev->thread);
md_new_event();
return 0;
--
2.39.2
From: Yu Kuai <[email protected]>
The lifetime of sync_thread:
1) Set MD_RECOVERY_NEEDED and wake up daemon thread (by ioctl/sysfs or
other events);
2) Daemon thread woke up, md_check_recovery() found that
MD_RECOVERY_NEEDED is set:
a) try to grab reconfig_mutex;
b) set MD_RECOVERY_RUNNING;
c) clear MD_RECOVERY_NEEDED, and then queue sync_work;
3) md_start_sync() choose sync_action, then register sync_thread;
4) md_do_sync() is done, set MD_RECOVERY_DONE and wake up daemon thread;
5) Daemon thread woke up, md_check_recovery() found that
MD_RECOVERY_DONE is set:
a) try to grab reconfig_mutex;
b) unregister sync_thread;
c) clear MD_RECOVERY_RUNNING and MD_RECOVERY_DONE;
Hence there is no such case that MD_RECOVERY_RUNNING is not set, while
sync_thread is registered.
Signed-off-by: Yu Kuai <[email protected]>
---
drivers/md/md.c | 14 ++++----------
drivers/md/raid5.c | 6 ++----
2 files changed, 6 insertions(+), 14 deletions(-)
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 9bdd57324c37..2208eed3baac 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -3314,8 +3314,7 @@ static ssize_t new_offset_store(struct md_rdev *rdev,
if (kstrtoull(buf, 10, &new_offset) < 0)
return -EINVAL;
- if (mddev->sync_thread ||
- test_bit(MD_RECOVERY_RUNNING,&mddev->recovery))
+ if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery))
return -EBUSY;
if (new_offset == rdev->data_offset)
/* reset is always permitted */
@@ -3993,8 +3992,7 @@ level_store(struct mddev *mddev, const char *buf, size_t len)
*/
rv = -EBUSY;
- if (mddev->sync_thread ||
- test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) ||
+ if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) ||
mddev->reshape_position != MaxSector ||
mddev->sysfs_active)
goto out_unlock;
@@ -6388,7 +6386,6 @@ static int md_set_readonly(struct mddev *mddev, struct block_device *bdev)
mutex_lock(&mddev->open_mutex);
if ((mddev->pers && atomic_read(&mddev->openers) > !!bdev) ||
- mddev->sync_thread ||
test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) {
pr_warn("md: %s still in use.\n",mdname(mddev));
err = -EBUSY;
@@ -6441,7 +6438,6 @@ static int do_md_stop(struct mddev *mddev, int mode,
mutex_lock(&mddev->open_mutex);
if ((mddev->pers && atomic_read(&mddev->openers) > !!bdev) ||
mddev->sysfs_active ||
- mddev->sync_thread ||
test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) {
pr_warn("md: %s still in use.\n",mdname(mddev));
mutex_unlock(&mddev->open_mutex);
@@ -7287,8 +7283,7 @@ static int update_size(struct mddev *mddev, sector_t num_sectors)
* of each device. If num_sectors is zero, we find the largest size
* that fits.
*/
- if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) ||
- mddev->sync_thread)
+ if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery))
return -EBUSY;
if (!md_is_rdwr(mddev))
return -EROFS;
@@ -7325,8 +7320,7 @@ static int update_raid_disks(struct mddev *mddev, int raid_disks)
if (raid_disks <= 0 ||
(mddev->max_disks && raid_disks >= mddev->max_disks))
return -EINVAL;
- if (mddev->sync_thread ||
- test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) ||
+ if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) ||
test_bit(MD_RESYNCING_REMOTE, &mddev->recovery) ||
mddev->reshape_position != MaxSector)
return -EBUSY;
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 26e1e8a5e941..e3a216e51e3f 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -7025,10 +7025,8 @@ raid5_store_stripe_size(struct mddev *mddev, const char *page, size_t len)
pr_debug("md/raid: change stripe_size from %lu to %lu\n",
conf->stripe_size, new);
- if (mddev->sync_thread ||
- test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) ||
- mddev->reshape_position != MaxSector ||
- mddev->sysfs_active) {
+ if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) ||
+ mddev->reshape_position != MaxSector || mddev->sysfs_active) {
err = -EBUSY;
goto out_unlock;
}
--
2.39.2
From: Yu Kuai <[email protected]>
Before refactoring idle and frozen from action_store, interruptible apis
is used so that hungtask warning won't be triggered if it takes too long
to finish idle/frozen sync_thread. So change to use interruptible apis.
In order not to make stop_sync_thread() more complicated, factor out a
helper prepare_to_stop_sync_thread() to replace stop_sync_thread().
Also return error to user if idle/frozen_sync_thread() failed, otherwise
user will be misleaded.
Fixes: 130443d60b1b ("md: refactor idle/frozen_sync_thread() to fix deadlock")
Fixes: 8e8e2518fcec ("md: Close race when setting 'action' to 'idle'.")
Signed-off-by: Yu Kuai <[email protected]>
---
drivers/md/md.c | 105 ++++++++++++++++++++++++++++++------------------
1 file changed, 67 insertions(+), 38 deletions(-)
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 60f99768a1a9..9ea05de79fe4 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -4846,26 +4846,34 @@ action_show(struct mddev *mddev, char *page)
return sprintf(page, "%s\n", type);
}
+static bool sync_thread_stopped(struct mddev *mddev, int *sync_seq)
+{
+ if (!test_bit(MD_RECOVERY_RUNNING, &mddev->recovery))
+ return true;
+
+ if (sync_seq && *sync_seq != atomic_read(&mddev->sync_seq))
+ return true;
+
+ return false;
+}
+
/**
- * stop_sync_thread() - wait for sync_thread to stop if it's running.
+ * prepare_to_stop_sync_thread() - prepare to stop sync_thread if it's running.
* @mddev: the array.
- * @locked: if set, reconfig_mutex will still be held after this function
- * return; if not set, reconfig_mutex will be released after this
- * function return.
- * @check_seq: if set, only wait for curent running sync_thread to stop, noted
- * that new sync_thread can still start.
+ * @unlock: whether or not caller want to release reconfig_mutex if
+ * sync_thread is not running.
+ *
+ * Return true if sync_thread is running, release reconfig_mutex and do
+ * preparatory work to stop sync_thread, caller should wait for
+ * sync_thread_stopped() to return true. Return false if sync_thread is not
+ * running, reconfig_mutex will be released if @unlock is set.
*/
-static void stop_sync_thread(struct mddev *mddev, bool locked, bool check_seq)
+static bool prepare_to_stop_sync_thread(struct mddev *mddev, bool unlock)
{
- int sync_seq;
-
- if (check_seq)
- sync_seq = atomic_read(&mddev->sync_seq);
-
if (!test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) {
- if (!locked)
+ if (unlock)
mddev_unlock(mddev);
- return;
+ return false;
}
mddev_unlock(mddev);
@@ -4879,53 +4887,67 @@ static void stop_sync_thread(struct mddev *mddev, bool locked, bool check_seq)
if (work_pending(&mddev->sync_work))
flush_work(&mddev->sync_work);
- wait_event(resync_wait,
- !test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) ||
- (check_seq && sync_seq != atomic_read(&mddev->sync_seq)));
-
- if (locked)
- mddev_lock_nointr(mddev);
+ return true;
}
-static void idle_sync_thread(struct mddev *mddev)
+static int idle_sync_thread(struct mddev *mddev)
{
- mutex_lock(&mddev->sync_mutex);
+ int sync_seq = atomic_read(&mddev->sync_seq);
+ int err = mutex_lock_interruptible(&mddev->sync_mutex);
+
+ if (err)
+ return err;
clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
- if (mddev_lock(mddev)) {
+ err = mddev_lock(mddev);
+ if (err) {
mutex_unlock(&mddev->sync_mutex);
- return;
+ return err;
}
- stop_sync_thread(mddev, false, true);
+ if (prepare_to_stop_sync_thread(mddev, true))
+ err = wait_event_interruptible(resync_wait,
+ sync_thread_stopped(mddev, &sync_seq));
+
mutex_unlock(&mddev->sync_mutex);
+
+ return err;
}
-static void frozen_sync_thread(struct mddev *mddev)
+static int frozen_sync_thread(struct mddev *mddev)
{
- mutex_lock(&mddev->sync_mutex);
+ int err = mutex_lock_interruptible(&mddev->sync_mutex);
+
+ if (err)
+ return err;
set_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
- if (mddev_lock(mddev)) {
+ err = mddev_lock(mddev);
+ if (err) {
mutex_unlock(&mddev->sync_mutex);
- return;
+ return err;
}
- stop_sync_thread(mddev, false, false);
+ if (prepare_to_stop_sync_thread(mddev, true))
+ err = wait_event_interruptible(resync_wait,
+ sync_thread_stopped(mddev, NULL));
mutex_unlock(&mddev->sync_mutex);
+
+ return err;
}
static ssize_t
action_store(struct mddev *mddev, const char *page, size_t len)
{
+ int err = 0;
+
if (!mddev->pers || !mddev->pers->sync_request)
return -EINVAL;
-
if (cmd_match(page, "idle"))
- idle_sync_thread(mddev);
+ err = idle_sync_thread(mddev);
else if (cmd_match(page, "frozen"))
- frozen_sync_thread(mddev);
+ err = frozen_sync_thread(mddev);
else if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery))
return -EBUSY;
else if (cmd_match(page, "resync"))
@@ -4934,7 +4956,6 @@ action_store(struct mddev *mddev, const char *page, size_t len)
clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
set_bit(MD_RECOVERY_RECOVER, &mddev->recovery);
} else if (cmd_match(page, "reshape")) {
- int err;
if (mddev->pers->start_reshape == NULL)
return -EINVAL;
err = mddev_lock(mddev);
@@ -4980,7 +5001,7 @@ action_store(struct mddev *mddev, const char *page, size_t len)
set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
md_wakeup_thread(mddev->thread);
sysfs_notify_dirent_safe(mddev->sysfs_action);
- return len;
+ return err ? err : len;
}
static struct md_sysfs_entry md_scan_mode =
@@ -6280,7 +6301,11 @@ static void md_clean(struct mddev *mddev)
static void __md_stop_writes(struct mddev *mddev)
{
- stop_sync_thread(mddev, true, false);
+ if (prepare_to_stop_sync_thread(mddev, false)) {
+ wait_event(resync_wait, sync_thread_stopped(mddev, NULL));
+ mddev_lock_nointr(mddev);
+ }
+
del_timer_sync(&mddev->safemode_timer);
if (mddev->pers && mddev->pers->quiesce) {
@@ -6369,7 +6394,8 @@ static int md_set_readonly(struct mddev *mddev, struct block_device *bdev)
set_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
}
- stop_sync_thread(mddev, false, false);
+ if (prepare_to_stop_sync_thread(mddev, true))
+ wait_event(resync_wait, sync_thread_stopped(mddev, NULL));
wait_event(mddev->sb_wait,
!test_bit(MD_SB_CHANGE_PENDING, &mddev->sb_flags));
mddev_lock_nointr(mddev);
@@ -6421,7 +6447,10 @@ static int do_md_stop(struct mddev *mddev, int mode,
set_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
}
- stop_sync_thread(mddev, true, false);
+ if (prepare_to_stop_sync_thread(mddev, false)) {
+ wait_event(resync_wait, sync_thread_stopped(mddev, NULL));
+ mddev_lock_nointr(mddev);
+ }
mutex_lock(&mddev->open_mutex);
if ((mddev->pers && atomic_read(&mddev->openers) > !!bdev) ||
--
2.39.2
Hi,
Sorry for the late reply.
The first two patches of the set look good, so I applied them to
md-tmp-6.9 branch. However, this one needs a respin.
On Thu, Dec 28, 2023 at 4:58 AM Yu Kuai <[email protected]> wrote:
>
> From: Yu Kuai <[email protected]>
>
> Before refactoring idle and frozen from action_store, interruptible apis
> is used so that hungtask warning won't be triggered if it takes too long
> to finish idle/frozen sync_thread. So change to use interruptible apis.
This paragraph is confusing. Please rephrase it.
>
> In order not to make stop_sync_thread() more complicated, factor out a
> helper prepare_to_stop_sync_thread() to replace stop_sync_thread().
>
> Also return error to user if idle/frozen_sync_thread() failed, otherwise
> user will be misleaded.
s/misleaded/misled/
>
> Fixes: 130443d60b1b ("md: refactor idle/frozen_sync_thread() to fix deadlock")
> Fixes: 8e8e2518fcec ("md: Close race when setting 'action' to 'idle'.")
Please add more information about what is being fixed here, so that
we can make a clear decision on whether the fix needs to be back
ported to stable kernels.
> Signed-off-by: Yu Kuai <[email protected]>
> ---
> drivers/md/md.c | 105 ++++++++++++++++++++++++++++++------------------
> 1 file changed, 67 insertions(+), 38 deletions(-)
>
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index 60f99768a1a9..9ea05de79fe4 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -4846,26 +4846,34 @@ action_show(struct mddev *mddev, char *page)
> return sprintf(page, "%s\n", type);
> }
>
> +static bool sync_thread_stopped(struct mddev *mddev, int *sync_seq)
I think we need a comment for this.
> +{
> + if (!test_bit(MD_RECOVERY_RUNNING, &mddev->recovery))
> + return true;
> +
> + if (sync_seq && *sync_seq != atomic_read(&mddev->sync_seq))
> + return true;
> +
> + return false;
> +}
> +
> /**
> - * stop_sync_thread() - wait for sync_thread to stop if it's running.
> + * prepare_to_stop_sync_thread() - prepare to stop sync_thread if it's running.
> * @mddev: the array.
> - * @locked: if set, reconfig_mutex will still be held after this function
> - * return; if not set, reconfig_mutex will be released after this
> - * function return.
> - * @check_seq: if set, only wait for curent running sync_thread to stop, noted
> - * that new sync_thread can still start.
> + * @unlock: whether or not caller want to release reconfig_mutex if
> + * sync_thread is not running.
> + *
> + * Return true if sync_thread is running, release reconfig_mutex and do
> + * preparatory work to stop sync_thread, caller should wait for
> + * sync_thread_stopped() to return true. Return false if sync_thread is not
> + * running, reconfig_mutex will be released if @unlock is set.
> */
I found prepare_to_stop_sync_thread very hard to reason. Please try to
rephrase the comment or refactor the code. Maybe it makes sense to put
the following logic and its variations to a separate function:
if (prepare_to_stop_sync_thread(mddev, false)) {
wait_event(resync_wait, sync_thread_stopped(mddev, NULL));
mddev_lock_nointr(mddev);
}
Thanks,
Song
> -static void stop_sync_thread(struct mddev *mddev, bool locked, bool check_seq)
> +static bool prepare_to_stop_sync_thread(struct mddev *mddev, bool unlock)
> {
> - int sync_seq;
[...]
Hi,
在 2024/01/30 14:37, Song Liu 写道:
> Hi,
>
> Sorry for the late reply.
>
> The first two patches of the set look good, so I applied them to
> md-tmp-6.9 branch. However, this one needs a respin.
We are fixing dm-raid regressions, so I'll not send a new version until
that work is done. :)
>
> On Thu, Dec 28, 2023 at 4:58 AM Yu Kuai <[email protected]> wrote:
>>
>> From: Yu Kuai <[email protected]>
>>
>> Before refactoring idle and frozen from action_store, interruptible apis
>> is used so that hungtask warning won't be triggered if it takes too long
>> to finish idle/frozen sync_thread. So change to use interruptible apis.
>
> This paragraph is confusing. Please rephrase it.
>
>>
>> In order not to make stop_sync_thread() more complicated, factor out a
>> helper prepare_to_stop_sync_thread() to replace stop_sync_thread().
>>
>> Also return error to user if idle/frozen_sync_thread() failed, otherwise
>> user will be misleaded.
>
> s/misleaded/misled/
>
>>
>> Fixes: 130443d60b1b ("md: refactor idle/frozen_sync_thread() to fix deadlock")
>> Fixes: 8e8e2518fcec ("md: Close race when setting 'action' to 'idle'.")
>
> Please add more information about what is being fixed here, so that
> we can make a clear decision on whether the fix needs to be back
> ported to stable kernels.
8e8e2518fcec added the interruptible apis first, however, it doesn't
return error to user if it's interrupted.
130443d60b1b deleted the interruptible apis.
Perhaps I should split this patch into two minor patches, one for each
fixed tag.
>
>> Signed-off-by: Yu Kuai <[email protected]>
>> ---
>> drivers/md/md.c | 105 ++++++++++++++++++++++++++++++------------------
>> 1 file changed, 67 insertions(+), 38 deletions(-)
>>
>> diff --git a/drivers/md/md.c b/drivers/md/md.c
>> index 60f99768a1a9..9ea05de79fe4 100644
>> --- a/drivers/md/md.c
>> +++ b/drivers/md/md.c
>> @@ -4846,26 +4846,34 @@ action_show(struct mddev *mddev, char *page)
>> return sprintf(page, "%s\n", type);
>> }
>>
>> +static bool sync_thread_stopped(struct mddev *mddev, int *sync_seq)
>
> I think we need a comment for this.
>
>> +{
>> + if (!test_bit(MD_RECOVERY_RUNNING, &mddev->recovery))
>> + return true;
>> +
>> + if (sync_seq && *sync_seq != atomic_read(&mddev->sync_seq))
>> + return true;
>> +
>> + return false;
>> +}
>> +
>> /**
>> - * stop_sync_thread() - wait for sync_thread to stop if it's running.
>> + * prepare_to_stop_sync_thread() - prepare to stop sync_thread if it's running.
>> * @mddev: the array.
>> - * @locked: if set, reconfig_mutex will still be held after this function
>> - * return; if not set, reconfig_mutex will be released after this
>> - * function return.
>> - * @check_seq: if set, only wait for curent running sync_thread to stop, noted
>> - * that new sync_thread can still start.
>> + * @unlock: whether or not caller want to release reconfig_mutex if
>> + * sync_thread is not running.
>> + *
>> + * Return true if sync_thread is running, release reconfig_mutex and do
>> + * preparatory work to stop sync_thread, caller should wait for
>> + * sync_thread_stopped() to return true. Return false if sync_thread is not
>> + * running, reconfig_mutex will be released if @unlock is set.
>> */
>
> I found prepare_to_stop_sync_thread very hard to reason. Please try to
> rephrase the comment or refactor the code. Maybe it makes sense to put
> the following logic and its variations to a separate function:
>
> if (prepare_to_stop_sync_thread(mddev, false)) {
> wait_event(resync_wait, sync_thread_stopped(mddev, NULL));
> mddev_lock_nointr(mddev);
> }
I can do this, but there are 5 callers and only two of them can use the
separate caller. Pehaps something like this?
void stop_sync_thread(struct mddev *mddev, bool wait_sb)
{
if (prepare_to_stop_sync_thread(mddev, wait_sb)) {
wait_event(resync_wait, ...);
if (!wait_sb) {
mddev_lock_nointr(mddev);
return;
}
}
if (wait_sb) {
wait_event(sb_wait, ...);
mddev_lock_nointr(mddev);
}
}
int stop_sync_thread_interruptible(struct mddev *mddev, bool check_sync_seq)
{
..
}
Thanks,
Kuai
>
> Thanks,
> Song
>
>> -static void stop_sync_thread(struct mddev *mddev, bool locked, bool check_seq)
>> +static bool prepare_to_stop_sync_thread(struct mddev *mddev, bool unlock)
>> {
>> - int sync_seq;
>
> [...]
> .
>
On Mon, Jan 29, 2024 at 11:04 PM Yu Kuai <[email protected]> wrote:
>
> Hi,
>
> 在 2024/01/30 14:37, Song Liu 写道:
> > Hi,
> >
> > Sorry for the late reply.
> >
> > The first two patches of the set look good, so I applied them to
> > md-tmp-6.9 branch. However, this one needs a respin.
>
> We are fixing dm-raid regressions, so I'll not send a new version until
> that work is done. :)
Sure. Fixing the regression is more urgent.
> >
> > On Thu, Dec 28, 2023 at 4:58 AM Yu Kuai <[email protected]> wrote:
> >>
> >> From: Yu Kuai <[email protected]>
[...]
> > I found prepare_to_stop_sync_thread very hard to reason. Please try to
> > rephrase the comment or refactor the code. Maybe it makes sense to put
> > the following logic and its variations to a separate function:
> >
> > if (prepare_to_stop_sync_thread(mddev, false)) {
> > wait_event(resync_wait, sync_thread_stopped(mddev, NULL));
> > mddev_lock_nointr(mddev);
> > }
>
> I can do this, but there are 5 callers and only two of them can use the
> separate caller. Pehaps something like this?
>
> void stop_sync_thread(struct mddev *mddev, bool wait_sb)
> {
> if (prepare_to_stop_sync_thread(mddev, wait_sb)) {
> wait_event(resync_wait, ...);
> if (!wait_sb) {
> mddev_lock_nointr(mddev);
> return;
> }
> }
>
> if (wait_sb) {
> wait_event(sb_wait, ...);
> mddev_lock_nointr(mddev);
> }
> }
I don't really like this version either. Let's think more about this
after fixing the dm-raid regressions.
Thanks,
Song
>
> int stop_sync_thread_interruptible(struct mddev *mddev, bool check_sync_seq)
> {
> ...
> }