[PATCH 4/8] Convert drivers to thread safe APIs for adding callbacks

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

 



From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>

* src/libxl/libxl_driver.c, src/lxc/lxc_driver.c,
  src/qemu/qemu_driver.c, src/remote/remote_driver.c,
  src/test/test_driver.c, src/uml/uml_driver.c,
  src/vbox/vbox_tmpl.c, src/xen/xen_driver.c: Convert
  to threadsafe APIs
---
 src/libxl/libxl_driver.c   |   18 ++++++------
 src/lxc/lxc_driver.c       |   18 ++++++------
 src/qemu/qemu_driver.c     |   18 ++++++------
 src/remote/remote_driver.c |   64 ++++++++++++++++++-------------------------
 src/test/test_driver.c     |   14 +++++-----
 src/uml/uml_driver.c       |   18 ++++++------
 src/vbox/vbox_tmpl.c       |   24 ++++++++--------
 src/xen/xen_driver.c       |   10 +++---
 8 files changed, 87 insertions(+), 97 deletions(-)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 46504dc..b9382ee 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -1115,8 +1115,8 @@ libxlClose(virConnectPtr conn ATTRIBUTE_UNUSED)
     libxlDriverPrivatePtr driver = conn->privateData;
 
     libxlDriverLock(driver);
-    virDomainEventCallbackListRemoveConn(conn,
-                                         driver->domainEventState->callbacks);
+    virDomainEventStateDeregisterConn(conn,
+                                      driver->domainEventState);
     libxlDriverUnlock(driver);
     conn->privateData = NULL;
     return 0;
