[libvirt] [PATCH v8 0/5] Partial posting of updates to Add quorum to libvirt

I took a few cycles to reformat the initial 5 patches of the add quorum support posted as a v7 here: http://www.redhat.com/archives/libvir-list/2015-December/msg00119.html These patches are easily separable from the rest of the series. Rather than see things linger for months on end, trying to make small leaps. Changes in the series are to reorder things slightly, follow some of the review comments from previous series, and a few other things along the way. I've looked at this way too long to - hopefully I haven't missed anything. Most I forget... One I do remember is the virStorageSourceCopy changes in patch 5 where I believe the "Get" and "Set" wanted to use the 'i' index rather than having the "Get" use the 'i' and the "Set" always use '0'. Matthias Gatto (5): virstoragefile: Add helper to get storage source backingStore virstoragefile: Add helper to set storage source backingStore virstoragefile: Use helper to get storage source backing store virstoragefile: Use helper to set storage source backing store virstoragefile: Convert storage source backingStore into backingStores src/conf/domain_conf.c | 25 +++++---- src/conf/storage_conf.c | 29 ++++++----- src/libvirt_private.syms | 2 + src/qemu/qemu_cgroup.c | 6 ++- src/qemu/qemu_domain.c | 2 +- src/qemu/qemu_driver.c | 35 ++++++++----- src/qemu/qemu_monitor_json.c | 4 +- src/security/security_dac.c | 3 +- src/security/security_selinux.c | 5 +- src/security/virt-aa-helper.c | 2 +- src/storage/storage_backend.c | 34 +++++++----- src/storage/storage_backend_fs.c | 46 +++++++++------- src/storage/storage_backend_gluster.c | 11 ++-- src/storage/storage_backend_logical.c | 15 ++++-- src/storage/storage_driver.c | 3 +- src/util/virstoragefile.c | 98 ++++++++++++++++++++++++++++++----- src/util/virstoragefile.h | 10 +++- tests/virstoragetest.c | 18 +++---- 18 files changed, 243 insertions(+), 105 deletions(-) -- 2.5.0

From: Matthias Gatto <matthias.gatto@outscale.com> Add a new helper - virStorageSourceGetBackingStore - to fetch the storage source backingStore pointer in order to make it easier to change the future format of the data. A future patch will adjust the backingStore pointer to become a table or array of backingStorePtr's accessible by the argument 'pos'. For now, if 'pos' > 0, the code will return NULL as if the backingStore pointer didn't exist. All callers in subsequent patches will start by passing a 0 as the parameter. Signed-off-by: Matthias Gatto <matthias.gatto@outscale.com> Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/libvirt_private.syms | 1 + src/util/virstoragefile.c | 23 +++++++++++++++++++++++ src/util/virstoragefile.h | 3 +++ 3 files changed, 27 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 55822ae..1c55370 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2196,6 +2196,7 @@ virStorageSourceClear; virStorageSourceCopy; virStorageSourceFree; virStorageSourceGetActualType; +virStorageSourceGetBackingStore; virStorageSourceGetSecurityLabelDef; virStorageSourceInitChainElement; virStorageSourceIsEmpty; diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 2aa1d90..2771c95 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1810,6 +1810,29 @@ virStorageSourcePoolDefCopy(const virStorageSourcePoolDef *src) /** + * virStorageSourceGetBackingStore: + * @src: virStorageSourcePtr containing the backing stores + * @pos: presently unused + * + * Return the @src backingStore pointer at @pos. For now, @pos is + * expected to be 0. A future patch will use @pos index into an array + * of storage backingStore pointers + * + * Returns: + * A pointer to the storage source backingStore @pos or + * NULL if the backingStore pointer cannot be found + */ +virStorageSourcePtr +virStorageSourceGetBackingStore(const virStorageSource *src, + size_t pos) +{ + if (!src || pos > 0) + return NULL; + return src->backingStore; +} + + +/** * virStorageSourcePtr: * * Deep-copies a virStorageSource structure. If @backing chain is true diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index b98fe25..8cd4854 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -289,6 +289,9 @@ struct _virStorageSource { # define DEV_BSIZE 512 # endif +virStorageSourcePtr virStorageSourceGetBackingStore(const virStorageSource *src, + size_t pos); + int virStorageFileProbeFormat(const char *path, uid_t uid, gid_t gid); int virStorageFileProbeFormatFromBuf(const char *path, char *buf, -- 2.5.0

On Wed, Dec 16, 2015 at 12:14 AM, John Ferlan <jferlan@redhat.com> wrote:
From: Matthias Gatto <matthias.gatto@outscale.com>
Add a new helper - virStorageSourceGetBackingStore - to fetch the storage source backingStore pointer in order to make it easier to change the future format of the data.
A future patch will adjust the backingStore pointer to become a table or array of backingStorePtr's accessible by the argument 'pos'.
For now, if 'pos' > 0, the code will return NULL as if the backingStore pointer didn't exist. All callers in subsequent patches will start by passing a 0 as the parameter.
Signed-off-by: Matthias Gatto <matthias.gatto@outscale.com> Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/libvirt_private.syms | 1 + src/util/virstoragefile.c | 23 +++++++++++++++++++++++ src/util/virstoragefile.h | 3 +++ 3 files changed, 27 insertions(+)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 55822ae..1c55370 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2196,6 +2196,7 @@ virStorageSourceClear; virStorageSourceCopy; virStorageSourceFree; virStorageSourceGetActualType; +virStorageSourceGetBackingStore; virStorageSourceGetSecurityLabelDef; virStorageSourceInitChainElement; virStorageSourceIsEmpty; diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 2aa1d90..2771c95 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1810,6 +1810,29 @@ virStorageSourcePoolDefCopy(const virStorageSourcePoolDef *src)
/** + * virStorageSourceGetBackingStore: + * @src: virStorageSourcePtr containing the backing stores + * @pos: presently unused + * + * Return the @src backingStore pointer at @pos. For now, @pos is + * expected to be 0. A future patch will use @pos index into an array + * of storage backingStore pointers + * + * Returns: + * A pointer to the storage source backingStore @pos or + * NULL if the backingStore pointer cannot be found + */ +virStorageSourcePtr +virStorageSourceGetBackingStore(const virStorageSource *src, + size_t pos) +{ + if (!src || pos > 0) + return NULL; + return src->backingStore; +} + + +/** * virStorageSourcePtr: * * Deep-copies a virStorageSource structure. If @backing chain is true diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index b98fe25..8cd4854 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -289,6 +289,9 @@ struct _virStorageSource { # define DEV_BSIZE 512 # endif
+virStorageSourcePtr virStorageSourceGetBackingStore(const virStorageSource *src, + size_t pos); + int virStorageFileProbeFormat(const char *path, uid_t uid, gid_t gid); int virStorageFileProbeFormatFromBuf(const char *path, char *buf, -- 2.5.0
ping

From: Matthias Gatto <matthias.gatto@outscale.com> Add a new helper - virStorageSourceSetBackingStore - to set the storage source backingStore pointer in order to make it easier to change the future format of the data. A future patch will adjust the backingStore pointer to become a table or array of backingStorePtr's accessible by the argument 'pos'. For now, if 'pos' > 0, the code will return NULL as if the backingStore pointer couldn't be set. All callers in subsequent patches will start by passing a 0 as the parameter. Signed-off-by: Matthias Gatto <matthias.gatto@outscale.com> Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/libvirt_private.syms | 1 + src/util/virstoragefile.c | 26 ++++++++++++++++++++++++++ src/util/virstoragefile.h | 4 ++++ 3 files changed, 31 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 1c55370..509fbae 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2206,6 +2206,7 @@ virStorageSourceParseRBDColonString; virStorageSourcePoolDefFree; virStorageSourcePoolModeTypeFromString; virStorageSourcePoolModeTypeToString; +virStorageSourceSetBackingStore; virStorageSourceUpdateBlockPhysicalSize; virStorageTypeFromString; virStorageTypeToString; diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 2771c95..43a7137 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1833,6 +1833,32 @@ virStorageSourceGetBackingStore(const virStorageSource *src, /** + * virStorageSourceSetBackingStore: + * @src: virStorageSourcePtr to hold @backingStore + * @backingStore - Pointer to the backingStore to store + * @pos - presently unused + * + * Set @backingStore in @src at @pos in src->backingStore. For now, pos + * is expected to be 0. A future patch will use pos as the position in + * the array of storage backingStore pointers + * + * Returns: + * 0 on success, -1 on failure + */ +int +virStorageSourceSetBackingStore(virStorageSourcePtr src, + virStorageSourcePtr backingStore, + size_t pos) +{ + if (pos > 0) + return -1; + + src->backingStore = backingStore; + return 0; +} + + +/** * virStorageSourcePtr: * * Deep-copies a virStorageSource structure. If @backing chain is true diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index 8cd4854..ce1cb5d 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -289,6 +289,10 @@ struct _virStorageSource { # define DEV_BSIZE 512 # endif +int virStorageSourceSetBackingStore(virStorageSourcePtr src, + virStorageSourcePtr backingStore, + size_t pos); + virStorageSourcePtr virStorageSourceGetBackingStore(const virStorageSource *src, size_t pos); -- 2.5.0

From: Matthias Gatto <matthias.gatto@outscale.com> Convert all ->backingStore fetches into a virStorageSourceGetBackingStore call using 0 as the pos in order to fetch. Signed-off-by: Matthias Gatto <matthias.gatto@outscale.com> Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/domain_conf.c | 22 ++++++++++++------- src/conf/storage_conf.c | 12 +++++----- src/qemu/qemu_cgroup.c | 6 +++-- src/qemu/qemu_domain.c | 2 +- src/qemu/qemu_driver.c | 20 +++++++++-------- src/qemu/qemu_monitor_json.c | 4 +++- src/security/security_dac.c | 3 ++- src/security/security_selinux.c | 5 +++-- src/security/virt-aa-helper.c | 2 +- src/storage/storage_backend.c | 34 +++++++++++++++++++---------- src/storage/storage_backend_fs.c | 41 ++++++++++++++++++++--------------- src/storage/storage_backend_gluster.c | 8 ++++--- src/storage/storage_backend_logical.c | 18 ++++++++++----- src/util/virstoragefile.c | 24 ++++++++++---------- tests/virstoragetest.c | 14 ++++++------ 15 files changed, 129 insertions(+), 86 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 5200c27..d60feeb 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18730,6 +18730,7 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf, { const char *type; const char *format; + virStorageSourcePtr backingStorePtr; if (!backingStore) { if (!backingStoreRaw) @@ -18759,9 +18760,11 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf, virBufferAsprintf(buf, "<format type='%s'/>\n", format); /* We currently don't output seclabels for backing chain element */ - if (virDomainDiskSourceFormatInternal(buf, backingStore, 0, 0, true) < 0 || - virDomainDiskBackingStoreFormat(buf, - backingStore->backingStore, + if (virDomainDiskSourceFormatInternal(buf, backingStore, 0, 0, true) < 0) + return -1; + + backingStorePtr = virStorageSourceGetBackingStore(backingStore, 0); + if (virDomainDiskBackingStoreFormat(buf, backingStorePtr, backingStore->backingStoreRaw, idx + 1) < 0) return -1; @@ -18881,10 +18884,13 @@ 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_DEF_FORMAT_INACTIVE) && - virDomainDiskBackingStoreFormat(buf, def->src->backingStore, - def->src->backingStoreRaw, 1) < 0) - return -1; + if (!(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE)) { + virStorageSourcePtr backingStore = + virStorageSourceGetBackingStore(def->src, 0); + if (virDomainDiskBackingStoreFormat(buf, backingStore, + def->src->backingStoreRaw, 1) < 0) + return -1; + } virBufferEscapeString(buf, "<backenddomain name='%s'/>\n", def->domain_name); @@ -22850,7 +22856,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 9b8abea..fb2ace5 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -1330,7 +1330,8 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, if (virStorageSize(unit, capacity, &ret->target.capacity) < 0) goto error; } else if (!(flags & VIR_VOL_XML_PARSE_NO_CAPACITY) && - !((flags & VIR_VOL_XML_PARSE_OPT_CAPACITY) && ret->target.backingStore)) { + !((flags & VIR_VOL_XML_PARSE_OPT_CAPACITY) && + virStorageSourceGetBackingStore(&ret->target, 0))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing capacity element")); goto error; } @@ -1593,6 +1594,7 @@ virStorageVolDefFormat(virStoragePoolDefPtr pool, virStorageVolDefPtr def) { virStorageVolOptionsPtr options; + virStorageSourcePtr backingStore; virBuffer buf = VIR_BUFFER_INITIALIZER; options = virStorageVolOptionsForPoolType(pool->type); @@ -1644,10 +1646,10 @@ virStorageVolDefFormat(virStoragePoolDefPtr pool, &def->target, "target") < 0) goto cleanup; - if (def->target.backingStore && - virStorageVolTargetDefFormat(options, &buf, - def->target.backingStore, - "backingStore") < 0) + backingStore = virStorageSourceGetBackingStore(&def->target, 0); + if (backingStore && virStorageVolTargetDefFormat(options, &buf, + backingStore, + "backingStore") < 0) goto cleanup; virBufferAdjustIndent(&buf, -2); diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 1c406ce..bcf4448 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -121,7 +121,8 @@ 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; @@ -139,7 +140,8 @@ 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 6f19d49..447b54f 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -3104,7 +3104,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 783a7cd..a129f22 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -14331,13 +14331,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); } @@ -16324,6 +16324,8 @@ qemuDomainBlockPullCommon(virQEMUDriverPtr driver, if (baseSource) { if (flags & VIR_DOMAIN_BLOCK_REBASE_RELATIVE) { + virStorageSourcePtr backingStore; + if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_CHANGE_BACKING_FILE)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("this QEMU binary doesn't support relative " @@ -16331,8 +16333,8 @@ qemuDomainBlockPullCommon(virQEMUDriverPtr driver, goto endjob; } - if (virStorageFileGetRelativeBackingPath(disk->src->backingStore, - baseSource, + backingStore = virStorageSourceGetBackingStore(disk->src, 0); + if (virStorageFileGetRelativeBackingPath(backingStore, baseSource, &backingPath) < 0) goto endjob; @@ -16728,7 +16730,7 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm, goto endjob; /* clear the _SHALLOW flag if there is only one layer */ - if (!disk->src->backingStore) + if (!virStorageSourceGetBackingStore(disk->src, 0)) flags &= ~VIR_DOMAIN_BLOCK_COPY_SHALLOW; /* unless the user provides a pre-created file, shallow copy into a raw @@ -17135,7 +17137,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); @@ -17143,14 +17145,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'"), @@ -19428,7 +19430,7 @@ qemuDomainGetStatsBlock(virQEMUDriverPtr driver, goto cleanup; visited++; backing_idx++; - src = src->backingStore; + src = virStorageSourceGetBackingStore(src, 0); } } diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index d4b6514..34b09a9 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -3781,7 +3781,9 @@ qemuMonitorJSONDiskNameLookupOne(virJSONValuePtr image, return NULL; if (top != target) { backing = virJSONValueObjectGetObject(image, "backing-image"); - return qemuMonitorJSONDiskNameLookupOne(backing, top->backingStore, + virStorageSourcePtr backingStore = + virStorageSourceGetBackingStore(top, 0); + return qemuMonitorJSONDiskNameLookupOne(backing, backingStore, target); } if (VIR_STRDUP(ret, virJSONValueObjectGetString(image, "filename")) < 0) diff --git a/src/security/security_dac.c b/src/security/security_dac.c index 80709fe..2ab57be 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -454,7 +454,8 @@ virSecurityDACSetDiskLabel(virSecurityManagerPtr mgr, { virStorageSourcePtr next; - for (next = disk->src; next; next = next->backingStore) { + for (next = disk->src; next; + next = virStorageSourceGetBackingStore(next, 0)) { if (virSecurityDACSetImageLabel(mgr, def, next) < 0) return -1; } diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c index 721c451..6628304 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -1213,7 +1213,7 @@ virSecuritySELinuxRestoreImageLabelInt(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 readonly/shared disks, because other VMs may @@ -1347,7 +1347,8 @@ virSecuritySELinuxSetDiskLabel(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 (virSecuritySELinuxSetImageLabelInternal(mgr, def, next, first) < 0) return -1; diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 5de56e5..dddde1c 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -967,7 +967,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, 0)) { 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 6915b8a..c21314d 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -498,7 +498,7 @@ virStorageBackendCreateRaw(virConnectPtr conn ATTRIBUTE_UNUSED, goto cleanup; } - if (vol->target.backingStore) { + if (virStorageSourceGetBackingStore(&vol->target, 0)) { virReportError(VIR_ERR_NO_SUPPORT, "%s", _("backing storage not supported for raw volumes")); goto cleanup; @@ -940,6 +940,7 @@ virStorageBackendCreateQemuImgCmdFromVol(virConnectPtr conn, .features = vol->target.features, .nocow = vol->target.nocow, }; + virStorageSourcePtr backingStore; virCheckFlags(VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA, NULL); @@ -988,12 +989,13 @@ virStorageBackendCreateQemuImgCmdFromVol(virConnectPtr conn, } } - if (vol->target.backingStore) { + backingStore = virStorageSourceGetBackingStore(&vol->target, 0); + if (backingStore) { int accessRetCode = -1; char *absolutePath = NULL; - info.backingFormat = vol->target.backingStore->format; - info.backingPath = vol->target.backingStore->path; + info.backingFormat = backingStore->format; + info.backingPath = backingStore->path; if (info.preallocate) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", @@ -1006,11 +1008,17 @@ virStorageBackendCreateQemuImgCmdFromVol(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 && - STRNEQ_NULLABLE(inputvol->target.backingStore->path, info.backingPath)) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("a different backing store cannot be specified.")); - return NULL; + if (inputvol) { + virStorageSourcePtr backingStorePtr = + virStorageSourceGetBackingStore(&inputvol->target, 0); + + if (backingStorePtr && + STRNEQ_NULLABLE(backingStorePtr->path, info.backingPath)) { + + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("a different backing store cannot be specified.")); + return NULL; + } } if (!(backingType = virStorageFileFormatTypeToString(info.backingFormat))) { @@ -1197,7 +1205,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")); @@ -1699,14 +1707,16 @@ virStorageBackendUpdateVolInfo(virStorageVolDefPtr vol, unsigned int readflags) { int ret; + virStorageSourcePtr backingStore; if ((ret = virStorageBackendUpdateVolTargetInfo(&vol->target, withBlockVolFormat, openflags, readflags)) < 0) return ret; - if (vol->target.backingStore && - (ret = virStorageBackendUpdateVolTargetInfo(vol->target.backingStore, + backingStore = virStorageSourceGetBackingStore(&vol->target, 0); + if (backingStore && + (ret = virStorageBackendUpdateVolTargetInfo(backingStore, withBlockVolFormat, VIR_STORAGE_VOL_OPEN_DEFAULT | VIR_STORAGE_VOL_OPEN_NOERROR, diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c index 692c9ff..cce8636 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -70,6 +70,7 @@ virStorageBackendProbeTarget(virStorageSourcePtr target, int ret = -1; int rc; virStorageSourcePtr meta = NULL; + virStorageSourcePtr backingStore; struct stat sb; if (encryption) @@ -99,37 +100,40 @@ virStorageBackendProbeTarget(virStorageSourcePtr target, if (!(target->backingStore = virStorageSourceNewFromBacking(meta))) goto cleanup; - target->backingStore->format = backingStoreFormat; + backingStore = virStorageSourceGetBackingStore(target, 0); + backingStore->format = backingStoreFormat; /* 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(backingStore)) { + virStorageSourceFree(backingStore); + target->backingStore = NULL; - if (VIR_ALLOC(target->backingStore) < 0) + if (VIR_ALLOC(backingStore) < 0) goto cleanup; - target->backingStore->type = VIR_STORAGE_TYPE_NETWORK; - target->backingStore->path = meta->backingStoreRaw; + target->backingStore = backingStore; + backingStore->type = VIR_STORAGE_TYPE_NETWORK; + backingStore->path = meta->backingStoreRaw; meta->backingStoreRaw = NULL; - target->backingStore->format = VIR_STORAGE_FILE_RAW; + backingStore->format = VIR_STORAGE_FILE_RAW; } - if (target->backingStore->format == VIR_STORAGE_FILE_AUTO) { - if ((rc = virStorageFileProbeFormat(target->backingStore->path, + if (backingStore->format == VIR_STORAGE_FILE_AUTO) { + if ((rc = virStorageFileProbeFormat(backingStore->path, -1, -1)) < 0) { /* If the backing file is currently unavailable or is * accessed via remote protocol only log an error, fake the * format as RAW and continue. Returning -1 here would * disable the whole storage pool, making it unavailable for * even maintenance. */ - target->backingStore->format = VIR_STORAGE_FILE_RAW; + backingStore->format = VIR_STORAGE_FILE_RAW; virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot probe backing volume format: %s"), - target->backingStore->path); + backingStore->path); } else { - target->backingStore->format = rc; + backingStore->format = rc; } } } @@ -891,6 +895,7 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED, struct stat statbuf; virStorageVolDefPtr vol = NULL; virStorageSourcePtr target = NULL; + virStorageSourcePtr backingStore; int direrr; int fd = -1, ret = -1; @@ -949,10 +954,12 @@ 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, - false, - VIR_STORAGE_VOL_OPEN_DEFAULT, 0)); + backingStore = virStorageSourceGetBackingStore(&vol->target, 0); + if (backingStore) { + ignore_value(virStorageBackendUpdateVolTargetInfo( + backingStore, + false, + VIR_STORAGE_VOL_OPEN_DEFAULT, 0)); /* If this failed, the backing file is currently unavailable, * the capacity, allocation, owner, group and mode are unknown. * An error message was raised, but we just continue. */ @@ -1130,7 +1137,7 @@ static int createFileDir(virConnectPtr conn ATTRIBUTE_UNUSED, return -1; } - if (vol->target.backingStore) { + if (virStorageSourceGetBackingStore(&vol->target, 0)) { virReportError(VIR_ERR_NO_SUPPORT, "%s", _("backing storage not supported for directories volumes")); return -1; diff --git a/src/storage/storage_backend_gluster.c b/src/storage/storage_backend_gluster.c index d2e79bc..9bddb3b 100644 --- a/src/storage/storage_backend_gluster.c +++ b/src/storage/storage_backend_gluster.c @@ -247,6 +247,7 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state, char *header = NULL; ssize_t len = VIR_STORAGE_MAX_HEADER; int backingFormat; + virStorageSourcePtr backingStore; *volptr = NULL; @@ -302,13 +303,14 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state, if (meta->backingStoreRaw) { if (VIR_ALLOC(vol->target.backingStore) < 0) goto cleanup; + backingStore = virStorageSourceGetBackingStore(&vol->target, 0); - vol->target.backingStore->path = meta->backingStoreRaw; + backingStore->path = meta->backingStoreRaw; if (backingFormat < 0) - vol->target.backingStore->format = VIR_STORAGE_FILE_RAW; + backingStore->format = VIR_STORAGE_FILE_RAW; else - vol->target.backingStore->format = backingFormat; + backingStore->format = backingFormat; meta->backingStoreRaw = NULL; } diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c index c52782f..ce84110 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') @@ -151,11 +152,14 @@ virStorageBackendLogicalMakeVol(char **const groups, if (VIR_ALLOC(vol->target.backingStore) < 0) goto cleanup; - if (virAsprintf(&vol->target.backingStore->path, "%s/%s", - pool->def->target.path, groups[1]) < 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; - vol->target.backingStore->format = VIR_STORAGE_POOL_LOGICAL_LVM2; + backingStore->format = VIR_STORAGE_POOL_LOGICAL_LVM2; + } } if (!vol->key && VIR_STRDUP(vol->key, groups[2]) < 0) @@ -843,6 +847,7 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn, virErrorPtr err; struct stat sb; bool created = false; + virStorageSourcePtr backingStore; if (vol->target.encryption != NULL) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -875,8 +880,9 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn, } virCommandAddArgFormat(cmd, "%lluK", VIR_DIV_UP(vol->target.capacity, 1024)); - if (vol->target.backingStore) - virCommandAddArgList(cmd, "-s", vol->target.backingStore->path, NULL); + backingStore = virStorageSourceGetBackingStore(&vol->target, 0); + if (backingStore) + virCommandAddArgList(cmd, "-s", backingStore->path, NULL); else virCommandAddArg(cmd, pool->def->source.name); diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 43a7137..7ab4a56 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1076,10 +1076,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; @@ -1334,8 +1334,9 @@ 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++; } @@ -1352,7 +1353,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); @@ -1387,7 +1388,7 @@ virStorageFileChainLookup(virStorageSourcePtr chain, } } *parent = chain; - chain = chain->backingStore; + chain = virStorageSourceGetBackingStore(chain, 0); i++; } @@ -1932,9 +1933,10 @@ virStorageSourceCopy(const virStorageSource *src, !(ret->auth = virStorageAuthDefCopy(src->auth))) goto error; - if (backingChain && src->backingStore) { - if (!(ret->backingStore = virStorageSourceCopy(src->backingStore, - true))) + if (backingChain) { + virStorageSourcePtr backingStore = + virStorageSourceGetBackingStore(src, 0); + if (!(ret->backingStore = virStorageSourceCopy(backingStore, true))) goto error; } @@ -2074,7 +2076,7 @@ virStorageSourceBackingStoreClear(virStorageSourcePtr def) VIR_FREE(def->backingStoreRaw); /* recursively free backing chain */ - virStorageSourceFree(def->backingStore); + virStorageSourceFree(virStorageSourceGetBackingStore(def, 0)); def->backingStore = NULL; } @@ -2937,7 +2939,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 38ce09e..5bd4637 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) { @@ -1044,8 +1044,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) \ @@ -1110,8 +1110,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); @@ -1157,8 +1157,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); -- 2.5.0

From: Matthias Gatto <matthias.gatto@outscale.com> Convert all ->backingStore stores into a virStorageSourceSetBackingStore call using 0 as the pos in order to store. Signed-off-by: Matthias Gatto <matthias.gatto@outscale.com> Signed-off-by: John Ferlan <jferlan@redhat.com> --- 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

From: Matthias Gatto <matthias.gatto@outscale.com> Convert the storage source backingStore pointer into an array of virStorageSourcePtr. This patch will rename src->backingStore to src->backingStores, add an nbackingStores, and adjust the code Get and Set functions to handle the the array. virStorageSourceSetBackingStore can expand the size of src->backingStores. Signed-off-by: Matthias Gatto <matthias.gatto@outscale.com> Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/util/virstoragefile.c | 61 ++++++++++++++++++++++++++++++----------------- src/util/virstoragefile.h | 3 ++- 2 files changed, 41 insertions(+), 23 deletions(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 1d96d7a..b917eb6 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1813,11 +1813,10 @@ virStorageSourcePoolDefCopy(const virStorageSourcePoolDef *src) /** * virStorageSourceGetBackingStore: * @src: virStorageSourcePtr containing the backing stores - * @pos: presently unused + * @pos: position of the backing store to get * - * Return the @src backingStore pointer at @pos. For now, @pos is - * expected to be 0. A future patch will use @pos index into an array - * of storage backingStore pointers + * Return the @src backingStore pointer at @pos in the array of + * storage backingStores pointers * * Returns: * A pointer to the storage source backingStore @pos or @@ -1827,9 +1826,9 @@ virStorageSourcePtr virStorageSourceGetBackingStore(const virStorageSource *src, size_t pos) { - if (!src || pos > 0) + if (!src || !src->backingStores || pos >= src->nBackingStores) return NULL; - return src->backingStore; + return src->backingStores[pos]; } @@ -1837,11 +1836,12 @@ virStorageSourceGetBackingStore(const virStorageSource *src, * virStorageSourceSetBackingStore: * @src: virStorageSourcePtr to hold @backingStore * @backingStore - Pointer to the backingStore to store - * @pos - presently unused + * @pos: position of the backing store to store * - * Set @backingStore in @src at @pos in src->backingStore. For now, pos - * is expected to be 0. A future patch will use pos as the position in - * the array of storage backingStore pointers + * Set @backingStore in @src at @pos in src->backingStores. If the + * backingStores array does not have the space to contain @backingStore, + * expand src->backingStores. If the entry at @pos already exists, then + * free it first before replacing with the new @backingStore. * * Returns: * 0 on success, -1 on failure @@ -1851,10 +1851,18 @@ virStorageSourceSetBackingStore(virStorageSourcePtr src, virStorageSourcePtr backingStore, size_t pos) { - if (pos > 0) + if (!src) return -1; - src->backingStore = backingStore; + if (pos >= src->nBackingStores) { + int nbr = pos - src->nBackingStores + 1; + if (VIR_EXPAND_N(src->backingStores, src->nBackingStores, nbr) < 0) + return -1; + } + + if (src->backingStores[pos]) + virStorageSourceFree(src->backingStores[pos]); + src->backingStores[pos] = backingStore; return 0; } @@ -1873,6 +1881,7 @@ virStorageSourceCopy(const virStorageSource *src, bool backingChain) { virStorageSourcePtr ret = NULL; + size_t i; if (VIR_ALLOC(ret) < 0) return NULL; @@ -1885,6 +1894,7 @@ virStorageSourceCopy(const virStorageSource *src, ret->physical = src->physical; ret->readonly = src->readonly; ret->shared = src->shared; + ret->nBackingStores = src->nBackingStores; /* storage driver metadata are not copied */ ret->drv = NULL; @@ -1933,15 +1943,17 @@ virStorageSourceCopy(const virStorageSource *src, !(ret->auth = virStorageAuthDefCopy(src->auth))) goto error; - if (backingChain) { - virStorageSourcePtr backingStore = - virStorageSourceGetBackingStore(src, 0); - virStorageSourcePtr backingStoreCopy = - virStorageSourceCopy(backingStore, true); + for (i = 0; i < src->nBackingStores; i++) { + if (backingChain) { + virStorageSourcePtr backingStore = + virStorageSourceGetBackingStore(src, i); + virStorageSourcePtr backingStoreCopy = + virStorageSourceCopy(backingStore, true); - if (!backingStoreCopy || - virStorageSourceSetBackingStore(ret, backingStoreCopy, 0) < 0) - goto error; + if (!backingStoreCopy || + virStorageSourceSetBackingStore(ret, backingStoreCopy, i) < 0) + goto error; + } } return ret; @@ -2073,6 +2085,8 @@ virStorageSourceIsEmpty(virStorageSourcePtr src) void virStorageSourceBackingStoreClear(virStorageSourcePtr def) { + size_t i; + if (!def) return; @@ -2080,8 +2094,11 @@ virStorageSourceBackingStoreClear(virStorageSourcePtr def) VIR_FREE(def->backingStoreRaw); /* recursively free backing chain */ - virStorageSourceFree(virStorageSourceGetBackingStore(def, 0)); - ignore_value(virStorageSourceSetBackingStore(def, NULL, 0)); + for (i = 0; i < def->nBackingStores; i++) + virStorageSourceFree(virStorageSourceGetBackingStore(def, i)); + if (def->nBackingStores > 0) + VIR_FREE(def->backingStores); + def->nBackingStores = 0; } diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index ce1cb5d..290c20f 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -270,7 +270,8 @@ struct _virStorageSource { bool shared; /* backing chain of the storage source */ - virStorageSourcePtr backingStore; + virStorageSourcePtr *backingStores; + size_t nBackingStores; /* metadata for storage driver access to remote and local volumes */ virStorageDriverDataPtr drv; -- 2.5.0
participants (2)
-
John Ferlan
-
Matthias Gatto