[PATCH v8 4/5] virstoragefile: Use helper to set storage source backing store

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

 



From: Matthias Gatto <matthias.gatto@xxxxxxxxxxxx>

Convert all ->backingStore stores into a virStorageSourceSetBackingStore
call using 0 as the pos in order to store.

Signed-off-by: Matthias Gatto <matthias.gatto@xxxxxxxxxxxx>
Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/conf/domain_conf.c                |  3 ++-
 src/conf/storage_conf.c               | 17 ++++++++++-------
 src/qemu/qemu_driver.c                | 15 +++++++++++----
 src/storage/storage_backend_fs.c      |  9 ++++++---
 src/storage/storage_backend_gluster.c |  5 +++--
 src/storage/storage_backend_logical.c | 15 +++++++--------
 src/storage/storage_driver.c          |  3 ++-
 src/util/virstoragefile.c             |  8 ++++++--
 tests/virstoragetest.c                |  4 ++--
 9 files changed, 49 insertions(+), 30 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index d60feeb..2341ee2 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6465,7 +6465,8 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
         virDomainDiskBackingStoreParse(ctxt, backingStore) < 0)
         goto cleanup;
 
-    src->backingStore = backingStore;
+    if (virStorageSourceSetBackingStore(src, backingStore, 0) < 0)
+        goto cleanup;
     ret = 0;
 
  cleanup:
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index fb2ace5..564af8a 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1259,6 +1259,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
     char *capacity = NULL;
     char *unit = NULL;
     char *backingStore = NULL;
+    virStorageSourcePtr backingStorePtr;
     xmlNodePtr node;
     xmlNodePtr *nodes = NULL;
     size_t i;
