Re: [libvirt] [PATCH v2 5/9] virstoragefile: Treat backingStore as a pointer or an array
On 21.01.2015 16:29, Matthias Gatto wrote: As explain in the former patchs, backingStore can be treat an array or a pointer. If we have only one backingStore we have to use it as a normal ptr but if there is more backing store, we use it as a pointer's array. Because it would be complicated to expend backingStore manually, and do the convertion from a pointer to an array, I've created the virStorageSourcePushBackingStore function to help. This function allocate an array of pointer only if there is more than 1 bs. Because we can not remove a child from a quorum, i didn't create the function virStorageSourcePopBackingStore. I've changed virStorageSourceBackingStoreClear, virStorageSourceSetBackingStore and virStorageSourceGetBackingStore to handle the case where backingStore is an array. Signed-off-by: Matthias Gatto matthias.ga...@outscale.com --- src/conf/storage_conf.c | 7 ++- src/libvirt_private.syms | 1 + src/storage/storage_backend_fs.c | 2 + src/storage/storage_backend_logical.c | 2 +- src/util/virstoragefile.c | 89 --- src/util/virstoragefile.h | 2 + 6 files changed, 94 insertions(+), 9 deletions(-) diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index fac85fa..41887eb 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -1343,7 +1343,12 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, if (VIR_ALLOC(backingStorePtr) 0) goto error; -backingStorePtr = virStorageSourceSetBackingStore(ret-target, backingStorePtr, 0); +if (!virStorageSourcePushBackingStore(ret-target)) +goto error; + +backingStorePtr = virStorageSourceSetBackingStore(ret-target, + backingStorePtr, + ret-target.nBackingStores - 1); backingStorePtr-path = backingStore; backingStore = NULL; diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 980235b..5752907 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2033,6 +2033,7 @@ virStorageSourceParseRBDColonString; virStorageSourcePoolDefFree; virStorageSourcePoolModeTypeFromString; virStorageSourcePoolModeTypeToString; +virStorageSourcePushBackingStore; virStorageSourceSetBackingStore; virStorageTypeFromString; virStorageTypeToString; diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c index a3b6688..0d8c5ad 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -112,6 +112,8 @@ virStorageBackendProbeTarget(virStorageSourcePtr target, if (VIR_ALLOC(backingStore) 0) goto cleanup; +if (virStorageSourcePushBackingStore(target) == false) +goto cleanup; virStorageSourceSetBackingStore(target, backingStore, 0); backingStore-type = VIR_STORAGE_TYPE_NETWORK; backingStore-path = meta-backingStoreRaw; diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c index fcec31f..cd8de85 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -148,7 +148,7 @@ 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 (virStorageSourcePushBackingStore(vol-target) == false) goto cleanup; if (virAsprintf(virStorageSourceGetBackingStore(vol-target, 0)-path, %s/%s, diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index ba38827..554aa8b 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1798,21 +1798,88 @@ virStorageSourcePoolDefCopy(const virStorageSourcePoolDef *src) } +/** + * virStorageSourceGetBackingStore: + * @src: virStorageSourcePtr containing the backing stores + * @pos: position of the backing store to get + * + * return the backingStore at the position of @pos + */ virStorageSourcePtr -virStorageSourceGetBackingStore(const virStorageSource *src, -size_t pos ATTRIBUTE_UNUSED) +virStorageSourceGetBackingStore(const virStorageSource *src, size_t pos) +{ +if (!src-backingStore || (pos 1 pos = src-nBackingStores)) +return NULL; +if (src-nBackingStores 2) +return src-backingStore; +return ((virStorageSourcePtr *)src-backingStore)[pos]; +} + + +/** + * virStorageSourcePushBackingStore: + * @src: virStorageSourcePtr to allocate the new backing store + * + * Allocate size for a new backingStorePtr in src-backingStore + * and update src-nBackingStores + * If we
Re: [libvirt] [PATCH v2 5/9] virstoragefile: Treat backingStore as a pointer or an array
On Wed, Jan 28, 2015 at 11:10 AM, Michal Privoznik mpriv...@redhat.com wrote: On 21.01.2015 16:29, Matthias Gatto wrote: As explain in the former patchs, backingStore can be treat an array or a pointer. If we have only one backingStore we have to use it as a normal ptr but if there is more backing store, we use it as a pointer's array. Because it would be complicated to expend backingStore manually, and do the convertion from a pointer to an array, I've created the virStorageSourcePushBackingStore function to help. This function allocate an array of pointer only if there is more than 1 bs. Because we can not remove a child from a quorum, i didn't create the function virStorageSourcePopBackingStore. I've changed virStorageSourceBackingStoreClear, virStorageSourceSetBackingStore and virStorageSourceGetBackingStore to handle the case where backingStore is an array. Signed-off-by: Matthias Gatto matthias.ga...@outscale.com --- src/conf/storage_conf.c | 7 ++- src/libvirt_private.syms | 1 + src/storage/storage_backend_fs.c | 2 + src/storage/storage_backend_logical.c | 2 +- src/util/virstoragefile.c | 89 --- src/util/virstoragefile.h | 2 + 6 files changed, 94 insertions(+), 9 deletions(-) diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index fac85fa..41887eb 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -1343,7 +1343,12 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, if (VIR_ALLOC(backingStorePtr) 0) goto error; -backingStorePtr = virStorageSourceSetBackingStore(ret-target, backingStorePtr, 0); +if (!virStorageSourcePushBackingStore(ret-target)) +goto error; + +backingStorePtr = virStorageSourceSetBackingStore(ret-target, + backingStorePtr, + ret-target.nBackingStores - 1); backingStorePtr-path = backingStore; backingStore = NULL; diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 980235b..5752907 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2033,6 +2033,7 @@ virStorageSourceParseRBDColonString; virStorageSourcePoolDefFree; virStorageSourcePoolModeTypeFromString; virStorageSourcePoolModeTypeToString; +virStorageSourcePushBackingStore; virStorageSourceSetBackingStore; virStorageTypeFromString; virStorageTypeToString; diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c index a3b6688..0d8c5ad 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -112,6 +112,8 @@ virStorageBackendProbeTarget(virStorageSourcePtr target, if (VIR_ALLOC(backingStore) 0) goto cleanup; +if (virStorageSourcePushBackingStore(target) == false) +goto cleanup; virStorageSourceSetBackingStore(target, backingStore, 0); backingStore-type = VIR_STORAGE_TYPE_NETWORK; backingStore-path = meta-backingStoreRaw; diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c index fcec31f..cd8de85 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -148,7 +148,7 @@ 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 (virStorageSourcePushBackingStore(vol-target) == false) goto cleanup; if (virAsprintf(virStorageSourceGetBackingStore(vol-target, 0)-path, %s/%s, diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index ba38827..554aa8b 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1798,21 +1798,88 @@ virStorageSourcePoolDefCopy(const virStorageSourcePoolDef *src) } +/** + * virStorageSourceGetBackingStore: + * @src: virStorageSourcePtr containing the backing stores + * @pos: position of the backing store to get + * + * return the backingStore at the position of @pos + */ virStorageSourcePtr -virStorageSourceGetBackingStore(const virStorageSource *src, -size_t pos ATTRIBUTE_UNUSED) +virStorageSourceGetBackingStore(const virStorageSource *src, size_t pos) +{ +if (!src-backingStore || (pos 1 pos = src-nBackingStores)) +return NULL; +if (src-nBackingStores 2) +return src-backingStore; +return ((virStorageSourcePtr *)src-backingStore)[pos]; +} + + +/** + * virStorageSourcePushBackingStore: + * @src: virStorageSourcePtr to allocate the new backing store + * + * Allocate size for a new backingStorePtr in