]> xenbits.xensource.com Git - libvirt.git/commitdiff
nodedev: Move device enumumeration out of nodeStateInitialize
authorJohn Ferlan <jferlan@redhat.com>
Wed, 22 Nov 2017 16:55:10 +0000 (11:55 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Thu, 4 Jan 2018 12:13:55 +0000 (07:13 -0500)
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 <jferlan@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
src/node_device/node_device_udev.c

index 1e1b71742bdf9dfa59373d15e98ef6d05ec21bfc..e0fca6159e05669866435fe62c37f0e8c1f91e56 100644 (file)
@@ -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;