Re: [libvirt] PATCH: 2/28: Kill off macros in test driver

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

 



The test driver has alot of convenience macros for for fetching the private
internal object impls from the public API parameters. Unfortunately these
rather obscure/hide code flow & variable accesses in the test driver, making
it hard to determine whether a method is thread safe. So this patch removes
all the macros, bringing this driver inline with the style of the other
drivers

 test.c |  899 ++++++++++++++++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 670 insertions(+), 229 deletions(-)

Daniel

diff --git a/src/test.c b/src/test.c
--- a/src/test.c
+++ b/src/test.c
@@ -86,80 +86,22 @@ static const virNodeInfo defaultNodeInfo
     2,
 };
 
-#define GET_DOMAIN(dom, ret)                                            \
-    testConnPtr privconn;                                               \
-    virDomainObjPtr privdom;                                            \
-                                                                        \
-    privconn = (testConnPtr)dom->conn->privateData;                     \
-    do {                                                                \
-        if ((privdom = virDomainFindByName(&privconn->domains,           \
-                                            (dom)->name)) == NULL) {    \
-            testError((dom)->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);  \
-            return (ret);                                               \
-        }                                                               \
-    } while (0)
 
-#define GET_NETWORK(net, ret)                                           \
-    testConnPtr privconn;                                               \
-    virNetworkObjPtr privnet;                                           \
-                                                                        \
-    privconn = (testConnPtr)net->conn->privateData;                     \
-    do {                                                                \
-        if ((privnet = virNetworkFindByName(&privconn->networks,        \
-                                            (net)->name)) == NULL) {    \
-            testError((net)->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);  \
-            return (ret);                                               \
-        }                                                               \
-    } while (0)
 
-#define GET_POOL(pool, ret)                                             \
-    testConnPtr privconn;                                               \
-    virStoragePoolObjPtr privpool;                                      \
-                                                                        \
-    privconn = (testConnPtr)pool->conn->privateData;                    \
-    do {                                                                \
-        if ((privpool = virStoragePoolObjFindByName(&privconn->pools,   \
-                                                    (pool)->name)) == NULL) {\
-            testError((pool)->conn, VIR_ERR_INVALID_ARG, __FUNCTION__); \
-            return (ret);                                               \
-        }                                                               \
-    } while (0)
 
-#define GET_POOL_FROM_VOL(vol, ret)                                     \
-    GET_POOL(testStoragePoolLookupByName((virConnectPtr)                \
-                                         vol->conn,                     \
-                                         vol->pool), ret)
 
-#define GET_VOL(vol, pool, ret)                                         \
-    virStorageVolDefPtr privvol;                                        \
-                                                                        \
-    privvol = virStorageVolDefFindByName(pool, vol->name);              \
-    do {                                                                \
-        if (!privvol) {                                                 \
-            testError(vol->conn, VIR_ERR_INVALID_STORAGE_VOL,           \
-                      _("no storage vol with matching name '%s'"),      \
-                      vol->name);                                       \
-            return (ret);                                               \
-        }                                                               \
-    } while (0)                                                         \
 
-
-#define GET_CONNECTION(conn)                                            \
-    testConnPtr privconn;                                               \
-                                                                        \
-    privconn = (testConnPtr)conn->privateData;
-
-#define POOL_IS_ACTIVE(pool, ret)                                       \
-    if (!virStoragePoolObjIsActive(pool)) {                             \
-        testError(obj->conn, VIR_ERR_INTERNAL_ERROR,                    \
-                  _("storage pool '%s' is not active"), pool->def->name); \
-       return (ret);                                                    \
+#define POOL_IS_ACTIVE(privpool, ret)                                   \
+    if (!virStoragePoolObjIsActive(privpool)) {                         \
+        testError(pool->conn, VIR_ERR_INTERNAL_ERROR,                   \
+                  _("storage pool '%s' is not active"), pool->name);    \
+        return (ret);                                                   \
     }                                                                   \
 
-#define POOL_IS_NOT_ACTIVE(pool, ret)                                   \
-    if (virStoragePoolObjIsActive(pool)) {                              \
-        testError(obj->conn, VIR_ERR_INTERNAL_ERROR,                    \
-                  _("storage pool '%s' is already active"), pool->def->name); \
+#define POOL_IS_NOT_ACTIVE(privpool, ret)                               \
+    if (virStoragePoolObjIsActive(privpool)) {                          \
+        testError(pool->conn, VIR_ERR_INTERNAL_ERROR,                   \
+                  _("storage pool '%s' is already active"), pool->name); \
         return (ret);                                                   \
     }                                                                   \
 
@@ -169,11 +111,11 @@ static const virNodeInfo defaultNodeInfo
 
 static virCapsPtr
 testBuildCapabilities(virConnectPtr conn) {
+    testConnPtr privconn = conn->privateData;
     virCapsPtr caps;
     virCapsGuestPtr guest;
     const char *const guest_types[] = { "hvm", "xen" };
     int i;
-    GET_CONNECTION(conn);
 
     if ((caps = virCapabilitiesNew(TEST_MODEL, 0, 0)) == NULL)
         goto no_memory;
@@ -673,7 +615,7 @@ static int testOpen(virConnectPtr conn,
 
 static int testClose(virConnectPtr conn)
 {
-    GET_CONNECTION(conn);
+    testConnPtr privconn = conn->privateData;
 
     virCapabilitiesFree(privconn->caps);
     virDomainObjListFree(&privconn->domains);
@@ -681,7 +623,7 @@ static int testClose(virConnectPtr conn)
     virStoragePoolObjListFree(&privconn->pools);
 
     VIR_FREE (privconn);
-    conn->privateData = conn;
+    conn->privateData = NULL;
     return 0;
 }
 
@@ -721,15 +663,16 @@ static int testNodeGetInfo(virConnectPtr
 static int testNodeGetInfo(virConnectPtr conn,
                            virNodeInfoPtr info)
 {
-    GET_CONNECTION(conn);
+    testConnPtr privconn = conn->privateData;
+
     memcpy(info, &privconn->nodeInfo, sizeof(virNodeInfo));
     return (0);
 }
 
 static char *testGetCapabilities (virConnectPtr conn)
 {
+    testConnPtr privconn = conn->privateData;
     char *xml;
-    GET_CONNECTION(conn);
 
     if ((xml = virCapabilitiesFormatXML(privconn->caps)) == NULL) {
         testError(conn, VIR_ERR_NO_MEMORY, NULL);
@@ -741,8 +684,8 @@ static char *testGetCapabilities (virCon
 
 static int testNumOfDomains(virConnectPtr conn)
 {
+    testConnPtr privconn = conn->privateData;
     unsigned int numActive = 0, i;
-    GET_CONNECTION(conn);
 
     for (i = 0 ; i < privconn->domains.count ; i++)
         if (virDomainIsActive(privconn->domains.objs[i]))
@@ -755,10 +698,10 @@ testDomainCreateXML(virConnectPtr conn, 
 testDomainCreateXML(virConnectPtr conn, const char *xml,
                       unsigned int flags ATTRIBUTE_UNUSED)
 {
+    testConnPtr privconn = conn->privateData;
     virDomainPtr ret;
     virDomainDefPtr def;
     virDomainObjPtr dom;
-    GET_CONNECTION(conn);
 
     if ((def = virDomainDefParseString(conn, privconn->caps, xml)) == NULL)
         return NULL;
@@ -782,9 +725,9 @@ static virDomainPtr testLookupDomainByID
 static virDomainPtr testLookupDomainByID(virConnectPtr conn,
                                          int id)
 {
+    testConnPtr privconn = conn->privateData;
     virDomainObjPtr dom = NULL;
     virDomainPtr ret;
-    GET_CONNECTION(conn);
 
     if ((dom = virDomainFindByID(&privconn->domains, id)) == NULL) {
         testError (conn, VIR_ERR_NO_DOMAIN, NULL);
@@ -801,9 +744,9 @@ static virDomainPtr testLookupDomainByUU
 static virDomainPtr testLookupDomainByUUID(virConnectPtr conn,
                                            const unsigned char *uuid)
 {
+    testConnPtr privconn = conn->privateData;
     virDomainPtr ret;
     virDomainObjPtr dom = NULL;
-    GET_CONNECTION(conn);
 
     if ((dom = virDomainFindByUUID(&privconn->domains, uuid)) == NULL) {
         testError (conn, VIR_ERR_NO_DOMAIN, NULL);
@@ -820,9 +763,9 @@ static virDomainPtr testLookupDomainByNa
 static virDomainPtr testLookupDomainByName(virConnectPtr conn,
                                            const char *name)
 {
+    testConnPtr privconn = conn->privateData;
     virDomainPtr ret;
     virDomainObjPtr dom = NULL;
-    GET_CONNECTION(conn);
 
     if ((dom = virDomainFindByName(&privconn->domains, name)) == NULL) {
         testError (conn, VIR_ERR_NO_DOMAIN, NULL);
@@ -840,8 +783,8 @@ static int testListDomains (virConnectPt
                             int *ids,
                             int maxids)
 {
+    testConnPtr privconn = conn->privateData;
     unsigned int n = 0, i;
-    GET_CONNECTION(conn);
 
     for (i = 0 ; i < privconn->domains.count && n < maxids ; i++)
         if (virDomainIsActive(privconn->domains.objs[i]))
@@ -852,7 +795,16 @@ static int testListDomains (virConnectPt
 
 static int testDestroyDomain (virDomainPtr domain)
 {
-    GET_DOMAIN(domain, -1);
+    testConnPtr privconn = domain->conn->privateData;
+    virDomainObjPtr privdom;
+
+    privdom = virDomainFindByName(&privconn->domains,
+                                  domain->name);
+
+    if (privdom == NULL) {
+        testError(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return -1;
+    }
 
     privdom->state = VIR_DOMAIN_SHUTOFF;
     privdom->def->id = -1;
@@ -866,7 +818,16 @@ static int testDestroyDomain (virDomainP
 
 static int testResumeDomain (virDomainPtr domain)
 {
-    GET_DOMAIN(domain, -1);
+    testConnPtr privconn = domain->conn->privateData;
+    virDomainObjPtr privdom;
+
+    privdom = virDomainFindByName(&privconn->domains,
+                                  domain->name);
+
+    if (privdom == NULL) {
+        testError(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return -1;
+    }
 
     if (privdom->state != VIR_DOMAIN_PAUSED) {
         testError(domain->conn,
@@ -881,7 +842,16 @@ static int testResumeDomain (virDomainPt
 
 static int testPauseDomain (virDomainPtr domain)
 {
-    GET_DOMAIN(domain, -1);
+    testConnPtr privconn = domain->conn->privateData;
+    virDomainObjPtr privdom;
+
+    privdom = virDomainFindByName(&privconn->domains,
+                                  domain->name);
+
+    if (privdom == NULL) {
+        testError(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return -1;
+    }
 
     if (privdom->state == VIR_DOMAIN_SHUTOFF ||
         privdom->state == VIR_DOMAIN_PAUSED) {
@@ -897,7 +867,16 @@ static int testPauseDomain (virDomainPtr
 
 static int testShutdownDomain (virDomainPtr domain)
 {
-    GET_DOMAIN(domain, -1);
+    testConnPtr privconn = domain->conn->privateData;
+    virDomainObjPtr privdom;
+
+    privdom = virDomainFindByName(&privconn->domains,
+                                  domain->name);
+
+    if (privdom == NULL) {
+        testError(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return -1;
+    }
 
     if (privdom->state == VIR_DOMAIN_SHUTOFF) {
         testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
@@ -916,7 +895,16 @@ static int testRebootDomain (virDomainPt
 static int testRebootDomain (virDomainPtr domain,
                              unsigned int action ATTRIBUTE_UNUSED)
 {
-    GET_DOMAIN(domain, -1);
+    testConnPtr privconn = domain->conn->privateData;
+    virDomainObjPtr privdom;
+
+    privdom = virDomainFindByName(&privconn->domains,
+                                  domain->name);
+
+    if (privdom == NULL) {
+        testError(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return -1;
+    }
 
     privdom->state = VIR_DOMAIN_SHUTDOWN;
     switch (privdom->def->onReboot) {
@@ -953,8 +941,17 @@ static int testGetDomainInfo (virDomainP
 static int testGetDomainInfo (virDomainPtr domain,
                               virDomainInfoPtr info)
 {
+    testConnPtr privconn = domain->conn->privateData;
     struct timeval tv;
-    GET_DOMAIN(domain, -1);
+    virDomainObjPtr privdom;
+
+    privdom = virDomainFindByName(&privconn->domains,
+                                  domain->name);
+
+    if (privdom == NULL) {
+        testError(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return -1;
+    }
 
     if (gettimeofday(&tv, NULL) < 0) {
         testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
@@ -977,9 +974,18 @@ static int testDomainSave(virDomainPtr d
 static int testDomainSave(virDomainPtr domain,
                           const char *path)
 {
+    testConnPtr privconn = domain->conn->privateData;
     char *xml;
     int fd, len;
-    GET_DOMAIN(domain, -1);
+    virDomainObjPtr privdom;
+
+    privdom = virDomainFindByName(&privconn->domains,
+                                  domain->name);
+
+    if (privdom == NULL) {
+        testError(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return -1;
+    }
 
     xml = testDomainDumpXML(domain, 0);
     if (xml == NULL) {
@@ -1037,12 +1043,12 @@ static int testDomainRestore(virConnectP
 static int testDomainRestore(virConnectPtr conn,
                              const char *path)
 {
+    testConnPtr privconn = conn->privateData;
     char *xml;
     char magic[15];
     int fd, len;
     virDomainDefPtr def;
     virDomainObjPtr dom;
-    GET_CONNECTION(conn);
 
     if ((fd = open(path, O_RDONLY)) < 0) {
         testError(conn, VIR_ERR_INTERNAL_ERROR,
@@ -1106,8 +1112,17 @@ static int testDomainCoreDump(virDomainP
                               const char *to,
                               int flags ATTRIBUTE_UNUSED)
 {
+    testConnPtr privconn = domain->conn->privateData;
     int fd;
-    GET_DOMAIN(domain, -1);
+    virDomainObjPtr privdom;
+
+    privdom = virDomainFindByName(&privconn->domains,
+                                  domain->name);
+
+    if (privdom == NULL) {
+        testError(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return -1;
+    }
 
     if ((fd = open(to, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR)) < 0) {
         testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
@@ -1145,7 +1160,16 @@ static char *testGetOSType(virDomainPtr 
 }
 
 static unsigned long testGetMaxMemory(virDomainPtr domain) {
-    GET_DOMAIN(domain, -1);
+    testConnPtr privconn = domain->conn->privateData;
+    virDomainObjPtr privdom;
+
+    privdom = virDomainFindByName(&privconn->domains,
+                                  domain->name);
+
+    if (privdom == NULL) {
+        testError(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return -1;
+    }
 
     return privdom->def->maxmem;
 }
@@ -1153,7 +1177,16 @@ static int testSetMaxMemory(virDomainPtr
 static int testSetMaxMemory(virDomainPtr domain,
                             unsigned long memory)
 {
-    GET_DOMAIN(domain, -1);
+    testConnPtr privconn = domain->conn->privateData;
+    virDomainObjPtr privdom;
+
+    privdom = virDomainFindByName(&privconn->domains,
+                                  domain->name);
+
+    if (privdom == NULL) {
+        testError(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return -1;
+    }
 
     /* XXX validate not over host memory wrt to other domains */
     privdom->def->maxmem = memory;
@@ -1163,7 +1196,16 @@ static int testSetMemory(virDomainPtr do
 static int testSetMemory(virDomainPtr domain,
                          unsigned long memory)
 {
-    GET_DOMAIN(domain, -1);
+    testConnPtr privconn = domain->conn->privateData;
+    virDomainObjPtr privdom;
+
+    privdom = virDomainFindByName(&privconn->domains,
+                                  domain->name);
+
+    if (privdom == NULL) {
+        testError(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return -1;
+    }
 
     if (memory > privdom->def->maxmem) {
         testError(domain->conn,
@@ -1177,7 +1219,13 @@ static int testSetMemory(virDomainPtr do
 
 static int testSetVcpus(virDomainPtr domain,
                         unsigned int nrCpus) {
-    GET_DOMAIN(domain, -1);
+    testConnPtr privconn = domain->conn->privateData;
+    virDomainObjPtr privdom;
+    if ((privdom = virDomainFindByName(&privconn->domains,
+                                       domain->name)) == NULL) {
+        testError(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return -1;
+    }
 
     /* We allow more cpus in guest than host */
     if (nrCpus > 32) {
@@ -1191,8 +1239,14 @@ static int testSetVcpus(virDomainPtr dom
 
 static char *testDomainDumpXML(virDomainPtr domain, int flags)
 {
+    testConnPtr privconn = domain->conn->privateData;
     virDomainDefPtr def;
-    GET_DOMAIN(domain, NULL);
+    virDomainObjPtr privdom;
+    if ((privdom = virDomainFindByName(&privconn->domains,
+                                       domain->name)) == NULL) {
+        testError(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return NULL;
+    }
 
     def = (flags & VIR_DOMAIN_XML_INACTIVE) &&
         privdom->newDef ? privdom->newDef : privdom->def;
@@ -1203,8 +1257,8 @@ static char *testDomainDumpXML(virDomain
 }
 
 static int testNumOfDefinedDomains(virConnectPtr conn) {
+    testConnPtr privconn = conn->privateData;
     unsigned int numInactive = 0, i;
-    GET_CONNECTION(conn);
 
     for (i = 0 ; i < privconn->domains.count ; i++)
         if (!virDomainIsActive(privconn->domains.objs[i]))
@@ -1216,8 +1270,8 @@ static int testListDefinedDomains(virCon
 static int testListDefinedDomains(virConnectPtr conn,
                                   char **const names,
                                   int maxnames) {
+    testConnPtr privconn = conn->privateData;
     unsigned int n = 0, i;
-    GET_CONNECTION(conn);
 
     memset(names, 0, sizeof(*names)*maxnames);
     for (i = 0 ; i < privconn->domains.count && n < maxnames ; i++)
@@ -1236,10 +1290,10 @@ no_memory:
 
 static virDomainPtr testDomainDefineXML(virConnectPtr conn,
                                         const char *xml) {
+    testConnPtr privconn = conn->privateData;
     virDomainPtr ret;
     virDomainDefPtr def;
     virDomainObjPtr dom;
-    GET_CONNECTION(conn);
 
     if ((def = virDomainDefParseString(conn, privconn->caps, xml)) == NULL)
         return NULL;
@@ -1262,9 +1316,8 @@ static int testNodeGetCellsFreeMemory(vi
 static int testNodeGetCellsFreeMemory(virConnectPtr conn,
                                       unsigned long long *freemems,
                                       int startCell, int maxCells) {
+    testConnPtr privconn = conn->privateData;
     int i, j;
-
-    GET_CONNECTION(conn);
 
     if (startCell > privconn->numCells) {
         testError(conn, VIR_ERR_INVALID_ARG,
@@ -1283,7 +1336,16 @@ static int testNodeGetCellsFreeMemory(vi
 
 
 static int testDomainCreate(virDomainPtr domain) {
-    GET_DOMAIN(domain, -1);
+    testConnPtr privconn = domain->conn->privateData;
+    virDomainObjPtr privdom;
+
+    privdom = virDomainFindByName(&privconn->domains,
+                                  domain->name);
+
+    if (privdom == NULL) {
+        testError(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return -1;
+    }
 
     if (privdom->state != VIR_DOMAIN_SHUTOFF) {
         testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
@@ -1298,7 +1360,16 @@ static int testDomainCreate(virDomainPtr
 }
 
 static int testDomainUndefine(virDomainPtr domain) {
-    GET_DOMAIN(domain, -1);
+    testConnPtr privconn = domain->conn->privateData;
+    virDomainObjPtr privdom;
+
+    privdom = virDomainFindByName(&privconn->domains,
+                                  domain->name);
+
+    if (privdom == NULL) {
+        testError(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return -1;
+    }
 
     if (privdom->state != VIR_DOMAIN_SHUTOFF) {
         testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
@@ -1316,7 +1387,17 @@ static int testDomainGetAutostart(virDom
 static int testDomainGetAutostart(virDomainPtr domain,
                                   int *autostart)
 {
-    GET_DOMAIN(domain, -1);
+    testConnPtr privconn = domain->conn->privateData;
+    virDomainObjPtr privdom;
+
+    privdom = virDomainFindByName(&privconn->domains,
+                                  domain->name);
+
+    if (privdom == NULL) {
+        testError(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return -1;
+    }
+
     *autostart = privdom->autostart;
     return (0);
 }
@@ -1325,7 +1406,17 @@ static int testDomainSetAutostart(virDom
 static int testDomainSetAutostart(virDomainPtr domain,
                                   int autostart)
 {
-    GET_DOMAIN(domain, -1);
+    testConnPtr privconn = domain->conn->privateData;
+    virDomainObjPtr privdom;
+
+    privdom = virDomainFindByName(&privconn->domains,
+                                  domain->name);
+
+    if (privdom == NULL) {
+        testError(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return -1;
+    }
+
     privdom->autostart = autostart ? 1 : 0;
     return (0);
 }
@@ -1347,7 +1438,17 @@ static int testDomainGetSchedulerParams(
                                         virSchedParameterPtr params,
                                         int *nparams)
 {
-    GET_DOMAIN(domain, -1);
+    testConnPtr privconn = domain->conn->privateData;
+    virDomainObjPtr privdom;
+
+    privdom = virDomainFindByName(&privconn->domains,
+                                  domain->name);
+
+    if (privdom == NULL) {
+        testError(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return -1;
+    }
+
     if (*nparams != 1) {
         testError(domain->conn, VIR_ERR_INVALID_ARG, "nparams");
         return (-1);
@@ -1365,7 +1466,17 @@ static int testDomainSetSchedulerParams(
                                         virSchedParameterPtr params,
                                         int nparams)
 {
-    GET_DOMAIN(domain, -1);
+    testConnPtr privconn = domain->conn->privateData;
+    virDomainObjPtr privdom;
+
+    privdom = virDomainFindByName(&privconn->domains,
+                                  domain->name);
+
+    if (privdom == NULL) {
+        testError(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return -1;
+    }
+
     if (nparams != 1) {
         testError(domain->conn, VIR_ERR_INVALID_ARG, "nparams");
         return (-1);
@@ -1402,8 +1513,8 @@ static virNetworkPtr testLookupNetworkBy
 static virNetworkPtr testLookupNetworkByUUID(virConnectPtr conn,
                                            const unsigned char *uuid)
 {
-    virNetworkObjPtr net = NULL;
-    GET_CONNECTION(conn);
+    testConnPtr privconn = conn->privateData;
+    virNetworkObjPtr net;
 
     if ((net = virNetworkFindByUUID(&privconn->networks, uuid)) == NULL) {
         testError (conn, VIR_ERR_NO_NETWORK, NULL);
@@ -1416,8 +1527,8 @@ static virNetworkPtr testLookupNetworkBy
 static virNetworkPtr testLookupNetworkByName(virConnectPtr conn,
                                              const char *name)
 {
+    testConnPtr privconn = conn->privateData;
     virNetworkObjPtr net = NULL;
-    GET_CONNECTION(conn);
 
     if ((net = virNetworkFindByName(&privconn->networks, name)) == NULL) {
         testError (conn, VIR_ERR_NO_NETWORK, NULL);
@@ -1429,8 +1540,8 @@ static virNetworkPtr testLookupNetworkBy
 
 
 static int testNumNetworks(virConnectPtr conn) {
+    testConnPtr privconn = conn->privateData;
     int numActive = 0, i;
-    GET_CONNECTION(conn);
 
     for (i = 0 ; i < privconn->networks.count ; i++)
         if (virNetworkIsActive(privconn->networks.objs[i]))
@@ -1440,8 +1551,8 @@ static int testNumNetworks(virConnectPtr
 }
 
 static int testListNetworks(virConnectPtr conn, char **const names, int nnames) {
+    testConnPtr privconn = conn->privateData;
     int n = 0, i;
-    GET_CONNECTION(conn);
 
     memset(names, 0, sizeof(*names)*nnames);
     for (i = 0 ; i < privconn->networks.count && n < nnames ; i++)
@@ -1459,8 +1570,8 @@ no_memory:
 }
 
 static int testNumDefinedNetworks(virConnectPtr conn) {
+    testConnPtr privconn = conn->privateData;
     int numInactive = 0, i;
-    GET_CONNECTION(conn);
 
     for (i = 0 ; i < privconn->networks.count ; i++)
         if (!virNetworkIsActive(privconn->networks.objs[i]))
@@ -1470,8 +1581,8 @@ static int testNumDefinedNetworks(virCon
 }
 
 static int testListDefinedNetworks(virConnectPtr conn, char **const names, int nnames) {
+    testConnPtr privconn = conn->privateData;
     int n = 0, i;
-    GET_CONNECTION(conn);
 
     memset(names, 0, sizeof(*names)*nnames);
     for (i = 0 ; i < privconn->networks.count && n < nnames ; i++)
@@ -1489,9 +1600,9 @@ no_memory:
 }
 
 static virNetworkPtr testNetworkCreate(virConnectPtr conn, const char *xml) {
+    testConnPtr privconn = conn->privateData;
     virNetworkDefPtr def;
     virNetworkObjPtr net;
-    GET_CONNECTION(conn);
 
     if ((def = virNetworkDefParseString(conn, xml)) == NULL)
         return NULL;
@@ -1507,9 +1618,9 @@ static virNetworkPtr testNetworkCreate(v
 }
 
 static virNetworkPtr testNetworkDefine(virConnectPtr conn, const char *xml) {
+    testConnPtr privconn = conn->privateData;
     virNetworkDefPtr def;
     virNetworkObjPtr net;
-    GET_CONNECTION(conn);
 
     if ((def = virNetworkDefParseString(conn, xml)) == NULL)
         return NULL;
@@ -1525,7 +1636,16 @@ static virNetworkPtr testNetworkDefine(v
 }
 
 static int testNetworkUndefine(virNetworkPtr network) {
-    GET_NETWORK(network, -1);
+    testConnPtr privconn = network->conn->privateData;
+    virNetworkObjPtr privnet;
+
+    privnet = virNetworkFindByName(&privconn->networks,
+                                   network->name);
+
+    if (privnet == NULL) {
+        testError(network->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return -1;
+    }
 
     if (virNetworkIsActive(privnet)) {
         testError(network->conn, VIR_ERR_INTERNAL_ERROR,
@@ -1540,7 +1660,16 @@ static int testNetworkUndefine(virNetwor
 }
 
 static int testNetworkStart(virNetworkPtr network) {
-    GET_NETWORK(network, -1);
+    testConnPtr privconn = network->conn->privateData;
+    virNetworkObjPtr privnet;
+
+    privnet = virNetworkFindByName(&privconn->networks,
+                                   network->name);
+
+    if (privnet == NULL) {
+        testError(network->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return -1;
+    }
 
     if (virNetworkIsActive(privnet)) {
         testError(network->conn, VIR_ERR_INTERNAL_ERROR,
@@ -1554,7 +1683,16 @@ static int testNetworkStart(virNetworkPt
 }
 
 static int testNetworkDestroy(virNetworkPtr network) {
-    GET_NETWORK(network, -1);
+    testConnPtr privconn = network->conn->privateData;
+    virNetworkObjPtr privnet;
+
+    privnet = virNetworkFindByName(&privconn->networks,
+                                   network->name);
+
+    if (privnet == NULL) {
+        testError(network->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return -1;
+    }
 
     privnet->active = 0;
     if (!privnet->persistent) {
@@ -1565,14 +1703,33 @@ static int testNetworkDestroy(virNetwork
 }
 
 static char *testNetworkDumpXML(virNetworkPtr network, int flags ATTRIBUTE_UNUSED) {
-    GET_NETWORK(network, NULL);
+    testConnPtr privconn = network->conn->privateData;
+    virNetworkObjPtr privnet;
+
+    privnet = virNetworkFindByName(&privconn->networks,
+                                   network->name);
+
+    if (privnet == NULL) {
+        testError(network->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return NULL;
+    }
 
     return virNetworkDefFormat(network->conn, privnet->def);
 }
 
 static char *testNetworkGetBridgeName(virNetworkPtr network) {
+    testConnPtr privconn = network->conn->privateData;
     char *bridge = NULL;
-    GET_NETWORK(network, NULL);
+    virNetworkObjPtr privnet;
+
+    privnet = virNetworkFindByName(&privconn->networks,
+                                   network->name);
+
+    if (privnet == NULL) {
+        testError(network->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return NULL;
+    }
+
     if (privnet->def->bridge &&
         !(bridge = strdup(privnet->def->bridge))) {
         testError(network->conn, VIR_ERR_NO_MEMORY, "network");
@@ -1583,14 +1740,34 @@ static char *testNetworkGetBridgeName(vi
 
 static int testNetworkGetAutostart(virNetworkPtr network,
                                    int *autostart) {
-    GET_NETWORK(network, -1);
+    testConnPtr privconn = network->conn->privateData;
+    virNetworkObjPtr privnet;
+
+    privnet = virNetworkFindByName(&privconn->networks,
+                                   network->name);
+
+    if (privnet == NULL) {
+        testError(network->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return -1;
+    }
+
     *autostart = privnet->autostart;
     return (0);
 }
 
 static int testNetworkSetAutostart(virNetworkPtr network,
                                    int autostart) {
-    GET_NETWORK(network, -1);
+    testConnPtr privconn = network->conn->privateData;
+    virNetworkObjPtr privnet;
+
+    privnet = virNetworkFindByName(&privconn->networks,
+                                   network->name);
+
+    if (privnet == NULL) {
+        testError(network->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return -1;
+    }
+
     privnet->autostart = autostart ? 1 : 0;
     return (0);
 }
@@ -1633,10 +1810,12 @@ static virStoragePoolPtr
 static virStoragePoolPtr
 testStoragePoolLookupByUUID(virConnectPtr conn,
                             const unsigned char *uuid) {
+    testConnPtr privconn = conn->privateData;
     virStoragePoolObjPtr pool = NULL;
-    GET_CONNECTION(conn);
 
-    if ((pool = virStoragePoolObjFindByUUID(&privconn->pools, uuid)) == NULL) {
+    pool = virStoragePoolObjFindByUUID(&privconn->pools, uuid);
+
+    if (pool == NULL) {
         testError (conn, VIR_ERR_NO_STORAGE_POOL, NULL);
         return NULL;
     }
@@ -1647,10 +1826,12 @@ static virStoragePoolPtr
 static virStoragePoolPtr
 testStoragePoolLookupByName(virConnectPtr conn,
                             const char *name) {
+    testConnPtr privconn = conn->privateData;
     virStoragePoolObjPtr pool = NULL;
-    GET_CONNECTION(conn);
 
-    if ((pool = virStoragePoolObjFindByName(&privconn->pools, name)) == NULL) {
+    pool = virStoragePoolObjFindByName(&privconn->pools, name);
+
+    if (pool == NULL) {
         testError (conn, VIR_ERR_NO_STORAGE_POOL, NULL);
         return NULL;
     }
@@ -1665,9 +1846,8 @@ testStoragePoolLookupByVolume(virStorage
 
 static int
 testStorageNumPools(virConnectPtr conn) {
-
+    testConnPtr privconn = conn->privateData;
     int numActive = 0, i;
-    GET_CONNECTION(conn);
 
     for (i = 0 ; i < privconn->pools.count ; i++)
         if (virStoragePoolObjIsActive(privconn->pools.objs[i]))
@@ -1680,8 +1860,8 @@ testStorageListPools(virConnectPtr conn,
 testStorageListPools(virConnectPtr conn,
                      char **const names,
                      int nnames) {
+    testConnPtr privconn = conn->privateData;
     int n = 0, i;
-    GET_CONNECTION(conn);
 
     memset(names, 0, sizeof(*names)*nnames);
     for (i = 0 ; i < privconn->pools.count && n < nnames ; i++)
@@ -1700,9 +1880,8 @@ no_memory:
 
 static int
 testStorageNumDefinedPools(virConnectPtr conn) {
-
+    testConnPtr privconn = conn->privateData;
     int numInactive = 0, i;
-    GET_CONNECTION(conn);
 
     for (i = 0 ; i < privconn->pools.count ; i++)
         if (!virStoragePoolObjIsActive(privconn->pools.objs[i]))
@@ -1715,8 +1894,8 @@ testStorageListDefinedPools(virConnectPt
 testStorageListDefinedPools(virConnectPtr conn,
                             char **const names,
                             int nnames) {
+    testConnPtr privconn = conn->privateData;
     int n = 0, i;
-    GET_CONNECTION(conn);
 
     memset(names, 0, sizeof(*names)*nnames);
     for (i = 0 ; i < privconn->pools.count && n < nnames ; i++)
@@ -1738,12 +1917,22 @@ testStoragePoolRefresh(virStoragePoolPtr
                        unsigned int flags ATTRIBUTE_UNUSED);
 
 static int
-testStoragePoolStart(virStoragePoolPtr obj,
+testStoragePoolStart(virStoragePoolPtr pool,
                      unsigned int flags ATTRIBUTE_UNUSED) {
-    GET_POOL(obj, -1);
+    testConnPtr privconn = pool->conn->privateData;
+    virStoragePoolObjPtr privpool;
+
+    privpool = virStoragePoolObjFindByName(&privconn->pools,
+                                           pool->name);
+
+    if (privpool == NULL) {
+        testError(pool->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return -1;
+    }
+
     POOL_IS_NOT_ACTIVE(privpool, -1);
 
-    if (testStoragePoolRefresh(obj, 0) == 0)
+    if (testStoragePoolRefresh(pool, 0) == 0)
         return -1;
     privpool->active = 1;
 
@@ -1764,9 +1953,9 @@ testStoragePoolCreate(virConnectPtr conn
 testStoragePoolCreate(virConnectPtr conn,
                       const char *xml,
                       unsigned int flags ATTRIBUTE_UNUSED) {
+    testConnPtr privconn = conn->privateData;
     virStoragePoolDefPtr def;
     virStoragePoolObjPtr pool;
-    GET_CONNECTION(conn);
 
     if (!(def = virStoragePoolDefParse(conn, xml, NULL)))
         return NULL;
@@ -1797,9 +1986,9 @@ testStoragePoolDefine(virConnectPtr conn
 testStoragePoolDefine(virConnectPtr conn,
                       const char *xml,
                       unsigned int flags ATTRIBUTE_UNUSED) {
+    testConnPtr privconn = conn->privateData;
     virStoragePoolDefPtr def;
     virStoragePoolObjPtr pool;
-    GET_CONNECTION(conn);
 
     if (!(def = virStoragePoolDefParse(conn, xml, NULL)))
         return NULL;
@@ -1822,8 +2011,18 @@ testStoragePoolDefine(virConnectPtr conn
 }
 
 static int
-testStoragePoolUndefine(virStoragePoolPtr obj) {
-    GET_POOL(obj, -1);
+testStoragePoolUndefine(virStoragePoolPtr pool) {
+    testConnPtr privconn = pool->conn->privateData;
+    virStoragePoolObjPtr privpool;
+
+    privpool = virStoragePoolObjFindByName(&privconn->pools,
+                                           pool->name);
+
+    if (privpool == NULL) {
+        testError(pool->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return -1;
+    }
+
     POOL_IS_NOT_ACTIVE(privpool, -1);
 
     virStoragePoolObjRemove(&privconn->pools, privpool);
@@ -1832,9 +2031,19 @@ testStoragePoolUndefine(virStoragePoolPt
 }
 
 static int
-testStoragePoolBuild(virStoragePoolPtr obj,
+testStoragePoolBuild(virStoragePoolPtr pool,
                      unsigned int flags ATTRIBUTE_UNUSED) {
-    GET_POOL(obj, -1);
+    testConnPtr privconn = pool->conn->privateData;
+    virStoragePoolObjPtr privpool;
+
+    privpool = virStoragePoolObjFindByName(&privconn->pools,
+                                           pool->name);
+
+    if (privpool == NULL) {
+        testError(pool->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return -1;
+    }
+
     POOL_IS_NOT_ACTIVE(privpool, -1);
 
     return 0;
@@ -1842,9 +2051,23 @@ testStoragePoolBuild(virStoragePoolPtr o
 
 
 static int
-testStoragePoolDestroy(virStoragePoolPtr obj) {
-    GET_POOL(obj, -1);
-    POOL_IS_ACTIVE(privpool, -1);
+testStoragePoolDestroy(virStoragePoolPtr pool) {
+    testConnPtr privconn = pool->conn->privateData;
+    virStoragePoolObjPtr privpool;
+
+    privpool = virStoragePoolObjFindByName(&privconn->pools,
+                                           pool->name);
+
+    if (privpool == NULL) {
+        testError(pool->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return -1;
+    }
+
+    if (!virStoragePoolObjIsActive(privpool)) {
+        testError(pool->conn, VIR_ERR_INTERNAL_ERROR,
+                  _("storage pool '%s' is not active"), pool->name);
+        return -1;
+    }
 
     privpool->active = 0;
 
@@ -1856,9 +2079,19 @@ testStoragePoolDestroy(virStoragePoolPtr
 
 
 static int
-testStoragePoolDelete(virStoragePoolPtr obj,
+testStoragePoolDelete(virStoragePoolPtr pool,
                       unsigned int flags ATTRIBUTE_UNUSED) {
-    GET_POOL(obj, -1);
+    testConnPtr privconn = pool->conn->privateData;
+    virStoragePoolObjPtr privpool;
+
+    privpool = virStoragePoolObjFindByName(&privconn->pools,
+                                           pool->name);
+
+    if (privpool == NULL) {
+        testError(pool->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return -1;
+    }
+
     POOL_IS_NOT_ACTIVE(privpool, -1);
 
     return 0;
@@ -1866,19 +2099,42 @@ testStoragePoolDelete(virStoragePoolPtr 
 
 
 static int
-testStoragePoolRefresh(virStoragePoolPtr obj,
+testStoragePoolRefresh(virStoragePoolPtr pool,
                        unsigned int flags ATTRIBUTE_UNUSED) {
-    GET_POOL(obj, -1);
-    POOL_IS_ACTIVE(privpool, -1);
+    testConnPtr privconn = pool->conn->privateData;
+    virStoragePoolObjPtr privpool;
+
+    privpool = virStoragePoolObjFindByName(&privconn->pools,
+                                           pool->name);
+
+    if (privpool == NULL) {
+        testError(pool->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return -1;
+    }
+
+    if (!virStoragePoolObjIsActive(privpool)) {
+        testError(pool->conn, VIR_ERR_INTERNAL_ERROR,
+                  _("storage pool '%s' is not active"), pool->name);
+        return -1;
+    }
 
     return 0;
 }
 
 
 static int
-testStoragePoolGetInfo(virStoragePoolPtr obj,
+testStoragePoolGetInfo(virStoragePoolPtr pool,
                        virStoragePoolInfoPtr info) {
-    GET_POOL(obj, -1);
+    testConnPtr privconn = pool->conn->privateData;
+    virStoragePoolObjPtr privpool;
+
+    privpool = virStoragePoolObjFindByName(&privconn->pools,
+                                           pool->name);
+
+    if (privpool == NULL) {
+        testError(pool->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return -1;
+    }
 
     memset(info, 0, sizeof(virStoragePoolInfo));
     if (privpool->active)
@@ -1893,17 +2149,35 @@ testStoragePoolGetInfo(virStoragePoolPtr
 }
 
 static char *
-testStoragePoolDumpXML(virStoragePoolPtr obj,
+testStoragePoolDumpXML(virStoragePoolPtr pool,
                        unsigned int flags ATTRIBUTE_UNUSED) {
-    GET_POOL(obj, NULL);
+    testConnPtr privconn = pool->conn->privateData;
+    virStoragePoolObjPtr privpool;
 
-    return virStoragePoolDefFormat(obj->conn, privpool->def);
+    privpool = virStoragePoolObjFindByName(&privconn->pools,
+                                           pool->name);
+
+    if (privpool == NULL) {
+        testError(pool->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return NULL;
+    }
+
+    return virStoragePoolDefFormat(pool->conn, privpool->def);
 }
 
 static int
-testStoragePoolGetAutostart(virStoragePoolPtr obj,
+testStoragePoolGetAutostart(virStoragePoolPtr pool,
                             int *autostart) {
-    GET_POOL(obj, -1);
+    testConnPtr privconn = pool->conn->privateData;
+    virStoragePoolObjPtr privpool;
+
+    privpool = virStoragePoolObjFindByName(&privconn->pools,
+                                           pool->name);
+
+    if (privpool == NULL) {
+        testError(pool->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return -1;
+    }
 
     if (!privpool->configFile) {
         *autostart = 0;
@@ -1915,12 +2189,21 @@ testStoragePoolGetAutostart(virStoragePo
 }
 
 static int
-testStoragePoolSetAutostart(virStoragePoolPtr obj,
+testStoragePoolSetAutostart(virStoragePoolPtr pool,
                             int autostart) {
-    GET_POOL(obj, -1);
+    testConnPtr privconn = pool->conn->privateData;
+    virStoragePoolObjPtr privpool;
+
+    privpool = virStoragePoolObjFindByName(&privconn->pools,
+                                           pool->name);
+
+    if (privpool == NULL) {
+        testError(pool->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return -1;
+    }
 
     if (!privpool->configFile) {
-        testError(obj->conn, VIR_ERR_INVALID_ARG,
+        testError(pool->conn, VIR_ERR_INVALID_ARG,
                   "%s", _("pool has no config file"));
         return -1;
     }
@@ -1936,25 +2219,54 @@ testStoragePoolSetAutostart(virStoragePo
 
 
 static int
-testStoragePoolNumVolumes(virStoragePoolPtr obj) {
-    GET_POOL(obj, -1);
-    POOL_IS_ACTIVE(privpool, -1);
+testStoragePoolNumVolumes(virStoragePoolPtr pool) {
+    testConnPtr privconn = pool->conn->privateData;
+    virStoragePoolObjPtr privpool;
+
+    privpool = virStoragePoolObjFindByName(&privconn->pools,
+                                           pool->name);
+
+    if (privpool == NULL) {
+        testError(pool->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return -1;
+    }
+
+    if (!virStoragePoolObjIsActive(privpool)) {
+        testError(pool->conn, VIR_ERR_INTERNAL_ERROR,
+                  _("storage pool '%s' is not active"), pool->name);
+        return -1;
+    }
 
     return privpool->volumes.count;
 }
 
 static int
-testStoragePoolListVolumes(virStoragePoolPtr obj,
+testStoragePoolListVolumes(virStoragePoolPtr pool,
                            char **const names,
                            int maxnames) {
-    GET_POOL(obj, -1);
-    POOL_IS_ACTIVE(privpool, -1);
+    testConnPtr privconn = pool->conn->privateData;
+    virStoragePoolObjPtr privpool;
     int i = 0, n = 0;
+
+    privpool = virStoragePoolObjFindByName(&privconn->pools,
+                                           pool->name);
+
+    if (privpool == NULL) {
+        testError(pool->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return -1;
+    }
+
+
+    if (!virStoragePoolObjIsActive(privpool)) {
+        testError(pool->conn, VIR_ERR_INTERNAL_ERROR,
+                  _("storage pool '%s' is not active"), pool->name);
+        return -1;
+    }
 
     memset(names, 0, maxnames);
     for (i = 0 ; i < privpool->volumes.count && n < maxnames ; i++) {
         if ((names[n++] = strdup(privpool->volumes.objs[i]->name)) == NULL) {
-            testError(obj->conn, VIR_ERR_NO_MEMORY, "%s", _("name"));
+            testError(pool->conn, VIR_ERR_NO_MEMORY, "%s", _("name"));
             goto cleanup;
         }
     }
@@ -1971,39 +2283,56 @@ testStoragePoolListVolumes(virStoragePoo
 
 
 static virStorageVolPtr
-testStorageVolumeLookupByName(virStoragePoolPtr obj,
+testStorageVolumeLookupByName(virStoragePoolPtr pool,
                               const char *name ATTRIBUTE_UNUSED) {
-    GET_POOL(obj, NULL);
-    POOL_IS_ACTIVE(privpool, NULL);
-    virStorageVolDefPtr vol = virStorageVolDefFindByName(privpool, name);
+    testConnPtr privconn = pool->conn->privateData;
+    virStoragePoolObjPtr privpool;
+    virStorageVolDefPtr privvol;
 
-    if (!vol) {
-        testError(obj->conn, VIR_ERR_INVALID_STORAGE_VOL,
+    privpool = virStoragePoolObjFindByName(&privconn->pools,
+                                           pool->name);
+
+    if (privpool == NULL) {
+        testError(pool->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return NULL;
+    }
+
+
+    if (!virStoragePoolObjIsActive(privpool)) {
+        testError(pool->conn, VIR_ERR_INTERNAL_ERROR,
+                  _("storage pool '%s' is not active"), pool->name);
+        return NULL;
+    }
+
+    privvol = virStorageVolDefFindByName(privpool, name);
+
+    if (!privvol) {
+        testError(pool->conn, VIR_ERR_INVALID_STORAGE_VOL,
                   _("no storage vol with matching name '%s'"), name);
         return NULL;
     }
 
-    return virGetStorageVol(obj->conn, privpool->def->name,
-                            vol->name, vol->key);
+    return virGetStorageVol(pool->conn, privpool->def->name,
+                            privvol->name, privvol->key);
 }
 
 
 static virStorageVolPtr
 testStorageVolumeLookupByKey(virConnectPtr conn,
                              const char *key) {
-    GET_CONNECTION(conn);
+    testConnPtr privconn = conn->privateData;
     unsigned int i;
 
     for (i = 0 ; i < privconn->pools.count ; i++) {
         if (virStoragePoolObjIsActive(privconn->pools.objs[i])) {
-            virStorageVolDefPtr vol =
+            virStorageVolDefPtr privvol =
                 virStorageVolDefFindByKey(privconn->pools.objs[i], key);
 
-            if (vol)
+            if (privvol)
                 return virGetStorageVol(conn,
                                         privconn->pools.objs[i]->def->name,
-                                        vol->name,
-                                        vol->key);
+                                        privvol->name,
+                                        privvol->key);
         }
     }
 
@@ -2015,19 +2344,19 @@ static virStorageVolPtr
 static virStorageVolPtr
 testStorageVolumeLookupByPath(virConnectPtr conn,
                               const char *path) {
-    GET_CONNECTION(conn);
+    testConnPtr privconn = conn->privateData;
     unsigned int i;
 
     for (i = 0 ; i < privconn->pools.count ; i++) {
         if (virStoragePoolObjIsActive(privconn->pools.objs[i])) {
-            virStorageVolDefPtr vol =
+            virStorageVolDefPtr privvol =
                 virStorageVolDefFindByPath(privconn->pools.objs[i], path);
 
-            if (vol)
+            if (privvol)
                 return virGetStorageVol(conn,
                                         privconn->pools.objs[i]->def->name,
-                                        vol->name,
-                                        vol->key);
+                                        privvol->name,
+                                        privvol->key);
         }
     }
 
@@ -2037,31 +2366,47 @@ testStorageVolumeLookupByPath(virConnect
 }
 
 static virStorageVolPtr
-testStorageVolumeCreateXML(virStoragePoolPtr obj,
+testStorageVolumeCreateXML(virStoragePoolPtr pool,
                            const char *xmldesc,
                            unsigned int flags ATTRIBUTE_UNUSED) {
-    GET_POOL(obj, NULL);
-    POOL_IS_ACTIVE(privpool, NULL);
-    virStorageVolDefPtr vol;
+    testConnPtr privconn = pool->conn->privateData;
+    virStoragePoolObjPtr privpool;
+    virStorageVolDefPtr privvol;
 
-    vol = virStorageVolDefParse(obj->conn, privpool->def, xmldesc, NULL);
-    if (vol == NULL)
+    privpool = virStoragePoolObjFindByName(&privconn->pools,
+                                           pool->name);
+
+    if (privpool == NULL) {
+        testError(pool->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return NULL;
+    }
+
+
+    if (!virStoragePoolObjIsActive(privpool)) {
+        testError(pool->conn, VIR_ERR_INTERNAL_ERROR,
+                  _("storage pool '%s' is not active"), pool->name);
+        return NULL;
+    }
+
+
+    privvol = virStorageVolDefParse(pool->conn, privpool->def, xmldesc, NULL);
+    if (privvol == NULL)
         return NULL;
 
-    if (virStorageVolDefFindByName(privpool, vol->name)) {
-        testError(obj->conn, VIR_ERR_INVALID_STORAGE_POOL,
+    if (virStorageVolDefFindByName(privpool, privvol->name)) {
+        testError(pool->conn, VIR_ERR_INVALID_STORAGE_POOL,
                   "%s", _("storage vol already exists"));
-        virStorageVolDefFree(vol);
+        virStorageVolDefFree(privvol);
         return NULL;
     }
 
     /* Make sure enough space */
-    if ((privpool->def->allocation + vol->allocation) >
+    if ((privpool->def->allocation + privvol->allocation) >
          privpool->def->capacity) {
-        testError(obj->conn, VIR_ERR_INTERNAL_ERROR,
+        testError(pool->conn, VIR_ERR_INTERNAL_ERROR,
                   _("Not enough free space in pool for volume '%s'"),
-                  vol->name);
-        virStorageVolDefFree(vol);
+                  privvol->name);
+        virStorageVolDefFree(privvol);
         return NULL;
     }
     privpool->def->available = (privpool->def->capacity -
@@ -2069,46 +2414,72 @@ testStorageVolumeCreateXML(virStoragePoo
 
     if (VIR_REALLOC_N(privpool->volumes.objs,
                       privpool->volumes.count+1) < 0) {
-        testError(obj->conn, VIR_ERR_NO_MEMORY, NULL);
-        virStorageVolDefFree(vol);
+        testError(pool->conn, VIR_ERR_NO_MEMORY, NULL);
+        virStorageVolDefFree(privvol);
         return NULL;
     }
 
-    if (VIR_ALLOC_N(vol->target.path, strlen(privpool->def->target.path) +
-                    1 + strlen(vol->name) + 1) < 0) {
-        virStorageVolDefFree(vol);
-        testError(obj->conn, VIR_ERR_NO_MEMORY, "%s", _("target"));
+    if (VIR_ALLOC_N(privvol->target.path,
+                    strlen(privpool->def->target.path) +
+                    1 + strlen(privvol->name) + 1) < 0) {
+        virStorageVolDefFree(privvol);
+        testError(pool->conn, VIR_ERR_NO_MEMORY, "%s", _("target"));
         return NULL;
     }
 
-    strcpy(vol->target.path, privpool->def->target.path);
-    strcat(vol->target.path, "/");
-    strcat(vol->target.path, vol->name);
-    vol->key = strdup(vol->target.path);
-    if (vol->key == NULL) {
-        virStorageVolDefFree(vol);
-        testError(obj->conn, VIR_ERR_INTERNAL_ERROR, "%s",
+    strcpy(privvol->target.path, privpool->def->target.path);
+    strcat(privvol->target.path, "/");
+    strcat(privvol->target.path, privvol->name);
+    privvol->key = strdup(privvol->target.path);
+    if (privvol->key == NULL) {
+        virStorageVolDefFree(privvol);
+        testError(pool->conn, VIR_ERR_INTERNAL_ERROR, "%s",
                   _("storage vol key"));
         return NULL;
     }
 
-    privpool->def->allocation += vol->allocation;
+    privpool->def->allocation += privvol->allocation;
     privpool->def->available = (privpool->def->capacity -
                                 privpool->def->allocation);
 
-    privpool->volumes.objs[privpool->volumes.count++] = vol;
+    privpool->volumes.objs[privpool->volumes.count++] = privvol;
 
-    return virGetStorageVol(obj->conn, privpool->def->name, vol->name,
-                            vol->key);
+    return virGetStorageVol(pool->conn, privpool->def->name,
+                            privvol->name, privvol->key);
 }
 
 static int
-testStorageVolumeDelete(virStorageVolPtr obj,
+testStorageVolumeDelete(virStorageVolPtr vol,
                         unsigned int flags ATTRIBUTE_UNUSED) {
-    GET_POOL_FROM_VOL(obj, -1);
-    POOL_IS_ACTIVE(privpool, -1);
-    GET_VOL(obj, privpool, -1);
+    testConnPtr privconn = vol->conn->privateData;
+    virStoragePoolObjPtr privpool;
+    virStorageVolDefPtr privvol;
     int i;
+
+    privpool = virStoragePoolObjFindByName(&privconn->pools,
+                                           vol->pool);
+
+    if (privpool == NULL) {
+        testError(vol->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return -1;
+    }
+
+
+    privvol = virStorageVolDefFindByName(privpool, vol->name);
+
+    if (privvol == NULL) {
+        testError(vol->conn, VIR_ERR_INVALID_STORAGE_VOL,
+                  _("no storage vol with matching name '%s'"),
+                  vol->name);
+        return -1;
+    }
+
+    if (!virStoragePoolObjIsActive(privpool)) {
+        testError(vol->conn, VIR_ERR_INTERNAL_ERROR,
+                  _("storage pool '%s' is not active"), vol->pool);
+        return -1;
+    }
+
 
     privpool->def->allocation -= privvol->allocation;
     privpool->def->available = (privpool->def->capacity -
@@ -2151,11 +2522,34 @@ static int testStorageVolumeTypeForPool(
 }
 
 static int
-testStorageVolumeGetInfo(virStorageVolPtr obj,
+testStorageVolumeGetInfo(virStorageVolPtr vol,
                          virStorageVolInfoPtr info) {
-    GET_POOL_FROM_VOL(obj, -1);
-    POOL_IS_ACTIVE(privpool, -1);
-    GET_VOL(obj, privpool, -1);
+    testConnPtr privconn = vol->conn->privateData;
+    virStoragePoolObjPtr privpool;
+    virStorageVolDefPtr privvol;
+
+    privpool = virStoragePoolObjFindByName(&privconn->pools,
+                                           vol->pool);
+
+    if (privpool == NULL) {
+        testError(vol->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return -1;
+    }
+
+    privvol = virStorageVolDefFindByName(privpool, vol->name);
+
+    if (privvol == NULL) {
+        testError(vol->conn, VIR_ERR_INVALID_STORAGE_VOL,
+                  _("no storage vol with matching name '%s'"),
+                  vol->name);
+        return -1;
+    }
+
+    if (!virStoragePoolObjIsActive(privpool)) {
+        testError(vol->conn, VIR_ERR_INTERNAL_ERROR,
+                  _("storage pool '%s' is not active"), vol->pool);
+        return -1;
+    }
 
     memset(info, 0, sizeof(*info));
     info->type = testStorageVolumeTypeForPool(privpool->def->type);
@@ -2166,25 +2560,72 @@ testStorageVolumeGetInfo(virStorageVolPt
 }
 
 static char *
-testStorageVolumeGetXMLDesc(virStorageVolPtr obj,
+testStorageVolumeGetXMLDesc(virStorageVolPtr vol,
                             unsigned int flags ATTRIBUTE_UNUSED) {
-    GET_POOL_FROM_VOL(obj, NULL);
-    POOL_IS_ACTIVE(privpool, NULL);
-    GET_VOL(obj, privpool, NULL);
+    testConnPtr privconn = vol->conn->privateData;
+    virStoragePoolObjPtr privpool;
+    virStorageVolDefPtr privvol;
 
-    return virStorageVolDefFormat(obj->conn, privpool->def, privvol);
+    privpool = virStoragePoolObjFindByName(&privconn->pools,
+                                           vol->pool);
+
+    if (privpool == NULL) {
+        testError(vol->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return NULL;
+    }
+
+    privvol = virStorageVolDefFindByName(privpool, vol->name);
+
+    if (privvol == NULL) {
+        testError(vol->conn, VIR_ERR_INVALID_STORAGE_VOL,
+                  _("no storage vol with matching name '%s'"),
+                  vol->name);
+        return NULL;
+    }
+
+    if (!virStoragePoolObjIsActive(privpool)) {
+        testError(vol->conn, VIR_ERR_INTERNAL_ERROR,
+                  _("storage pool '%s' is not active"), vol->pool);
+        return NULL;
+    }
+
+    return virStorageVolDefFormat(vol->conn, privpool->def, privvol);
 }
 
 static char *
-testStorageVolumeGetPath(virStorageVolPtr obj) {
-    GET_POOL_FROM_VOL(obj, NULL);
-    POOL_IS_ACTIVE(privpool, NULL);
-    GET_VOL(obj, privpool, NULL);
+testStorageVolumeGetPath(virStorageVolPtr vol) {
+    testConnPtr privconn = vol->conn->privateData;
+    virStoragePoolObjPtr privpool;
+    virStorageVolDefPtr privvol;
     char *ret;
+
+
+    privpool = virStoragePoolObjFindByName(&privconn->pools,
+                                           vol->pool);
+
+    if (privpool == NULL) {
+        testError(vol->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return NULL;
+    }
+
+    privvol = virStorageVolDefFindByName(privpool, vol->name);
+
+    if (privvol == NULL) {
+        testError(vol->conn, VIR_ERR_INVALID_STORAGE_VOL,
+                  _("no storage vol with matching name '%s'"),
+                  vol->name);
+        return NULL;
+    }
+
+    if (!virStoragePoolObjIsActive(privpool)) {
+        testError(vol->conn, VIR_ERR_INTERNAL_ERROR,
+                  _("storage pool '%s' is not active"), vol->pool);
+        return NULL;
+    }
 
     ret = strdup(privvol->target.path);
     if (ret == NULL) {
-        testError(obj->conn, VIR_ERR_NO_MEMORY, "%s", _("path"));
+        testError(vol->conn, VIR_ERR_NO_MEMORY, "%s", _("path"));
         return NULL;
     }
     return ret;

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