[libvirt PATCH 10/10] vz_driver: Use automatic mutex management

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

 



Signed-off-by: Tim Wiederhake <twiederh@xxxxxxxxxx>
---
 src/vz/vz_driver.c | 50 +++++++++++++++++++---------------------------
 1 file changed, 20 insertions(+), 30 deletions(-)

diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index 2107785ab2..82323cb1b2 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -2018,53 +2018,43 @@ vzConnectRegisterCloseCallback(virConnectPtr conn,
                                virFreeCallback freecb)
 {
     struct _vzConn *privconn = conn->privateData;
-    int ret = -1;
 
     if (virConnectRegisterCloseCallbackEnsureACL(conn) < 0)
         return -1;
 
-    virObjectLock(privconn->driver);
+    VIR_WITH_OBJECT_LOCK_GUARD(privconn->driver) {
+        if (virConnectCloseCallbackDataGetCallback(privconn->closeCallback) != NULL) {
+            virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                           _("A close callback is already registered"));
+            return -1;
+        }
 
-    if (virConnectCloseCallbackDataGetCallback(privconn->closeCallback) != NULL) {
-        virReportError(VIR_ERR_OPERATION_INVALID, "%s",
-                       _("A close callback is already registered"));
-        goto cleanup;
+        virConnectCloseCallbackDataRegister(privconn->closeCallback, conn, cb,
+                                            opaque, freecb);
     }
 
-    virConnectCloseCallbackDataRegister(privconn->closeCallback, conn, cb,
-                                        opaque, freecb);
-    ret = 0;
-
- cleanup:
-    virObjectUnlock(privconn->driver);
-
-    return ret;
+    return 0;
 }
 
 static int
 vzConnectUnregisterCloseCallback(virConnectPtr conn, virConnectCloseFunc cb)
 {
     struct _vzConn *privconn = conn->privateData;
-    int ret = -1;
 
     if (virConnectUnregisterCloseCallbackEnsureACL(conn) < 0)
         return -1;
 
-    virObjectLock(privconn->driver);
+    VIR_WITH_OBJECT_LOCK_GUARD(privconn->driver) {
+        if (virConnectCloseCallbackDataGetCallback(privconn->closeCallback) != cb) {
+            virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                           _("A different callback was requested"));
+            return -1;
+        }
 
-    if (virConnectCloseCallbackDataGetCallback(privconn->closeCallback) != cb) {
-        virReportError(VIR_ERR_OPERATION_INVALID, "%s",
-                       _("A different callback was requested"));
-        goto cleanup;
+        virConnectCloseCallbackDataUnregister(privconn->closeCallback, cb);
     }
 
-    virConnectCloseCallbackDataUnregister(privconn->closeCallback, cb);
-    ret = 0;
-
- cleanup:
-    virObjectUnlock(privconn->driver);
-
-    return ret;
+    return 0;
 }
 
 static int vzDomainSetMemoryFlags(virDomainPtr domain, unsigned long memory,
@@ -3795,9 +3785,9 @@ vzConnectGetAllDomainStats(virConnectPtr conn,
         virDomainStatsRecordPtr tmp;
         virDomainObj *dom = doms[i];
 
-        virObjectLock(dom);
-        tmp = vzDomainGetAllStats(conn, dom);
-        virObjectUnlock(dom);
+        VIR_WITH_OBJECT_LOCK_GUARD(dom) {
+            tmp = vzDomainGetAllStats(conn, dom);
+        }
 
         if (!tmp)
             goto cleanup;
-- 
2.31.1




[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