@@ -3404,9 +3404,9 @@ libxlDomainEventRegister(virConnectPtr conn,
     int ret;
 
     libxlDriverLock(driver);
-    ret = virDomainEventCallbackListAdd(conn,
-                                        driver->domainEventState->callbacks,
-                                        callback, opaque, freecb);
+    ret = virDomainEventStateRegister(conn,
+                                      driver->domainEventState,
+                                      callback, opaque, freecb);
     libxlDriverUnlock(driver);
 
     return ret;
@@ -3851,10 +3851,10 @@ libxlDomainEventRegisterAny(virConnectPtr conn, virDomainPtr dom, int eventID,
     int ret;
 
     libxlDriverLock(driver);
-    if (virDomainEventCallbackListAddID(conn,
-                                        driver->domainEventState->callbacks,
-                                        dom, eventID, callback, opaque,
-                                        freecb, &ret) < 0)
+    if (virDomainEventStateRegisterID(conn,
+                                      driver->domainEventState,
+                                      dom, eventID, callback, opaque,
+                                      freecb, &ret) < 0)
         ret = -1;
     libxlDriverUnlock(driver);
 
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 6b17c75..6a9ebde 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -179,8 +179,8 @@ static int lxcClose(virConnectPtr conn)
     lxc_driver_t *driver = conn->privateData;
 
     lxcDriverLock(driver);
-    virDomainEventCallbackListRemoveConn(conn,
-                                         driver->domainEventState->callbacks);
+    virDomainEventStateDeregisterConn(conn,
+                                      driver->domainEventState);
     lxcProcessAutoDestroyRun(driver, conn);
     lxcDriverUnlock(driver);
 
@@ -2126,9 +2126,9 @@ lxcDomainEventRegister(virConnectPtr conn,
     int ret;
 
     lxcDriverLock(driver);
-    ret = virDomainEventCallbackListAdd(conn,
-                                        driver->domainEventState->callbacks,
-                                        callback, opaque, freecb);
+    ret = virDomainEventStateRegister(conn,
+                                      driver->domainEventState,
+                                      callback, opaque, freecb);
     lxcDriverUnlock(driver);
 
     return ret;
@@ -2164,10 +2164,10 @@ lxcDomainEventRegisterAny(virConnectPtr conn,
     int ret;
 
     lxcDriverLock(driver);
-    if (virDomainEventCallbackListAddID(conn,
-                                        driver->domainEventState->callbacks,
-                                        dom, eventID,
-                                        callback, opaque, freecb, &ret) < 0)
+    if (virDomainEventStateRegisterID(conn,
+                                      driver->domainEventState,
+                                      dom, eventID,
+                                      callback, opaque, freecb, &ret) < 0)
         ret = -1;
     lxcDriverUnlock(driver);
 
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 7423340..40bd30f 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -900,8 +900,8 @@ static int qemudClose(virConnectPtr conn) {
 
     /* Get rid of callbacks registered for this conn */
     qemuDriverLock(driver);
-    virDomainEventCallbackListRemoveConn(conn,
-                                         driver->domainEventState->callbacks);
+    virDomainEventStateDeregisterConn(conn,
+                                      driver->domainEventState);
     qemuProcessAutoDestroyRun(driver, conn);
     qemuDriverUnlock(driver);
 
@@ -8142,9 +8142,9 @@ qemuDomainEventRegister(virConnectPtr conn,
     int ret;
 
     qemuDriverLock(driver);
-    ret = virDomainEventCallbackListAdd(conn,
-                                        driver->domainEventState->callbacks,
-                                        callback, opaque, freecb);
+    ret = virDomainEventStateRegister(conn,
+                                      driver->domainEventState,
+                                      callback, opaque, freecb);
     qemuDriverUnlock(driver);
 
     return ret;
@@ -8180,10 +8180,10 @@ qemuDomainEventRegisterAny(virConnectPtr conn,
     int ret;
 
     qemuDriverLock(driver);
-    if (virDomainEventCallbackListAddID(conn,
-                                        driver->domainEventState->callbacks,
-                                        dom, eventID,
-                                        callback, opaque, freecb, &ret) < 0)
+    if (virDomainEventStateRegisterID(conn,
+                                      driver->domainEventState,
+                                      dom, eventID,
+                                      callback, opaque, freecb, &ret) < 0)
         ret = -1;
     qemuDriverUnlock(driver);
 
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index a0cf7d3..a10bcad 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -3124,13 +3124,8 @@ static int remoteDomainEventRegister(virConnectPtr conn,
 
     remoteDriverLock(priv);
 
-    if (priv->domainEventState->timer < 0) {
-         remoteError(VIR_ERR_NO_SUPPORT, "%s", _("no event support"));
-         goto done;
-    }
-
-    if ((count = virDomainEventCallbackListAdd(conn, priv->domainEventState->callbacks,
-                                               callback, opaque, freecb)) < 0) {
+    if ((count = virDomainEventStateRegister(conn, priv->domainEventState,
+                                             callback, opaque, freecb)) < 0) {
          remoteError(VIR_ERR_RPC, "%s", _("adding cb to list"));
          goto done;
     }
@@ -3155,17 +3150,16 @@ static int remoteDomainEventDeregister(virConnectPtr conn,
 {
     struct private_data *priv = conn->privateData;
     int rv = -1;
+    int count;
 
     remoteDriverLock(priv);
 
-    if (virDomainEventStateDeregister(conn,
-                                      priv->domainEventState,
-                                      callback) < 0)
+    if ((count = virDomainEventStateDeregister(conn,
+                                               priv->domainEventState,
+                                               callback)) < 0)
         goto done;
 
-    if (virDomainEventCallbackListCountID(conn,
-                                          priv->domainEventState->callbacks,
-                                          VIR_DOMAIN_EVENT_ID_LIFECYCLE) == 0) {
+    if (count == 0) {
         /* Tell the server when we are the last callback deregistering */
         if (call (conn, priv, 0, REMOTE_PROC_DOMAIN_EVENTS_DEREGISTER,
                   (xdrproc_t) xdr_void, (char *) NULL,
@@ -3763,20 +3757,15 @@ static int remoteDomainEventRegisterAny(virConnectPtr conn,
 
     remoteDriverLock(priv);
 
-    if (priv->domainEventState->timer < 0) {
-         remoteError(VIR_ERR_NO_SUPPORT, "%s", _("no event support"));
+    if ((count = virDomainEventStateRegisterID(conn,
+                                               priv->domainEventState,
+                                               dom, eventID,
+                                               callback, opaque, freecb,
+                                               &callbackID)) < 0) {
+         remoteError(VIR_ERR_RPC, "%s", _("adding cb to list"));
          goto done;
     }
 
-    if ((count = virDomainEventCallbackListAddID(conn,
-                                                 priv->domainEventState->callbacks,
-                                                 dom, eventID,
-                                                 callback, opaque, freecb,
-                                                 &callbackID)) < 0) {
-        remoteError(VIR_ERR_RPC, "%s", _("adding cb to list"));
-        goto done;
-    }
-
     /* If this is the first callback for this eventID, we need to enable
      * events on the server */
     if (count == 1) {
@@ -3785,9 +3774,9 @@ static int remoteDomainEventRegisterAny(virConnectPtr conn,
         if (call (conn, priv, 0, REMOTE_PROC_DOMAIN_EVENTS_REGISTER_ANY,
                   (xdrproc_t) xdr_remote_domain_events_register_any_args, (char *) &args,
                   (xdrproc_t) xdr_void, (char *)NULL) == -1) {
-            virDomainEventCallbackListRemoveID(conn,
-                                               priv->domainEventState->callbacks,
-                                               callbackID);
+            virDomainEventStateDeregisterID(conn,
+                                            priv->domainEventState,
+                                            callbackID);
             goto done;
         }
     }
@@ -3807,27 +3796,28 @@ static int remoteDomainEventDeregisterAny(virConnectPtr conn,
     int rv = -1;
     remote_domain_events_deregister_any_args args;
     int eventID;
+    int count;
 
     remoteDriverLock(priv);
 
-    if ((eventID = virDomainEventCallbackListEventID(conn,
-                                                     priv->domainEventState->callbacks,
-                                                     callbackID)) < 0) {
+    if ((eventID = virDomainEventStateEventID(conn,
+                                              priv->domainEventState,
+                                              callbackID)) < 0) {
         remoteError(VIR_ERR_RPC, _("unable to find callback ID %d"), callbackID);
         goto done;
     }
 
-    if (virDomainEventStateDeregisterID(conn,
-                                        priv->domainEventState,
-                                        callbackID) < 0)
+    if ((count = virDomainEventStateDeregisterID(conn,
+                                                 priv->domainEventState,
+                                                 callbackID)) < 0) {
+        remoteError(VIR_ERR_RPC, _("unable to find callback ID %d"), callbackID);
         goto done;
+    }
 
     /* If that was the last callback for this eventID, we need to disable
      * events on the server */
-    if (virDomainEventCallbackListCountID(conn,
-                                          priv->domainEventState->callbacks,
-                                          eventID) == 0) {
-        args.eventID = eventID;
+    if (count == 0) {
+        args.eventID = callbackID;
 
         if (call (conn, priv, 0, REMOTE_PROC_DOMAIN_EVENTS_DEREGISTER_ANY,
                   (xdrproc_t) xdr_remote_domain_events_deregister_any_args, (char *) &args,
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index f32990b..054a41a 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -5431,9 +5431,9 @@ testDomainEventRegister(virConnectPtr conn,
     int ret;
 
     testDriverLock(driver);
-    ret = virDomainEventCallbackListAdd(conn,
-                                        driver->domainEventState->callbacks,
-                                        callback, opaque, freecb);
+    ret = virDomainEventStateRegister(conn,
+                                      driver->domainEventState,
+                                      callback, opaque, freecb);
     testDriverUnlock(driver);
 
     return ret;
@@ -5469,10 +5469,10 @@ testDomainEventRegisterAny(virConnectPtr conn,
     int ret;
 
     testDriverLock(driver);
-    if (virDomainEventCallbackListAddID(conn,
-                                        driver->domainEventState->callbacks,
-                                        dom, eventID,
-                                        callback, opaque, freecb, &ret) < 0)
+    if (virDomainEventStateRegisterID(conn,
+                                      driver->domainEventState,
+                                      dom, eventID,
+                                      callback, opaque, freecb, &ret) < 0)
         ret = -1;
     testDriverUnlock(driver);
 
diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
index 420488d..4d875c8 100644
--- a/src/uml/uml_driver.c
+++ b/src/uml/uml_driver.c
@@ -1194,8 +1194,8 @@ static int umlClose(virConnectPtr conn) {
     struct uml_driver *driver = conn->privateData;
 
     umlDriverLock(driver);
-    virDomainEventCallbackListRemoveConn(conn,
-                                         driver->domainEventState->callbacks);
+    virDomainEventStateDeregisterConn(conn,
+                                      driver->domainEventState);
     umlProcessAutoDestroyRun(driver, conn);
     umlDriverUnlock(driver);
 
@@ -2447,9 +2447,9 @@ umlDomainEventRegister(virConnectPtr conn,
     int ret;
 
     umlDriverLock(driver);
-    ret = virDomainEventCallbackListAdd(conn,
-                                        driver->domainEventState->callbacks,
-                                        callback, opaque, freecb);
+    ret = virDomainEventStateRegister(conn,
+                                      driver->domainEventState,
+                                      callback, opaque, freecb);
     umlDriverUnlock(driver);
 
     return ret;
@@ -2483,10 +2483,10 @@ umlDomainEventRegisterAny(virConnectPtr conn,
     int ret;
 
     umlDriverLock(driver);
-    if (virDomainEventCallbackListAddID(conn,
-                                        driver->domainEventState->callbacks,
-                                        dom, eventID,
-                                        callback, opaque, freecb, &ret) < 0)
+    if (virDomainEventStateRegisterID(conn,
+                                      driver->domainEventState,
+                                      dom, eventID,
+                                      callback, opaque, freecb, &ret) < 0)
         ret = -1;
     umlDriverUnlock(driver);
 
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 670de9c..1fb369b 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -7188,12 +7188,12 @@ static int vboxDomainEventRegister (virConnectPtr conn,
              * later you can iterate over them
              */
 
-            ret = virDomainEventCallbackListAdd(conn, data->domainEvents->callbacks,
-                                                callback, opaque, freecb);
-            VIR_DEBUG("virDomainEventCallbackListAdd (ret = %d) ( conn: %p, "
-                  "data->domainEvents->callbacks: %p, callback: %p, opaque: %p, "
-                  "freecb: %p )", ret, conn, data->domainEvents->callbacks, callback,
-                  opaque, freecb);
+            ret = virDomainEventStateRegister(conn, data->domainEvents,
+                                              callback, opaque, freecb);
+            VIR_DEBUG("virDomainEventStateRegister (ret = %d) ( conn: %p, "
+                      "callback: %p, opaque: %p, "
+                      "freecb: %p )", ret, conn, callback,
+                      opaque, freecb);
         }
     }
 
@@ -7280,13 +7280,13 @@ static int vboxDomainEventRegisterAny(virConnectPtr conn,
              * later you can iterate over them
              */
 
-            if (virDomainEventCallbackListAddID(conn, data->domainEvents->callbacks,
-                                                dom, eventID,
-                                                callback, opaque, freecb, &ret) < 0)
+            if (virDomainEventStateRegisterID(conn, data->domainEvents,
+                                              dom, eventID,
+                                              callback, opaque, freecb, &ret) < 0)
                 ret = -1;
-            VIR_DEBUG("virDomainEventCallbackListAddID (ret = %d) ( conn: %p, "
-                      "data->domainEvents->callbacks: %p, callback: %p, opaque: %p, "
-                      "freecb: %p )", ret, conn, data->domainEvents->callbacks, callback,
+            VIR_DEBUG("virDomainEventStateRegisterID (ret = %d) ( conn: %p, "
+                      "callback: %p, opaque: %p, "
+                      "freecb: %p )", ret, conn, callback,
                       opaque, freecb);
         }
     }
diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index b11dd9e..a2399dd 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -1847,8 +1847,8 @@ xenUnifiedDomainEventRegister(virConnectPtr conn,
         return -1;
     }
 
-    ret = virDomainEventCallbackListAdd(conn, priv->domainEvents->callbacks,
-                                        callback, opaque, freefunc);
+    ret = virDomainEventStateRegister(conn, priv->domainEvents,
+                                      callback, opaque, freefunc);
 
     xenUnifiedUnlock(priv);
     return (ret);
@@ -1897,9 +1897,9 @@ xenUnifiedDomainEventRegisterAny(virConnectPtr conn,
         return -1;
     }
 
-    if (virDomainEventCallbackListAddID(conn, priv->domainEvents->callbacks,
-                                        dom, eventID,
-                                        callback, opaque, freefunc, &ret) < 0)
+    if (virDomainEventStateRegisterID(conn, priv->domainEvents,
+                                      dom, eventID,
+                                      callback, opaque, freefunc, &ret) < 0)
         ret = -1;
 
     xenUnifiedUnlock(priv);
-- 
1.7.7.4

--
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]