[PATCH v6 6/9] nodedev: udev: Split udevEventHandleCallback in two functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch splits udevEventHandleCallback in two (introduces
udevEventHandleThread) in order to be later able to refactor the latter
to actually become a normal thread which will wait some time for the
kernel to create the whole sysfs tree for a device as we cannot do that
in the event loop directly.

Signed-off-by: Erik Skultety <eskultet@xxxxxxxxxx>
---
 src/node_device/node_device_udev.c | 41 +++++++++++++++++++++++++++-----------
 1 file changed, 29 insertions(+), 12 deletions(-)

diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index 6882517e6..0167ad596 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -1679,32 +1679,49 @@ udevEventMonitorSanityCheck(udevEventDataPtr priv,
 
 
 static void
+udevEventHandleThread(void *opaque)
+{
+    udevEventDataPtr priv = driver->privateData;
+    int fd = (intptr_t) opaque;
+    struct udev_device *device = NULL;
+
+    virObjectLock(priv);
+
+    if (!udevEventMonitorSanityCheck(priv, fd)) {
+        virObjectUnlock(priv);
+        return;
+    }
+
+    device = udev_monitor_receive_device(priv->udev_monitor);
+    virObjectUnlock(priv);
+
+    if (device == NULL) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("udev_monitor_receive_device returned NULL"));
+        return;
+    }
+
+    udevHandleOneDevice(device);
+    udev_device_unref(device);
+}
+
+
+static void
 udevEventHandleCallback(int watch ATTRIBUTE_UNUSED,
                         int fd,
                         int events ATTRIBUTE_UNUSED,
                         void *data ATTRIBUTE_UNUSED)
 {
     udevEventDataPtr priv = driver->privateData;
-    struct udev_device *device = NULL;
 
     virObjectLock(priv);
-
     if (!udevEventMonitorSanityCheck(priv, fd)) {
         virObjectUnlock(priv);
         return;
     }
-
-    device = udev_monitor_receive_device(priv->udev_monitor);
     virObjectUnlock(priv);
 
-    if (device == NULL) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("udev_monitor_receive_device returned NULL"));
-        return;
-    }
-
-    udevHandleOneDevice(device);
-    udev_device_unref(device);
+    udevEventHandleThread((void *)(intptr_t) fd);
 }
 
 
-- 
2.13.6

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux