[PATCH REPOST 6/6] test: Use virStoragePoolObjGetDef accessor

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

 



In preparation for privatizing the object, use the accessor.

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

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index e84acf3228..1c48347994 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -1037,6 +1037,7 @@ testOpenVolumesForPool(const char *file,
                        virStoragePoolObjPtr obj,
                        int objidx)
 {
+    virStoragePoolDefPtr def = virStoragePoolObjGetDef(obj);
     char *vol_xpath;
     size_t i;
     int num, ret = -1;
@@ -1058,12 +1059,12 @@ testOpenVolumesForPool(const char *file,
         if (!node)
             goto error;
 
-        if (!(volDef = virStorageVolDefParseNode(obj->def, ctxt->doc, node, 0)))
+        if (!(volDef = virStorageVolDefParseNode(def, ctxt->doc, node, 0)))
             goto error;
 
         if (!volDef->target.path) {
             if (virAsprintf(&volDef->target.path, "%s/%s",
-                            obj->def->target.path, volDef->name) < 0)
+                            def->target.path, volDef->name) < 0)
                 goto error;
         }
 
@@ -1073,8 +1074,8 @@ testOpenVolumesForPool(const char *file,
         if (virStoragePoolObjAddVol(obj, volDef) < 0)
             goto error;
 
-        obj->def->allocation += volDef->target.allocation;
-        obj->def->available = (obj->def->capacity - obj->def->allocation);
+        def->allocation += volDef->target.allocation;
+        def->available = (def->capacity - def->allocation);
         volDef = NULL;
     }
 
@@ -4056,10 +4057,11 @@ static int
 testStoragePoolObjSetDefaults(virStoragePoolObjPtr obj)
 {
     char *configFile;
+    virStoragePoolDefPtr def = virStoragePoolObjGetDef(obj);
 
-    obj->def->capacity = defaultPoolCap;
-    obj->def->allocation = defaultPoolAlloc;
-    obj->def->available = defaultPoolCap - defaultPoolAlloc;
+    def->capacity = defaultPoolCap;
+    def->allocation = defaultPoolAlloc;
+    def->available = defaultPoolCap - defaultPoolAlloc;
 
     if (VIR_STRDUP(configFile, "") < 0)
         return -1;
@@ -4156,13 +4158,14 @@ testStoragePoolLookupByUUID(virConnectPtr conn,
 {
     testDriverPtr privconn = conn->privateData;
     virStoragePoolObjPtr obj;
+    virStoragePoolDefPtr def;
     virStoragePoolPtr pool = NULL;
 
     if (!(obj = testStoragePoolObjFindByUUID(privconn, uuid)))
         return NULL;
+    def = virStoragePoolObjGetDef(obj);
 
-    pool = virGetStoragePool(conn, obj->def->name, obj->def->uuid,
-                             NULL, NULL);
+    pool = virGetStoragePool(conn, def->name, def->uuid, NULL, NULL);
 
     virStoragePoolObjUnlock(obj);
     return pool;
@@ -4175,13 +4178,14 @@ testStoragePoolLookupByName(virConnectPtr conn,
 {
     testDriverPtr privconn = conn->privateData;
     virStoragePoolObjPtr obj;
+    virStoragePoolDefPtr def;
     virStoragePoolPtr pool = NULL;
 
     if (!(obj = testStoragePoolObjFindByName(privconn, name)))
         return NULL;
+    def = virStoragePoolObjGetDef(obj);
 
-    pool = virGetStoragePool(conn, obj->def->name, obj->def->uuid,
-                             NULL, NULL);
+    pool = virGetStoragePool(conn, def->name, def->uuid, NULL, NULL);
 
     virStoragePoolObjUnlock(obj);
     return pool;
@@ -4426,38 +4430,40 @@ testStoragePoolCreateXML(virConnectPtr conn,
                          unsigned int flags)
 {
     testDriverPtr privconn = conn->privateData;
-    virStoragePoolDefPtr def;
+    virStoragePoolDefPtr newDef;
     virStoragePoolObjPtr obj = NULL;
+    virStoragePoolDefPtr def;
     virStoragePoolPtr pool = NULL;
     virObjectEventPtr event = NULL;
 
     virCheckFlags(0, NULL);
 
     testDriverLock(privconn);
-    if (!(def = virStoragePoolDefParseString(xml)))
+    if (!(newDef = virStoragePoolDefParseString(xml)))
         goto cleanup;
 
-    obj = virStoragePoolObjFindByUUID(&privconn->pools, def->uuid);
+    obj = virStoragePoolObjFindByUUID(&privconn->pools, newDef->uuid);
     if (!obj)
-        obj = virStoragePoolObjFindByName(&privconn->pools, def->name);
+        obj = virStoragePoolObjFindByName(&privconn->pools, newDef->name);
     if (obj) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        "%s", _("storage pool already exists"));
         goto cleanup;
     }
 
-    if (!(obj = virStoragePoolObjAssignDef(&privconn->pools, def)))
+    if (!(obj = virStoragePoolObjAssignDef(&privconn->pools, newDef)))
         goto cleanup;
-    def = NULL;
+    newDef = NULL;
+    def = virStoragePoolObjGetDef(obj);
 
-    if (obj->def->source.adapter.type == VIR_STORAGE_ADAPTER_TYPE_FC_HOST) {
+    if (def->source.adapter.type == VIR_STORAGE_ADAPTER_TYPE_FC_HOST) {
         /* In the real code, we'd call virVHBAManageVport followed by
          * find_new_device, but we cannot do that here since we're not
          * mocking udev. The mock routine will copy an existing vHBA and
          * rename a few fields to mock that. */
         if (testCreateVport(privconn,
-                            obj->def->source.adapter.data.fchost.wwnn,
-                            obj->def->source.adapter.data.fchost.wwpn) < 0) {
+                            def->source.adapter.data.fchost.wwnn,
+                            def->source.adapter.data.fchost.wwpn) < 0) {
             virStoragePoolObjRemove(&privconn->pools, obj);
             obj = NULL;
             goto cleanup;
@@ -4477,14 +4483,14 @@ testStoragePoolCreateXML(virConnectPtr conn,
 
     virStoragePoolObjSetActive(obj, true);
 
-    event = virStoragePoolEventLifecycleNew(obj->def->name, obj->def->uuid,
+    event = virStoragePoolEventLifecycleNew(def->name, def->uuid,
                                             VIR_STORAGE_POOL_EVENT_STARTED,
                                             0);
 
-    pool = virGetStoragePool(conn, obj->def->name, obj->def->uuid, NULL, NULL);
+    pool = virGetStoragePool(conn, def->name, def->uuid, NULL, NULL);
 
  cleanup:
-    virStoragePoolDefFree(def);
+    virStoragePoolDefFree(newDef);
     testObjectEventQueue(privconn, event);
     if (obj)
         virStoragePoolObjUnlock(obj);
@@ -4499,26 +4505,28 @@ testStoragePoolDefineXML(virConnectPtr conn,
                          unsigned int flags)
 {
     testDriverPtr privconn = conn->privateData;
-    virStoragePoolDefPtr def;
+    virStoragePoolDefPtr newDef;
     virStoragePoolObjPtr obj = NULL;
+    virStoragePoolDefPtr def;
     virStoragePoolPtr pool = NULL;
     virObjectEventPtr event = NULL;
 
     virCheckFlags(0, NULL);
 
     testDriverLock(privconn);
-    if (!(def = virStoragePoolDefParseString(xml)))
+    if (!(newDef = virStoragePoolDefParseString(xml)))
         goto cleanup;
 
-    def->capacity = defaultPoolCap;
-    def->allocation = defaultPoolAlloc;
-    def->available = defaultPoolCap - defaultPoolAlloc;
+    newDef->capacity = defaultPoolCap;
+    newDef->allocation = defaultPoolAlloc;
+    newDef->available = defaultPoolCap - defaultPoolAlloc;
 
-    if (!(obj = virStoragePoolObjAssignDef(&privconn->pools, def)))
+    if (!(obj = virStoragePoolObjAssignDef(&privconn->pools, newDef)))
         goto cleanup;
-    def = NULL;
+    newDef = NULL;
+    def = virStoragePoolObjGetDef(obj);
 
-    event = virStoragePoolEventLifecycleNew(obj->def->name, obj->def->uuid,
+    event = virStoragePoolEventLifecycleNew(def->name, def->uuid,
                                             VIR_STORAGE_POOL_EVENT_DEFINED,
                                             0);
 
@@ -4528,10 +4536,10 @@ testStoragePoolDefineXML(virConnectPtr conn,
         goto cleanup;
     }
 
-    pool = virGetStoragePool(conn, obj->def->name, obj->def->uuid, NULL, NULL);
+    pool = virGetStoragePool(conn, def->name, def->uuid, NULL, NULL);
 
  cleanup:
-    virStoragePoolDefFree(def);
+    virStoragePoolDefFree(newDef);
     testObjectEventQueue(privconn, event);
     if (obj)
         virStoragePoolObjUnlock(obj);
@@ -4624,24 +4632,25 @@ testStoragePoolDestroy(virStoragePoolPtr pool)
 {
     testDriverPtr privconn = pool->conn->privateData;
     virStoragePoolObjPtr obj;
+    virStoragePoolDefPtr def;
     int ret = -1;
     virObjectEventPtr event = NULL;
 
     if (!(obj = testStoragePoolObjFindActiveByName(privconn, pool->name)))
         return -1;
+    def = virStoragePoolObjGetDef(obj);
 
     virStoragePoolObjSetActive(obj, false);
 
-    if (obj->def->source.adapter.type ==
-        VIR_STORAGE_ADAPTER_TYPE_FC_HOST) {
+    if (def->source.adapter.type == VIR_STORAGE_ADAPTER_TYPE_FC_HOST) {
         if (testDestroyVport(privconn,
-                             obj->def->source.adapter.data.fchost.wwnn,
-                             obj->def->source.adapter.data.fchost.wwpn) < 0)
+                             def->source.adapter.data.fchost.wwnn,
+                             def->source.adapter.data.fchost.wwpn) < 0)
             goto cleanup;
     }
 
-    event = virStoragePoolEventLifecycleNew(obj->def->name,
-                                            obj->def->uuid,
+    event = virStoragePoolEventLifecycleNew(def->name,
+                                            def->uuid,
                                             VIR_STORAGE_POOL_EVENT_STOPPED,
                                             0);
 
@@ -4710,18 +4719,20 @@ testStoragePoolGetInfo(virStoragePoolPtr pool,
 {
     testDriverPtr privconn = pool->conn->privateData;
     virStoragePoolObjPtr obj;
+    virStoragePoolDefPtr def;
 
     if (!(obj = testStoragePoolObjFindByName(privconn, pool->name)))
         return -1;
+    def = virStoragePoolObjGetDef(obj);
 
     memset(info, 0, sizeof(virStoragePoolInfo));
     if (virStoragePoolObjIsActive(obj))
         info->state = VIR_STORAGE_POOL_RUNNING;
     else
         info->state = VIR_STORAGE_POOL_INACTIVE;
-    info->capacity = obj->def->capacity;
-    info->allocation = obj->def->allocation;
-    info->available = obj->def->available;
+    info->capacity = def->capacity;
+    info->allocation = def->allocation;
+    info->available = def->available;
 
     virStoragePoolObjUnlock(obj);
     return 0;
@@ -4741,7 +4752,7 @@ testStoragePoolGetXMLDesc(virStoragePoolPtr pool,
     if (!(obj = testStoragePoolObjFindByName(privconn, pool->name)))
         return NULL;
 
-    ret = virStoragePoolDefFormat(obj->def);
+    ret = virStoragePoolDefFormat(virStoragePoolObjGetDef(obj));
 
     virStoragePoolObjUnlock(obj);
     return ret;
@@ -4881,16 +4892,18 @@ testStorageVolLookupByName(virStoragePoolPtr pool,
 {
     testDriverPtr privconn = pool->conn->privateData;
     virStoragePoolObjPtr obj;
+    virStoragePoolDefPtr def;
     virStorageVolDefPtr privvol;
     virStorageVolPtr ret = NULL;
 
     if (!(obj = testStoragePoolObjFindActiveByName(privconn, pool->name)))
         return NULL;
+    def = virStoragePoolObjGetDef(obj);
 
     if (!(privvol = testStorageVolDefFindByName(obj, name)))
         goto cleanup;
 
-    ret = virGetStorageVol(pool->conn, obj->def->name,
+    ret = virGetStorageVol(pool->conn, def->name,
                            privvol->name, privvol->key,
                            NULL, NULL);
 
@@ -4906,6 +4919,7 @@ testStorageVolLookupByKey(virConnectPtr conn,
 {
     testDriverPtr privconn = conn->privateData;
     virStoragePoolObjPtr obj;
+    virStoragePoolDefPtr def;
     size_t i;
     virStorageVolPtr ret = NULL;
 
@@ -4913,14 +4927,13 @@ testStorageVolLookupByKey(virConnectPtr conn,
     for (i = 0; i < privconn->pools.count; i++) {
         obj = privconn->pools.objs[i];
         virStoragePoolObjLock(obj);
+        def = virStoragePoolObjGetDef(obj);
         if (virStoragePoolObjIsActive(obj)) {
             virStorageVolDefPtr privvol = virStorageVolDefFindByKey(obj, key);
 
             if (privvol) {
-                ret = virGetStorageVol(conn,
-                                       obj->def->name,
-                                       privvol->name,
-                                       privvol->key,
+                ret = virGetStorageVol(conn, def->name,
+                                       privvol->name, privvol->key,
                                        NULL, NULL);
                 virStoragePoolObjUnlock(obj);
                 break;
@@ -4944,6 +4957,7 @@ testStorageVolLookupByPath(virConnectPtr conn,
 {
     testDriverPtr privconn = conn->privateData;
     virStoragePoolObjPtr obj;
+    virStoragePoolDefPtr def;
     size_t i;
     virStorageVolPtr ret = NULL;
 
@@ -4951,14 +4965,13 @@ testStorageVolLookupByPath(virConnectPtr conn,
     for (i = 0; i < privconn->pools.count; i++) {
         obj = privconn->pools.objs[i];
         virStoragePoolObjLock(obj);
+        def = virStoragePoolObjGetDef(obj);
         if (virStoragePoolObjIsActive(obj)) {
             virStorageVolDefPtr privvol = virStorageVolDefFindByPath(obj, path);
 
             if (privvol) {
-                ret = virGetStorageVol(conn,
-                                       obj->def->name,
-                                       privvol->name,
-                                       privvol->key,
+                ret = virGetStorageVol(conn, def->name,
+                                       privvol->name, privvol->key,
                                        NULL, NULL);
                 virStoragePoolObjUnlock(obj);
                 break;
@@ -4983,6 +4996,7 @@ testStorageVolCreateXML(virStoragePoolPtr pool,
 {
     testDriverPtr privconn = pool->conn->privateData;
     virStoragePoolObjPtr obj;
+    virStoragePoolDefPtr def;
     virStorageVolDefPtr privvol = NULL;
     virStorageVolPtr ret = NULL;
 
@@ -4990,8 +5004,9 @@ testStorageVolCreateXML(virStoragePoolPtr pool,
 
     if (!(obj = testStoragePoolObjFindActiveByName(privconn, pool->name)))
         return NULL;
+    def = virStoragePoolObjGetDef(obj);
 
-    privvol = virStorageVolDefParseString(obj->def, xmldesc, 0);
+    privvol = virStorageVolDefParseString(def, xmldesc, 0);
     if (privvol == NULL)
         goto cleanup;
 
@@ -5002,8 +5017,8 @@ testStorageVolCreateXML(virStoragePoolPtr pool,
     }
 
     /* Make sure enough space */
-    if ((obj->def->allocation + privvol->target.allocation) >
-         obj->def->capacity) {
+    if ((def->allocation + privvol->target.allocation) >
+         def->capacity) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Not enough free space in pool for volume '%s'"),
                        privvol->name);
@@ -5011,17 +5026,17 @@ testStorageVolCreateXML(virStoragePoolPtr pool,
     }
 
     if (virAsprintf(&privvol->target.path, "%s/%s",
-                    obj->def->target.path, privvol->name) < 0)
+                    def->target.path, privvol->name) < 0)
         goto cleanup;
 
     if (VIR_STRDUP(privvol->key, privvol->target.path) < 0 ||
         virStoragePoolObjAddVol(obj, privvol) < 0)
         goto cleanup;
 
-    obj->def->allocation += privvol->target.allocation;
-    obj->def->available = (obj->def->capacity - obj->def->allocation);
+    def->allocation += privvol->target.allocation;
+    def->available = (def->capacity - def->allocation);
 
-    ret = virGetStorageVol(pool->conn, obj->def->name,
+    ret = virGetStorageVol(pool->conn, def->name,
                            privvol->name, privvol->key,
                            NULL, NULL);
     privvol = NULL;
@@ -5041,6 +5056,7 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool,
 {
     testDriverPtr privconn = pool->conn->privateData;
     virStoragePoolObjPtr obj;
+    virStoragePoolDefPtr def;
     virStorageVolDefPtr privvol = NULL, origvol = NULL;
     virStorageVolPtr ret = NULL;
 
@@ -5048,8 +5064,9 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool,
 
     if (!(obj = testStoragePoolObjFindActiveByName(privconn, pool->name)))
         return NULL;
+    def = virStoragePoolObjGetDef(obj);
 
-    privvol = virStorageVolDefParseString(obj->def, xmldesc, 0);
+    privvol = virStorageVolDefParseString(def, xmldesc, 0);
     if (privvol == NULL)
         goto cleanup;
 
@@ -5068,27 +5085,26 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool,
     }
 
     /* Make sure enough space */
-    if ((obj->def->allocation + privvol->target.allocation) >
-         obj->def->capacity) {
+    if ((def->allocation + privvol->target.allocation) > def->capacity) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Not enough free space in pool for volume '%s'"),
                        privvol->name);
         goto cleanup;
     }
-    obj->def->available = (obj->def->capacity - obj->def->allocation);
+    def->available = (def->capacity - def->allocation);
 
     if (virAsprintf(&privvol->target.path, "%s/%s",
-                    obj->def->target.path, privvol->name) < 0)
+                    def->target.path, privvol->name) < 0)
         goto cleanup;
 
     if (VIR_STRDUP(privvol->key, privvol->target.path) < 0 ||
         virStoragePoolObjAddVol(obj, privvol) < 0)
         goto cleanup;
 
-    obj->def->allocation += privvol->target.allocation;
-    obj->def->available = (obj->def->capacity - obj->def->allocation);
+    def->allocation += privvol->target.allocation;
+    def->available = (def->capacity - def->allocation);
 
-    ret = virGetStorageVol(pool->conn, obj->def->name,
+    ret = virGetStorageVol(pool->conn, def->name,
                            privvol->name, privvol->key,
                            NULL, NULL);
     privvol = NULL;
@@ -5106,6 +5122,7 @@ testStorageVolDelete(virStorageVolPtr vol,
 {
     testDriverPtr privconn = vol->conn->privateData;
     virStoragePoolObjPtr obj;
+    virStoragePoolDefPtr def;
     virStorageVolDefPtr privvol;
     int ret = -1;
 
@@ -5113,12 +5130,13 @@ testStorageVolDelete(virStorageVolPtr vol,
 
     if (!(obj = testStoragePoolObjFindActiveByName(privconn, vol->pool)))
         return -1;
+    def = virStoragePoolObjGetDef(obj);
 
     if (!(privvol = testStorageVolDefFindByName(obj, vol->name)))
         goto cleanup;
 
-    obj->def->allocation -= privvol->target.allocation;
-    obj->def->available = (obj->def->capacity - obj->def->allocation);
+    def->allocation -= privvol->target.allocation;
+    def->available = (def->capacity - def->allocation);
 
     virStoragePoolObjRemoveVol(obj, privvol);
 
@@ -5151,17 +5169,19 @@ testStorageVolGetInfo(virStorageVolPtr vol,
 {
     testDriverPtr privconn = vol->conn->privateData;
     virStoragePoolObjPtr obj;
+    virStoragePoolDefPtr def;
     virStorageVolDefPtr privvol;
     int ret = -1;
 
     if (!(obj = testStoragePoolObjFindActiveByName(privconn, vol->pool)))
         return -1;
+    def = virStoragePoolObjGetDef(obj);
 
     if (!(privvol = testStorageVolDefFindByName(obj, vol->name)))
         goto cleanup;
 
     memset(info, 0, sizeof(*info));
-    info->type = testStorageVolumeTypeForPool(obj->def->type);
+    info->type = testStorageVolumeTypeForPool(def->type);
     info->capacity = privvol->target.capacity;
     info->allocation = privvol->target.allocation;
     ret = 0;
@@ -5189,7 +5209,7 @@ testStorageVolGetXMLDesc(virStorageVolPtr vol,
     if (!(privvol = testStorageVolDefFindByName(obj, vol->name)))
         goto cleanup;
 
-    ret = virStorageVolDefFormat(obj->def, privvol);
+    ret = virStorageVolDefFormat(virStoragePoolObjGetDef(obj), privvol);
 
  cleanup:
     virStoragePoolObjUnlock(obj);
-- 
2.13.6

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux