From: John Ferlan Date: Wed, 22 Nov 2017 16:55:10 +0000 (-0500) Subject: nodedev: Move device enumumeration out of nodeStateInitialize X-Git-Tag: v4.0.0-rc1~74 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9f0ae0b1;p=thirdparty%2Flibvirt.git nodedev: Move device enumumeration out of nodeStateInitialize Let's move the udevEnumerateDevices into a thread to "speed up" the initialization process. If the enumeration fails we can set the Quit flag to ensure that udevEventHandleCallback will not run. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety --- diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c index 1e1b71742b..e0fca6159e 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1891,6 +1891,25 @@ udevSetupSystemDev(void) } +static void +nodeStateInitializeEnumerate(void *opaque) +{ + struct udev *udev = opaque; + udevEventDataPtr priv = driver->privateData; + + /* Populate with known devices */ + if (udevEnumerateDevices(udev) != 0) + goto error; + + return; + + error: + virObjectLock(priv); + priv->threadQuit = true; + virObjectUnlock(priv); +} + + static int udevPCITranslateInit(bool privileged ATTRIBUTE_UNUSED) { @@ -1922,6 +1941,7 @@ nodeStateInitialize(bool privileged, { udevEventDataPtr priv = NULL; struct udev *udev = NULL; + virThread enumThread; if (VIR_ALLOC(driver) < 0) return -1; @@ -2002,9 +2022,12 @@ nodeStateInitialize(bool privileged, if (udevSetupSystemDev() != 0) goto cleanup; - /* Populate with known devices */ - if (udevEnumerateDevices(udev) != 0) + if (virThreadCreate(&enumThread, false, nodeStateInitializeEnumerate, + udev) < 0) { + virReportSystemError(errno, "%s", + _("failed to create udev enumerate thread")); goto cleanup; + } return 0;