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

[libvirt] [PATCH v2 2/5] udev: Split udevEventHandleCallback in two functions



This patch splits udevEventHandleCallback in two (introduces
udevEventHandleThread) in order to be later able to refactor the latter
to actually become a detached 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 redhat com>
---
 src/node_device/node_device_udev.c | 53 ++++++++++++++++++++++++++------------
 1 file changed, 36 insertions(+), 17 deletions(-)

diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index 0b4e22f29..9e3a0f9d7 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -1646,36 +1646,55 @@ udevCheckMonitorFD(struct udev_monitor *udev_monitor, int fd)
 
 
 static void
+udevEventHandleThread(void *opaque ATTRIBUTE_UNUSED)
+{
+    struct udev_device *device = NULL;
+    struct udev_monitor *udev_monitor = NULL;
+    int fd = (intptr_t) opaque;
+
+    nodeDeviceLock();
+    udev_monitor = DRV_STATE_UDEV_MONITOR(driver);
+
+    if (!udevCheckMonitorFD(udev_monitor, fd))
+        goto unlock;
+
+    device = udev_monitor_receive_device(udev_monitor);
+    if (device == NULL) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("udev_monitor_receive_device returned NULL"));
+        goto unlock;
+    }
+    nodeDeviceUnlock();
+    udevHandleOneDevice(device);
+
+ cleanup:
+    udev_device_unref(device);
+    return;
+
+ unlock:
+    nodeDeviceUnlock();
+    goto cleanup;
+}
+
+
+static void
 udevEventHandleCallback(int watch ATTRIBUTE_UNUSED,
                         int fd,
                         int events ATTRIBUTE_UNUSED,
                         void *data ATTRIBUTE_UNUSED)
 {
-    struct udev_device *device = NULL;
     struct udev_monitor *udev_monitor = NULL;
 
     nodeDeviceLock();
     udev_monitor = DRV_STATE_UDEV_MONITOR(driver);
 
-    if (!udevCheckMonitorFD(udev_monitor, fd))
-        goto unlock;
-
-    if (!(device = udev_monitor_receive_device(udev_monitor))) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("udev_monitor_receive_device returned NULL"));
-        goto unlock;
+    if (!udevCheckMonitorFD(udev_monitor, fd)) {
+        nodeDeviceUnlock();
+        return;
     }
-
     nodeDeviceUnlock();
-    udevHandleOneDevice(device);
-
- cleanup:
-    udev_device_unref(device);
-    return;
 
- unlock:
-    nodeDeviceUnlock();
-    goto cleanup;
+    udevEventHandleThread((void *)(intptr_t) fd);
 }
 
 
-- 
2.13.3


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