[PATCH 3/8] test: Refactor test driver domain object retrieval

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

 



Add testDomObjFromDomainLocked and reuse it together with
testDomObjFromDomain to retrieve domain objects in the qemu driver
instead of open-coding it in every API.
---
 src/test/test_driver.c | 409 +++++++++++--------------------------------------
 1 file changed, 92 insertions(+), 317 deletions(-)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 6613ed7..dc6e49a 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -477,13 +477,12 @@ static int testStoragePoolObjSetDefaults(virStoragePoolObjPtr pool);
 static int testNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info);

 static virDomainObjPtr
-testDomObjFromDomain(virDomainPtr domain)
+testDomObjFromDomainLocked(testConnPtr driver,
+                           virDomainPtr domain)
 {
     virDomainObjPtr vm;
-    testConnPtr driver = domain->conn->privateData;
     char uuidstr[VIR_UUID_STRING_BUFLEN];

-    testDriverLock(driver);
     vm = virDomainObjListFindByUUIDRef(driver->domains, domain->uuid);
     if (!vm) {
         virUUIDFormat(domain->uuid, uuidstr);
@@ -492,10 +491,22 @@ testDomObjFromDomain(virDomainPtr domain)
                        uuidstr, domain->name);
     }

-    testDriverUnlock(driver);
     return vm;
 }

