[PATCH v2 02/12] storage: Introduce virStoragePoolObjNew

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

 



Create/use a helper to perform object allocation.

Adjust storagevolxml2argvtest.c in order to use the allocator and
setting of the obj->def.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/conf/virstorageobj.c       | 31 +++++++++++++++++++++----------
 src/conf/virstorageobj.h       |  3 +++
 src/libvirt_private.syms       |  1 +
 tests/storagevolxml2argvtest.c | 20 +++++++++++---------
 4 files changed, 36 insertions(+), 19 deletions(-)

diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c
index ebda9fe..eb7664c 100644
--- a/src/conf/virstorageobj.c
+++ b/src/conf/virstorageobj.c
@@ -37,6 +37,26 @@
 VIR_LOG_INIT("conf.virstorageobj");
 
 
+virStoragePoolObjPtr
+virStoragePoolObjNew(void)
+{
+    virStoragePoolObjPtr obj;
+
+    if (VIR_ALLOC(obj) < 0)
+        return NULL;
+
+    if (virMutexInit(&obj->lock) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("cannot initialize mutex"));
+        VIR_FREE(obj);
+        return NULL;
+    }
+    virStoragePoolObjLock(obj);
+    obj->active = 0;
+    return obj;
+}
+
+
 virStoragePoolDefPtr
 virStoragePoolObjGetDef(virStoragePoolObjPtr obj)
 {
@@ -421,17 +441,8 @@ virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools,
         return obj;
     }
 
-    if (VIR_ALLOC(obj) < 0)
-        return NULL;
-
-    if (virMutexInit(&obj->lock) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("cannot initialize mutex"));
-        VIR_FREE(obj);
+    if (!(obj = virStoragePoolObjNew()))
         return NULL;
-    }
-    virStoragePoolObjLock(obj);
-    obj->active = 0;
 
     if (VIR_APPEND_ELEMENT_COPY(pools->objs, pools->count, obj) < 0) {
         virStoragePoolObjUnlock(obj);
diff --git a/src/conf/virstorageobj.h b/src/conf/virstorageobj.h
index a5ed8f8..401c4d5 100644
--- a/src/conf/virstorageobj.h
+++ b/src/conf/virstorageobj.h
@@ -70,6 +70,9 @@ typedef bool
 (*virStoragePoolObjListFilter)(virConnectPtr conn,
                                virStoragePoolDefPtr def);
 
+virStoragePoolObjPtr
+virStoragePoolObjNew(void);
+
 virStoragePoolDefPtr
 virStoragePoolObjGetDef(virStoragePoolObjPtr obj);
 
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 8bb1cbc..fc884fa 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1071,6 +1071,7 @@ virStoragePoolObjListFree;
 virStoragePoolObjLoadAllConfigs;
 virStoragePoolObjLoadAllState;
 virStoragePoolObjLock;
+virStoragePoolObjNew;
 virStoragePoolObjNumOfStoragePools;
 virStoragePoolObjNumOfVolumes;
 virStoragePoolObjRemove;
diff --git a/tests/storagevolxml2argvtest.c b/tests/storagevolxml2argvtest.c
index 9e43204..2ee3dba 100644
--- a/tests/storagevolxml2argvtest.c
+++ b/tests/storagevolxml2argvtest.c
@@ -50,18 +50,19 @@ testCompareXMLToArgvFiles(bool shouldFail,
     virConnectPtr conn;
 
     virStorageVolDefPtr vol = NULL, inputvol = NULL;
-    virStoragePoolDefPtr pool = NULL;
+    virStoragePoolDefPtr def = NULL;
     virStoragePoolDefPtr inputpool = NULL;
-    virStoragePoolObj poolobj = {.def = NULL };
-
+    virStoragePoolObjPtr obj = NULL;
 
     if (!(conn = virGetConnect()))
         goto cleanup;
 
-    if (!(pool = virStoragePoolDefParseFile(poolxml)))
+    if (!(def = virStoragePoolDefParseFile(poolxml)))
         goto cleanup;
 
-    poolobj.def = pool;
+    if (!(obj = virStoragePoolObjNew()))
+        goto cleanup;
+    virStoragePoolObjSetDef(obj, def);
 
     if (inputpoolxml) {
         if (!(inputpool = virStoragePoolDefParseFile(inputpoolxml)))
@@ -71,17 +72,17 @@ testCompareXMLToArgvFiles(bool shouldFail,
     if (inputvolxml)
         parse_flags |= VIR_VOL_XML_PARSE_NO_CAPACITY;
 
-    if (!(vol = virStorageVolDefParseFile(pool, volxml, parse_flags)))
+    if (!(vol = virStorageVolDefParseFile(def, volxml, parse_flags)))
         goto cleanup;
 
     if (inputvolxml &&
         !(inputvol = virStorageVolDefParseFile(inputpool, inputvolxml, 0)))
         goto cleanup;
 
-    testSetVolumeType(vol, pool);
+    testSetVolumeType(vol, def);
     testSetVolumeType(inputvol, inputpool);
 
-    cmd = virStorageBackendCreateQemuImgCmdFromVol(conn, &poolobj, vol,
+    cmd = virStorageBackendCreateQemuImgCmdFromVol(conn, obj, vol,
                                                    inputvol, flags,
                                                    create_tool, imgformat,
                                                    NULL);
@@ -102,12 +103,13 @@ testCompareXMLToArgvFiles(bool shouldFail,
     ret = 0;
 
  cleanup:
-    virStoragePoolDefFree(pool);
+    virStoragePoolDefFree(def);
     virStoragePoolDefFree(inputpool);
     virStorageVolDefFree(vol);
     virStorageVolDefFree(inputvol);
     virCommandFree(cmd);
     VIR_FREE(actualCmdline);
+    virStoragePoolObjUnlock(obj);
     virObjectUnref(conn);
     return ret;
 }
-- 
2.9.5

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