diff mbox series

[v2,1/3] md: Don't clear MD_CLOSING when the raid is about to stop

Message ID 20240117093707.2767209-2-linan666@huaweicloud.com (mailing list archive)
State Superseded, archived
Headers show
Series md: Don't clear MD_CLOSING when the raid is about to stop | expand

Commit Message

Li Nan Jan. 17, 2024, 9:37 a.m. UTC
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.

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>
---
 drivers/md/md.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

Comments

Mariusz Tkaczyk Jan. 18, 2024, 7:35 a.m. UTC | #1
On Wed, 17 Jan 2024 17:37:05 +0800
linan666@huaweicloud.com wrote:

> 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.
> 
> 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>
> ---
>  drivers/md/md.c | 16 +++++++++++++++-
>  1 file changed, 15 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index 9bdd57324c37..4bf821b89415 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;
> @@ -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 flag the
> +			 * MD_CLOSING to prevent reuse.
> +			 */
> +			did_set_md_closing = false;

Hello Nan,
The meaning of the "did_set_md_closing" is to notify that MD_CLOSING was set in
this function, to know how to behave on error.
You gave it another meaning "Do not clear MD_CLOSING because we want it to stay"
Please consider how to solve this confusion. I see the comment you added but I
think we can have this solved better, maybe just name it as "clear_md_closing"?

Anyway it looks acceptable to me:
Acked-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>

Thanks,
Mariusz
Li Nan Jan. 22, 2024, 2:14 a.m. UTC | #2
在 2024/1/18 15:35, Mariusz Tkaczyk 写道:
> On Wed, 17 Jan 2024 17:37:05 +0800
> linan666@huaweicloud.com wrote:
> 
>> 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.
>>
>> 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>
>> ---
>>   drivers/md/md.c | 16 +++++++++++++++-
>>   1 file changed, 15 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/md/md.c b/drivers/md/md.c
>> index 9bdd57324c37..4bf821b89415 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;
>> @@ -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 flag the
>> +			 * MD_CLOSING to prevent reuse.
>> +			 */
>> +			did_set_md_closing = false;
> 
> Hello Nan,
> The meaning of the "did_set_md_closing" is to notify that MD_CLOSING was set in
> this function, to know how to behave on error.
> You gave it another meaning "Do not clear MD_CLOSING because we want it to stay"
> Please consider how to solve this confusion. I see the comment you added but I
> think we can have this solved better, maybe just name it as "clear_md_closing"?
> 

Thanks for your review, I will rename it in next version.

> Anyway it looks acceptable to me:
> Acked-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
> 
> Thanks,
> Mariusz
> 
> .
diff mbox series

Patch

diff --git a/drivers/md/md.c b/drivers/md/md.c
index 9bdd57324c37..4bf821b89415 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;
@@ -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 flag the
+			 * MD_CLOSING to prevent reuse.
+			 */
+			did_set_md_closing = false;
 		goto unlock;
 
 	case STOP_ARRAY_RO: