[PATCH 17/19] storage: Use virStoragePoolObj accessors for storage test API's

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

 



In preparation for privatizing the object, use the accessors.

Perform some minor code cleanup along the w/r/t spacing, line wraps, etc.

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

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 6ea3a5b..af5955d 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -1042,6 +1042,7 @@ testOpenVolumesForPool(const char *file,
                        virStoragePoolObjPtr obj,
                        int objidx)
 {
+    virStoragePoolDefPtr objdef = virStoragePoolObjGetDef(obj);
     char *vol_xpath;
     size_t i;
     int num, ret = -1;
@@ -1063,13 +1064,13 @@ testOpenVolumesForPool(const char *file,
         if (!node)
             goto error;
 
-        def = virStorageVolDefParseNode(obj->def, ctxt->doc, node, 0);
+        def = virStorageVolDefParseNode(objdef, ctxt->doc, node, 0);
         if (!def)
             goto error;
 
         if (def->target.path == NULL) {
             if (virAsprintf(&def->target.path, "%s/%s",
-                            obj->def->target.path, def->name) < 0)
+                            objdef->target.path, def->name) < 0)
                 goto error;
         }
 
@@ -1079,8 +1080,8 @@ testOpenVolumesForPool(const char *file,
         if (virStoragePoolObjAddVol(obj, def) < 0)
             goto error;
 
-        obj->def->allocation += def->target.allocation;
-        obj->def->available = (obj->def->capacity - obj->def->allocation);
+        objdef->allocation += def->target.allocation;
+        objdef->available = (objdef->capacity - objdef->allocation);
         def = NULL;
     }
 
@@ -1127,7 +1128,7 @@ testParseStorage(testDriverPtr privconn,
             virStoragePoolObjUnlock(obj);
             goto error;
         }
