From: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
To: Martin Wilck <mwilck@suse.com>
Cc: Li Xiao Keng <lixiaokeng@huawei.com>, Song Liu <song@kernel.org>,
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: Thu, 16 Mar 2023 11:44:32 +0100 [thread overview]
Message-ID: <20230316114314.00003004@linux.intel.com> (raw)
In-Reply-To: <e5e2cf8fc9903aab6a781c5b925d12023a59b387.camel@suse.com>
On Wed, 15 Mar 2023 16:01:26 +0100
Martin Wilck <mwilck@suse.com> wrote:
> On Wed, 2023-03-15 at 22:57 +0800, Li Xiao Keng wrote:
> >
> >
> > On 2023/3/15 22:14, Martin Wilck wrote:
> > > On Wed, 2023-03-15 at 21:10 +0800, Li Xiao Keng wrote:
> > > > >
> > > > I test move close() after ioctl(). The reason of EBUSY is that
> > > > mdadm
> > > > open(sdf) with O_EXCL. So fd should be closed before ioctl. When
> > > > I
> > > > remove
> > > > O_EXCL, ioctl() will return success.
> > >
> > > This makes sense. I suppose mdadm must use O_EXCL if it modifies
> > > RAID
> > > meta data, otherwise data corruption is just too likely. It is also
> > > impossible to drop the O_EXCL flag with fcntl() without closing the
> > > fd.
> > >
> > > So, if mdadm must close the fd before calling ioctl(), the race can
> > > hardly be avoided. The close() will cause a uevent, and nothing
> > > prevents the udev rules from running before the ioctl() returns.
> > >
> > Now I find that close() cause a change udev. Is it necessary to
> > import
> > "mdadm --incremental --export" when change udev cause? Can we ignore
> > it?
>
> Normally this is what you want to happen if a change uevent for a MD
> member device is processed.
>
> The case you're looking at is the exception, as another instance of
> mdamn is handling the device right at this point in time.
>
> Martin
>
Hi,
Code snipped from Incremental, devname seems to be our disk:
/* 4/ Check if array exists.
*/
if (map_lock(&map))
pr_err("failed to get exclusive lock on mapfile\n");
/* Now check we can get O_EXCL. If not, probably "mdadm -A" has
* taken over
*/
dfd = dev_open(devname, O_RDONLY|O_EXCL);
The map_lock in --add should resolve your issue. It seems to be simplest
option. I we cannot lock udev effectively then it seems to be the best one.
We need to control adding the device because external metadata is quite
different and for example in IMSM the initial metadata doesn't point to
container wanted by user. Hope it clarifies all objections here.
I don't see any blocker from using locking mechanism for --add.
Thanks,
Mariusz
next prev parent reply other threads:[~2023-03-16 10:44 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
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 [this message]
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=20230316114314.00003004@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 \
--cc=song@kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).