mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yu Kuai <yukuai1@huaweicloud.com>
To: linan666@huaweicloud.com, song@kernel.org, neilb@suse.com,
	shli@fb.com, mariusz.tkaczyk@linux.intel.com
Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org,
	yi.zhang@huawei.com, houtao1@huawei.com, yangerkun@huawei.com,
	"yukuai (C)" <yukuai3@huawei.com>
Subject: Re: [PATCH v4 1/4] md: Don't clear MD_CLOSING when the raid is about to stop
Date: Sat, 27 Jan 2024 16:38:03 +0800	[thread overview]
Message-ID: <51145653-9f9b-e6d5-1b3a-2b25ed3e95f1@huaweicloud.com> (raw)
In-Reply-To: <20240126092254.1314908-2-linan666@huaweicloud.com>

Hi,

在 2024/01/26 17:22, linan666@huaweicloud.com 写道:
> From: Li Nan <linan122@huawei.com>
> 
> The raid should not be opened anymore when it is about to be stopped.
> However, other processes can open it again if the flag MD_CLOSING is
> cleared before exiting. From now on, this flag will not be cleared when
> the raid will be stopped.

This patch looks good, just one nit below:
> 
> Fixes: 065e519e71b2 ("md: MD_CLOSING needs to be cleared after called md_set_readonly or do_md_stop")
> Signed-off-by: Li Nan <linan122@huawei.com>
> Acked-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
> ---
>   drivers/md/md.c | 22 ++++++++++++++++++----
>   1 file changed, 18 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index 9bdd57324c37..06550fe34aa1 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -6254,7 +6254,15 @@ static void md_clean(struct mddev *mddev)
>   	mddev->persistent = 0;
>   	mddev->level = LEVEL_NONE;
>   	mddev->clevel[0] = 0;
> -	mddev->flags = 0;
> +	/*
> +	 * Don't clear MD_CLOSING, or mddev can be opened again.
> +	 * 'hold_active != 0' means mddev is still in the creation
> +	 * process and will be used later.
> +	 */
> +	if (mddev->hold_active)
> +		mddev->flags = 0;
> +	else
> +		mddev->flags &= BIT_ULL_MASK(MD_CLOSING);
>   	mddev->sb_flags = 0;
>   	mddev->ro = MD_RDWR;
>   	mddev->metadata_type[0] = 0;
> @@ -7600,7 +7608,7 @@ static int md_ioctl(struct block_device *bdev, blk_mode_t mode,
>   	int err = 0;
>   	void __user *argp = (void __user *)arg;
>   	struct mddev *mddev = NULL;
> -	bool did_set_md_closing = false;
> +	bool clear_md_closing = false;
>   
>   	if (!md_ioctl_valid(cmd))
>   		return -ENOTTY;
> @@ -7684,7 +7692,7 @@ static int md_ioctl(struct block_device *bdev, blk_mode_t mode,
>   			err = -EBUSY;
>   			goto out;
>   		}
> -		did_set_md_closing = true;
> +		clear_md_closing = true;
>   		mutex_unlock(&mddev->open_mutex);
>   		sync_blockdev(bdev);
>   	}
> @@ -7728,6 +7736,12 @@ static int md_ioctl(struct block_device *bdev, blk_mode_t mode,
>   
>   	case STOP_ARRAY:
>   		err = do_md_stop(mddev, 0, bdev);
> +		if (!err)
> +			/*
> +			 * mddev has been stopped, keep the flag
> +			 * MD_CLOSING to prevent reuse.
> +			 */
> +			clear_md_closing = false;
>   		goto unlock;
>   
>   	case STOP_ARRAY_RO:
> @@ -7826,7 +7840,7 @@ static int md_ioctl(struct block_device *bdev, blk_mode_t mode,
>   				     mddev_unlock(mddev);
>   
>   out:
> -	if(did_set_md_closing)
> +	if (clear_md_closing)

I think code will be simplier if we just remove this local variable, and
replace this with:
if (test_bit(MD_CLOSING, &mddev->flags) && (err || cmd == STOP_ARRAY_RO))

And the same for patch 3.

Thanks,
Kuai

>   		clear_bit(MD_CLOSING, &mddev->flags);
>   	return err;
>   }
> 


  reply	other threads:[~2024-01-27  8:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-26  9:22 [PATCH v4 0/4] " linan666
2024-01-26  9:22 ` [PATCH v4 1/4] " linan666
2024-01-27  8:38   ` Yu Kuai [this message]
2024-01-26  9:22 ` [PATCH v4 2/4] md: factor out a helper to sync mddev linan666
2024-01-26  9:22 ` [PATCH v4 3/4] md: sync blockdev before stopping raid or setting readonly linan666
2024-01-26  9:22 ` [PATCH v4 4/4] md: check mddev->pers before calling md_set_readonly() linan666

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=51145653-9f9b-e6d5-1b3a-2b25ed3e95f1@huaweicloud.com \
    --to=yukuai1@huaweicloud.com \
    --cc=houtao1@huawei.com \
    --cc=linan666@huaweicloud.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=mariusz.tkaczyk@linux.intel.com \
    --cc=neilb@suse.com \
    --cc=shli@fb.com \
    --cc=song@kernel.org \
    --cc=yangerkun@huawei.com \
    --cc=yi.zhang@huawei.com \
    --cc=yukuai3@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®