Re: [PATCH] md: suspend array while updating raid1 raid_disks via sysfs

"Yu Kuai" <[email protected]>
Newsgroups gmane.linux.raid,gmane.linux.kernel
Message-ID <[email protected]>
Hi,

在 2025/12/18 17:06, dannyshih 写道:
> From: FengWei Shih <[email protected]>
>
> When an I/O error occurs, the corresponding r1bio might be queued during
> raid1_reshape() and not released. Leads to r1bio release with wrong
> raid_disks.

Please be more specific about the problem, mempool_destroy() will warn about
object still in use, and free r1bio with updated conf->raid_disks will cause
problem like memory oob.

>
> * raid1_reshape() calls freeze_array(), which only waits for r1bios be
>    queued or released.
>
> Since only normal I/O might be queued while an I/O error occurs, suspending
> the array avoids this issue.
>
> Signed-off-by: FengWei Shih <[email protected]>
> ---
>   drivers/md/md.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index e5922a682953..6424652bce6e 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -4402,12 +4402,13 @@ raid_disks_store(struct mddev *mddev, const char *buf, size_t len)
>   {
>   	unsigned int n;
>   	int err;
> +	bool need_suspend = (mddev->pers && mddev->level == 1);

Perhaps just suspend the array unconditionally, this will make sense.

>   
>   	err = kstrtouint(buf, 10, &n);
>   	if (err < 0)
>   		return err;
>   
> -	err = mddev_lock(mddev);
> +	err = need_suspend ? mddev_suspend_and_lock(mddev) : mddev_lock(mddev);
>   	if (err)
>   		return err;
>   	if (mddev->pers)
> @@ -4432,7 +4433,7 @@ raid_disks_store(struct mddev *mddev, const char *buf, size_t len)
>   	} else
>   		mddev->raid_disks = n;
>   out_unlock:
> -	mddev_unlock(mddev);
> +	need_suspend ? mddev_unlock_and_resume(mddev) : mddev_unlock(mddev);
>   	return err ? err : len;
>   }
>   static struct md_sysfs_entry md_raid_disks =

-- 
Thansk,
Kuai
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.