From: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
To: Martin Wilck <mwilck@suse.com>
Cc: Li Xiao Keng <lixiaokeng@huawei.com>,
Jes Sorensen <jes@trained-monkey.org>,
Paul Menzel <pmenzel@molgen.mpg.de>, Coly Li <colyli@suse.de>,
linux-raid@vger.kernel.org, linfeilong <linfeilong@huawei.com>,
louhongxiang@huawei.com,
"liuzhiqiang (I)" <liuzhiqiang26@huawei.com>,
miaoguanqin <miaoguanqin@huawei.com>
Subject: Re: [QUESTION] How to fix the race of "mdadm --add" and "mdadm mdadm --incremental --export"
Date: Tue, 14 Mar 2023 16:59:38 +0100 [thread overview]
Message-ID: <20230314165938.00003030@linux.intel.com> (raw)
In-Reply-To: <c00c211a3126d7a30c662117d28f3a4a9c81f7dc.camel@suse.com>
On Tue, 14 Mar 2023 16:04:23 +0100
Martin Wilck <mwilck@suse.com> wrote:
> On Tue, 2023-03-14 at 22:58 +0800, Li Xiao Keng wrote:
> > Hi,
> > Here we meet a question. When we add a new disk to a raid, it may
> > return
> > -EBUSY.
> > The main process of --add(for example md0, sdf):
> > 1.dev_open(sdf)
> > 2.add_to_super
> > 3.write_init_super
> > 4.fsync(fd)
> > 5.close(fd)
> > 6.ioctl(ADD_NEW_DISK).
> > However, there will be some udev(change of sdf) event after step5.
> > Then
> > "/usr/sbin/mdadm --incremental --export $devnode --offroot
> > $env{DEVLINKS}"
> > will be run, and the sdf will be added to md0. After that, step6 will
> > return
> > -EBUSY.
> > It is a problem to user. First time adding disk does not return
> > success
> > but disk is actually added. And I have no good idea to deal with it.
> > Please
> > give some great advice.
>
> I haven't looked at the code in detail, but off the top of my head, it
> should help to execute step 5 after step 6. The close() in step 5
> triggers the uevent via inotify; doing it after the ioctl should avoid
> the above problem.
Hi,
That will result in EBUSY in everytime. mdadm will always handle
descriptor and kernel will refuse to add the drive.
>
> Another obvious workaround in mdadm would be to check the state of the
> array in the EBUSY case and find out that the disk had already been
> added.
>
> But again, this was just a high-level guess.
>
> Martin
>
Hmm... I'm not a native expert but why we cannot write metadata after adding
drive to array? Why kernel can't handle that?
Ideally, we should lock device and block udev- I know that there is flock
based API to do that but I'm not sure if flock() won't cause the same problem.
There is also something like "udev-md-raid-creating.rules". Maybe we can reuse
it?
Thanks,
Mariusz
next prev parent reply other threads:[~2023-03-14 15:59 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-14 14:58 [QUESTION] How to fix the race of "mdadm --add" and "mdadm mdadm --incremental --export" Li Xiao Keng
2023-03-14 15:04 ` Martin Wilck
2023-03-14 15:59 ` Mariusz Tkaczyk [this message]
2023-03-14 16:11 ` Martin Wilck
2023-03-15 10:10 ` Mariusz Tkaczyk
2023-03-15 13:10 ` Li Xiao Keng
2023-03-15 14:14 ` Martin Wilck
2023-03-15 14:57 ` Li Xiao Keng
2023-03-15 15:01 ` Martin Wilck
2023-03-16 10:44 ` Mariusz Tkaczyk
2023-03-20 15:36 ` Martin Wilck
2023-03-20 15:51 ` Mariusz Tkaczyk
2023-03-14 16:40 ` Coly Li
2023-03-15 2:25 ` Li Xiao Keng
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=20230314165938.00003030@linux.intel.com \
--to=mariusz.tkaczyk@linux.intel.com \
--cc=colyli@suse.de \
--cc=jes@trained-monkey.org \
--cc=linfeilong@huawei.com \
--cc=linux-raid@vger.kernel.org \
--cc=liuzhiqiang26@huawei.com \
--cc=lixiaokeng@huawei.com \
--cc=louhongxiang@huawei.com \
--cc=miaoguanqin@huawei.com \
--cc=mwilck@suse.com \
--cc=pmenzel@molgen.mpg.de \
/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 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.