+static virDomainObjPtr
+testDomObjFromDomain(virDomainPtr domain)
+{
+    testConnPtr driver = domain->conn->privateData;
+    virDomainObjPtr ret;
+
+    testDriverLock(driver);
+    ret = testDomObjFromDomainLocked(driver, domain);
+    testDriverUnlock(driver);
+
+    return ret;
+}
+
 static char *
 testDomainGenerateIfname(virDomainDefPtr domdef)
 {
@@ -1688,43 +1699,28 @@ static int testConnectNumOfDomains(virConnectPtr conn)

 static int testDomainIsActive(virDomainPtr dom)
 {
-    testConnPtr privconn = dom->conn->privateData;
     virDomainObjPtr obj;
-    int ret = -1;
+    int ret;

-    testDriverLock(privconn);
-    obj = virDomainObjListFindByUUID(privconn->domains, dom->uuid);
-    testDriverUnlock(privconn);
-    if (!obj) {
-        virReportError(VIR_ERR_NO_DOMAIN, NULL);
-        goto cleanup;
-    }
-    ret = virDomainObjIsActive(obj);
+    if (!(obj = testDomObjFromDomain(dom)))
+        return -1;

- cleanup:
-    if (obj)
-        virObjectUnlock(obj);
+    ret = virDomainObjIsActive(obj);
+    virDomainObjEndAPI(&obj);
     return ret;
 }

 static int testDomainIsPersistent(virDomainPtr dom)
 {
-    testConnPtr privconn = dom->conn->privateData;
     virDomainObjPtr obj;
-    int ret = -1;
+    int ret;
+
+    if (!(obj = testDomObjFromDomain(dom)))
+        return -1;

-    testDriverLock(privconn);
-    obj = virDomainObjListFindByUUID(privconn->domains, dom->uuid);
-    testDriverUnlock(privconn);
-    if (!obj) {
-        virReportError(VIR_ERR_NO_DOMAIN, NULL);
-        goto cleanup;
-    }
     ret = obj->persistent;

- cleanup:
-    if (obj)
-        virObjectUnlock(obj);
+    virDomainObjEndAPI(&obj);
     return ret;
 }

@@ -1885,13 +1881,9 @@ static int testDomainDestroy(virDomainPtr domain)
     int ret = -1;

     testDriverLock(privconn);
-    privdom = virDomainObjListFindByName(privconn->domains,
-                                         domain->name);

-    if (privdom == NULL) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+    if (!(privdom = testDomObjFromDomainLocked(privconn, domain)))
         goto cleanup;
-    }

     testDomainShutdownState(domain, privdom, VIR_DOMAIN_SHUTOFF_DESTROYED);
     event = virDomainEventLifecycleNewFromObj(privdom,
@@ -1917,15 +1909,8 @@ static int testDomainResume(virDomainPtr domain)
     virObjectEventPtr event = NULL;
     int ret = -1;

-    testDriverLock(privconn);
-    privdom = virDomainObjListFindByName(privconn->domains,
-                                         domain->name);
-    testDriverUnlock(privconn);
-
-    if (privdom == NULL) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        goto cleanup;
-    }
+    if (!(privdom = testDomObjFromDomain(domain)))
+        return -1;

     if (virDomainObjGetState(privdom, NULL) != VIR_DOMAIN_PAUSED) {
         virReportError(VIR_ERR_INTERNAL_ERROR, _("domain '%s' not paused"),
@@ -1958,15 +1943,8 @@ static int testDomainSuspend(virDomainPtr domain)
     int ret = -1;
     int state;

-    testDriverLock(privconn);
-    privdom = virDomainObjListFindByName(privconn->domains,
-                                         domain->name);
-    testDriverUnlock(privconn);
-
-    if (privdom == NULL) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        goto cleanup;
-    }
+    if (!(privdom = testDomObjFromDomain(domain)))
+        return -1;

     state = virDomainObjGetState(privdom, NULL);
     if (state == VIR_DOMAIN_SHUTOFF || state == VIR_DOMAIN_PAUSED) {
@@ -2003,13 +1981,9 @@ static int testDomainShutdownFlags(virDomainPtr domain,
     virCheckFlags(0, -1);

     testDriverLock(privconn);
-    privdom = virDomainObjListFindByName(privconn->domains,
-                                         domain->name);

-    if (privdom == NULL) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+    if (!(privdom = testDomObjFromDomainLocked(privconn, domain)))
         goto cleanup;
-    }

     if (virDomainObjGetState(privdom, NULL) == VIR_DOMAIN_SHUTOFF) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -2049,13 +2023,9 @@ static int testDomainReboot(virDomainPtr domain,
     int ret = -1;

     testDriverLock(privconn);
-    privdom = virDomainObjListFindByName(privconn->domains,
-                                         domain->name);

-    if (privdom == NULL) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+    if (!(privdom = testDomObjFromDomainLocked(privconn, domain)))
         goto cleanup;
-    }

     virDomainObjSetState(privdom, VIR_DOMAIN_SHUTDOWN,
                          VIR_DOMAIN_SHUTDOWN_USER);
@@ -2109,20 +2079,12 @@ static int testDomainReboot(virDomainPtr domain,
 static int testDomainGetInfo(virDomainPtr domain,
                              virDomainInfoPtr info)
 {
-    testConnPtr privconn = domain->conn->privateData;
     struct timeval tv;
     virDomainObjPtr privdom;
     int ret = -1;

-    testDriverLock(privconn);
-    privdom = virDomainObjListFindByName(privconn->domains,
-                                         domain->name);
-    testDriverUnlock(privconn);
-
-    if (privdom == NULL) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        goto cleanup;
-    }
+    if (!(privdom = testDomObjFromDomain(domain)))
+        return -1;

     if (gettimeofday(&tv, NULL) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -2148,28 +2110,18 @@ testDomainGetState(virDomainPtr domain,
                    int *reason,
                    unsigned int flags)
 {
-    testConnPtr privconn = domain->conn->privateData;
     virDomainObjPtr privdom;
-    int ret = -1;

     virCheckFlags(0, -1);

-    testDriverLock(privconn);
-    privdom = virDomainObjListFindByName(privconn->domains,
-                                         domain->name);
-    testDriverUnlock(privconn);
-
-    if (privdom == NULL) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        goto cleanup;
-    }
+    if (!(privdom = testDomObjFromDomain(domain)))
+        return -1;

     *state = virDomainObjGetState(privdom, reason);
-    ret = 0;

- cleanup:
     virDomainObjEndAPI(&privdom);
-    return ret;
+
+    return 0;
 }

 #define TEST_SAVE_MAGIC "TestGuestMagic"
@@ -2194,13 +2146,9 @@ testDomainSaveFlags(virDomainPtr domain, const char *path,
     }

     testDriverLock(privconn);
-    privdom = virDomainObjListFindByName(privconn->domains,
-                                         domain->name);

-    if (privdom == NULL) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+    if (!(privdom = testDomObjFromDomainLocked(privconn, domain)))
         goto cleanup;
-    }

     xml = virDomainDefFormat(privdom->def,
                              VIR_DOMAIN_DEF_FORMAT_SECURE);
@@ -2398,13 +2346,9 @@ static int testDomainCoreDumpWithFormat(virDomainPtr domain,
     virCheckFlags(VIR_DUMP_CRASH, -1);

     testDriverLock(privconn);
-    privdom = virDomainObjListFindByName(privconn->domains,
-                                         domain->name);

-    if (privdom == NULL) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+    if (!(privdom = testDomObjFromDomainLocked(privconn, domain)))
         goto cleanup;
-    }

     if ((fd = open(to, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR)) < 0) {
         virReportSystemError(errno,
@@ -2475,23 +2419,14 @@ testDomainGetOSType(virDomainPtr dom ATTRIBUTE_UNUSED)
 static unsigned long long
 testDomainGetMaxMemory(virDomainPtr domain)
 {
-    testConnPtr privconn = domain->conn->privateData;
     virDomainObjPtr privdom;
     unsigned long long ret = 0;

-    testDriverLock(privconn);
-    privdom = virDomainObjListFindByName(privconn->domains,
-                                         domain->name);
-    testDriverUnlock(privconn);
-
-    if (privdom == NULL) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        goto cleanup;
-    }
+    if (!(privdom = testDomObjFromDomain(domain)))
+        return 0;

     ret = virDomainDefGetMemoryActual(privdom->def);

- cleanup:
     virDomainObjEndAPI(&privdom);
     return ret;
 }
@@ -2499,45 +2434,26 @@ testDomainGetMaxMemory(virDomainPtr domain)
 static int testDomainSetMaxMemory(virDomainPtr domain,
                                   unsigned long memory)
 {
-    testConnPtr privconn = domain->conn->privateData;
     virDomainObjPtr privdom;
-    int ret = -1;

-    testDriverLock(privconn);
-    privdom = virDomainObjListFindByName(privconn->domains,
-                                         domain->name);
-    testDriverUnlock(privconn);
-
-    if (privdom == NULL) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        goto cleanup;
-    }
+    if (!(privdom = testDomObjFromDomain(domain)))
+        return -1;

     /* XXX validate not over host memory wrt to other domains */
     virDomainDefSetMemoryInitial(privdom->def, memory);
-    ret = 0;

- cleanup:
     virDomainObjEndAPI(&privdom);
-    return ret;
+    return 0;
 }

 static int testDomainSetMemory(virDomainPtr domain,
                                unsigned long memory)
 {
-    testConnPtr privconn = domain->conn->privateData;
     virDomainObjPtr privdom;
     int ret = -1;

-    testDriverLock(privconn);
-    privdom = virDomainObjListFindByName(privconn->domains,
-                                         domain->name);
-    testDriverUnlock(privconn);
-
-    if (privdom == NULL) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        goto cleanup;
-    }
+    if (!(privdom = testDomObjFromDomain(domain)))
+        return -1;

     if (memory > virDomainDefGetMemoryActual(privdom->def)) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
@@ -2555,7 +2471,6 @@ static int testDomainSetMemory(virDomainPtr domain,
 static int
 testDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags)
 {
-    testConnPtr privconn = domain->conn->privateData;
     virDomainObjPtr vm;
     virDomainDefPtr def;
     int ret = -1;
@@ -2564,17 +2479,8 @@ testDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags)
                   VIR_DOMAIN_AFFECT_CONFIG |
                   VIR_DOMAIN_VCPU_MAXIMUM, -1);

-    testDriverLock(privconn);
-    vm = virDomainObjListFindByUUID(privconn->domains, domain->uuid);
-    testDriverUnlock(privconn);
-
-    if (!vm) {
-        char uuidstr[VIR_UUID_STRING_BUFLEN];
-        virUUIDFormat(domain->uuid, uuidstr);
-        virReportError(VIR_ERR_NO_DOMAIN,
-                       _("no domain with matching uuid '%s'"), uuidstr);
-        goto cleanup;
-    }
+    if (!(vm = testDomObjFromDomain(domain)))
+        return -1;

     if (!(def = virDomainObjGetOneDef(vm, flags)))
         goto cleanup;
@@ -2582,8 +2488,7 @@ testDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags)
     ret = (flags & VIR_DOMAIN_VCPU_MAXIMUM) ? def->maxvcpus : def->vcpus;

  cleanup:
