[libvirt] [PATCH v2 6/9] virConnectBaselineCPU public API implementation

Daniel Veillard veillard at redhat.com
Thu Feb 11 16:56:29 UTC 2010


On Thu, Feb 11, 2010 at 04:43:56PM +0100, Jiri Denemark wrote:
> Signed-off-by: Jiri Denemark <jdenemar at redhat.com>
> ---
>  src/libvirt.c |   57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 57 insertions(+), 0 deletions(-)
> 
> diff --git a/src/libvirt.c b/src/libvirt.c
> index f9ff881..0c3271c 100644
> --- a/src/libvirt.c
> +++ b/src/libvirt.c
> @@ -11090,3 +11090,60 @@ error:
>      virDispatchError(conn);
>      return VIR_CPU_COMPARE_ERROR;
>  }
> +
> +
> +/**
> + * virConnectBaselineCPU:
> + *
> + * @conn: virConnect connection
> + * @xmlCPUs: array of XML descriptions of host CPUs
> + * @ncpus: number of CPUs in xmlCPUs
> + * @flags: fine-tuning flags, currently unused, pass 0.
> + *
> + * Computes the most feature-rich CPU which is compatible with all given
> + * host CPUs.
> + *
> + * Returns XML description of the computed CPU or NULL on error.
> + */
> +char *
> +virConnectBaselineCPU(virConnectPtr conn,
> +                      const char **xmlCPUs,
> +                      unsigned int ncpus,
> +                      unsigned int flags)
> +{
> +    unsigned int i;
> +
> +    VIR_DEBUG("conn=%p, xmlCPUs=%p, ncpus=%u, flags=%u",
> +              conn, xmlCPUs, ncpus, flags);
> +    if (xmlCPUs) {
> +        for (i = 0; i < ncpus; i++)
> +            VIR_DEBUG("xmlCPUs[%u]=%s", i, xmlCPUs[i]);

   Hum ... what if xmlCPUs[i] == NULL ... we should not crash there
maybe this should be tested and that loop being done after
VIR_IS_CONNECT(conn) check and xmlCPUs == NULL check

> +    }
> +
> +    virResetLastError();
> +
> +    if (!VIR_IS_CONNECT(conn)) {
> +        virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
> +        virDispatchError(NULL);
> +        return NULL;
> +    }
> +    if (xmlCPUs == NULL) {
> +        virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
> +        goto error;
> +    }
> +
> +    if (conn->driver->cpuBaseline) {
> +        char *cpu;
> +
> +        cpu = conn->driver->cpuBaseline(conn, xmlCPUs, ncpus, flags);
> +        if (!cpu)
> +            goto error;
> +        return cpu;
> +    }
> +
> +    virLibConnError(conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
> +
> +error:
> +    virDispatchError(conn);
> +    return NULL;
> +}

  ACK once the potential crash on entry is fixed.

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