* [RESEND] md: adding a new flag MD_DELETING
@ 2021-06-05 15:29 Lidong Zhong
2021-06-09 5:29 ` Song Liu
2021-06-09 6:32 ` Paul Menzel
0 siblings, 2 replies; 4+ messages in thread
From: Lidong Zhong @ 2021-06-05 15:29 UTC (permalink / raw)
To: song; +Cc: linux-raid
The mddev data structure is freed in mddev_delayed_delete(), which is
schedualed after the array is deconfigured completely when stopping. So
there is a race window between md_open() and do_md_stop(), which leads
to /dev/mdX can still be opened by userspace even it's not accessible
any more. As a result, a DeviceDisappeared event will not be able to be
monitored by mdadm in monitor mode. This patch tries to fix it by adding
this new flag MD_DELETING.
Signed-off-by: Lidong Zhong <lidong.zhong@suse.com>
---
drivers/md/md.c | 4 +++-
drivers/md/md.h | 2 ++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 49f897fbb89b..e8fa100a0777 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -6456,6 +6456,7 @@ static int do_md_stop(struct mddev *mddev, int mode,
md_clean(mddev);
if (mddev->hold_active == UNTIL_STOP)
mddev->hold_active = 0;
+ set_bit(MD_DELETING, &mddev->flags);
}
md_new_event(mddev);
sysfs_notify_dirent_safe(mddev->sysfs_state);
@@ -7843,7 +7844,8 @@ static int md_open(struct block_device *bdev, fmode_t mode)
if ((err = mutex_lock_interruptible(&mddev->open_mutex)))
goto out;
- if (test_bit(MD_CLOSING, &mddev->flags)) {
+ if (test_bit(MD_CLOSING, &mddev->flags) ||
+ (test_bit(MD_DELETING, &mddev->flags) && mddev->pers == NULL)) {
mutex_unlock(&mddev->open_mutex);
err = -ENODEV;
goto out;
diff --git a/drivers/md/md.h b/drivers/md/md.h
index fb7eab58cfd5..b70f8885da7a 100644
--- a/drivers/md/md.h
+++ b/drivers/md/md.h
@@ -262,6 +262,8 @@ enum mddev_flags {
MD_BROKEN, /* This is used in RAID-0/LINEAR only, to stop
* I/O in case an array member is gone/failed.
*/
+ MD_DELETING, /* If set, we are deleting the array, do not open
+ * it then */
};
enum mddev_sb_flags {
--
2.26.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [RESEND] md: adding a new flag MD_DELETING
2021-06-05 15:29 [RESEND] md: adding a new flag MD_DELETING Lidong Zhong
@ 2021-06-09 5:29 ` Song Liu
2021-06-10 0:53 ` Zhong Lidong
2021-06-09 6:32 ` Paul Menzel
1 sibling, 1 reply; 4+ messages in thread
From: Song Liu @ 2021-06-09 5:29 UTC (permalink / raw)
To: Lidong Zhong; +Cc: linux-raid
Hi Lidong,
On Sat, Jun 5, 2021 at 8:29 AM Lidong Zhong <lidong.zhong@suse.com> wrote:
>
> The mddev data structure is freed in mddev_delayed_delete(), which is
> schedualed after the array is deconfigured completely when stopping. So
> there is a race window between md_open() and do_md_stop(), which leads
> to /dev/mdX can still be opened by userspace even it's not accessible
> any more. As a result, a DeviceDisappeared event will not be able to be
> monitored by mdadm in monitor mode. This patch tries to fix it by adding
> this new flag MD_DELETING.
>
> Signed-off-by: Lidong Zhong <lidong.zhong@suse.com>
The patch still contains a lot of bad format strings. How did you send
it? I guess
it is not from git-send-email?
Thanks,
Song
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RESEND] md: adding a new flag MD_DELETING
2021-06-05 15:29 [RESEND] md: adding a new flag MD_DELETING Lidong Zhong
2021-06-09 5:29 ` Song Liu
@ 2021-06-09 6:32 ` Paul Menzel
1 sibling, 0 replies; 4+ messages in thread
From: Paul Menzel @ 2021-06-09 6:32 UTC (permalink / raw)
To: Lidong Zhong; +Cc: linux-raid, Song Liu
Dear Lidong,
Am 05.06.21 um 17:29 schrieb Lidong Zhong:
I’d use imperative mood in the commit message summary [1]: md:
> Add new flag MD_DELETING
> The mddev data structure is freed in mddev_delayed_delete(), which is
> schedualed after the array is deconfigured completely when stopping. So
scheduled
> there is a race window between md_open() and do_md_stop(), which leads
> to /dev/mdX can still be opened by userspace even it's not accessible
> any more. As a result, a DeviceDisappeared event will not be able to be
> monitored by mdadm in monitor mode. This patch tries to fix it by adding
> this new flag MD_DELETING.
>
> Signed-off-by: Lidong Zhong <lidong.zhong@suse.com>
> ---
> drivers/md/md.c | 4 +++-
> drivers/md/md.h | 2 ++
> 2 files changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index 49f897fbb89b..e8fa100a0777 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -6456,6 +6456,7 @@ static int do_md_stop(struct mddev *mddev, int mode,
> md_clean(mddev);
> if (mddev->hold_active == UNTIL_STOP)
> mddev->hold_active = 0;
> + set_bit(MD_DELETING, &mddev->flags);
> }
> md_new_event(mddev);
> sysfs_notify_dirent_safe(mddev->sysfs_state);
> @@ -7843,7 +7844,8 @@ static int md_open(struct block_device *bdev, fmode_t mode)
> if ((err = mutex_lock_interruptible(&mddev->open_mutex)))
> goto out;
>
> - if (test_bit(MD_CLOSING, &mddev->flags)) {
> + if (test_bit(MD_CLOSING, &mddev->flags) ||
> + (test_bit(MD_DELETING, &mddev->flags) && mddev->pers == NULL)) {
> mutex_unlock(&mddev->open_mutex);
> err = -ENODEV;
> goto out;
> diff --git a/drivers/md/md.h b/drivers/md/md.h
> index fb7eab58cfd5..b70f8885da7a 100644
> --- a/drivers/md/md.h
> +++ b/drivers/md/md.h
> @@ -262,6 +262,8 @@ enum mddev_flags {
> MD_BROKEN, /* This is used in RAID-0/LINEAR only, to stop
> * I/O in case an array member is gone/failed.
> */
> + MD_DELETING, /* If set, we are deleting the array, do not open
> + * it then */
> };
>
> enum mddev_sb_flags {
Kind regards,
Paul
[1]: https://chris.beams.io/posts/git-commit/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RESEND] md: adding a new flag MD_DELETING
2021-06-09 5:29 ` Song Liu
@ 2021-06-10 0:53 ` Zhong Lidong
0 siblings, 0 replies; 4+ messages in thread
From: Zhong Lidong @ 2021-06-10 0:53 UTC (permalink / raw)
To: Song Liu; +Cc: linux-raid
On 6/9/21 1:29 PM, Song Liu wrote:
> Hi Lidong,
>
> On Sat, Jun 5, 2021 at 8:29 AM Lidong Zhong <lidong.zhong@suse.com> wrote:
>>
>> The mddev data structure is freed in mddev_delayed_delete(), which is
>> schedualed after the array is deconfigured completely when stopping. So
>> there is a race window between md_open() and do_md_stop(), which leads
>> to /dev/mdX can still be opened by userspace even it's not accessible
>> any more. As a result, a DeviceDisappeared event will not be able to be
>> monitored by mdadm in monitor mode. This patch tries to fix it by adding
>> this new flag MD_DELETING.
>>
>> Signed-off-by: Lidong Zhong <lidong.zhong@suse.com>
>
> The patch still contains a lot of bad format strings. How did you send
> it? I guess
> it is not from git-send-email?
>
Hi Song,
Sorry it still doesn't work, but I did send it from git-send-email. I'll
send the patch after I figure out the reason.
Regards,
Lidong
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-06-10 0:54 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-05 15:29 [RESEND] md: adding a new flag MD_DELETING Lidong Zhong
2021-06-09 5:29 ` Song Liu
2021-06-10 0:53 ` Zhong Lidong
2021-06-09 6:32 ` Paul Menzel
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.