]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: Introduce function for allocating virStorageSource
authorPeter Krempa <pkrempa@redhat.com>
Thu, 14 Feb 2019 15:20:25 +0000 (16:20 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 18 Feb 2019 09:27:30 +0000 (10:27 +0100)
Add virStorageSourceNew and refactor places allocating that structure to
use the helper.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
14 files changed:
src/conf/domain_conf.c
src/conf/snapshot_conf.c
src/conf/storage_conf.c
src/libvirt_private.syms
src/qemu/qemu_domain.c
src/qemu/qemu_driver.c
src/qemu/qemu_migration.c
src/storage/storage_backend_gluster.c
src/storage/storage_backend_logical.c
src/storage/storage_util.c
src/util/virstoragefile.c
src/util/virstoragefile.h
tests/qemublocktest.c
tests/virstoragetest.c

index cd69323f2872cd2ff7b5cb2870d3e20aed7e2825..614fae9b4fdf50090d9f5b1ee2deb127a52bd154 100644 (file)
@@ -1881,7 +1881,7 @@ virDomainDiskDefNew(virDomainXMLOptionPtr xmlopt)
     if (VIR_ALLOC(ret) < 0)
         return NULL;
 
-    if (VIR_ALLOC(ret->src) < 0)
+    if (!(ret->src = virStorageSourceNew()))
         goto error;
 
     if (xmlopt &&
@@ -2099,7 +2099,7 @@ virDomainFSDefNew(void)
     if (VIR_ALLOC(ret) < 0)
         return NULL;
 
-    if (VIR_ALLOC(ret->src) < 0)
+    if (!(ret->src = virStorageSourceNew()))
         goto cleanup;
 
     return ret;
@@ -7674,7 +7674,7 @@ virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodePtr sourcenode,
 
     /* For the purposes of command line creation, this needs to look
      * like a disk storage source */
-    if (VIR_ALLOC(iscsisrc->src) < 0)
+    if (!(iscsisrc->src = virStorageSourceNew()))
         return -1;
     iscsisrc->src->type = VIR_STORAGE_TYPE_NETWORK;
     iscsisrc->src->protocol = VIR_STORAGE_NET_PROTOCOL_ISCSI;
@@ -9167,7 +9167,7 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
         goto cleanup;
     }
 
-    if (VIR_ALLOC(backingStore) < 0)
+    if (!(backingStore = virStorageSourceNew()))
         goto cleanup;
 
     /* backing store is always read-only */
@@ -9325,7 +9325,7 @@ virDomainDiskDefMirrorParse(virDomainDiskDefPtr def,
     char *blockJob = NULL;
     int ret = -1;
 
-    if (VIR_ALLOC(def->mirror) < 0)
+    if (!(def->mirror = virStorageSourceNew()))
         goto cleanup;
 
     if ((blockJob = virXMLPropString(cur, "job"))) {
index b16f450a011badb2f5553eae6b586af55b756ab1..5127ebbdfdd0ee5a9e34ee37c38a9bf1268c1874 100644 (file)
@@ -122,7 +122,7 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node,
 
     ctxt->node = node;
 
-    if (VIR_ALLOC(def->src) < 0)
+    if (!(def->src = virStorageSourceNew()))
         goto cleanup;
 
     def->name = virXMLPropString(node, "name");
@@ -621,7 +621,7 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def,
         if (virBitmapIsBitSet(map, i))
             continue;
         disk = &def->disks[ndisks++];
-        if (VIR_ALLOC(disk->src) < 0)
+        if (!(disk->src = virStorageSourceNew()))
             goto cleanup;
         if (VIR_STRDUP(disk->name, def->dom->disks[i]->dst) < 0)
             goto cleanup;
index a2ddecf0f27840fa2dd8a8d241e14e66e28880e5..d7c17db6692164f4e47d34f169fe8cf29b9474f0 100644 (file)
@@ -1200,7 +1200,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
     }
 
     if ((backingStore = virXPathString("string(./backingStore/path)", ctxt))) {
-        if (VIR_ALLOC(def->target.backingStore) < 0)
+        if (!(def->target.backingStore = virStorageSourceNew()))
             return NULL;
 
         def->target.backingStore->type = VIR_STORAGE_TYPE_FILE;
index 67579742fda44c1fd91b96e4275c5e9bc60d0385..0a959c4bf9907db0d2fead27aa9e928957b10ec5 100644 (file)
@@ -2925,6 +2925,7 @@ virStorageSourceIsLocalStorage;
 virStorageSourceIsRelative;
 virStorageSourceIsSameLocation;
 virStorageSourceNetworkAssignDefaultPorts;
+virStorageSourceNew;
 virStorageSourceNewFromBacking;
 virStorageSourceNewFromBackingAbsolute;
 virStorageSourceParseRBDColonString;
index ac01e861f702cc0c7fa714768bf54319842dc2e3..0c8feb25be3496771e4c806646093dd117da4cb3 100644 (file)
@@ -2742,7 +2742,7 @@ qemuDomainObjPrivateXMLParseJobNBDSource(xmlNodePtr node,
         goto cleanup;
     }
 
-    if (VIR_ALLOC(migrSource) < 0)
+    if (!(migrSource = virStorageSourceNew()))
         goto cleanup;
 
     if (!(type = virXMLPropString(ctxt->node, "type"))) {
@@ -9050,7 +9050,7 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
 
         /* terminate the chain for such images as the code below would do */
         if (!disksrc->backingStore &&
-            VIR_ALLOC(disksrc->backingStore) < 0)
+            !(disksrc->backingStore = virStorageSourceNew()))
             goto cleanup;
 
         /* host cdrom requires special treatment in qemu, so we need to check
index 971f915619af7c0ace735d2e136b93606d87762e..f94955a22fadf4c6b957cfdd0b7f85bdce5da487 100644 (file)
@@ -17984,7 +17984,7 @@ qemuDomainBlockRebase(virDomainPtr dom, const char *path, const char *base,
         return qemuDomainBlockPullCommon(driver, vm, path, base, bandwidth, flags);
 
     /* If we got here, we are doing a block copy rebase. */
-    if (VIR_ALLOC(dest) < 0)
+    if (!(dest = virStorageSourceNew()))
         goto cleanup;
     dest->type = (flags & VIR_DOMAIN_BLOCK_REBASE_COPY_DEV) ?
         VIR_STORAGE_TYPE_BLOCK : VIR_STORAGE_TYPE_FILE;
index c93ae33476c1d95abedf0ba43e18ebbe17be56bb..8a9dbb5e630370e6a5cee714d454e44240cfbc67 100644 (file)
@@ -794,14 +794,14 @@ qemuMigrationSrcNBDStorageCopyBlockdev(virQEMUDriverPtr driver,
 
     VIR_DEBUG("starting blockdev mirror for disk=%s to host=%s", diskAlias, host);
 
-    if (VIR_ALLOC(copysrc) < 0)
+    if (!(copysrc = virStorageSourceNew()))
         goto cleanup;
 
     copysrc->type = VIR_STORAGE_TYPE_NETWORK;
     copysrc->protocol = VIR_STORAGE_NET_PROTOCOL_NBD;
     copysrc->format = VIR_STORAGE_FILE_RAW;
 
-    if (VIR_ALLOC(copysrc->backingStore) < 0)
+    if (!(copysrc->backingStore = virStorageSourceNew()))
         goto cleanup;
 
     if (VIR_STRDUP(copysrc->path, diskAlias) < 0)
index 846a647cb6139eb33b9666098c765ed723a50e35..854ecf2b67fa30f40409b60a27642c7fc4592f14 100644 (file)
@@ -294,7 +294,7 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state,
         goto cleanup;
 
     if (meta->backingStoreRaw) {
-        if (VIR_ALLOC(vol->target.backingStore) < 0)
+        if (!(vol->target.backingStore = virStorageSourceNew()))
             goto cleanup;
 
         vol->target.backingStore->type = VIR_STORAGE_TYPE_NETWORK;
index f153d23aec85e06ab63dfb3b65b3f1482f13ac04..77e4dfb8b183d1e4fe0b0e0be4df1f2c45394a56 100644 (file)
@@ -308,7 +308,7 @@ virStorageBackendLogicalMakeVol(char **const groups,
      *  lv is created with "--virtualsize").
      */
     if (groups[1] && STRNEQ(groups[1], "") && (groups[1][0] != '[')) {
-        if (VIR_ALLOC(vol->target.backingStore) < 0)
+        if (!(vol->target.backingStore = virStorageSourceNew()))
             goto cleanup;
 
         if (virAsprintf(&vol->target.backingStore->path, "%s/%s",
index f18e38733a3e30632f847dc96b4443f94e6b7d0f..3a6cc34b6896a4538600eabfc03dda338c8d3b26 100644 (file)
@@ -3402,7 +3402,7 @@ storageBackendProbeTarget(virStorageSourcePtr target,
         if (!virStorageSourceIsLocalStorage(target->backingStore)) {
             virStorageSourceFree(target->backingStore);
 
-            if (VIR_ALLOC(target->backingStore) < 0)
+            if (!(target->backingStore = virStorageSourceNew()))
                 return -1;
 
             target->backingStore->type = VIR_STORAGE_TYPE_NETWORK;
@@ -3576,7 +3576,7 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr pool)
         goto cleanup;
     VIR_DIR_CLOSE(dir);
 
-    if (VIR_ALLOC(target))
+    if (!(target = virStorageSourceNew()))
         goto cleanup;
 
     if ((fd = open(def->target.path, O_RDONLY)) < 0) {
index a6d44b64a4ecf8506bedef421a7e8046edc2516a..7f52a5fdc7dbd013ec2ec734a5f5916e34481342 100644 (file)
@@ -2245,7 +2245,7 @@ virStorageSourceCopy(const virStorageSource *src,
 {
     virStorageSourcePtr def = NULL;
 
-    if (VIR_ALLOC(def) < 0)
+    if (!(def = virStorageSourceNew()))
         return NULL;
 
     def->id = src->id;
@@ -2562,6 +2562,18 @@ virStorageSourceClear(virStorageSourcePtr def)
 }
 
 
+virStorageSourcePtr
+virStorageSourceNew(void)
+{
+    virStorageSourcePtr ret = NULL;
+
+    if (VIR_ALLOC(ret) < 0)
+        return NULL;
+
+    return ret;
+}
+
+
 void
 virStorageSourceFree(virStorageSourcePtr def)
 {
@@ -2580,7 +2592,7 @@ virStorageSourceNewFromBackingRelative(virStorageSourcePtr parent,
     virStorageSourcePtr def;
     VIR_AUTOFREE(char *) dirname = NULL;
 
-    if (VIR_ALLOC(def) < 0)
+    if (!(def = virStorageSourceNew()))
         return NULL;
 
     /* store relative name */
@@ -3627,7 +3639,7 @@ virStorageSourceNewFromBackingAbsolute(const char *path)
     virStorageSourcePtr def;
     int rc;
 
-    if (VIR_ALLOC(def) < 0)
+    if (!(def = virStorageSourceNew()))
         return NULL;
 
     if (virStorageIsFile(path)) {
@@ -4900,7 +4912,7 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
         }
     } else {
         /* add terminator */
-        if (VIR_ALLOC(backingStore) < 0)
+        if (!(backingStore = virStorageSourceNew()))
             goto cleanup;
     }
 
index 8c3a36d4730982ee15299a801ec463cb62a7cfd9..48af06653ef35192707ed586d738fc3ab1460377 100644 (file)
@@ -431,6 +431,7 @@ int virStorageSourceGetActualType(const virStorageSource *def);
 bool virStorageSourceIsLocalStorage(const virStorageSource *src);
 bool virStorageSourceIsEmpty(virStorageSourcePtr src);
 bool virStorageSourceIsBlockLocal(const virStorageSource *src);
+virStorageSourcePtr virStorageSourceNew(void);
 void virStorageSourceFree(virStorageSourcePtr def);
 void virStorageSourceBackingStoreClear(virStorageSourcePtr def);
 int virStorageSourceUpdatePhysicalSize(virStorageSourcePtr src,
index d7e5e72a0b14558f7b9ca46e44c083bc613ab9a6..813b20a08d14385c4764927744ca777832a7e8e4 100644 (file)
@@ -55,7 +55,7 @@ testBackingXMLjsonXML(const void *args)
     VIR_AUTOPTR(virStorageSource) xmlsrc = NULL;
     VIR_AUTOPTR(virStorageSource) jsonsrc = NULL;
 
-    if (VIR_ALLOC(xmlsrc) < 0)
+    if (!(xmlsrc = virStorageSourceNew()))
         return -1;
 
     xmlsrc->type = data->type;
index 646ae78ff048be1fb0a598b210855ef2cc512a78..da70beb1f7cfde42abe4de9f539a5b1b1b799d96 100644 (file)
@@ -98,7 +98,7 @@ testStorageFileGetMetadata(const char *path,
     virStorageSourcePtr ret = NULL;
     VIR_AUTOPTR(virStorageSource) def = NULL;
 
-    if (VIR_ALLOC(def) < 0)
+    if (!(def = virStorageSourceNew()))
         return NULL;
 
     def->type = VIR_STORAGE_TYPE_FILE;