[libvirt] [PATCH 5/9] virstoragefile: Treat backingStore as a pointer or an array
Michal Privoznik
mprivozn at redhat.com
Tue Jan 13 14:46:17 UTC 2015
On 08.12.2014 19:31, 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.gatto at outscale.com>
> ---
> src/conf/storage_conf.c | 3 +-
> src/libvirt_private.syms | 1 +
> src/storage/storage_backend_fs.c | 2 +-
> src/storage/storage_backend_logical.c | 2 +-
> src/util/virstoragefile.c | 87 ++++++++++++++++++++++++++++++++---
> src/util/virstoragefile.h | 2 +
> 6 files changed, 87 insertions(+), 10 deletions(-)
>
> diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c
> index 300c990..edec124 100644
> --- a/src/storage/storage_backend_logical.c
> +++ b/src/storage/storage_backend_logical.c
> +/**
> + * virStorageSourcePushBackingStore:
> + * @src: virStorageSourcePtr to allocate the new backing store
> + *
> + * Allocate size for a new backing store in src->backingStore
> + * and update src->nBackingStores
> + * If we have less than 2 backing stores, we treat src->backingStore
> + * as a pointer otherwise we treat it as an array of virStorageSourcePtr
> + */
> +bool
> +virStorageSourcePushBackingStore(virStorageSourcePtr src)
> +{
> + virStorageSourcePtr tmp;
> + virStorageSourcePtr *tmp2;
> +
> + if (src->nBackingStores == 1) {
> +/* If we need more than one backing store we need an array
> + * Because we don't want to lose our data from the old Backing Store
> + * we copy the pointer from src->backingStore to src->backingStore[0] */
I'd expect the comments to be indented with the code.
> + tmp = src->backingStore;
> + if (VIR_ALLOC_N(tmp2, 1) < 0)
> + return false;
> + src->backingStore = (virStorageSourcePtr)tmp2;
> + src->nBackingStores += 1;
> + virStorageSourceSetBackingStore(src, tmp, 0);
> + } else if (src->nBackingStores > 1) {
> + tmp2 = ((virStorageSourcePtr *)src->backingStore);
> + if (VIR_EXPAND_N(tmp2, src->nBackingStores, 1) < 0)
> + return false;
> + src->backingStore = (virStorageSourcePtr)tmp2;
> + } else {
> +/* Most of the time we use only one backingStore
> + * So we don't need to allocate an array */
> + src->nBackingStores += 1;
> + }
> + return true;
> +}
> +
Michal
More information about the libvir-list
mailing list