From: Hannes Reinecke <hare@suse.de>
To: Daniel Wagner <dwagner@suse.de>,
"linux-nvme@lists.infradead.org" <linux-nvme@lists.infradead.org>
Cc: Keith Busch <kbusch@kernel.org>, Christoph Hellwig <hch@lst.de>,
Sagi Grimberg <sagi@grimberg.me>
Subject: Re: race between nvme device creation and discovery?
Date: Mon, 5 Feb 2024 14:02:04 +0900 [thread overview]
Message-ID: <e0e89568-d3af-4d4e-9652-59d04f2c1977@suse.de> (raw)
In-Reply-To: <i4bmvgd3u7shgizqgtdtssdz5v3wc76l6bcce6fcbvoft32gzk@rztzeut4azvj>
On 2/2/24 23:16, Daniel Wagner wrote:
> I am trying to figure out why some of the blktests fail randomly when
> running with FC as transport. This failure only appear when the
> autoconnect is running in the background. A clear indication we still
> have some sort of interference with it.
>
> nvme/030 fails a bit more often then the rest, and it might just because
> it issues several 'nvme discover' commands, many other tests only a one.
>
> When a test fails, it fails with
>
> failed to lookup subsystem for controller nvme0
>
> which is from libnvme when it iterates over sysfs to gather infos.
>
> subsysname = nvme_ctrl_lookup_subsystem_name(r, name);
> if (!subsysname) {
> nvme_msg(r, LOG_ERR,
> "failed to lookup subsystem for controller %s\n",
> name);
> errno = ENXIO;
> return NULL;
> }
>
> My current theory is when a new controller isa dded is not atomic from
> the POV userland and thus libnvme is able to observe a situation when
> there is controller but the matching subsystem is not yet visible.
>
> So something like:
>
> nvme_init_ctrl
> cdev_device_add
>
> // libnvme iterates over sysfs
>
> nvme_init_ctrl_finish
> nvme_init_identify
> nvme_init_subsystem
> device_add // nvme-subsys%d
> sysfs_create_link // subsys->dev -> ctrl-device
>
> Does this any sense? And if so what could be done? Should we add some
> retry logic to libnvme?
>
Hehe. Good old sysfs.
This is a common issue with sysfs, and we've even had a retry loop in
udev back in them days to avoid these kind of things.
Point is, uevent will be sent out with device_add(), causing udev to
run, running udev rules, and eventually call into libnvme to scan the
device. But as you rightly pointed out, the sysfs link is only created
_after_ the event has been sent, so there's a race window during which
libnvme will fails to read the link, landing us with the scenario above.
While we could add a retry logic to libnvme, I'm not really convinced
this is a good idea; in the end, who's to tell how long we should wait?
A second? Several seconds? A minute? Several minutes?
Also not that sysfs_create_link() has a return code, so the link might
not be created at all ...
A possibly better way here would be to suppress uevents on device_add(),
and only send out events once the device is fully set up, ie just before
the 'return 0'.
Let me see if I can whip up a patch ...
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), GF: Ivo Totev, Andrew McDonald,
Werner Knoblich
next prev parent reply other threads:[~2024-02-05 5:02 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-02 15:16 race between nvme device creation and discovery? Daniel Wagner
2024-02-05 5:02 ` Hannes Reinecke [this message]
2024-02-05 7:47 ` Daniel Wagner
2024-02-05 7:57 ` Hannes Reinecke
2024-02-05 8:46 ` Daniel Wagner
2024-02-05 9:20 ` Maurizio Lombardi
2024-02-05 9:20 ` Maurizio Lombardi
2024-02-05 10:07 ` Daniel Wagner
2024-02-05 10:17 ` Daniel Wagner
2024-02-05 17:13 ` Daniel Wagner
2024-02-06 12:45 ` Daniel Wagner
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=e0e89568-d3af-4d4e-9652-59d04f2c1977@suse.de \
--to=hare@suse.de \
--cc=dwagner@suse.de \
--cc=hch@lst.de \
--cc=kbusch@kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=sagi@grimberg.me \
/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