[PATCH v2 19/20] node_device_udev: Pass the `udevEventData` via parameter and use refcounting

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

 



Instead of accessing the global `driver` object pass the `udevEventData` as
parameter to the thread handler and watch callback. This has the advantage that:
1. proper refcounting
2. easier to read and test

Reviewed-by: Jonathon Jongsma <jjongsma@xxxxxxxxxx>
Reviewed-by: Boris Fiuczynski <fiuczy@xxxxxxxxxxxxx>
Signed-off-by: Marc Hartmayer <mhartmay@xxxxxxxxxxxxx>
---
 src/node_device/node_device_udev.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index 8687be942722..14d44d5bcd0e 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -1863,7 +1863,7 @@ udevEventMonitorSanityCheck(udevEventData *priv,
 
 /**
  * udevEventHandleThread
- * @opaque: unused
+ * @opaque: udevEventData
  *
  * Thread to handle the udevEventHandleCallback processing when udev
  * tells us there's a device change for us (add, modify, delete, etc).
@@ -1882,9 +1882,9 @@ udevEventMonitorSanityCheck(udevEventData *priv,
  * would still come into play.
  */
 static void
-udevEventHandleThread(void *opaque G_GNUC_UNUSED)
+udevEventHandleThread(void *opaque)
 {
-    udevEventData *priv = driver->privateData;
+    g_autoptr(udevEventData) priv = opaque;
     struct udev_device *device = NULL;
 
     /* continue rather than break from the loop on non-fatal errors */
@@ -1950,9 +1950,9 @@ static void
 udevEventHandleCallback(int watch G_GNUC_UNUSED,
                         int fd,
                         int events G_GNUC_UNUSED,
-                        void *data G_GNUC_UNUSED)
+                        void *data)
 {
-    udevEventData *priv = driver->privateData;
+    udevEventData *priv = data;
     VIR_LOCK_GUARD lock = virObjectLockGuard(priv);
 
     if (!udevEventMonitorSanityCheck(priv, fd))
@@ -2489,7 +2489,7 @@ nodeStateInitialize(bool privileged,
 
     priv->udevThread = g_new0(virThread, 1);
     if (virThreadCreateFull(priv->udevThread, true, udevEventHandleThread,
-                            "udev-event", false, NULL) < 0) {
+                            "udev-event", false, virObjectRef(priv)) < 0) {
         virReportSystemError(errno, "%s",
                              _("failed to create udev handler thread"));
         goto unlock;
@@ -2505,7 +2505,7 @@ nodeStateInitialize(bool privileged,
      * that appear while the enumeration is taking place.  */
     priv->watch = virEventAddHandle(udev_monitor_get_fd(priv->udev_monitor),
                                     VIR_EVENT_HANDLE_READABLE,
-                                    udevEventHandleCallback, NULL, NULL);
+                                    udevEventHandleCallback, virObjectRef(priv), virObjectUnref);
     if (priv->watch == -1)
         goto unlock;
 
-- 
2.34.1
_______________________________________________
Devel mailing list -- devel@xxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx




[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