Re: [PATCHv1.5 18/27] conf: Add functions to copy and free network disk source definitions

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

 



On 26.11.2013 17:49, Peter Krempa wrote:
> To simplify operations on virDomainDiskHostDef arrays we will need deep
> copy and freeing functions. Add and properly export them.
> ---
>  src/conf/domain_conf.c   | 55 +++++++++++++++++++++++++++++++++++++++++++++---
>  src/conf/domain_conf.h   |  3 +++
>  src/libvirt_private.syms |  2 ++
>  3 files changed, 57 insertions(+), 3 deletions(-)
> 
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index 0561d9d..e0d6903 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -1216,9 +1216,7 @@ void virDomainDiskDefFree(virDomainDiskDefPtr def)
>          VIR_FREE(def->seclabels);
>      }
> 
> -    for (i = 0; i < def->nhosts; i++)
> -        virDomainDiskHostDefClear(&def->hosts[i]);
> -    VIR_FREE(def->hosts);
> +    virDomainDiskHostDefFree(def->nhosts, def->hosts);
> 
>      VIR_FREE(def);
>  }
> @@ -1233,6 +1231,57 @@ void virDomainDiskHostDefClear(virDomainDiskHostDefPtr def)
>      VIR_FREE(def->socket);
>  }
> 
> +
> +void
> +virDomainDiskHostDefFree(size_t nhosts,
> +                         virDomainDiskHostDefPtr hosts)
> +{
> +    size_t i;
> +
> +    if (!hosts)
> +        return;
> +
> +    for (i = 0; i < nhosts; i++)
> +        virDomainDiskHostDefClear(&hosts[i]);
> +
> +    VIR_FREE(hosts);
> +}
> +
> +
> +virDomainDiskHostDefPtr
> +virDomainDiskHostDefCopy(size_t nhosts,
> +                         virDomainDiskHostDefPtr hosts)
> +{
> +    virDomainDiskHostDefPtr ret = NULL;
> +    size_t i;
> +
> +    if (VIR_ALLOC_N(ret, nhosts) < 0)
> +        goto error;
> +
> +    for (i = 0; i < nhosts; i++) {
> +        virDomainDiskHostDefPtr src = &hosts[i];
> +        virDomainDiskHostDefPtr dst = &ret[i];
> +
> +        dst->transport = src->transport;
> +
> +        if (VIR_STRDUP(dst->name, src->name) < 0)
> +            goto error;
> +
> +        if (VIR_STRDUP(dst->port, src->port) < 0)
> +            goto error;
> +
> +        if (VIR_STRDUP(dst->socket, src->socket) < 0)
> +            goto error;

Could have been joined into one 'if' with or-ed VIR_STRDUP(). But this
is just fine too.

> +    }
> +
> +    return ret;
> +
> +error:
> +    virDomainDiskHostDefFree(nhosts, ret);
> +    return NULL;
> +}
> +
> +
>  void virDomainControllerDefFree(virDomainControllerDefPtr def)
>  {
>      if (!def)
> diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
> index e9800a5..ee018f0 100644
> --- a/src/conf/domain_conf.h
> +++ b/src/conf/domain_conf.h
> @@ -2211,6 +2211,9 @@ void virDomainInputDefFree(virDomainInputDefPtr def);
>  void virDomainDiskDefFree(virDomainDiskDefPtr def);
>  void virDomainLeaseDefFree(virDomainLeaseDefPtr def);
>  void virDomainDiskHostDefClear(virDomainDiskHostDefPtr def);
> +void virDomainDiskHostDefFree(size_t nhosts, virDomainDiskHostDefPtr hosts);
> +virDomainDiskHostDefPtr virDomainDiskHostDefCopy(size_t nhosts,
> +                                                 virDomainDiskHostDefPtr hosts);
>  int virDomainDeviceFindControllerModel(virDomainDefPtr def,
>                                         virDomainDeviceInfoPtr info,
>                                         int controllerType);
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index aeb3568..f952a12 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -198,6 +198,8 @@ virDomainDiskFindByBusAndDst;
>  virDomainDiskGeometryTransTypeFromString;
>  virDomainDiskGeometryTransTypeToString;
>  virDomainDiskHostDefClear;
> +virDomainDiskHostDefCopy;
> +virDomainDiskHostDefFree;
>  virDomainDiskIndexByName;
>  virDomainDiskInsert;
>  virDomainDiskInsertPreAlloced;
> 

ACK

Michal

--
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]