Re: [libvirt] PATCH: 4/28: Thread safety for test driver

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

 



This patch makes the test driver thread safe, adding a global driver lock,
and the neccessary locking calls on domain/network/storagepool objects.

You'll notice there are many calls to

 virDomainObjUnlock

but very few corresponding  calls to

   virDomainObjLock

This is because the contract of  virDomainFindByUUID declares that the
object it returns is already locked.

Methods which create / delete virDomainObj instances have to keep the
global driver lock held for their whole duration, but others can drop
it immediately after getting the virDomainObjPtr instance.

 src/test.c      |  460 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
 tests/virsh-all |    1 
 2 files changed, 420 insertions(+), 41 deletions(-)

Daniel

diff --git a/src/test.c b/src/test.c
--- a/src/test.c
+++ b/src/test.c
@@ -58,6 +58,8 @@ typedef struct _testCell *testCellPtr;
 #define MAX_CELLS 128
 
 struct _testConn {
+    PTHREAD_MUTEX_T(lock);
+
     char path[PATH_MAX];
     int nextDomID;
     virCapsPtr caps;
@@ -90,6 +92,16 @@ static const virNodeInfo defaultNodeInfo
 #define testError(conn, code, fmt...)                               \
         virReportErrorHelper(conn, VIR_FROM_TEST, code, __FILE__, \
                                __FUNCTION__, __LINE__, fmt)
+
+static void testDriverLock(testConnPtr driver)
+{
+    pthread_mutex_lock(&driver->lock);
+}
+
+static void testDriverUnlock(testConnPtr driver)
+{
+    pthread_mutex_unlock(&driver->lock);
+}
 
 static virCapsPtr
 testBuildCapabilities(virConnectPtr conn) {
@@ -200,6 +212,8 @@ static int testOpenDefault(virConnectPtr
         return VIR_DRV_OPEN_ERROR;
     }
     conn->privateData = privconn;
+    pthread_mutex_init(&privconn->lock, NULL);
+    testDriverLock(privconn);
 
     if (gettimeofday(&tv, NULL) < 0) {
         testError(NULL, VIR_ERR_INTERNAL_ERROR, "%s", _("getting time of day"));
@@ -232,6 +246,7 @@ static int testOpenDefault(virConnectPtr
     domobj->def->id = privconn->nextDomID++;
     domobj->state = VIR_DOMAIN_RUNNING;
     domobj->persistent = 1;
+    virDomainObjUnlock(domobj);
 
     if (!(netdef = virNetworkDefParseString(conn, defaultNetworkXML)))
         goto error;
@@ -241,6 +256,7 @@ static int testOpenDefault(virConnectPtr
     }
     netobj->active = 1;
     netobj->persistent = 1;
+    virNetworkObjUnlock(netobj);
 
     if (!(pooldef = virStoragePoolDefParse(conn, defaultPoolXML, NULL)))
         goto error;
@@ -250,10 +266,15 @@ static int testOpenDefault(virConnectPtr
         virStoragePoolDefFree(pooldef);
         goto error;
     }
-    if (testStoragePoolObjSetDefaults(poolobj) == -1)
+
+    if (testStoragePoolObjSetDefaults(poolobj) == -1) {
+        virStoragePoolObjUnlock(poolobj);
         goto error;
+    }
     poolobj->active = 1;
+    virStoragePoolObjUnlock(poolobj);
 
+    testDriverUnlock(privconn);
     return VIR_DRV_OPEN_SUCCESS;
 
 error:
@@ -261,6 +282,7 @@ error:
     virNetworkObjListFree(&privconn->networks);
     virStoragePoolObjListFree(&privconn->pools);
     virCapabilitiesFree(privconn->caps);
+    testDriverUnlock(privconn);
     VIR_FREE(privconn);
     return VIR_DRV_OPEN_ERROR;
 }
@@ -307,6 +329,8 @@ static int testOpenFromFile(virConnectPt
         return VIR_DRV_OPEN_ERROR;
     }
     conn->privateData = privconn;
+    pthread_mutex_init(&privconn->lock, NULL);
+    testDriverLock(privconn);
 
     if (!(privconn->caps = testBuildCapabilities(conn)))
         goto error;
@@ -445,6 +469,7 @@ static int testOpenFromFile(virConnectPt
         dom->state = VIR_DOMAIN_RUNNING;
         dom->def->id = privconn->nextDomID++;
         dom->persistent = 1;
+        virDomainObjUnlock(dom);
     }
     if (domains != NULL)
         VIR_FREE(domains);
@@ -478,8 +503,8 @@ static int testOpenFromFile(virConnectPt
             virNetworkDefFree(def);
             goto error;
         }
-
         net->persistent = 1;
+        virNetworkObjUnlock(net);
     }
     if (networks != NULL)
         VIR_FREE(networks);
@@ -529,15 +554,19 @@ static int testOpenFromFile(virConnectPt
             goto error;
         }
 
-        if (testStoragePoolObjSetDefaults(pool) == -1)
+        if (testStoragePoolObjSetDefaults(pool) == -1) {
+            virStoragePoolObjUnlock(pool);
             goto error;
+        }
         pool->active = 1;
+        virStoragePoolObjUnlock(pool);
     }
     if (pools != NULL)
         VIR_FREE(pools);
 
     xmlXPathFreeContext(ctxt);
     xmlFreeDoc(xml);
+    testDriverUnlock(privconn);
 
     return (0);
 
@@ -552,6 +581,7 @@ static int testOpenFromFile(virConnectPt
     virDomainObjListFree(&privconn->domains);
     virNetworkObjListFree(&privconn->networks);
     virStoragePoolObjListFree(&privconn->pools);
+    testDriverUnlock(privconn);
     VIR_FREE(privconn);
     conn->privateData = NULL;
     return VIR_DRV_OPEN_ERROR;
@@ -598,11 +628,12 @@ static int testClose(virConnectPtr conn)
 static int testClose(virConnectPtr conn)
 {
     testConnPtr privconn = conn->privateData;
-
+    testDriverLock(privconn);
     virCapabilitiesFree(privconn->caps);
     virDomainObjListFree(&privconn->domains);
     virNetworkObjListFree(&privconn->networks);
     virStoragePoolObjListFree(&privconn->pools);
+    testDriverUnlock(privconn);
 
     VIR_FREE (privconn);
     conn->privateData = NULL;
@@ -646,8 +677,9 @@ static int testNodeGetInfo(virConnectPtr
                            virNodeInfoPtr info)
 {
     testConnPtr privconn = conn->privateData;
-
+    testDriverLock(privconn);
     memcpy(info, &privconn->nodeInfo, sizeof(virNodeInfo));
+    testDriverUnlock(privconn);
     return (0);
 }
 
@@ -655,10 +687,10 @@ static char *testGetCapabilities (virCon
 {
     testConnPtr privconn = conn->privateData;
     char *xml;
-
+    testDriverLock(privconn);
     if ((xml = virCapabilitiesFormatXML(privconn->caps)) == NULL)
         testError(conn, VIR_ERR_NO_MEMORY, NULL);
-
+    testDriverUnlock(privconn);
     return xml;
 }
 
@@ -667,9 +699,11 @@ static int testNumOfDomains(virConnectPt
     testConnPtr privconn = conn->privateData;
     unsigned int numActive = 0, i;
 
+    testDriverLock(privconn);
     for (i = 0 ; i < privconn->domains.count ; i++)
         if (virDomainIsActive(privconn->domains.objs[i]))
             numActive++;
+    testDriverUnlock(privconn);
 
     return numActive;
 }
@@ -681,8 +715,9 @@ testDomainCreateXML(virConnectPtr conn, 
     testConnPtr privconn = conn->privateData;
     virDomainPtr ret = NULL;
     virDomainDefPtr def;
-    virDomainObjPtr dom;
+    virDomainObjPtr dom = NULL;
 
+    testDriverLock(privconn);
     if ((def = virDomainDefParseString(conn, privconn->caps, xml)) == NULL)
         goto cleanup;
 
@@ -699,6 +734,9 @@ testDomainCreateXML(virConnectPtr conn, 
         ret->id = def->id;
 
 cleanup:
+    if (dom)
+        virDomainObjUnlock(dom);
+    testDriverUnlock(privconn);
     return ret;
 }
 
@@ -710,7 +748,11 @@ static virDomainPtr testLookupDomainByID
     virDomainPtr ret = NULL;
     virDomainObjPtr dom;
 
-    if ((dom = virDomainFindByID(&privconn->domains, id)) == NULL) {
+    testDriverLock(privconn);
+    dom = virDomainFindByID(&privconn->domains, id);
+    testDriverUnlock(privconn);
+
+    if (dom == NULL) {
         testError (conn, VIR_ERR_NO_DOMAIN, NULL);
         goto cleanup;
     }
@@ -720,6 +762,8 @@ static virDomainPtr testLookupDomainByID
         ret->id = dom->def->id;
 
 cleanup:
+    if (dom)
+        virDomainObjUnlock(dom);
     return ret;
 }
 
@@ -730,7 +774,11 @@ static virDomainPtr testLookupDomainByUU
     virDomainPtr ret = NULL;
     virDomainObjPtr dom ;
 
-    if ((dom = virDomainFindByUUID(&privconn->domains, uuid)) == NULL) {
+    testDriverLock(privconn);
+    dom = virDomainFindByUUID(&privconn->domains, uuid);
+    testDriverUnlock(privconn);
+
+    if (dom == NULL) {
         testError (conn, VIR_ERR_NO_DOMAIN, NULL);
         goto cleanup;
     }
@@ -740,6 +788,8 @@ static virDomainPtr testLookupDomainByUU
         ret->id = dom->def->id;
 
 cleanup:
+    if (dom)
+        virDomainObjUnlock(dom);
     return ret;
 }
 
@@ -750,7 +800,11 @@ static virDomainPtr testLookupDomainByNa
     virDomainPtr ret = NULL;
     virDomainObjPtr dom;
 
-    if ((dom = virDomainFindByName(&privconn->domains, name)) == NULL) {
+    testDriverLock(privconn);
+    dom = virDomainFindByName(&privconn->domains, name);
+    testDriverUnlock(privconn);
+
+    if (dom == NULL) {
         testError (conn, VIR_ERR_NO_DOMAIN, NULL);
         goto cleanup;
     }
@@ -760,6 +814,8 @@ static virDomainPtr testLookupDomainByNa
         ret->id = dom->def->id;
 
 cleanup:
+    if (dom)
+        virDomainObjUnlock(dom);
     return ret;
 }
 
@@ -770,9 +826,14 @@ static int testListDomains (virConnectPt
     testConnPtr privconn = conn->privateData;
     unsigned int n = 0, i;
 
-    for (i = 0 ; i < privconn->domains.count && n < maxids ; i++)
+    testDriverLock(privconn);
+    for (i = 0 ; i < privconn->domains.count && n < maxids ; i++) {
+        virDomainObjLock(privconn->domains.objs[i]);
         if (virDomainIsActive(privconn->domains.objs[i]))
             ids[n++] = privconn->domains.objs[i]->def->id;
+        virDomainObjUnlock(privconn->domains.objs[i]);
+    }
+    testDriverUnlock(privconn);
 
     return n;
 }
@@ -783,6 +844,7 @@ static int testDestroyDomain (virDomainP
     virDomainObjPtr privdom;
     int ret = -1;
 
+    testDriverLock(privconn);
     privdom = virDomainFindByName(&privconn->domains,
                                   domain->name);
 
@@ -797,10 +859,14 @@ static int testDestroyDomain (virDomainP
     if (!privdom->persistent) {
         virDomainRemoveInactive(&privconn->domains,
                                 privdom);
+        privdom = NULL;
     }
 
     ret = 0;
 cleanup:
+    if (privdom)
+        virDomainObjUnlock(privdom);
+    testDriverUnlock(privconn);
     return ret;
 }
 
@@ -810,8 +876,10 @@ static int testResumeDomain (virDomainPt
     virDomainObjPtr privdom;
     int ret = -1;
 
+    testDriverLock(privconn);
     privdom = virDomainFindByName(&privconn->domains,
                                   domain->name);
+    testDriverUnlock(privconn);
 
     if (privdom == NULL) {
         testError(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
@@ -829,6 +897,8 @@ static int testResumeDomain (virDomainPt
     ret = 0;
 
 cleanup:
+    if (privdom)
+        virDomainObjUnlock(privdom);
     return ret;
 }
 
@@ -838,8 +908,10 @@ static int testPauseDomain (virDomainPtr
     virDomainObjPtr privdom;
     int ret = -1;
 
+    testDriverLock(privconn);
     privdom = virDomainFindByName(&privconn->domains,
                                   domain->name);
+    testDriverUnlock(privconn);
 
     if (privdom == NULL) {
         testError(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
@@ -858,6 +930,8 @@ static int testPauseDomain (virDomainPtr
     ret = 0;
 
 cleanup:
+    if (privdom)
+        virDomainObjUnlock(privdom);
     return ret;
 }
 
@@ -867,6 +941,7 @@ static int testShutdownDomain (virDomain
     virDomainObjPtr privdom;
     int ret = -1;
 
+    testDriverLock(privconn);
     privdom = virDomainFindByName(&privconn->domains,
                                   domain->name);
 
@@ -884,9 +959,17 @@ static int testShutdownDomain (virDomain
     privdom->state = VIR_DOMAIN_SHUTOFF;
     domain->id = -1;
     privdom->def->id = -1;
+    if (!privdom->persistent) {
+        virDomainRemoveInactive(&privconn->domains,
+                                privdom);
+        privdom = NULL;
+    }
     ret = 0;
 
 cleanup:
+    if (privdom)
+        virDomainObjUnlock(privdom);
+    testDriverUnlock(privconn);
     return ret;
 }
 
@@ -898,6 +981,7 @@ static int testRebootDomain (virDomainPt
     virDomainObjPtr privdom;
     int ret = -1;
 
+    testDriverLock(privconn);
     privdom = virDomainFindByName(&privconn->domains,
                                   domain->name);
 
@@ -935,9 +1019,18 @@ static int testRebootDomain (virDomainPt
         break;
     }
 
+    if (privdom->state == VIR_DOMAIN_SHUTOFF && !privdom->persistent) {
+        virDomainRemoveInactive(&privconn->domains,
+                                privdom);
+        privdom = NULL;
+    }
+
     ret = 0;
 
 cleanup:
+    if (privdom)
+        virDomainObjUnlock(privdom);
+    testDriverUnlock(privconn);
     return ret;
 }
 
@@ -949,8 +1042,10 @@ static int testGetDomainInfo (virDomainP
     virDomainObjPtr privdom;
     int ret = -1;
 
+    testDriverLock(privconn);
     privdom = virDomainFindByName(&privconn->domains,
                                   domain->name);
+    testDriverUnlock(privconn);
 
     if (privdom == NULL) {
         testError(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
@@ -971,6 +1066,8 @@ static int testGetDomainInfo (virDomainP
     ret = 0;
 
 cleanup:
+    if (privdom)
+        virDomainObjUnlock(privdom);
     return ret;
 }
 
@@ -988,6 +1085,7 @@ static int testDomainSave(virDomainPtr d
     virDomainObjPtr privdom;
     int ret = -1;
 
+    testDriverLock(privconn);
     privdom = virDomainFindByName(&privconn->domains,
                                   domain->name);
 
@@ -1042,6 +1140,7 @@ static int testDomainSave(virDomainPtr d
     if (!privdom->persistent) {
         virDomainRemoveInactive(&privconn->domains,
                                 privdom);
+        privdom = NULL;
     }
     ret = 0;
 
@@ -1056,7 +1155,9 @@ cleanup:
             close(fd);
         unlink(path);
     }
-
+    if (privdom)
+        virDomainObjUnlock(privdom);
+    testDriverUnlock(privconn);
     return ret;
 }
 
@@ -1069,7 +1170,7 @@ static int testDomainRestore(virConnectP
     int fd = -1;
     int len;
     virDomainDefPtr def = NULL;
-    virDomainObjPtr dom;
+    virDomainObjPtr dom = NULL;
     int ret = -1;
 
     if ((fd = open(path, O_RDONLY)) < 0) {
@@ -1108,6 +1209,7 @@ static int testDomainRestore(virConnectP
     }
     xml[len] = '\0';
 
+    testDriverLock(privconn);
     def = virDomainDefParseString(conn, privconn->caps, xml);
     if (!def)
         goto cleanup;
@@ -1126,6 +1228,9 @@ cleanup:
     VIR_FREE(xml);
     if (fd != -1)
         close(fd);
+    if (dom)
+        virDomainObjUnlock(dom);
+    testDriverUnlock(privconn);
     return ret;
 }
 
@@ -1138,6 +1243,7 @@ static int testDomainCoreDump(virDomainP
     virDomainObjPtr privdom;
     int ret = -1;
 
+    testDriverLock(privconn);
     privdom = virDomainFindByName(&privconn->domains,
                                   domain->name);
 
@@ -1168,12 +1274,16 @@ static int testDomainCoreDump(virDomainP
     if (!privdom->persistent) {
         virDomainRemoveInactive(&privconn->domains,
                                 privdom);
+        privdom = NULL;
     }
     ret = 0;
 
 cleanup:
     if (fd != -1)
         close(fd);
+    if (privdom)
+        virDomainObjUnlock(privdom);
+    testDriverUnlock(privconn);
     return ret;
 }
 
@@ -1189,8 +1299,10 @@ static unsigned long testGetMaxMemory(vi
     virDomainObjPtr privdom;
     unsigned long ret = -1;
 
+    testDriverLock(privconn);
     privdom = virDomainFindByName(&privconn->domains,
                                   domain->name);
+    testDriverUnlock(privconn);
 
     if (privdom == NULL) {
         testError(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
@@ -1200,6 +1312,8 @@ static unsigned long testGetMaxMemory(vi
     ret = privdom->def->maxmem;
 
 cleanup:
+    if (privdom)
+        virDomainObjUnlock(privdom);
     return ret;
 }
 
@@ -1210,8 +1324,10 @@ static int testSetMaxMemory(virDomainPtr
     virDomainObjPtr privdom;
     int ret = -1;
 
+    testDriverLock(privconn);
     privdom = virDomainFindByName(&privconn->domains,
                                   domain->name);
+    testDriverUnlock(privconn);
 
     if (privdom == NULL) {
         testError(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
@@ -1223,6 +1339,8 @@ static int testSetMaxMemory(virDomainPtr
     ret = 0;
 
 cleanup:
+    if (privdom)
+        virDomainObjUnlock(privdom);
     return ret;
 }
 
@@ -1233,8 +1351,10 @@ static int testSetMemory(virDomainPtr do
     virDomainObjPtr privdom;
     int ret = -1;
 
+    testDriverLock(privconn);
     privdom = virDomainFindByName(&privconn->domains,
                                   domain->name);
+    testDriverUnlock(privconn);
 
     if (privdom == NULL) {
         testError(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
@@ -1251,6 +1371,8 @@ static int testSetMemory(virDomainPtr do
     ret = 0;
 
 cleanup:
+    if (privdom)
+        virDomainObjUnlock(privdom);
     return ret;
 }
 
@@ -1260,8 +1382,12 @@ static int testSetVcpus(virDomainPtr dom
     virDomainObjPtr privdom;
     int ret = -1;
 
-    if ((privdom = virDomainFindByName(&privconn->domains,
-                                       domain->name)) == NULL) {
+    testDriverLock(privconn);
+    privdom = virDomainFindByName(&privconn->domains,
+                                  domain->name);
+    testDriverUnlock(privconn);
+
+    if (privdom == NULL) {
         testError(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
         goto cleanup;
     }
@@ -1276,6 +1402,8 @@ static int testSetVcpus(virDomainPtr dom
     ret = 0;
 
 cleanup:
+    if (privdom)
+        virDomainObjUnlock(privdom);
     return ret;
 }
 
@@ -1286,8 +1414,12 @@ static char *testDomainDumpXML(virDomain
     virDomainObjPtr privdom;
     char *ret = NULL;
 
-    if ((privdom = virDomainFindByName(&privconn->domains,
-                                       domain->name)) == NULL) {
+    testDriverLock(privconn);
+    privdom = virDomainFindByName(&privconn->domains,
+                                  domain->name);
+    testDriverUnlock(privconn);
+
+    if (privdom == NULL) {
         testError(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
         goto cleanup;
     }
@@ -1300,6 +1432,8 @@ static char *testDomainDumpXML(virDomain
                              flags);
 
 cleanup:
+    if (privdom)
+        virDomainObjUnlock(privdom);
     return ret;
 }
 
@@ -1307,9 +1441,14 @@ static int testNumOfDefinedDomains(virCo
     testConnPtr privconn = conn->privateData;
     unsigned int numInactive = 0, i;
 
-    for (i = 0 ; i < privconn->domains.count ; i++)
+    testDriverLock(privconn);
+    for (i = 0 ; i < privconn->domains.count ; i++) {
+        virDomainObjLock(privconn->domains.objs[i]);
         if (!virDomainIsActive(privconn->domains.objs[i]))
             numInactive++;
+        virDomainObjUnlock(privconn->domains.objs[i]);
+    }
+    testDriverUnlock(privconn);
 
     return numInactive;
 }
@@ -1320,11 +1459,18 @@ static int testListDefinedDomains(virCon
     testConnPtr privconn = conn->privateData;
     unsigned int n = 0, i;
 
+    testDriverLock(privconn);
     memset(names, 0, sizeof(*names)*maxnames);
-    for (i = 0 ; i < privconn->domains.count && n < maxnames ; i++)
+    for (i = 0 ; i < privconn->domains.count && n < maxnames ; i++) {
+        virDomainObjLock(privconn->domains.objs[i]);
         if (!virDomainIsActive(privconn->domains.objs[i]) &&
-            !(names[n++] = strdup(privconn->domains.objs[i]->def->name)))
+            !(names[n++] = strdup(privconn->domains.objs[i]->def->name))) {
+            virDomainObjUnlock(privconn->domains.objs[i]);
             goto no_memory;
+        }
+        virDomainObjUnlock(privconn->domains.objs[i]);
+    }
+    testDriverUnlock(privconn);
 
     return n;
 
@@ -1332,6 +1478,7 @@ no_memory:
     testError(conn, VIR_ERR_NO_MEMORY, NULL);
     for (n = 0 ; n < maxnames ; n++)
         VIR_FREE(names[n]);
+    testDriverUnlock(privconn);
     return -1;
 }
 
@@ -1340,8 +1487,9 @@ static virDomainPtr testDomainDefineXML(
     testConnPtr privconn = conn->privateData;
     virDomainPtr ret = NULL;
     virDomainDefPtr def;
-    virDomainObjPtr dom;
+    virDomainObjPtr dom = NULL;
 
+    testDriverLock(privconn);
     if ((def = virDomainDefParseString(conn, privconn->caps, xml)) == NULL)
         goto cleanup;
 
@@ -1359,6 +1507,9 @@ static virDomainPtr testDomainDefineXML(
 
 cleanup:
     virDomainDefFree(def);
+    if (dom)
+        virDomainObjUnlock(dom);
+    testDriverUnlock(privconn);
     return ret;
 }
 
@@ -1369,6 +1520,7 @@ static int testNodeGetCellsFreeMemory(vi
     int i, j;
     int ret = -1;
 
+    testDriverLock(privconn);
     if (startCell > privconn->numCells) {
         testError(conn, VIR_ERR_INVALID_ARG,
                   "%s", _("Range exceeds available cells"));
@@ -1383,6 +1535,7 @@ static int testNodeGetCellsFreeMemory(vi
     ret = j;
 
 cleanup:
+    testDriverUnlock(privconn);
     return ret;
 }
 
@@ -1392,6 +1545,7 @@ static int testDomainCreate(virDomainPtr
     virDomainObjPtr privdom;
     int ret = -1;
 
+    testDriverLock(privconn);
     privdom = virDomainFindByName(&privconn->domains,
                                   domain->name);
 
@@ -1411,6 +1565,9 @@ static int testDomainCreate(virDomainPtr
     ret = 0;
 
 cleanup:
+    if (privdom)
+        virDomainObjUnlock(privdom);
+    testDriverUnlock(privconn);
     return ret;
 }
 
@@ -1419,6 +1576,7 @@ static int testDomainUndefine(virDomainP
     virDomainObjPtr privdom;
     int ret = -1;
 
+    testDriverLock(privconn);
     privdom = virDomainFindByName(&privconn->domains,
                                   domain->name);
 
@@ -1434,11 +1592,16 @@ static int testDomainUndefine(virDomainP
     }
 
     privdom->state = VIR_DOMAIN_SHUTOFF;
+    virDomainObjUnlock(privdom);
     virDomainRemoveInactive(&privconn->domains,
                             privdom);
+    privdom = NULL;
     ret = 0;
 
 cleanup:
+    if (privdom)
+        virDomainObjUnlock(privdom);
+    testDriverUnlock(privconn);
     return ret;
 }
 
@@ -1449,8 +1612,10 @@ static int testDomainGetAutostart(virDom
     virDomainObjPtr privdom;
     int ret = -1;
 
+    testDriverLock(privconn);
     privdom = virDomainFindByName(&privconn->domains,
                                   domain->name);
+    testDriverUnlock(privconn);
 
     if (privdom == NULL) {
         testError(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
@@ -1461,6 +1626,8 @@ static int testDomainGetAutostart(virDom
     ret = 0;
 
 cleanup:
+    if (privdom)
+        virDomainObjUnlock(privdom);
     return ret;
 }
 
@@ -1472,8 +1639,10 @@ static int testDomainSetAutostart(virDom
     virDomainObjPtr privdom;
     int ret = -1;
 
+    testDriverLock(privconn);
     privdom = virDomainFindByName(&privconn->domains,
                                   domain->name);
+    testDriverUnlock(privconn);
 
     if (privdom == NULL) {
         testError(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
@@ -1484,6 +1653,8 @@ static int testDomainSetAutostart(virDom
     ret = 0;
 
 cleanup:
+    if (privdom)
+        virDomainObjUnlock(privdom);
     return ret;
 }
 
@@ -1508,8 +1679,10 @@ static int testDomainGetSchedulerParams(
     virDomainObjPtr privdom;
     int ret = -1;
 
+    testDriverLock(privconn);
     privdom = virDomainFindByName(&privconn->domains,
                                   domain->name);
+    testDriverUnlock(privconn);
 
     if (privdom == NULL) {
         testError(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
@@ -1528,6 +1701,8 @@ static int testDomainGetSchedulerParams(
     ret = 0;
 
 cleanup:
+    if (privdom)
+        virDomainObjUnlock(privdom);
     return ret;
 }
 
@@ -1540,8 +1715,10 @@ static int testDomainSetSchedulerParams(
     virDomainObjPtr privdom;
     int ret = -1;
 
+    testDriverLock(privconn);
     privdom = virDomainFindByName(&privconn->domains,
                                   domain->name);
+    testDriverUnlock(privconn);
 
     if (privdom == NULL) {
         testError(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
@@ -1565,6 +1742,8 @@ static int testDomainSetSchedulerParams(
     ret = 0;
 
 cleanup:
+    if (privdom)
+        virDomainObjUnlock(privdom);
     return ret;
 }
 
@@ -1591,7 +1770,11 @@ static virNetworkPtr testLookupNetworkBy
     virNetworkObjPtr net;
     virNetworkPtr ret = NULL;
 
-    if ((net = virNetworkFindByUUID(&privconn->networks, uuid)) == NULL) {
+    testDriverLock(privconn);
+    net = virNetworkFindByUUID(&privconn->networks, uuid);
+    testDriverUnlock(privconn);
+
+    if (net == NULL) {
         testError (conn, VIR_ERR_NO_NETWORK, NULL);
         goto cleanup;
     }
@@ -1599,6 +1782,8 @@ static virNetworkPtr testLookupNetworkBy
     ret = virGetNetwork(conn, net->def->name, net->def->uuid);
 
 cleanup:
+    if (net)
+        virNetworkObjUnlock(net);
     return ret;
 }
 
@@ -1609,7 +1794,11 @@ static virNetworkPtr testLookupNetworkBy
     virNetworkObjPtr net;
     virNetworkPtr ret = NULL;
 
-    if ((net = virNetworkFindByName(&privconn->networks, name)) == NULL) {
+    testDriverLock(privconn);
+    net = virNetworkFindByName(&privconn->networks, name);
+    testDriverUnlock(privconn);
+
+    if (net == NULL) {
         testError (conn, VIR_ERR_NO_NETWORK, NULL);
         goto cleanup;
     }
@@ -1617,6 +1806,8 @@ static virNetworkPtr testLookupNetworkBy
     ret = virGetNetwork(conn, net->def->name, net->def->uuid);
 
 cleanup:
+    if (net)
+        virNetworkObjUnlock(net);
     return ret;
 }
 
@@ -1625,9 +1816,14 @@ static int testNumNetworks(virConnectPtr
     testConnPtr privconn = conn->privateData;
     int numActive = 0, i;
 
-    for (i = 0 ; i < privconn->networks.count ; i++)
+    testDriverLock(privconn);
+    for (i = 0 ; i < privconn->networks.count ; i++) {
+        virNetworkObjLock(privconn->networks.objs[i]);
         if (virNetworkIsActive(privconn->networks.objs[i]))
             numActive++;
+        virNetworkObjUnlock(privconn->networks.objs[i]);
+    }
+    testDriverUnlock(privconn);
 
     return numActive;
 }
@@ -1636,11 +1832,18 @@ static int testListNetworks(virConnectPt
     testConnPtr privconn = conn->privateData;
     int n = 0, i;
 
+    testDriverLock(privconn);
     memset(names, 0, sizeof(*names)*nnames);
-    for (i = 0 ; i < privconn->networks.count && n < nnames ; i++)
+    for (i = 0 ; i < privconn->networks.count && n < nnames ; i++) {
+        virNetworkObjLock(privconn->networks.objs[i]);
         if (virNetworkIsActive(privconn->networks.objs[i]) &&
-            !(names[n++] = strdup(privconn->networks.objs[i]->def->name)))
+            !(names[n++] = strdup(privconn->networks.objs[i]->def->name))) {
+            virNetworkObjUnlock(privconn->networks.objs[i]);
             goto no_memory;
+        }
+        virNetworkObjUnlock(privconn->networks.objs[i]);
+    }
+    testDriverUnlock(privconn);
 
     return n;
 
@@ -1648,6 +1851,7 @@ no_memory:
     testError(conn, VIR_ERR_NO_MEMORY, NULL);
     for (n = 0 ; n < nnames ; n++)
         VIR_FREE(names[n]);
+    testDriverUnlock(privconn);
     return -1;
 }
 
@@ -1655,9 +1859,14 @@ static int testNumDefinedNetworks(virCon
     testConnPtr privconn = conn->privateData;
     int numInactive = 0, i;
 
-    for (i = 0 ; i < privconn->networks.count ; i++)
+    testDriverLock(privconn);
+    for (i = 0 ; i < privconn->networks.count ; i++) {
+        virNetworkObjLock(privconn->networks.objs[i]);
         if (!virNetworkIsActive(privconn->networks.objs[i]))
             numInactive++;
+        virNetworkObjUnlock(privconn->networks.objs[i]);
+    }
+    testDriverUnlock(privconn);
 
     return numInactive;
 }
@@ -1666,11 +1875,18 @@ static int testListDefinedNetworks(virCo
     testConnPtr privconn = conn->privateData;
     int n = 0, i;
 
+    testDriverLock(privconn);
     memset(names, 0, sizeof(*names)*nnames);
-    for (i = 0 ; i < privconn->networks.count && n < nnames ; i++)
+    for (i = 0 ; i < privconn->networks.count && n < nnames ; i++) {
+        virNetworkObjLock(privconn->networks.objs[i]);
         if (!virNetworkIsActive(privconn->networks.objs[i]) &&
-            !(names[n++] = strdup(privconn->networks.objs[i]->def->name)))
+            !(names[n++] = strdup(privconn->networks.objs[i]->def->name))) {
+            virNetworkObjUnlock(privconn->networks.objs[i]);
             goto no_memory;
+        }
+        virNetworkObjUnlock(privconn->networks.objs[i]);
+    }
+    testDriverUnlock(privconn);
 
     return n;
 
@@ -1678,15 +1894,17 @@ no_memory:
     testError(conn, VIR_ERR_NO_MEMORY, NULL);
     for (n = 0 ; n < nnames ; n++)
         VIR_FREE(names[n]);
+    testDriverUnlock(privconn);
     return -1;
 }
 
 static virNetworkPtr testNetworkCreate(virConnectPtr conn, const char *xml) {
     testConnPtr privconn = conn->privateData;
     virNetworkDefPtr def;
-    virNetworkObjPtr net;
+    virNetworkObjPtr net = NULL;
     virNetworkPtr ret = NULL;
 
+    testDriverLock(privconn);
     if ((def = virNetworkDefParseString(conn, xml)) == NULL)
         goto cleanup;
 
@@ -1701,15 +1919,19 @@ static virNetworkPtr testNetworkCreate(v
 
 cleanup:
     virNetworkDefFree(def);
+    if (net)
+        virNetworkObjUnlock(net);
+    testDriverUnlock(privconn);
     return ret;
 }
 
 static virNetworkPtr testNetworkDefine(virConnectPtr conn, const char *xml) {
     testConnPtr privconn = conn->privateData;
     virNetworkDefPtr def;
-    virNetworkObjPtr net;
+    virNetworkObjPtr net = NULL;
     virNetworkPtr ret = NULL;
 
+    testDriverLock(privconn);
     if ((def = virNetworkDefParseString(conn, xml)) == NULL)
         goto cleanup;
 
@@ -1724,6 +1946,9 @@ static virNetworkPtr testNetworkDefine(v
 
 cleanup:
     virNetworkDefFree(def);
+    if (net)
+        virNetworkObjUnlock(net);
+    testDriverUnlock(privconn);
     return ret;
 }
 
@@ -1732,6 +1957,7 @@ static int testNetworkUndefine(virNetwor
     virNetworkObjPtr privnet;
     int ret = -1;
 
+    testDriverLock(privconn);
     privnet = virNetworkFindByName(&privconn->networks,
                                    network->name);
 
@@ -1748,9 +1974,13 @@ static int testNetworkUndefine(virNetwor
 
     virNetworkRemoveInactive(&privconn->networks,
                              privnet);
+    privnet = NULL;
     ret = 0;
 
 cleanup:
+    if (privnet)
+        virNetworkObjUnlock(privnet);
+    testDriverUnlock(privconn);
     return ret;
 }
 
@@ -1759,8 +1989,10 @@ static int testNetworkStart(virNetworkPt
     virNetworkObjPtr privnet;
     int ret = -1;
 
+    testDriverLock(privconn);
     privnet = virNetworkFindByName(&privconn->networks,
                                    network->name);
+    testDriverUnlock(privconn);
 
     if (privnet == NULL) {
         testError(network->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
@@ -1777,6 +2009,8 @@ static int testNetworkStart(virNetworkPt
     ret = 0;
 
 cleanup:
+    if (privnet)
+        virNetworkObjUnlock(privnet);
     return ret;
 }
 
@@ -1785,6 +2019,7 @@ static int testNetworkDestroy(virNetwork
     virNetworkObjPtr privnet;
     int ret = -1;
 
+    testDriverLock(privconn);
     privnet = virNetworkFindByName(&privconn->networks,
                                    network->name);
 
@@ -1797,10 +2032,14 @@ static int testNetworkDestroy(virNetwork
     if (!privnet->persistent) {
         virNetworkRemoveInactive(&privconn->networks,
                                  privnet);
+        privnet = NULL;
     }
     ret = 0;
 
 cleanup:
+    if (privnet)
+        virNetworkObjUnlock(privnet);
+    testDriverUnlock(privconn);
     return ret;
 }
 
@@ -1809,8 +2048,10 @@ static char *testNetworkDumpXML(virNetwo
     virNetworkObjPtr privnet;
     char *ret = NULL;
 
+    testDriverLock(privconn);
     privnet = virNetworkFindByName(&privconn->networks,
                                    network->name);
+    testDriverUnlock(privconn);
 
     if (privnet == NULL) {
         testError(network->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
@@ -1820,6 +2061,8 @@ static char *testNetworkDumpXML(virNetwo
     ret = virNetworkDefFormat(network->conn, privnet->def);
 
 cleanup:
+    if (privnet)
+        virNetworkObjUnlock(privnet);
     return ret;
 }
 
@@ -1828,8 +2071,10 @@ static char *testNetworkGetBridgeName(vi
     char *bridge = NULL;
     virNetworkObjPtr privnet;
 
+    testDriverLock(privconn);
     privnet = virNetworkFindByName(&privconn->networks,
                                    network->name);
+    testDriverUnlock(privconn);
 
     if (privnet == NULL) {
         testError(network->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
@@ -1843,6 +2088,8 @@ static char *testNetworkGetBridgeName(vi
     }
 
 cleanup:
+    if (privnet)
+        virNetworkObjUnlock(privnet);
     return bridge;
 }
 
@@ -1852,8 +2099,10 @@ static int testNetworkGetAutostart(virNe
     virNetworkObjPtr privnet;
     int ret = -1;
 
+    testDriverLock(privconn);
     privnet = virNetworkFindByName(&privconn->networks,
                                    network->name);
+    testDriverUnlock(privconn);
 
     if (privnet == NULL) {
         testError(network->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
@@ -1864,6 +2113,8 @@ static int testNetworkGetAutostart(virNe
     ret = 0;
 
 cleanup:
+    if (privnet)
+        virNetworkObjUnlock(privnet);
     return ret;
 }
 
@@ -1873,8 +2124,10 @@ static int testNetworkSetAutostart(virNe
     virNetworkObjPtr privnet;
     int ret = -1;
 
+    testDriverLock(privconn);
     privnet = virNetworkFindByName(&privconn->networks,
                                    network->name);
+    testDriverUnlock(privconn);
 
     if (privnet == NULL) {
         testError(network->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
@@ -1885,6 +2138,8 @@ static int testNetworkSetAutostart(virNe
     ret = 0;
 
 cleanup:
+    if (privnet)
+        virNetworkObjUnlock(privnet);
     return ret;
 }
 
@@ -1930,7 +2185,9 @@ testStoragePoolLookupByUUID(virConnectPt
     virStoragePoolObjPtr pool;
     virStoragePoolPtr ret = NULL;
 
+    testDriverLock(privconn);
     pool = virStoragePoolObjFindByUUID(&privconn->pools, uuid);
+    testDriverUnlock(privconn);
 
     if (pool == NULL) {
         testError (conn, VIR_ERR_NO_STORAGE_POOL, NULL);
@@ -1940,6 +2197,8 @@ testStoragePoolLookupByUUID(virConnectPt
     ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid);
 
 cleanup:
+    if (pool)
+        virStoragePoolObjUnlock(pool);
     return ret;
 }
 
@@ -1950,7 +2209,9 @@ testStoragePoolLookupByName(virConnectPt
     virStoragePoolObjPtr pool;
     virStoragePoolPtr ret = NULL;
 
+    testDriverLock(privconn);
     pool = virStoragePoolObjFindByName(&privconn->pools, name);
+    testDriverUnlock(privconn);
 
     if (pool == NULL) {
         testError (conn, VIR_ERR_NO_STORAGE_POOL, NULL);
@@ -1960,6 +2221,8 @@ testStoragePoolLookupByName(virConnectPt
     ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid);
 
 cleanup:
+    if (pool)
+        virStoragePoolObjUnlock(pool);
     return ret;
 }
 
@@ -1973,9 +2236,11 @@ testStorageNumPools(virConnectPtr conn) 
     testConnPtr privconn = conn->privateData;
     int numActive = 0, i;
 
+    testDriverLock(privconn);
     for (i = 0 ; i < privconn->pools.count ; i++)
         if (virStoragePoolObjIsActive(privconn->pools.objs[i]))
             numActive++;
+    testDriverUnlock(privconn);
 
     return numActive;
 }
@@ -1987,11 +2252,18 @@ testStorageListPools(virConnectPtr conn,
     testConnPtr privconn = conn->privateData;
     int n = 0, i;
 
+    testDriverLock(privconn);
     memset(names, 0, sizeof(*names)*nnames);
-    for (i = 0 ; i < privconn->pools.count && n < nnames ; i++)
+    for (i = 0 ; i < privconn->pools.count && n < nnames ; i++) {
+        virStoragePoolObjLock(privconn->pools.objs[i]);
         if (virStoragePoolObjIsActive(privconn->pools.objs[i]) &&
-            !(names[n++] = strdup(privconn->pools.objs[i]->def->name)))
+            !(names[n++] = strdup(privconn->pools.objs[i]->def->name))) {
+            virStoragePoolObjUnlock(privconn->pools.objs[i]);
             goto no_memory;
+        }
+        virStoragePoolObjUnlock(privconn->pools.objs[i]);
+    }
+    testDriverUnlock(privconn);
 
     return n;
 
@@ -1999,6 +2271,7 @@ no_memory:
     testError(conn, VIR_ERR_NO_MEMORY, NULL);
     for (n = 0 ; n < nnames ; n++)
         VIR_FREE(names[n]);
+    testDriverUnlock(privconn);
     return -1;
 }
 
@@ -2007,9 +2280,14 @@ testStorageNumDefinedPools(virConnectPtr
     testConnPtr privconn = conn->privateData;
     int numInactive = 0, i;
 
-    for (i = 0 ; i < privconn->pools.count ; i++)
+    testDriverLock(privconn);
+    for (i = 0 ; i < privconn->pools.count ; i++) {
+        virStoragePoolObjLock(privconn->pools.objs[i]);
         if (!virStoragePoolObjIsActive(privconn->pools.objs[i]))
             numInactive++;
+        virStoragePoolObjUnlock(privconn->pools.objs[i]);
+    }
+    testDriverUnlock(privconn);
 
     return numInactive;
 }
@@ -2021,11 +2299,18 @@ testStorageListDefinedPools(virConnectPt
     testConnPtr privconn = conn->privateData;
     int n = 0, i;
 
+    testDriverLock(privconn);
     memset(names, 0, sizeof(*names)*nnames);
-    for (i = 0 ; i < privconn->pools.count && n < nnames ; i++)
+    for (i = 0 ; i < privconn->pools.count && n < nnames ; i++) {
+        virStoragePoolObjLock(privconn->pools.objs[i]);
         if (!virStoragePoolObjIsActive(privconn->pools.objs[i]) &&
-            !(names[n++] = strdup(privconn->pools.objs[i]->def->name)))
+            !(names[n++] = strdup(privconn->pools.objs[i]->def->name))) {
+            virStoragePoolObjUnlock(privconn->pools.objs[i]);
             goto no_memory;
+        }
+        virStoragePoolObjUnlock(privconn->pools.objs[i]);
+    }
+    testDriverUnlock(privconn);
 
     return n;
 
@@ -2033,6 +2318,7 @@ no_memory:
     testError(conn, VIR_ERR_NO_MEMORY, NULL);
     for (n = 0 ; n < nnames ; n++)
         VIR_FREE(names[n]);
+    testDriverUnlock(privconn);
     return -1;
 }
 
@@ -2047,8 +2333,10 @@ testStoragePoolStart(virStoragePoolPtr p
     virStoragePoolObjPtr privpool;
     int ret = -1;
 
+    testDriverLock(privconn);
     privpool = virStoragePoolObjFindByName(&privconn->pools,
                                            pool->name);
+    testDriverUnlock(privconn);
 
     if (privpool == NULL) {
         testError(pool->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
@@ -2067,6 +2355,8 @@ testStoragePoolStart(virStoragePoolPtr p
     ret = 0;
 
 cleanup:
+    if (privpool)
+        virStoragePoolObjUnlock(privpool);
     return ret;
 }
 
@@ -2086,9 +2376,10 @@ testStoragePoolCreate(virConnectPtr conn
                       unsigned int flags ATTRIBUTE_UNUSED) {
     testConnPtr privconn = conn->privateData;
     virStoragePoolDefPtr def;
-    virStoragePoolObjPtr pool;
+    virStoragePoolObjPtr pool = NULL;
     virStoragePoolPtr ret = NULL;
 
+    testDriverLock(privconn);
     if (!(def = virStoragePoolDefParse(conn, xml, NULL)))
         goto cleanup;
 
@@ -2117,6 +2408,9 @@ testStoragePoolCreate(virConnectPtr conn
 
 cleanup:
     virStoragePoolDefFree(def);
+    if (pool)
+        virStoragePoolObjUnlock(pool);
+    testDriverUnlock(privconn);
     return ret;
 }
 
@@ -2126,9 +2420,10 @@ testStoragePoolDefine(virConnectPtr conn
                       unsigned int flags ATTRIBUTE_UNUSED) {
     testConnPtr privconn = conn->privateData;
     virStoragePoolDefPtr def;
-    virStoragePoolObjPtr pool;
+    virStoragePoolObjPtr pool = NULL;
     virStoragePoolPtr ret = NULL;
 
+    testDriverLock(privconn);
     if (!(def = virStoragePoolDefParse(conn, xml, NULL)))
         goto cleanup;
 
@@ -2151,6 +2446,9 @@ testStoragePoolDefine(virConnectPtr conn
 
 cleanup:
     virStoragePoolDefFree(def);
+    if (pool)
+        virStoragePoolObjUnlock(pool);
+    testDriverUnlock(privconn);
     return ret;
 }
 
@@ -2160,6 +2458,7 @@ testStoragePoolUndefine(virStoragePoolPt
     virStoragePoolObjPtr privpool;
     int ret = -1;
 
+    testDriverLock(privconn);
     privpool = virStoragePoolObjFindByName(&privconn->pools,
                                            pool->name);
 
@@ -2178,6 +2477,9 @@ testStoragePoolUndefine(virStoragePoolPt
     ret = 0;
 
 cleanup:
+    if (privpool)
+        virStoragePoolObjUnlock(privpool);
+    testDriverUnlock(privconn);
     return ret;
 }
 
@@ -2188,8 +2490,10 @@ testStoragePoolBuild(virStoragePoolPtr p
     virStoragePoolObjPtr privpool;
     int ret = -1;
 
+    testDriverLock(privconn);
     privpool = virStoragePoolObjFindByName(&privconn->pools,
                                            pool->name);
+    testDriverUnlock(privconn);
 
     if (privpool == NULL) {
         testError(pool->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
@@ -2203,6 +2507,8 @@ testStoragePoolBuild(virStoragePoolPtr p
     }
 
 cleanup:
+    if (privpool)
+        virStoragePoolObjUnlock(privpool);
     return ret;
 }
 
@@ -2213,6 +2519,7 @@ testStoragePoolDestroy(virStoragePoolPtr
     virStoragePoolObjPtr privpool;
     int ret = -1;
 
+    testDriverLock(privconn);
     privpool = virStoragePoolObjFindByName(&privconn->pools,
                                            pool->name);
 
@@ -2229,11 +2536,16 @@ testStoragePoolDestroy(virStoragePoolPtr
 
     privpool->active = 0;
 
-    if (privpool->configFile == NULL)
+    if (privpool->configFile == NULL) {
         virStoragePoolObjRemove(&privconn->pools, privpool);
+        privpool = NULL;
+    }
     ret = 0;
 
 cleanup:
+    if (privpool)
+        virStoragePoolObjUnlock(privpool);
+    testDriverUnlock(privconn);
     return ret;
 }
 
@@ -2245,8 +2557,10 @@ testStoragePoolDelete(virStoragePoolPtr 
     virStoragePoolObjPtr privpool;
     int ret = -1;
 
+    testDriverLock(privconn);
     privpool = virStoragePoolObjFindByName(&privconn->pools,
                                            pool->name);
+    testDriverUnlock(privconn);
 
     if (privpool == NULL) {
         testError(pool->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
@@ -2262,6 +2576,8 @@ testStoragePoolDelete(virStoragePoolPtr 
     ret = 0;
 
 cleanup:
+    if (privpool)
+        virStoragePoolObjUnlock(privpool);
     return ret;
 }
 
@@ -2273,8 +2589,10 @@ testStoragePoolRefresh(virStoragePoolPtr
     virStoragePoolObjPtr privpool;
     int ret = -1;
 
+    testDriverLock(privconn);
     privpool = virStoragePoolObjFindByName(&privconn->pools,
                                            pool->name);
+    testDriverUnlock(privconn);
 
     if (privpool == NULL) {
         testError(pool->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
@@ -2289,6 +2607,8 @@ testStoragePoolRefresh(virStoragePoolPtr
     ret = 0;
 
 cleanup:
+    if (privpool)
+        virStoragePoolObjUnlock(privpool);
     return ret;
 }
 
@@ -2300,8 +2620,10 @@ testStoragePoolGetInfo(virStoragePoolPtr
     virStoragePoolObjPtr privpool;
     int ret = -1;
 
+    testDriverLock(privconn);
     privpool = virStoragePoolObjFindByName(&privconn->pools,
                                            pool->name);
+    testDriverUnlock(privconn);
 
     if (privpool == NULL) {
         testError(pool->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
@@ -2319,6 +2641,8 @@ testStoragePoolGetInfo(virStoragePoolPtr
     ret = 0;
 
 cleanup:
+    if (privpool)
+        virStoragePoolObjUnlock(privpool);
     return ret;
 }
 
@@ -2329,8 +2653,10 @@ testStoragePoolDumpXML(virStoragePoolPtr
     virStoragePoolObjPtr privpool;
     char *ret = NULL;
 
+    testDriverLock(privconn);
     privpool = virStoragePoolObjFindByName(&privconn->pools,
                                            pool->name);
+    testDriverUnlock(privconn);
 
     if (privpool == NULL) {
         testError(pool->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
@@ -2340,6 +2666,8 @@ testStoragePoolDumpXML(virStoragePoolPtr
     ret = virStoragePoolDefFormat(pool->conn, privpool->def);
 
 cleanup:
+    if (privpool)
+        virStoragePoolObjUnlock(privpool);
     return ret;
 }
 
@@ -2350,8 +2678,10 @@ testStoragePoolGetAutostart(virStoragePo
     virStoragePoolObjPtr privpool;
     int ret = -1;
 
+    testDriverLock(privconn);
     privpool = virStoragePoolObjFindByName(&privconn->pools,
                                            pool->name);
+    testDriverUnlock(privconn);
 
     if (privpool == NULL) {
         testError(pool->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
@@ -2366,6 +2696,8 @@ testStoragePoolGetAutostart(virStoragePo
     ret = 0;
 
 cleanup:
+    if (privpool)
+        virStoragePoolObjUnlock(privpool);
     return ret;
 }
 
@@ -2376,8 +2708,10 @@ testStoragePoolSetAutostart(virStoragePo
     virStoragePoolObjPtr privpool;
     int ret = -1;
 
+    testDriverLock(privconn);
     privpool = virStoragePoolObjFindByName(&privconn->pools,
                                            pool->name);
+    testDriverUnlock(privconn);
 
     if (privpool == NULL) {
         testError(pool->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
@@ -2395,6 +2729,8 @@ testStoragePoolSetAutostart(virStoragePo
     ret = 0;
 
 cleanup:
+    if (privpool)
+        virStoragePoolObjUnlock(privpool);
     return ret;
 }
 
@@ -2405,8 +2741,10 @@ testStoragePoolNumVolumes(virStoragePool
     virStoragePoolObjPtr privpool;
     int ret = -1;
 
+    testDriverLock(privconn);
     privpool = virStoragePoolObjFindByName(&privconn->pools,
                                            pool->name);
+    testDriverUnlock(privconn);
 
     if (privpool == NULL) {
         testError(pool->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
@@ -2422,6 +2760,8 @@ testStoragePoolNumVolumes(virStoragePool
     ret = privpool->volumes.count;
 
 cleanup:
+    if (privpool)
+        virStoragePoolObjUnlock(privpool);
     return ret;
 }
 
@@ -2434,9 +2774,10 @@ testStoragePoolListVolumes(virStoragePoo
     int i = 0, n = 0;
 
     memset(names, 0, maxnames);
-
+    testDriverLock(privconn);
     privpool = virStoragePoolObjFindByName(&privconn->pools,
                                            pool->name);
+    testDriverUnlock(privconn);
 
     if (privpool == NULL) {
         testError(pool->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
@@ -2457,6 +2798,7 @@ testStoragePoolListVolumes(virStoragePoo
         }
     }
 
+    virStoragePoolObjUnlock(privpool);
     return n;
 
  cleanup:
@@ -2464,6 +2806,8 @@ testStoragePoolListVolumes(virStoragePoo
         VIR_FREE(names[i]);
 
     memset(names, 0, maxnames);
+    if (privpool)
+        virStoragePoolObjUnlock(privpool);
     return -1;
 }
 
@@ -2476,8 +2820,10 @@ testStorageVolumeLookupByName(virStorage
     virStorageVolDefPtr privvol;
     virStorageVolPtr ret = NULL;
 
+    testDriverLock(privconn);
     privpool = virStoragePoolObjFindByName(&privconn->pools,
                                            pool->name);
+    testDriverUnlock(privconn);
 
     if (privpool == NULL) {
         testError(pool->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
@@ -2503,6 +2849,8 @@ testStorageVolumeLookupByName(virStorage
                            privvol->name, privvol->key);
 
 cleanup:
+    if (privpool)
+        virStoragePoolObjUnlock(privpool);
     return ret;
 }
 
@@ -2514,7 +2862,9 @@ testStorageVolumeLookupByKey(virConnectP
     unsigned int i;
     virStorageVolPtr ret = NULL;
 
+    testDriverLock(privconn);
     for (i = 0 ; i < privconn->pools.count ; i++) {
+        virStoragePoolObjLock(privconn->pools.objs[i]);
         if (virStoragePoolObjIsActive(privconn->pools.objs[i])) {
             virStorageVolDefPtr privvol =
                 virStorageVolDefFindByKey(privconn->pools.objs[i], key);
@@ -2524,10 +2874,13 @@ testStorageVolumeLookupByKey(virConnectP
                                        privconn->pools.objs[i]->def->name,
                                        privvol->name,
                                        privvol->key);
+                virStoragePoolObjUnlock(privconn->pools.objs[i]);
                 break;
             }
         }
+        virStoragePoolObjUnlock(privconn->pools.objs[i]);
     }
+    testDriverUnlock(privconn);
 
     if (!ret)
         testError(conn, VIR_ERR_INVALID_STORAGE_VOL,
@@ -2543,7 +2896,9 @@ testStorageVolumeLookupByPath(virConnect
     unsigned int i;
     virStorageVolPtr ret = NULL;
 
+    testDriverLock(privconn);
     for (i = 0 ; i < privconn->pools.count ; i++) {
+        virStoragePoolObjLock(privconn->pools.objs[i]);
         if (virStoragePoolObjIsActive(privconn->pools.objs[i])) {
             virStorageVolDefPtr privvol =
                 virStorageVolDefFindByPath(privconn->pools.objs[i], path);
@@ -2553,10 +2908,13 @@ testStorageVolumeLookupByPath(virConnect
                                        privconn->pools.objs[i]->def->name,
                                        privvol->name,
                                        privvol->key);
+                virStoragePoolObjUnlock(privconn->pools.objs[i]);
                 break;
             }
+            virStoragePoolObjUnlock(privconn->pools.objs[i]);
         }
     }
+    testDriverUnlock(privconn);
 
     if (!ret)
         testError(conn, VIR_ERR_INVALID_STORAGE_VOL,
@@ -2574,8 +2932,10 @@ testStorageVolumeCreateXML(virStoragePoo
     virStorageVolDefPtr privvol = NULL;
     virStorageVolPtr ret = NULL;
 
+    testDriverLock(privconn);
     privpool = virStoragePoolObjFindByName(&privconn->pools,
                                            pool->name);
+    testDriverUnlock(privconn);
 
     if (privpool == NULL) {
         testError(pool->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
@@ -2646,6 +3006,8 @@ testStorageVolumeCreateXML(virStoragePoo
 
 cleanup:
     virStorageVolDefFree(privvol);
+    if (privpool)
+        virStoragePoolObjUnlock(privpool);
     return ret;
 }
 
@@ -2658,8 +3020,10 @@ testStorageVolumeDelete(virStorageVolPtr
     int i;
     int ret = -1;
 
+    testDriverLock(privconn);
     privpool = virStoragePoolObjFindByName(&privconn->pools,
                                            vol->pool);
+    testDriverUnlock(privconn);
 
     if (privpool == NULL) {
         testError(vol->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
@@ -2709,6 +3073,8 @@ testStorageVolumeDelete(virStorageVolPtr
     ret = 0;
 
 cleanup:
+    if (privpool)
+        virStoragePoolObjUnlock(privpool);
     return ret;
 }
 
@@ -2733,8 +3099,10 @@ testStorageVolumeGetInfo(virStorageVolPt
     virStorageVolDefPtr privvol;
     int ret = -1;
 
+    testDriverLock(privconn);
     privpool = virStoragePoolObjFindByName(&privconn->pools,
                                            vol->pool);
+    testDriverUnlock(privconn);
 
     if (privpool == NULL) {
         testError(vol->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
@@ -2763,6 +3131,8 @@ testStorageVolumeGetInfo(virStorageVolPt
     ret = 0;
 
 cleanup:
+    if (privpool)
+        virStoragePoolObjUnlock(privpool);
     return ret;
 }
 
@@ -2774,8 +3144,10 @@ testStorageVolumeGetXMLDesc(virStorageVo
     virStorageVolDefPtr privvol;
     char *ret = NULL;
 
+    testDriverLock(privconn);
     privpool = virStoragePoolObjFindByName(&privconn->pools,
                                            vol->pool);
+    testDriverUnlock(privconn);
 
     if (privpool == NULL) {
         testError(vol->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
@@ -2800,6 +3172,8 @@ testStorageVolumeGetXMLDesc(virStorageVo
     ret = virStorageVolDefFormat(vol->conn, privpool->def, privvol);
 
 cleanup:
+    if (privpool)
+        virStoragePoolObjUnlock(privpool);
     return ret;
 }
 
@@ -2810,8 +3184,10 @@ testStorageVolumeGetPath(virStorageVolPt
     virStorageVolDefPtr privvol;
     char *ret = NULL;
 
+    testDriverLock(privconn);
     privpool = virStoragePoolObjFindByName(&privconn->pools,
                                            vol->pool);
+    testDriverUnlock(privconn);
 
     if (privpool == NULL) {
         testError(vol->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
@@ -2838,6 +3214,8 @@ testStorageVolumeGetPath(virStorageVolPt
         testError(vol->conn, VIR_ERR_NO_MEMORY, "%s", _("path"));
 
 cleanup:
+    if (privpool)
+        virStoragePoolObjUnlock(privpool);
     return ret;
 }
 
diff --git a/tests/virsh-all b/tests/virsh-all
--- a/tests/virsh-all
+++ b/tests/virsh-all
@@ -22,6 +22,7 @@ fi
 fi
 
 test -z "$srcdir" && srcdir=$(pwd)
+test -z "$abs_top_srcdir" && abs_top_srcdir=$(pwd)/..
 . "$srcdir/test-lib.sh"
 
 fail=0

-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

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