-    if (vm)
-        virObjectUnlock(vm);
+    virDomainObjEndAPI(&vm);
     return ret;
 }

@@ -2622,14 +2527,8 @@ testDomainSetVcpusFlags(virDomainPtr domain, unsigned int nrCpus,
         return -1;
     }

-    testDriverLock(privconn);
-    privdom = virDomainObjListFindByUUID(privconn->domains, domain->uuid);
-    testDriverUnlock(privconn);
-
-    if (privdom == NULL) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        goto cleanup;
-    }
+    if (!(privdom = testDomObjFromDomain(domain)))
+        return -1;

     if (!virDomainObjIsActive(privdom) && (flags & VIR_DOMAIN_AFFECT_LIVE)) {
         virReportError(VIR_ERR_OPERATION_INVALID,
@@ -2680,8 +2579,7 @@ testDomainSetVcpusFlags(virDomainPtr domain, unsigned int nrCpus,
     }

  cleanup:
-    if (privdom)
-        virObjectUnlock(privdom);
+    virDomainObjEndAPI(&privdom);
     return ret;
 }

@@ -2706,14 +2604,8 @@ static int testDomainGetVcpus(virDomainPtr domain,
     struct timeval tv;
     unsigned long long statbase;

-    testDriverLock(privconn);
-    privdom = virDomainObjListFindByName(privconn->domains, domain->name);
-    testDriverUnlock(privconn);
-
-    if (privdom == NULL) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        goto cleanup;
-    }
+    if (!(privdom = testDomObjFromDomain(domain)))
+        return -1;

     if (!virDomainObjIsActive(privdom)) {
         virReportError(VIR_ERR_OPERATION_INVALID,
@@ -2791,14 +2683,8 @@ static int testDomainPinVcpu(virDomainPtr domain,
     int maxcpu, hostcpus, privmaplen;
     int ret = -1;

-    testDriverLock(privconn);
-    privdom = virDomainObjListFindByName(privconn->domains, domain->name);
-    testDriverUnlock(privconn);
-
-    if (privdom == NULL) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        goto cleanup;
-    }
+    if (!(privdom = testDomObjFromDomain(domain)))
+        return -1;

     if (!virDomainObjIsActive(privdom)) {
         virReportError(VIR_ERR_OPERATION_INVALID,
@@ -2836,30 +2722,20 @@ static int testDomainPinVcpu(virDomainPtr domain,

 static char *testDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
 {
-    testConnPtr privconn = domain->conn->privateData;
     virDomainDefPtr def;
     virDomainObjPtr privdom;
     char *ret = NULL;

     /* Flags checked by virDomainDefFormat */

-    testDriverLock(privconn);
-    privdom = virDomainObjListFindByName(privconn->domains,
-                                         domain->name);
-    testDriverUnlock(privconn);
-
-    if (privdom == NULL) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        goto cleanup;
-    }
+    if (!(privdom = testDomObjFromDomain(domain)))
+        return NULL;

     def = (flags & VIR_DOMAIN_XML_INACTIVE) &&
         privdom->newDef ? privdom->newDef : privdom->def;

-    ret = virDomainDefFormat(def,
-                             virDomainDefFormatConvertXMLFlags(flags));
+    ret = virDomainDefFormat(def, virDomainDefFormatConvertXMLFlags(flags));

- cleanup:
     virDomainObjEndAPI(&privdom);
     return ret;
 }
@@ -2960,25 +2836,17 @@ static char *testDomainGetMetadata(virDomainPtr dom,
 {
     testConnPtr privconn = dom->conn->privateData;
     virDomainObjPtr privdom;
-    char *ret = NULL;
+    char *ret;

     virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
                   VIR_DOMAIN_AFFECT_CONFIG, NULL);

-    testDriverLock(privconn);
-    privdom = virDomainObjListFindByName(privconn->domains,
-                                         dom->name);
-    testDriverUnlock(privconn);
-
-    if (privdom == NULL) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        goto cleanup;
-    }
+    if (!(privdom = testDomObjFromDomain(dom)))
+        return NULL;

     ret = virDomainObjGetMetadata(privdom, type, uri, privconn->caps,
                                   privconn->xmlopt, flags);

- cleanup:
     virDomainObjEndAPI(&privdom);
     return ret;
 }
@@ -2992,26 +2860,18 @@ static int testDomainSetMetadata(virDomainPtr dom,
 {
     testConnPtr privconn = dom->conn->privateData;
     virDomainObjPtr privdom;
-    int ret = -1;
+    int ret;

     virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
                   VIR_DOMAIN_AFFECT_CONFIG, -1);

-    testDriverLock(privconn);
-    privdom = virDomainObjListFindByName(privconn->domains,
-                                         dom->name);
-    testDriverUnlock(privconn);
-
-    if (privdom == NULL) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        goto cleanup;
-    }
+    if (!(privdom = testDomObjFromDomain(dom)))
+        return -1;

     ret = virDomainObjSetMetadata(privdom, type, metadata, key, uri,
                                   privconn->caps, privconn->xmlopt,
                                   NULL, NULL, flags);

- cleanup:
     virDomainObjEndAPI(&privdom);
     return ret;
 }
@@ -3056,13 +2916,9 @@ static int testDomainCreateWithFlags(virDomainPtr domain, unsigned int flags)
     virCheckFlags(0, -1);

     testDriverLock(privconn);
-    privdom = virDomainObjListFindByName(privconn->domains,
-                                         domain->name);

-    if (privdom == NULL) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+    if (!(privdom = testDomObjFromDomainLocked(privconn, domain)))
         goto cleanup;
-    }

     if (virDomainObjGetState(privdom, NULL) != VIR_DOMAIN_SHUTOFF) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -3106,13 +2962,9 @@ static int testDomainUndefineFlags(virDomainPtr domain,
                   VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA, -1);

     testDriverLock(privconn);
-    privdom = virDomainObjListFindByName(privconn->domains,
-                                         domain->name);

-    if (privdom == NULL) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+    if (!(privdom = testDomObjFromDomainLocked(privconn, domain)))
         goto cleanup;
-    }

     if (privdom->hasManagedSave &&
         !(flags & VIR_DOMAIN_UNDEFINE_MANAGED_SAVE)) {
@@ -3168,52 +3020,30 @@ static int testDomainUndefine(virDomainPtr domain)
 static int testDomainGetAutostart(virDomainPtr domain,
                                   int *autostart)
 {
-    testConnPtr privconn = domain->conn->privateData;
     virDomainObjPtr privdom;
-    int ret = -1;

-    testDriverLock(privconn);
-    privdom = virDomainObjListFindByName(privconn->domains,
-                                         domain->name);
-    testDriverUnlock(privconn);
-
-    if (privdom == NULL) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        goto cleanup;
-    }
+    if (!(privdom = testDomObjFromDomain(domain)))
+        return -1;

     *autostart = privdom->autostart;
-    ret = 0;

- cleanup:
     virDomainObjEndAPI(&privdom);
-    return ret;
+    return 0;
 }


 static int testDomainSetAutostart(virDomainPtr domain,
                                   int autostart)
 {
-    testConnPtr privconn = domain->conn->privateData;
     virDomainObjPtr privdom;
-    int ret = -1;

-    testDriverLock(privconn);
-    privdom = virDomainObjListFindByName(privconn->domains,
-                                         domain->name);
-    testDriverUnlock(privconn);
-
-    if (privdom == NULL) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        goto cleanup;
-    }
+    if (!(privdom = testDomObjFromDomain(domain)))
+        return -1;

     privdom->autostart = autostart ? 1 : 0;
-    ret = 0;

- cleanup:
     virDomainObjEndAPI(&privdom);
-    return ret;
+    return 0;
 }

 static char *testDomainGetSchedulerType(virDomainPtr domain ATTRIBUTE_UNUSED,
@@ -3235,21 +3065,13 @@ testDomainGetSchedulerParametersFlags(virDomainPtr domain,
                                       int *nparams,
                                       unsigned int flags)
 {
-    testConnPtr privconn = domain->conn->privateData;
     virDomainObjPtr privdom;
     int ret = -1;

     virCheckFlags(0, -1);

-    testDriverLock(privconn);
-    privdom = virDomainObjListFindByName(privconn->domains,
-                                         domain->name);
-    testDriverUnlock(privconn);
-
-    if (privdom == NULL) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        goto cleanup;
-    }
+    if (!(privdom = testDomObjFromDomain(domain)))
+        return -1;

     if (virTypedParameterAssign(params, VIR_DOMAIN_SCHEDULER_WEIGHT,
                                 VIR_TYPED_PARAM_UINT, 50) < 0)
@@ -3279,7 +3101,6 @@ testDomainSetSchedulerParametersFlags(virDomainPtr domain,
                                       int nparams,
                                       unsigned int flags)
 {
-    testConnPtr privconn = domain->conn->privateData;
     virDomainObjPtr privdom;
     int ret = -1;
     size_t i;
@@ -3291,15 +3112,8 @@ testDomainSetSchedulerParametersFlags(virDomainPtr domain,
                                NULL) < 0)
         return -1;

-    testDriverLock(privconn);
-    privdom = virDomainObjListFindByName(privconn->domains,
-                                         domain->name);
-    testDriverUnlock(privconn);
-
-    if (privdom == NULL) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        goto cleanup;
-    }
+    if (!(privdom = testDomObjFromDomain(domain)))
+        return -1;

     for (i = 0; i < nparams; i++) {
         if (STREQ(params[i].field, VIR_DOMAIN_SCHEDULER_WEIGHT)) {
@@ -3310,7 +3124,6 @@ testDomainSetSchedulerParametersFlags(virDomainPtr domain,

     ret = 0;

- cleanup:
     virDomainObjEndAPI(&privdom);
     return ret;
 }
@@ -3327,7 +3140,6 @@ static int testDomainBlockStats(virDomainPtr domain,
                                 const char *path,
                                 virDomainBlockStatsPtr stats)
 {
-    testConnPtr privconn = domain->conn->privateData;
     virDomainObjPtr privdom;
     struct timeval tv;
     unsigned long long statbase;
@@ -3339,15 +3151,8 @@ static int testDomainBlockStats(virDomainPtr domain,
         return ret;
     }

-    testDriverLock(privconn);
-    privdom = virDomainObjListFindByName(privconn->domains,
-                                         domain->name);
-    testDriverUnlock(privconn);
-
-    if (privdom == NULL) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        goto error;
-    }
+    if (!(privdom = testDomObjFromDomain(domain)))
+        return ret;

     if (virDomainDiskIndexByName(privdom->def, path, false) < 0) {
         virReportError(VIR_ERR_INVALID_ARG,
@@ -3379,22 +3184,14 @@ static int testDomainInterfaceStats(virDomainPtr domain,
                                     const char *path,
                                     virDomainInterfaceStatsPtr stats)
 {
-    testConnPtr privconn = domain->conn->privateData;
     virDomainObjPtr privdom;
     struct timeval tv;
     unsigned long long statbase;
     size_t i;
     int found = 0, ret = -1;

-    testDriverLock(privconn);
-    privdom = virDomainObjListFindByName(privconn->domains,
-                                         domain->name);
-    testDriverUnlock(privconn);
-
-    if (privdom == NULL) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        goto error;
-    }
+    if (!(privdom = testDomObjFromDomain(domain)))
+        return -1;

     for (i = 0; i < privdom->def->nnets; i++) {
         if (privdom->def->nets[i]->ifname &&
@@ -6138,14 +5935,8 @@ testDomainManagedSave(virDomainPtr dom, unsigned int flags)
                   VIR_DOMAIN_SAVE_RUNNING |
                   VIR_DOMAIN_SAVE_PAUSED, -1);

-    testDriverLock(privconn);
-    vm = virDomainObjListFindByName(privconn->domains, dom->name);
-    testDriverUnlock(privconn);
-
-    if (vm == NULL) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        goto cleanup;
-    }
+    if (!(vm = testDomObjFromDomain(dom)))
+        return -1;

     if (!virDomainObjIsActive(vm)) {
         virReportError(VIR_ERR_OPERATION_INVALID,
@@ -6181,50 +5972,34 @@ testDomainManagedSave(virDomainPtr dom, unsigned int flags)
 static int
 testDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags)
 {
-    testConnPtr privconn = dom->conn->privateData;
     virDomainObjPtr vm;
-    int ret = -1;
+    int ret;

     virCheckFlags(0, -1);

-    testDriverLock(privconn);
-
-    vm = virDomainObjListFindByName(privconn->domains, dom->name);
-    if (vm == NULL) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        goto cleanup;
-    }
+    if (!(vm = testDomObjFromDomain(dom)))
+        return -1;

     ret = vm->hasManagedSave;
- cleanup:
+
     virDomainObjEndAPI(&vm);
-    testDriverUnlock(privconn);
     return ret;
 }

 static int
 testDomainManagedSaveRemove(virDomainPtr dom, unsigned int flags)
 {
-    testConnPtr privconn = dom->conn->privateData;
     virDomainObjPtr vm;
-    int ret = -1;

     virCheckFlags(0, -1);

-    testDriverLock(privconn);
-
-    vm = virDomainObjListFindByName(privconn->domains, dom->name);
-    if (vm == NULL) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        goto cleanup;
-    }
+    if (!(vm = testDomObjFromDomain(dom)))
+        return -1;

     vm->hasManagedSave = false;
-    ret = 0;
- cleanup:
+
     virDomainObjEndAPI(&vm);
-    testDriverUnlock(privconn);
-    return ret;
+    return 0;
 }


-- 
2.4.1

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