On 9/20/22 3:23 PM, Jonathon Jongsma wrote:
Rather than listening to 'add' udev events, listen for
'bind' events
instead. When we get an 'add' event, the sysfs tree for the device is
often not ready yet. In that case we sleep in a loop until the sysfs
tree appears, or give up after a timeout.
udev added the 'bind' event to give userspace a signal that indicated
when driver-specific attributes were available to be used. In other
words, the sysfs tree *should* be ready and usable at this point.
But just to be safe, we'll leave the wait loop in the code to handle
corner cases, with the hope that it'll never be used.
The udev 'bind' event was added in kernel 4.14 and the oldest platform
we support has kernel 4.18, so it should be safe to make this change.
Previous discussion on the mailing list:
https://listman.redhat.com/archives/libvir-list/2022-August/233933.html
Signed-off-by: Jonathon Jongsma <jjongsma(a)redhat.com>
Reviewed-by: Laine Stump <laine(a)redhat.com>
(I'm giving this based on the assumption that you've tried it out with a
few examples of adding devices and they properly show up in virsh
nodedev-list, etc. There is always the chance may be some odd case where
the bind event isn't generated when it should be, but we're never going
to find out by just talking about it :-))
---
src/node_device/node_device_udev.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index 07c10f0d88..781a8b32a6 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -1759,7 +1759,7 @@ udevHandleOneDevice(struct udev_device *device)
VIR_DEBUG("udev action: '%s': %s", action,
udev_device_get_syspath(device));
- if (STREQ(action, "add") || STREQ(action, "change"))
+ if (STREQ(action, "bind") || STREQ(action, "change"))
return udevAddOneDevice(device);
if (STREQ(action, "remove"))