[libvirt] [PATCH 2/3] Helper function for making a deep-copy of virCPUDefPtr

Daniel Veillard veillard at redhat.com
Fri Mar 26 16:15:46 UTC 2010


On Fri, Mar 26, 2010 at 02:11:35PM +0100, Jiri Denemark wrote:
> ---
>  src/conf/cpu_conf.c      |   37 +++++++++++++++++++++++++++++++++++++
>  src/conf/cpu_conf.h      |    3 +++
>  src/libvirt_private.syms |    1 +
>  3 files changed, 41 insertions(+), 0 deletions(-)
> 
> diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c
> index 612e376..cf91930 100644
> --- a/src/conf/cpu_conf.c
> +++ b/src/conf/cpu_conf.c
> @@ -67,6 +67,43 @@ virCPUDefFree(virCPUDefPtr def)
>  }
>  
>  
> +virCPUDefPtr
> +virCPUDefCopy(const virCPUDefPtr cpu)
> +{
> +    virCPUDefPtr copy;
> +    unsigned int i;
> +
> +    if (!cpu)
> +        return NULL;
> +
> +    if (VIR_ALLOC(copy) < 0
> +        || (cpu->arch && !(copy->arch = strdup(cpu->arch)))
> +        || (cpu->model && !(copy->model = strdup(cpu->model)))
> +        || VIR_ALLOC_N(copy->features, cpu->nfeatures) < 0)
> +        goto no_memory;
> +
> +    copy->type = cpu->type;
> +    copy->match = cpu->match;
> +    copy->sockets = cpu->sockets;
> +    copy->cores = cpu->cores;
> +    copy->threads = cpu->threads;
> +    copy->nfeatures = cpu->nfeatures;
> +
> +    for (i = 0; i < copy->nfeatures; i++) {
> +        copy->features[i].policy = cpu->features[i].policy;
> +        if (!(copy->features[i].name = strdup(cpu->features[i].name)))
> +            goto no_memory;
> +    }
> +
> +    return copy;
> +
> +no_memory:
> +    virReportOOMError();
> +    virCPUDefFree(copy);
> +    return NULL;
> +}
> +

  Somehow I was expecting something recursive due to deep-copy title

  ACK,

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel at veillard.com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/




More information about the libvir-list mailing list