@@ -1295,20 +1296,22 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
     }
 
     if ((backingStore = virXPathString("string(./backingStore/path)", ctxt))) {
-        if (VIR_ALLOC(ret->target.backingStore) < 0)
+        if (VIR_ALLOC(backingStorePtr) < 0)
             goto error;
 
-        ret->target.backingStore->path = backingStore;
+        if (virStorageSourceSetBackingStore(&ret->target, backingStorePtr, 0) < 0)
+            goto error;
+        backingStorePtr->path = backingStore;
         backingStore = NULL;
 
         if (options->formatFromString) {
             char *format = virXPathString("string(./backingStore/format/@type)", ctxt);
             if (format == NULL)
-                ret->target.backingStore->format = options->defaultFormat;
+                backingStorePtr->format = options->defaultFormat;
             else
-                ret->target.backingStore->format = (options->formatFromString)(format);
+                backingStorePtr->format = (options->formatFromString)(format);
 
-            if (ret->target.backingStore->format < 0) {
+            if (backingStorePtr->format < 0) {
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                                _("unknown volume format type %s"), format);
                 VIR_FREE(format);
@@ -1317,9 +1320,9 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
             VIR_FREE(format);
         }
 
-        if (VIR_ALLOC(ret->target.backingStore->perms) < 0)
+        if (VIR_ALLOC(backingStorePtr->perms) < 0)
             goto error;
-        if (virStorageDefParsePerms(ctxt, ret->target.backingStore->perms,
+        if (virStorageDefParsePerms(ctxt, backingStorePtr->perms,
                                     "./backingStore/permissions") < 0)
             goto error;
     }
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index a129f22..e023b85 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -14283,12 +14283,19 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
     /* Update vm in place to match changes.  */
     need_unlink = false;
 
-    newDiskSrc->backingStore = disk->src;
+    if (virStorageSourceSetBackingStore(newDiskSrc, disk->src, 0) < 0) {
+        ret = -1;
+        goto cleanup;
+    }
     disk->src = newDiskSrc;
     newDiskSrc = NULL;
 
     if (persistDisk) {
-        persistDiskSrc->backingStore = persistDisk->src;
+        if (virStorageSourceSetBackingStore(persistDiskSrc,
+                                            persistDisk->src, 0) < 0) {
+            ret = -1;
+            goto cleanup;
+        }
         persistDisk->src = persistDiskSrc;
         persistDiskSrc = NULL;
     }
@@ -14332,13 +14339,13 @@ qemuDomainSnapshotUndoSingleDiskActive(virQEMUDriverPtr driver,
     /* Update vm in place to match changes. */
     tmp = disk->src;
     disk->src = virStorageSourceGetBackingStore(tmp, 0);
-    tmp->backingStore = NULL;
+    ignore_value(virStorageSourceSetBackingStore(tmp, NULL, 0));
     virStorageSourceFree(tmp);
 
     if (persistDisk) {
         tmp = persistDisk->src;
         persistDisk->src = virStorageSourceGetBackingStore(tmp, 0);
-        tmp->backingStore = NULL;
+        ignore_value(virStorageSourceSetBackingStore(tmp, NULL, 0));
         virStorageSourceFree(tmp);
     }
 }
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index cce8636..4bca2ee 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -97,7 +97,9 @@ virStorageBackendProbeTarget(virStorageSourcePtr target,
         goto cleanup;
 
     if (meta->backingStoreRaw) {
-        if (!(target->backingStore = virStorageSourceNewFromBacking(meta)))
+        if (virStorageSourceSetBackingStore(target,
+                                            virStorageSourceNewFromBacking(meta),
+                                            0) < 0)
             goto cleanup;
 
         backingStore = virStorageSourceGetBackingStore(target, 0);
@@ -108,12 +110,13 @@ virStorageBackendProbeTarget(virStorageSourcePtr target,
          * and put the string from the metadata as the path of the target. */
         if (!virStorageSourceIsLocalStorage(backingStore)) {
             virStorageSourceFree(backingStore);
-            target->backingStore = NULL;
+            ignore_value(virStorageSourceSetBackingStore(target, NULL, 0));
 
             if (VIR_ALLOC(backingStore) < 0)
                 goto cleanup;
 
-            target->backingStore = backingStore;
+            if (virStorageSourceSetBackingStore(target, backingStore, 0) < 0)
+                goto cleanup;
             backingStore->type = VIR_STORAGE_TYPE_NETWORK;
             backingStore->path = meta->backingStoreRaw;
             meta->backingStoreRaw = NULL;
diff --git a/src/storage/storage_backend_gluster.c b/src/storage/storage_backend_gluster.c
index 9bddb3b..8b89433 100644
--- a/src/storage/storage_backend_gluster.c
+++ b/src/storage/storage_backend_gluster.c
@@ -301,9 +301,10 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state,
         goto cleanup;
 
     if (meta->backingStoreRaw) {
-        if (VIR_ALLOC(vol->target.backingStore) < 0)
+        if (VIR_ALLOC(backingStore) < 0)
+            goto cleanup;
+        if (virStorageSourceSetBackingStore(&vol->target, backingStore, 0) < 0)
             goto cleanup;
-        backingStore = virStorageSourceGetBackingStore(&vol->target, 0);
 
         backingStore->path = meta->backingStoreRaw;
 
diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c
index ce84110..99abaaa 100644
--- a/src/storage/storage_backend_logical.c
+++ b/src/storage/storage_backend_logical.c
@@ -149,17 +149,16 @@ 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 (VIR_ALLOC(backingStore) < 0)
             goto cleanup;
 
-        backingStore = virStorageSourceGetBackingStore(&vol->target, 0);
-        if (backingStore) {
-            if (virAsprintf(&backingStore->path, "%s/%s",
-                            pool->def->target.path, groups[1]) < 0)
-                goto cleanup;
+        if (virStorageSourceSetBackingStore(&vol->target, backingStore, 0) < 0)
+            goto cleanup;
+        if (virAsprintf(&backingStore->path, "%s/%s",
+                        pool->def->target.path, groups[1]) < 0)
+            goto cleanup;
 
-            backingStore->format = VIR_STORAGE_POOL_LOGICAL_LVM2;
-        }
+        backingStore->format = VIR_STORAGE_POOL_LOGICAL_LVM2;
     }
 
     if (!vol->key && VIR_STRDUP(vol->key, groups[2]) < 0)
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index bbf21f6..963e325 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -3064,7 +3064,8 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
         goto cleanup;
     }
 
-    src->backingStore = backingStore;
+    if (virStorageSourceSetBackingStore(src, backingStore, 0) < 0)
+        goto cleanup;
     backingStore = NULL;
     ret = 0;
 
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 7ab4a56..1d96d7a 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1936,7 +1936,11 @@ virStorageSourceCopy(const virStorageSource *src,
     if (backingChain) {
         virStorageSourcePtr backingStore =
             virStorageSourceGetBackingStore(src, 0);
-        if (!(ret->backingStore = virStorageSourceCopy(backingStore, true)))
+        virStorageSourcePtr backingStoreCopy =
+            virStorageSourceCopy(backingStore, true);
+
+        if (!backingStoreCopy ||
+            virStorageSourceSetBackingStore(ret, backingStoreCopy, 0) < 0)
             goto error;
     }
 
@@ -2077,7 +2081,7 @@ virStorageSourceBackingStoreClear(virStorageSourcePtr def)
 
     /* recursively free backing chain */
     virStorageSourceFree(virStorageSourceGetBackingStore(def, 0));
-    def->backingStore = NULL;
+    ignore_value(virStorageSourceSetBackingStore(def, NULL, 0));
 }
 
 
diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
index 5bd4637..58f505d 100644
--- a/tests/virstoragetest.c
+++ b/tests/virstoragetest.c
@@ -583,9 +583,9 @@ testPathRelativePrepare(void)
 
     for (i = 0; i < ARRAY_CARDINALITY(backingchain); i++) {
         if (i < ARRAY_CARDINALITY(backingchain) - 1)
-            backingchain[i].backingStore = &backingchain[i + 1];
+            virStorageSourceSetBackingStore(&backingchain[i], &backingchain[i + 1], 0);
         else
-            backingchain[i].backingStore = NULL;
+            virStorageSourceSetBackingStore(&backingchain[i], NULL, 0);
 
         backingchain[i].relPath = NULL;
     }
-- 
2.5.0

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