Uniformize backing store usage by calling virStorageSourceGetBackingStore
instead of setting backing store manually.
Signed-off-by: Matthias Gatto <matthias.gatto(a)outscale.com>
---
src/conf/domain_conf.c | 7 ++++---
src/conf/storage_conf.c | 4 ++--
src/qemu/qemu_cgroup.c | 4 ++--
src/qemu/qemu_domain.c | 2 +-
src/qemu/qemu_driver.c | 12 ++++++------
src/security/security_dac.c | 2 +-
src/security/security_selinux.c | 4 ++--
src/security/virt-aa-helper.c | 2 +-
src/storage/storage_backend.c | 12 ++++++------
src/storage/storage_backend_fs.c | 8 ++++----
src/storage/storage_backend_logical.c | 2 +-
src/util/virstoragefile.c | 20 ++++++++++----------
tests/virstoragetest.c | 14 +++++++-------
13 files changed, 47 insertions(+), 46 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 2d81c37..b790fc5 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -16473,7 +16473,7 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf,
/* We currently don't output seclabels for backing chain element */
if (virDomainDiskSourceFormatInternal(buf, backingStore, 0, 0, true) < 0 ||
virDomainDiskBackingStoreFormat(buf,
- backingStore->backingStore,
+ virStorageSourceGetBackingStore(backingStore,
0),
backingStore->backingStoreRaw,
idx + 1) < 0)
return -1;
@@ -16595,7 +16595,8 @@ virDomainDiskDefFormat(virBufferPtr buf,
/* Don't format backingStore to inactive XMLs until the code for
* persistent storage of backing chains is ready. */
if (!(flags & VIR_DOMAIN_XML_INACTIVE) &&
- virDomainDiskBackingStoreFormat(buf, def->src->backingStore,
+ virDomainDiskBackingStoreFormat(buf,
+ virStorageSourceGetBackingStore(def->src, 0),
def->src->backingStoreRaw, 1) < 0)
return -1;
@@ -20554,7 +20555,7 @@ virDomainDiskDefForeachPath(virDomainDiskDefPtr disk,
}
}
- for (tmp = disk->src; tmp; tmp = tmp->backingStore) {
+ for (tmp = disk->src; tmp; tmp = virStorageSourceGetBackingStore(tmp, 0)) {
int actualType = virStorageSourceGetActualType(tmp);
/* execute the callback only for local storage */
if (actualType != VIR_STORAGE_TYPE_NETWORK &&
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 3987470..a8a90b4 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1642,9 +1642,9 @@ virStorageVolDefFormat(virStoragePoolDefPtr pool,
&def->target, "target") < 0)
goto cleanup;
- if (def->target.backingStore &&
+ if (virStorageSourceGetBackingStore(&(def->target), 0) &&
virStorageVolTargetDefFormat(options, &buf,
- def->target.backingStore,
+
virStorageSourceGetBackingStore(&(def->target), 0),
"backingStore") < 0)
goto cleanup;
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index 0e94cae..f878f4b 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -120,7 +120,7 @@ qemuSetupDiskCgroup(virDomainObjPtr vm,
virStorageSourcePtr next;
bool forceReadonly = false;
- for (next = disk->src; next; next = next->backingStore) {
+ for (next = disk->src; next; next = virStorageSourceGetBackingStore(next, 0)) {
if (qemuSetImageCgroupInternal(vm, next, false, forceReadonly) < 0)
return -1;
@@ -138,7 +138,7 @@ qemuTeardownDiskCgroup(virDomainObjPtr vm,
{
virStorageSourcePtr next;
- for (next = disk->src; next; next = next->backingStore) {
+ for (next = disk->src; next; next = virStorageSourceGetBackingStore(next, 0)) {
if (qemuSetImageCgroup(vm, next, true) < 0)
return -1;
}
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 220304f..9157e4d 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2708,7 +2708,7 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
if (virStorageSourceIsEmpty(disk->src))
goto cleanup;
- if (disk->src->backingStore) {
+ if (virStorageSourceGetBackingStore(disk->src, 0)) {
if (force_probe)
virStorageSourceBackingStoreClear(disk->src);
else
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 9152cf5..9ed5035 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -13496,13 +13496,13 @@ qemuDomainSnapshotUndoSingleDiskActive(virQEMUDriverPtr driver,
/* Update vm in place to match changes. */
tmp = disk->src;
- disk->src = tmp->backingStore;
+ disk->src = virStorageSourceGetBackingStore(tmp, 0);
tmp->backingStore = NULL;
virStorageSourceFree(tmp);
if (persistDisk) {
tmp = persistDisk->src;
- persistDisk->src = tmp->backingStore;
+ persistDisk->src = virStorageSourceGetBackingStore(tmp, 0);
tmp->backingStore = NULL;
virStorageSourceFree(tmp);
}
@@ -15637,7 +15637,7 @@ qemuDomainBlockJobImpl(virDomainObjPtr vm,
goto endjob;
}
- if (virStorageFileGetRelativeBackingPath(disk->src->backingStore,
+ if
(virStorageFileGetRelativeBackingPath(virStorageSourceGetBackingStore(disk->src, 0),
baseSource,
&backingPath) < 0)
goto endjob;
@@ -16359,7 +16359,7 @@ qemuDomainBlockCommit(virDomainPtr dom,
goto endjob;
}
- if (!topSource->backingStore) {
+ if (!virStorageSourceGetBackingStore(topSource, 0)) {
virReportError(VIR_ERR_INVALID_ARG,
_("top '%s' in chain for '%s' has no backing
file"),
topSource->path, path);
@@ -16367,14 +16367,14 @@ qemuDomainBlockCommit(virDomainPtr dom,
}
if (!base && (flags & VIR_DOMAIN_BLOCK_COMMIT_SHALLOW))
- baseSource = topSource->backingStore;
+ baseSource = virStorageSourceGetBackingStore(topSource, 0);
else if (virStorageFileParseChainIndex(disk->dst, base, &baseIndex) < 0 ||
!(baseSource = virStorageFileChainLookup(disk->src, topSource,
base, baseIndex, NULL)))
goto endjob;
if ((flags & VIR_DOMAIN_BLOCK_COMMIT_SHALLOW) &&
- baseSource != topSource->backingStore) {
+ baseSource != virStorageSourceGetBackingStore(topSource, 0)) {
virReportError(VIR_ERR_INVALID_ARG,
_("base '%s' is not immediately below '%s' in
chain "
"for '%s'"),
diff --git a/src/security/security_dac.c b/src/security/security_dac.c
index 85253af..ffff9d7 100644
--- a/src/security/security_dac.c
+++ b/src/security/security_dac.c
@@ -374,7 +374,7 @@ virSecurityDACSetSecurityDiskLabel(virSecurityManagerPtr mgr,
{
virStorageSourcePtr next;
- for (next = disk->src; next; next = next->backingStore) {
+ for (next = disk->src; next; next = virStorageSourceGetBackingStore(next, 0)) {
if (virSecurityDACSetSecurityImageLabel(mgr, def, next) < 0)
return -1;
}
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index f96be50..b6f206f 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -1140,7 +1140,7 @@ virSecuritySELinuxRestoreSecurityImageLabelInt(virSecurityManagerPtr
mgr,
* be tracked in domain XML, at which point labelskip should be a
* per-file attribute instead of a disk attribute. */
if (disk_seclabel && disk_seclabel->labelskip &&
- !src->backingStore)
+ !virStorageSourceGetBackingStore(src, 0))
return 0;
/* Don't restore labels on readoly/shared disks, because other VMs may
@@ -1270,7 +1270,7 @@ virSecuritySELinuxSetSecurityDiskLabel(virSecurityManagerPtr mgr,
bool first = true;
virStorageSourcePtr next;
- for (next = disk->src; next; next = next->backingStore) {
+ for (next = disk->src; next; next = virStorageSourceGetBackingStore(next, 0)) {
if (virSecuritySELinuxSetSecurityImageLabelInternal(mgr, def, next,
first) < 0)
return -1;
diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c
index 869bf18..3bd82bb 100644
--- a/src/security/virt-aa-helper.c
+++ b/src/security/virt-aa-helper.c
@@ -941,7 +941,7 @@ get_files(vahControl * ctl)
/* XXX - if we knew the qemu user:group here we could send it in
* so that the open could be re-tried as that user:group.
*/
- if (!disk->src->backingStore) {
+ if (!virStorageSourceGetBackingStore(disk->src)) {
bool probe = ctl->allowDiskFormatProbing;
virStorageFileGetMetadata(disk->src, -1, -1, probe, false);
}
diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index b990a82..266a59f 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -873,7 +873,7 @@ virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
}
- if (vol->target.backingStore) {
+ if (virStorageSourceGetBackingStore(&(vol->target), 0)) {
int accessRetCode = -1;
char *absolutePath = NULL;
@@ -890,7 +890,7 @@ virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
* backing store, not really sure what use it serves though, and it
* may cause issues with lvm. Untested essentially.
*/
- if (inputvol && inputvol->target.backingStore &&
+ if (inputvol &&
virStorageSourceGetBackingStore(&(inputvol->target), 0) &&
STRNEQ_NULLABLE(inputvol->target.backingStore->path,
vol->target.backingStore->path)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -959,7 +959,7 @@ virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
cmd = virCommandNew(create_tool);
convert = !!inputvol;
- backing = !inputvol && vol->target.backingStore;
+ backing = !inputvol && virStorageSourceGetBackingStore(&(vol->target),
0);
if (convert)
virCommandAddArgList(cmd, "convert", "-f", inputType,
"-O", type, NULL);
@@ -1086,7 +1086,7 @@ virStorageBackendCreateQcowCreate(virConnectPtr conn
ATTRIBUTE_UNUSED,
vol->target.format);
return -1;
}
- if (vol->target.backingStore != NULL) {
+ if (virStorageSourceGetBackingStore(&(vol->target), 0) != NULL) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("copy-on-write image not supported with "
"qcow-create"));
@@ -1491,8 +1491,8 @@ virStorageBackendUpdateVolInfo(virStorageVolDefPtr vol,
openflags)) < 0)
return ret;
- if (vol->target.backingStore &&
- (ret = virStorageBackendUpdateVolTargetInfo(vol->target.backingStore,
+ if (virStorageSourceGetBackingStore(&(vol->target), 0) &&
+ (ret =
virStorageBackendUpdateVolTargetInfo(virStorageSourceGetBackingStore(&(vol->target),
0),
updateCapacity,
withBlockVolFormat,
VIR_STORAGE_VOL_OPEN_DEFAULT |
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index 34f2153..d7bd1fb 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -104,8 +104,8 @@ virStorageBackendProbeTarget(virStorageSourcePtr target,
/* XXX: Remote storage doesn't play nicely with volumes backed by
* remote storage. To avoid trouble, just fake the backing store is RAW
* and put the string from the metadata as the path of the target. */
- if (!virStorageSourceIsLocalStorage(target->backingStore)) {
- virStorageSourceFree(target->backingStore);
+ if (!virStorageSourceIsLocalStorage(virStorageSourceGetBackingStore(target, 0)))
{
+ virStorageSourceFree(virStorageSourceGetBackingStore(target, 0));
if (VIR_ALLOC(target->backingStore) < 0)
goto cleanup;
@@ -900,8 +900,8 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn
ATTRIBUTE_UNUSED,
if (vol->target.format == VIR_STORAGE_FILE_DIR)
vol->type = VIR_STORAGE_VOL_DIR;
- if (vol->target.backingStore) {
-
ignore_value(virStorageBackendUpdateVolTargetInfo(vol->target.backingStore,
+ if (virStorageSourceGetBackingStore(&(vol->target), 0)) {
+
ignore_value(virStorageBackendUpdateVolTargetInfo(virStorageSourceGetBackingStore(&(vol->target),
0),
true, false,
VIR_STORAGE_VOL_OPEN_DEFAULT));
/* If this failed, the backing file is currently unavailable,
diff --git a/src/storage/storage_backend_logical.c
b/src/storage/storage_backend_logical.c
index 4959985..300c990 100644
--- a/src/storage/storage_backend_logical.c
+++ b/src/storage/storage_backend_logical.c
@@ -763,7 +763,7 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn,
}
virCommandAddArgFormat(cmd, "%lluK", VIR_DIV_UP(vol->target.capacity,
1024));
- if (vol->target.backingStore)
+ if (virStorageSourceGetBackingStore(&(vol->target), 0))
virCommandAddArgList(cmd, "-s", vol->target.backingStore->path,
NULL);
else
virCommandAddArg(cmd, pool->def->source.name);
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index ebcf7c3..fd0e68c 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1079,10 +1079,10 @@ virStorageFileChainGetBroken(virStorageSourcePtr chain,
if (!chain)
return 0;
- for (tmp = chain; tmp; tmp = tmp->backingStore) {
+ for (tmp = chain; tmp; tmp = virStorageSourceGetBackingStore(tmp, 0)) {
/* Break when we hit end of chain; report error if we detected
* a missing backing file, infinite loop, or other error */
- if (!tmp->backingStore && tmp->backingStoreRaw) {
+ if (!virStorageSourceGetBackingStore(tmp, 0) && tmp->backingStoreRaw)
{
if (VIR_STRDUP(*brokenFile, tmp->backingStoreRaw) < 0)
return -1;
@@ -1350,8 +1350,8 @@ virStorageFileChainLookup(virStorageSourcePtr chain,
*parent = NULL;
if (startFrom) {
- while (chain && chain != startFrom->backingStore) {
- chain = chain->backingStore;
+ while (chain && chain != virStorageSourceGetBackingStore(startFrom, 0))
{
+ chain = virStorageSourceGetBackingStore(chain, 0);
i++;
}
*parent = startFrom;
@@ -1359,7 +1359,7 @@ virStorageFileChainLookup(virStorageSourcePtr chain,
while (chain) {
if (!name && !idx) {
- if (!chain->backingStore)
+ if (!virStorageSourceGetBackingStore(chain, 0))
break;
} else if (idx) {
VIR_DEBUG("%zu: %s", i, chain->path);
@@ -1394,7 +1394,7 @@ virStorageFileChainLookup(virStorageSourcePtr chain,
}
}
*parent = chain;
- chain = chain->backingStore;
+ chain = virStorageSourceGetBackingStore(chain, 0);
i++;
}
@@ -1895,8 +1895,8 @@ virStorageSourceCopy(const virStorageSource *src,
!(ret->auth = virStorageAuthDefCopy(src->auth)))
goto error;
- if (backingChain && src->backingStore) {
- if (!(ret->backingStore = virStorageSourceCopy(src->backingStore,
+ if (backingChain && virStorageSourceGetBackingStore(src, 0)) {
+ if (!(ret->backingStore =
virStorageSourceCopy(virStorageSourceGetBackingStore(src, 0),
true)))
goto error;
}
@@ -2033,7 +2033,7 @@ virStorageSourceBackingStoreClear(virStorageSourcePtr def)
VIR_FREE(def->backingStoreRaw);
/* recursively free backing chain */
- virStorageSourceFree(def->backingStore);
+ virStorageSourceFree(virStorageSourceGetBackingStore(def, 0));
def->backingStore = NULL;
}
@@ -2847,7 +2847,7 @@ virStorageFileGetRelativeBackingPath(virStorageSourcePtr top,
*relpath = NULL;
- for (next = top; next; next = next->backingStore) {
+ for (next = top; next; next = virStorageSourceGetBackingStore(next, 0)) {
if (!next->relPath) {
ret = 1;
goto cleanup;
diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
index 2601edc..12670da 100644
--- a/tests/virstoragetest.c
+++ b/tests/virstoragetest.c
@@ -403,7 +403,7 @@ testStorageChain(const void *args)
}
VIR_FREE(expect);
VIR_FREE(actual);
- elt = elt->backingStore;
+ elt = virStorageSourceGetBackingStore(elt, 0);
i++;
}
if (i != data->nfiles) {
@@ -1029,8 +1029,8 @@ mymain(void)
ret = -1;
goto cleanup;
}
- chain2 = chain->backingStore;
- chain3 = chain2->backingStore;
+ chain2 = virStorageSourceGetBackingStore(chain, 0);
+ chain3 = virStorageSourceGetBackingStore(chain2, 0);
#define TEST_LOOKUP_TARGET(id, target, from, name, index, result, \
meta, parent) \
@@ -1095,8 +1095,8 @@ mymain(void)
ret = -1;
goto cleanup;
}
- chain2 = chain->backingStore;
- chain3 = chain2->backingStore;
+ chain2 = virStorageSourceGetBackingStore(chain, 0);
+ chain3 = virStorageSourceGetBackingStore(chain2, 0);
TEST_LOOKUP(28, NULL, "bogus", NULL, NULL, NULL);
TEST_LOOKUP(29, chain, "bogus", NULL, NULL, NULL);
@@ -1142,8 +1142,8 @@ mymain(void)
ret = -1;
goto cleanup;
}
- chain2 = chain->backingStore;
- chain3 = chain2->backingStore;
+ chain2 = virStorageSourceGetBackingStore(chain, 0);
+ chain3 = virStorageSourceGetBackingStore(chain2, 0);
TEST_LOOKUP(56, NULL, "bogus", NULL, NULL, NULL);
TEST_LOOKUP(57, NULL, "sub/link2", chain->path, chain, NULL);
--
1.8.3.1