[libvirt] [PATCH v3 4/9] virstoragefile: Always use virStorageSourceSetBackingStore to set backing store

Matthias Gatto matthias.gatto at outscale.com
Tue Feb 10 15:43:04 UTC 2015


Replace the parts of the code where a backing store is set manually
with virStorageSourceSetBackingStore

Signed-off-by: Matthias Gatto <matthias.gatto at outscale.com>
---
 src/conf/domain_conf.c                | 3 ++-
 src/conf/storage_conf.c               | 7 +++++--
 src/qemu/qemu_driver.c                | 8 ++++----
 src/storage/storage_backend_fs.c      | 8 +++++---
 src/storage/storage_backend_gluster.c | 4 ++--
 src/storage/storage_backend_logical.c | 9 ++++++---
 src/storage/storage_driver.c          | 2 +-
 src/util/virstoragefile.c             | 8 +++++---
 tests/virstoragetest.c                | 4 ++--
 9 files changed, 32 insertions(+), 21 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 32bf05c..2286665 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5659,7 +5659,8 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
         virDomainDiskBackingStoreParse(ctxt, backingStore) < 0)
         goto cleanup;
 
-    src->backingStore = backingStore;
+    if (!virStorageSourceSetBackingStore(src, backingStore, 0))
+        goto cleanup;
     ret = 0;
 
  cleanup:
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index f4f7e24..a3dac90 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1340,10 +1340,13 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
 
     if ((backingStore = virXPathString("string(./backingStore/path)", ctxt))) {
         virStorageSourcePtr backingStorePtr;
-        if (VIR_ALLOC(ret->target.backingStore) < 0)
+        if (VIR_ALLOC(backingStorePtr) < 0)
             goto error;
 
-        backingStorePtr = virStorageSourceGetBackingStore(&ret->target, 0);
+        if (!virStorageSourceSetBackingStore(&ret->target, backingStorePtr, 0)) {
+            VIR_FREE(backingStorePtr);
+            goto error;
+        }
         backingStorePtr->path = backingStore;
         backingStore = NULL;
 
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 8c65fd3..bdca5e0 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -13590,12 +13590,12 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
     /* Update vm in place to match changes.  */
     need_unlink = false;
 
-    newDiskSrc->backingStore = disk->src;
+    virStorageSourceSetBackingStore(newDiskSrc, disk->src, 0);
     disk->src = newDiskSrc;
     newDiskSrc = NULL;
 
     if (persistDisk) {
-        persistDiskSrc->backingStore = persistDisk->src;
+        virStorageSourceSetBackingStore(persistDiskSrc, persistDisk->src, 0);
         persistDisk->src = persistDiskSrc;
         persistDiskSrc = NULL;
     }
@@ -13639,13 +13639,13 @@ qemuDomainSnapshotUndoSingleDiskActive(virQEMUDriverPtr driver,
     /* Update vm in place to match changes. */
     tmp = disk->src;
     disk->src = virStorageSourceGetBackingStore(tmp, 0);
-    tmp->backingStore = NULL;
+    virStorageSourceSetBackingStore(tmp, NULL, 0);
     virStorageSourceFree(tmp);
 
     if (persistDisk) {
         tmp = persistDisk->src;
         persistDisk->src = virStorageSourceGetBackingStore(tmp, 0);
-        tmp->backingStore = NULL;
+        virStorageSourceSetBackingStore(tmp, NULL, 0);
         virStorageSourceFree(tmp);
     }
 }
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index 445d11d..18e19fe 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -97,10 +97,12 @@ virStorageBackendProbeTarget(virStorageSourcePtr target,
         goto cleanup;
 
     if (meta->backingStoreRaw) {
-        backingStore = virStorageSourceGetBackingStore(target, 0);
-        if (!(backingStore = virStorageSourceNewFromBacking(meta)))
+        if (!virStorageSourceSetBackingStore(target,
+                                             virStorageSourceNewFromBacking(meta),
+                                             0))
             goto cleanup;
 
+        backingStore = virStorageSourceGetBackingStore(target, 0);
         backingStore->format = backingStoreFormat;
 
         /* XXX: Remote storage doesn't play nicely with volumes backed by
@@ -112,7 +114,7 @@ virStorageBackendProbeTarget(virStorageSourcePtr target,
             if (VIR_ALLOC(backingStore) < 0)
                 goto cleanup;
 
-            target->backingStore = backingStore;
+            virStorageSourceSetBackingStore(target, backingStore, 0);
             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 fc48f0f..bb79024 100644
--- a/src/storage/storage_backend_gluster.c
+++ b/src/storage/storage_backend_gluster.c
@@ -301,9 +301,9 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state,
         goto cleanup;
 
     if (meta->backingStoreRaw) {
-        if (VIR_ALLOC(vol->target.backingStore) < 0)
+        if (VIR_ALLOC(backingStore) < 0)
             goto cleanup;
-        backingStore = virStorageSourceGetBackingStore(&vol->target, 0);
+        virStorageSourceSetBackingStore(&vol->target, backingStore, 0);
 
         backingStore->path = meta->backingStoreRaw;
 
diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c
index e9e0499..1afe809 100644
--- a/src/storage/storage_backend_logical.c
+++ b/src/storage/storage_backend_logical.c
@@ -88,6 +88,7 @@ virStorageBackendLogicalMakeVol(char **const groups,
     size_t i;
     int err, nextents, nvars, ret = -1;
     const char *attrs = groups[9];
+    virStorageSourcePtr backingStore;
 
     /* Skip inactive volume */
     if (attrs[4] != 'a')
@@ -148,14 +149,16 @@ virStorageBackendLogicalMakeVol(char **const groups,
      *  lv is created with "--virtualsize").
      */
     if (groups[1] && !STREQ(groups[1], "") && (groups[1][0] != '[')) {
-        if (VIR_ALLOC(vol->target.backingStore) < 0)
+        if (VIR_ALLOC(backingStore) < 0)
             goto cleanup;
 
-        if (virAsprintf(&virStorageSourceGetBackingStore(&vol->target, 0)->path, "%s/%s",
+        if (!virStorageSourceSetBackingStore(&vol->target, backingStore, 0))
+            goto cleanup;
+        if (virAsprintf(&backingStore->path, "%s/%s",
                         pool->def->target.path, groups[1]) < 0)
             goto cleanup;
 
-        virStorageSourceGetBackingStore(&vol->target, 0)->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 ad92c9b..92ba357 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -2881,7 +2881,7 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
         goto cleanup;
     }
 
-    src->backingStore = backingStore;
+    virStorageSourceSetBackingStore(src, backingStore, 0);
     backingStore = NULL;
     ret = 0;
 
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 0cc7c5e..d573aba 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1891,8 +1891,10 @@ virStorageSourceCopy(const virStorageSource *src,
         goto error;
 
     if (backingChain && virStorageSourceGetBackingStore(src, 0)) {
-        if (!(ret->backingStore = virStorageSourceCopy(virStorageSourceGetBackingStore(src, 0),
-                                                       true)))
+        if (!virStorageSourceSetBackingStore(ret,
+                                             virStorageSourceCopy(virStorageSourceGetBackingStore(src, 0),
+                                                                  true),
+                                             0))
             goto error;
     }
 
@@ -2029,7 +2031,7 @@ virStorageSourceBackingStoreClear(virStorageSourcePtr def)
 
     /* recursively free backing chain */
     virStorageSourceFree(virStorageSourceGetBackingStore(def, 0));
-    def->backingStore = NULL;
+    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;
     }
-- 
1.8.3.1




More information about the libvir-list mailing list