-        obj->active = 1;
+        virStoragePoolObjSetActive(obj, true);
 
         /* Find storage volumes */
         if (testOpenVolumesForPool(file, ctxt, obj, i+1) < 0) {
@@ -4001,12 +4002,18 @@ testInterfaceDestroy(virInterfacePtr iface,
 static int
 testStoragePoolObjSetDefaults(virStoragePoolObjPtr obj)
 {
+    char *configFile;
+    virStoragePoolDefPtr def = virStoragePoolObjGetDef(obj);
+
+    def->capacity = defaultPoolCap;
+    def->allocation = defaultPoolAlloc;
+    def->available = defaultPoolCap - defaultPoolAlloc;
 
-    obj->def->capacity = defaultPoolCap;
-    obj->def->allocation = defaultPoolAlloc;
-    obj->def->available = defaultPoolCap - defaultPoolAlloc;
+    if (VIR_STRDUP(configFile, "") < 0)
+        return -1;
 
-    return VIR_STRDUP(obj->configFile, "");
+    virStoragePoolObjSetConfigFile(obj, configFile);
+    return 0;
 }
 
 
@@ -4097,13 +4104,14 @@ testStoragePoolLookupByUUID(virConnectPtr conn,
 {
     testDriverPtr privconn = conn->privateData;
     virStoragePoolObjPtr obj;
+    virStoragePoolDefPtr def;
     virStoragePoolPtr ret = NULL;
 
     if (!(obj = testStoragePoolObjFindByUUID(privconn, uuid)))
         return NULL;
+    def = virStoragePoolObjGetDef(obj);
 
-    ret = virGetStoragePool(conn, obj->def->name, obj->def->uuid,
-                            NULL, NULL);
+    ret = virGetStoragePool(conn, def->name, def->uuid, NULL, NULL);
 
     virStoragePoolObjUnlock(obj);
     return ret;
@@ -4116,13 +4124,14 @@ testStoragePoolLookupByName(virConnectPtr conn,
 {
     testDriverPtr privconn = conn->privateData;
     virStoragePoolObjPtr obj;
+    virStoragePoolDefPtr def;
     virStoragePoolPtr ret = NULL;
 
     if (!(obj = testStoragePoolObjFindByName(privconn, name)))
         return NULL;
+    def = virStoragePoolObjGetDef(obj);
 
-    ret = virGetStoragePool(conn, obj->def->name, obj->def->uuid,
-                            NULL, NULL);
+    ret = virGetStoragePool(conn, def->name, def->uuid, NULL, NULL);
 
     virStoragePoolObjUnlock(obj);
     return ret;
@@ -4248,7 +4257,7 @@ testStoragePoolIsPersistent(virStoragePoolPtr pool)
     if (!(obj = testStoragePoolObjFindByUUID(privconn, pool->uuid)))
         return -1;
 
-    ret = obj->configFile ? 1 : 0;
+    ret = virStoragePoolObjGetConfigFile(obj) ? 1 : 0;
 
     virStoragePoolObjUnlock(obj);
     return ret;
@@ -4268,7 +4277,7 @@ testStoragePoolCreate(virStoragePoolPtr pool,
     if (!(obj = testStoragePoolObjFindInactiveByName(privconn, pool->name)))
         return -1;
 
-    obj->active = 1;
+    virStoragePoolObjSetActive(obj, true);
 
     event = virStoragePoolEventLifecycleNew(pool->name, pool->uuid,
                                             VIR_STORAGE_POOL_EVENT_STARTED,
@@ -4369,6 +4378,8 @@ testStoragePoolCreateXML(virConnectPtr conn,
     testDriverPtr privconn = conn->privateData;
     virStoragePoolDefPtr def;
     virStoragePoolObjPtr obj = NULL;
+    virStoragePoolDefPtr objdef;
+    char *configFile;
     virStoragePoolPtr ret = NULL;
     virObjectEventPtr event = NULL;
 
@@ -4390,15 +4401,16 @@ testStoragePoolCreateXML(virConnectPtr conn,
     if (!(obj = virStoragePoolObjAssignDef(&privconn->pools, def)))
         goto cleanup;
     def = NULL;
+    objdef = virStoragePoolObjGetDef(obj);
 
-    if (obj->def->source.adapter.type == VIR_STORAGE_ADAPTER_TYPE_FC_HOST) {
+    if (objdef->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) {
+                            objdef->source.adapter.data.fchost.wwnn,
+                            objdef->source.adapter.data.fchost.wwpn) < 0) {
             virStoragePoolObjRemove(&privconn->pools, obj);
             obj = NULL;
             goto cleanup;
@@ -4414,16 +4426,17 @@ testStoragePoolCreateXML(virConnectPtr conn,
     /* *SetDefaults fills this in for the persistent pools, but this
      * would be a transient pool so remove it; otherwise, the Destroy
      * code will not Remove the pool */
-    VIR_FREE(obj->configFile);
+    configFile = virStoragePoolObjGetConfigFile(obj);
+    VIR_FREE(configFile);
+    virStoragePoolObjSetConfigFile(obj, NULL);
 
-    obj->active = 1;
+    virStoragePoolObjSetActive(obj, true);
 
-    event = virStoragePoolEventLifecycleNew(obj->def->name, obj->def->uuid,
+    event = virStoragePoolEventLifecycleNew(objdef->name, objdef->uuid,
                                             VIR_STORAGE_POOL_EVENT_STARTED,
                                             0);
 
-    ret = virGetStoragePool(conn, obj->def->name, obj->def->uuid,
-                            NULL, NULL);
+    ret = virGetStoragePool(conn, objdef->name, objdef->uuid, NULL, NULL);
 
  cleanup:
     virStoragePoolDefFree(def);
@@ -4443,6 +4456,7 @@ testStoragePoolDefineXML(virConnectPtr conn,
     testDriverPtr privconn = conn->privateData;
     virStoragePoolDefPtr def;
     virStoragePoolObjPtr obj = NULL;
+    virStoragePoolDefPtr objdef;
     virStoragePoolPtr ret = NULL;
     virObjectEventPtr event = NULL;
 
@@ -4459,8 +4473,9 @@ testStoragePoolDefineXML(virConnectPtr conn,
     if (!(obj = virStoragePoolObjAssignDef(&privconn->pools, def)))
         goto cleanup;
     def = NULL;
+    objdef = virStoragePoolObjGetDef(obj);
 
-    event = virStoragePoolEventLifecycleNew(obj->def->name, obj->def->uuid,
+    event = virStoragePoolEventLifecycleNew(objdef->name, objdef->uuid,
                                             VIR_STORAGE_POOL_EVENT_DEFINED,
                                             0);
 
@@ -4470,8 +4485,7 @@ testStoragePoolDefineXML(virConnectPtr conn,
         goto cleanup;
     }
 
-    ret = virGetStoragePool(conn, obj->def->name, obj->def->uuid,
-                            NULL, NULL);
+    ret = virGetStoragePool(conn, objdef->name, objdef->uuid, NULL, NULL);
 
  cleanup:
     virStoragePoolDefFree(def);
@@ -4564,28 +4578,29 @@ 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);
 
-    obj->active = 0;
+    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);
 
-    if (obj->configFile == NULL) {
+    if (!(virStoragePoolObjGetConfigFile(obj))) {
         virStoragePoolObjRemove(&privconn->pools, obj);
         obj = NULL;
     }
@@ -4643,18 +4658,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 (obj->active)
+    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;
@@ -4674,7 +4691,7 @@ testStoragePoolGetXMLDesc(virStoragePoolPtr pool,
     if (!(obj = testStoragePoolObjFindByName(privconn, pool->name)))
         return NULL;
 
-    ret = virStoragePoolDefFormat(obj->def);
+    ret = virStoragePoolDefFormat(virStoragePoolObjGetDef(obj));
 
     virStoragePoolObjUnlock(obj);
     return ret;
@@ -4806,16 +4823,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);
 
@@ -4835,22 +4854,23 @@ testStorageVolLookupByKey(virConnectPtr conn,
 
     testDriverLock(privconn);
     for (i = 0; i < privconn->pools.count; i++) {
-        virStoragePoolObjLock(privconn->pools.objs[i]);
-        if (virStoragePoolObjIsActive(privconn->pools.objs[i])) {
-            virStorageVolDefPtr privvol =
-                virStorageVolDefFindByKey(privconn->pools.objs[i], key);
+        virStoragePoolObjPtr obj = privconn->pools.objs[i];
+        virStoragePoolDefPtr def;
+
+        virStoragePoolObjLock(obj);
+        def = virStoragePoolObjGetDef(obj);
+        if (virStoragePoolObjIsActive(obj)) {
+            virStorageVolDefPtr privvol = virStorageVolDefFindByKey(obj, key);
 
             if (privvol) {
-                ret = virGetStorageVol(conn,
-                                       privconn->pools.objs[i]->def->name,
-                                       privvol->name,
-                                       privvol->key,
+                ret = virGetStorageVol(conn, def->name,
+                                       privvol->name, privvol->key,
                                        NULL, NULL);
-                virStoragePoolObjUnlock(privconn->pools.objs[i]);
+                virStoragePoolObjUnlock(obj);
                 break;
             }
         }
-        virStoragePoolObjUnlock(privconn->pools.objs[i]);
+        virStoragePoolObjUnlock(obj);
     }
     testDriverUnlock(privconn);
 
@@ -4872,22 +4892,23 @@ testStorageVolLookupByPath(virConnectPtr conn,
 
     testDriverLock(privconn);
     for (i = 0; i < privconn->pools.count; i++) {
-        virStoragePoolObjLock(privconn->pools.objs[i]);
-        if (virStoragePoolObjIsActive(privconn->pools.objs[i])) {
-            virStorageVolDefPtr privvol =
-                virStorageVolDefFindByPath(privconn->pools.objs[i], path);
+        virStoragePoolObjPtr obj = privconn->pools.objs[i];
+        virStoragePoolDefPtr def;
+
+        virStoragePoolObjLock(obj);
+        def = virStoragePoolObjGetDef(obj);
+        if (virStoragePoolObjIsActive(obj)) {
+            virStorageVolDefPtr privvol = virStorageVolDefFindByPath(obj, path);
 
             if (privvol) {
-                ret = virGetStorageVol(conn,
-                                       privconn->pools.objs[i]->def->name,
-                                       privvol->name,
-                                       privvol->key,
+                ret = virGetStorageVol(conn, def->name,
+                                       privvol->name, privvol->key,
                                        NULL, NULL);
-                virStoragePoolObjUnlock(privconn->pools.objs[i]);
+                virStoragePoolObjUnlock(obj);
                 break;
             }
         }
-        virStoragePoolObjUnlock(privconn->pools.objs[i]);
+        virStoragePoolObjUnlock(obj);
     }
     testDriverUnlock(privconn);
 
@@ -4906,6 +4927,7 @@ testStorageVolCreateXML(virStoragePoolPtr pool,
 {
     testDriverPtr privconn = pool->conn->privateData;
     virStoragePoolObjPtr obj;
+    virStoragePoolDefPtr def;
     virStorageVolDefPtr privvol = NULL;
     virStorageVolPtr ret = NULL;
 
@@ -4913,8 +4935,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;
 
@@ -4925,8 +4948,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);
@@ -4934,17 +4957,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;
@@ -4964,6 +4987,7 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool,
 {
     testDriverPtr privconn = pool->conn->privateData;
     virStoragePoolObjPtr obj;
+    virStoragePoolDefPtr def;
     virStorageVolDefPtr privvol = NULL, origvol = NULL;
     virStorageVolPtr ret = NULL;
 
@@ -4971,8 +4995,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;
 
@@ -4991,27 +5016,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;
@@ -5029,6 +5053,7 @@ testStorageVolDelete(virStorageVolPtr vol,
 {
     testDriverPtr privconn = vol->conn->privateData;
     virStoragePoolObjPtr obj;
+    virStoragePoolDefPtr def;
     virStorageVolDefPtr privvol;
     int ret = -1;
 
@@ -5036,12 +5061,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);
 
@@ -5074,17 +5100,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;
@@ -5112,7 +5140,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.9.3

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