[PATCH v3 16/16] test: Clean up test driver Interface interactions

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

 



Now that we have self locking hash table for Interface object lookups,
there's no need to take the test driver lock in order to "lock" between
the various API's, so remove the Lock/Unlock logic accordingly.

Add a virInterfaceObjListFree during testDriverFree for the backupIfaces
"just in case". Also use the VIR_STEAL_PTR rather than inline the code.

Finally alter a couple of "if ((obj = function()) == NULL" to use the
more standard "if (!(obj = function()))" syntax.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/test/test_driver.c | 55 ++++++++++++--------------------------------------
 1 file changed, 13 insertions(+), 42 deletions(-)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 11e7fd8..ff2077c 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -155,6 +155,7 @@ testDriverFree(testDriverPtr driver)
     virNodeDeviceObjListFree(&driver->devs);
     virObjectUnref(driver->networks);
     virInterfaceObjListFree(driver->ifaces);
+    virInterfaceObjListFree(driver->backupIfaces);
     virStoragePoolObjListFree(&driver->pools);
     virObjectUnref(driver->eventState);
     virMutexUnlock(&driver->lock);
@@ -3630,11 +3631,7 @@ testInterfaceObjFindByName(testDriverPtr privconn,
 {
     virInterfaceObjPtr obj;
 
-    testDriverLock(privconn);
-    obj = virInterfaceObjListFindByName(privconn->ifaces, name);
-    testDriverUnlock(privconn);
-
-    if (!obj)
+    if (!(obj = virInterfaceObjListFindByName(privconn->ifaces, name)))
         virReportError(VIR_ERR_NO_INTERFACE,
                        _("no interface with matching name '%s'"),
                        name);
@@ -3647,12 +3644,8 @@ static int
 testConnectNumOfInterfaces(virConnectPtr conn)
 {
     testDriverPtr privconn = conn->privateData;
-    int ninterfaces;
 
-    testDriverLock(privconn);
-    ninterfaces = virInterfaceObjListNumOfInterfaces(privconn->ifaces, true);
-    testDriverUnlock(privconn);
-    return ninterfaces;
+    return virInterfaceObjListNumOfInterfaces(privconn->ifaces, true);
 }
 
 
@@ -3662,14 +3655,8 @@ testConnectListInterfaces(virConnectPtr conn,
                           int maxnames)
 {
     testDriverPtr privconn = conn->privateData;
-    int nnames;
 
-    testDriverLock(privconn);
-    nnames = virInterfaceObjListGetNames(privconn->ifaces, true,
-                                         names, maxnames);
-    testDriverUnlock(privconn);
-
-    return nnames;
+    return virInterfaceObjListGetNames(privconn->ifaces, true, names, maxnames);
 }
 
 
@@ -3677,12 +3664,8 @@ static int
 testConnectNumOfDefinedInterfaces(virConnectPtr conn)
 {
     testDriverPtr privconn = conn->privateData;
-    int ninterfaces;
 
-    testDriverLock(privconn);
-    ninterfaces = virInterfaceObjListNumOfInterfaces(privconn->ifaces, false);
-    testDriverUnlock(privconn);
-    return ninterfaces;
+    return virInterfaceObjListNumOfInterfaces(privconn->ifaces, false);
 }
 
 
@@ -3692,14 +3675,8 @@ testConnectListDefinedInterfaces(virConnectPtr conn,
                                  int maxnames)
 {
     testDriverPtr privconn = conn->privateData;
-    int nnames;
 
-    testDriverLock(privconn);
-    nnames = virInterfaceObjListGetNames(privconn->ifaces, false,
-                                         names, maxnames);
-    testDriverUnlock(privconn);
-
-    return nnames;
+    return virInterfaceObjListGetNames(privconn->ifaces, false, names, maxnames);
 }
 
 
@@ -3732,12 +3709,8 @@ testInterfaceLookupByMACString(virConnectPtr conn,
     char *ifacenames[] = { NULL, NULL };
     virInterfacePtr ret = NULL;
 
-    testDriverLock(privconn);
-    ifacect = virInterfaceObjListFindByMACString(privconn->ifaces, mac,
-                                                 ifacenames, 2);
-    testDriverUnlock(privconn);
-
-    if (ifacect == 0) {
+    if ((ifacect = virInterfaceObjListFindByMACString(privconn->ifaces, mac,
+                                                      ifacenames, 2)) == 0) {
         virReportError(VIR_ERR_NO_INTERFACE,
                        _("no interface with matching mac '%s'"), mac);
         goto cleanup;
@@ -3821,6 +3794,7 @@ testInterfaceChangeCommit(virConnectPtr conn,
     }
 
     virInterfaceObjListFree(privconn->backupIfaces);
+    privconn->backupIfaces = NULL;
     privconn->transaction_running = false;
 
     ret = 0;
@@ -3851,8 +3825,7 @@ testInterfaceChangeRollback(virConnectPtr conn,
     }
 
     virInterfaceObjListFree(privconn->ifaces);
-    privconn->ifaces = privconn->backupIfaces;
-    privconn->backupIfaces = NULL;
+    VIR_STEAL_PTR(privconn->ifaces, privconn->backupIfaces);
 
     privconn->transaction_running = false;
 
@@ -3899,11 +3872,10 @@ testInterfaceDefineXML(virConnectPtr conn,
 
     virCheckFlags(0, NULL);
 
-    testDriverLock(privconn);
-    if ((def = virInterfaceDefParseString(xmlStr)) == NULL)
-        goto cleanup;
+    if (!(def = virInterfaceDefParseString(xmlStr)))
+        return NULL;
 
-    if ((obj = virInterfaceObjListAssignDef(privconn->ifaces, def)) == NULL)
+    if (!(obj = virInterfaceObjListAssignDef(privconn->ifaces, def)))
         goto cleanup;
     def = NULL;
     objdef = virInterfaceObjGetDef(obj);
@@ -3913,7 +3885,6 @@ testInterfaceDefineXML(virConnectPtr conn,
  cleanup:
     virInterfaceDefFree(def);
     virInterfaceObjEndAPI(&obj);
-    testDriverUnlock(privconn);
     return ret;
 }
 
-- 
2.9.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