mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-02 01:45:17 +00:00
nodedev: udev: Hook up virFileWaitForAccess to work around uevent race
If we find ourselves in the situation that the 'add' uevent has been fired earlier than the sysfs tree for a device was created, we should use the best-effort approach and give kernel some predetermined amount of time, thus waiting for the attributes to be ready rather than discarding the device from our device list forever. If those don't appear in the given time frame, we need to move on, since libvirt can't wait indefinitely. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1463285 Signed-off-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
parent
caf26412b6
commit
1af4580408
@ -1188,9 +1188,23 @@ udevProcessMediatedDevice(struct udev_device *dev,
|
||||
char *canonicalpath = NULL;
|
||||
virNodeDevCapMdevPtr data = &def->caps->data.mdev;
|
||||
|
||||
if (virAsprintf(&linkpath, "%s/mdev_type", udev_device_get_syspath(dev)) < 0)
|
||||
/* Because of a kernel uevent race, we might get the 'add' event prior to
|
||||
* the sysfs tree being ready, so any attempt to access any sysfs attribute
|
||||
* would result in ENOENT and us dropping the device, so let's work around
|
||||
* it by waiting for the attributes to become available.
|
||||
*/
|
||||
|
||||
if (virAsprintf(&linkpath, "%s/mdev_type",
|
||||
udev_device_get_syspath(dev)) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virFileWaitForExists(linkpath, 1, 100) < 0) {
|
||||
virReportSystemError(errno,
|
||||
_("failed to wait for file '%s' to appear"),
|
||||
linkpath);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virFileResolveLink(linkpath, &canonicalpath) < 0) {
|
||||
virReportSystemError(errno, _("failed to resolve '%s'"), linkpath);
|
||||
goto cleanup;
|
||||
|
Loading…
x
Reference in New Issue
Block a user