Re: [PATCH v6 05/13] virstoragefile: change backingStore to backingStores.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Oct 29, 2015 at 14:43:12 +0100, Matthias Gatto wrote:
> The backingStore field was a virStorageSourcePtr.
> Because a quorum can contain more that one backingStore at the same level,
> it's now an array of 'virStorageSourcePtr'.
> 
> This patch rename  src->backingStore to src->backingStores,
> Made the necessary changes to virStorageSourceSetBackingStore
> and virStorageSourceGetBackingStore.
> virStorageSourceSetBackingStore can now expand the size of src->backingStores.
> 
> Signed-off-by: Matthias Gatto <matthias.gatto@xxxxxxxxxxxx>
> ---
>  src/storage/storage_backend.c    |  2 +-
>  src/storage/storage_backend_fs.c |  2 +-
>  src/util/virstoragefile.c        | 48 +++++++++++++++++++++++++++++++++-------
>  src/util/virstoragefile.h        |  3 ++-
>  4 files changed, 44 insertions(+), 11 deletions(-)

[...]

> 
> diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
> index cb96c5b..44bce91 100644
> --- a/src/util/virstoragefile.c
> +++ b/src/util/virstoragefile.c
> @@ -1809,21 +1809,48 @@ 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)
>  {
> -    return src->backingStore;
> +    if (!src || !src->backingStores || pos >= src->nBackingStores)
> +        return NULL;

The first two condition statements should be in the patch that
introduced this function.

> +    return src->backingStores[pos];
>  }
>  
>  
> +/**
> + * virStorageSourceSetBackingStore:
> + * @src: virStorageSourcePtr to hold @backingStore
> + * @backingStore: backingStore to store
> + * @pos: position of the backing store to store
> + *
> + * Set @backingStore at @pos in src->backingStores.
> + * If src->backingStores don't have the space to contain
> + * @backingStore, we expand src->backingStores
> + */
>  bool

As I've said earlier, libvirt's convention is to return -1 in case when
something failed.

>  virStorageSourceSetBackingStore(virStorageSourcePtr src,
>                                  virStorageSourcePtr backingStore,
> -                                size_t pos ATTRIBUTE_UNUSED)
> +                                size_t pos)
>  {
> -    src->backingStore = backingStore;
> -    return !!src->backingStore;
> +    if (!src)
> +        return false;
> +
> +    if (pos >= src->nBackingStores) {
> +        int nbr = pos - src->nBackingStores + 1;
> +        if (VIR_EXPAND_N(src->backingStores, src->nBackingStores, nbr) < 0)
> +            return false;
> +    }
> +
> +    src->backingStores[pos] = backingStore;

Shouldn't this free the backing store if it's being overwritten? Or
perhaps fail if it's already assigned?

> +    return true;
>  }
>  
>  

Attachment: signature.asc
Description: Digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]