[PATCH 11/20] test: introduce testDriverCloseInternal

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

 



Refactor testConnectClose as it's then obvious that conn->privateData
is set to NULL in all cases. In addition, 'testConnectCloseInternal'
can be better reused.

Signed-off-by: Marc Hartmayer <mhartmay@xxxxxxxxxxxxxxxxxx>
Reviewed-by: Boris Fiuczynski <fiuczy@xxxxxxxxxxxxxxxxxx>
---
 src/test/test_driver.c | 61 +++++++++++++++++++++++++++++---------------------
 1 file changed, 35 insertions(+), 26 deletions(-)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index d450be21704e..fca607f57d51 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -1429,10 +1429,36 @@ testConnectAuthenticate(virConnectPtr conn,
     return ret;
 }
 
-static virDrvOpenStatus testConnectOpen(virConnectPtr conn,
-                                        virConnectAuthPtr auth,
-                                        virConfPtr conf ATTRIBUTE_UNUSED,
-                                        unsigned int flags)
+
+static void
+testDriverCloseInternal(testDriverPtr driver)
+{
+    bool dflt = false;
+
+    if (driver == defaultPrivconn) {
+        dflt = true;
+        virMutexLock(&defaultLock);
+        if (--defaultConnections) {
+            virMutexUnlock(&defaultLock);
+            return;
+        }
+    }
+
+    testDriverLock(driver);
+    testDriverFree(driver);
+
+    if (dflt) {
+        defaultPrivconn = NULL;
+        virMutexUnlock(&defaultLock);
+    }
+}
+
+
+static virDrvOpenStatus
+testConnectOpen(virConnectPtr conn,
+                virConnectAuthPtr auth,
+                virConfPtr conf ATTRIBUTE_UNUSED,
+                unsigned int flags)
 {
     int ret;
 
@@ -1473,33 +1499,16 @@ static virDrvOpenStatus testConnectOpen(virConnectPtr conn,
     return VIR_DRV_OPEN_SUCCESS;
 }
 
-static int testConnectClose(virConnectPtr conn)
+
+static int
+testConnectClose(virConnectPtr conn)
 {
-    testDriverPtr privconn = conn->privateData;
-    bool dflt = false;
-
-    if (privconn == defaultPrivconn) {
-        dflt = true;
-        virMutexLock(&defaultLock);
-        if (--defaultConnections) {
-            conn->privateData = NULL;
-            virMutexUnlock(&defaultLock);
-            return 0;
-        }
-    }
-
-    testDriverLock(privconn);
-    testDriverFree(privconn);
-
-    if (dflt) {
-        defaultPrivconn = NULL;
-        virMutexUnlock(&defaultLock);
-    }
-
+    testDriverCloseInternal(conn->privateData);
     conn->privateData = NULL;
     return 0;
 }
 
+
 static int testConnectGetVersion(virConnectPtr conn ATTRIBUTE_UNUSED,
                                  unsigned long *hvVer)
 {
-- 
2.13.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]

  Powered by Linux