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

Re: [libvirt] [PATCH v2 1/5] cpu_models: add new public API



On Sat, Sep 07, 2013 at 01:11:22AM +0200, Giuseppe Scrivano wrote:
> The new function virConnectGetCPUModelNames allows to retrieve the list
> of CPU models known by the hypervisor for a specific architecture.
> 
> Signed-off-by: Giuseppe Scrivano <gscrivan redhat com>
> ---
>  include/libvirt/libvirt.h.in | 18 +++++++++++++
>  python/generator.py          |  1 +
>  src/cpu/cpu.c                | 64 ++++++++++++++++++++++++++++++++++++++++++++
>  src/cpu/cpu.h                |  3 +++
>  src/driver.h                 |  7 +++++
>  src/libvirt.c                | 47 ++++++++++++++++++++++++++++++++
>  src/libvirt_private.syms     |  1 +
>  src/libvirt_public.syms      |  5 ++++
>  tools/virsh-host.c           | 48 +++++++++++++++++++++++++++++++++
>  tools/virsh.pod              |  5 ++++

It is preferrable to have virsh changes separate from the public API
addition. Likewise I'd suggest th src/cpu/ changes be a separate patch.

> diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
> index a47e33c..43fb738 100644
> --- a/include/libvirt/libvirt.h.in
> +++ b/include/libvirt/libvirt.h.in
> @@ -4006,6 +4006,24 @@ int virConnectCompareCPU(virConnectPtr conn,
>                           const char *xmlDesc,
>                           unsigned int flags);
>  
> +/**
> + * virConnectGetCPUModelNames:
> + *
> + * @conn: virConnect connection
> + * @arch: Architecture
> + * @models: NULL terminated array of the CPU models supported for the specified
> + * architecture.  Each element and the array itself must be freed by the caller
> + * with free.
> + * @flags: extra flags; not used yet, so callers should always pass 0.
> + *
> + * Get the list of supported CPU models for a specific architecture.
> + *
> + * Returns -1 on error, 0 on success.

I'd suggest

  Returns -1 on error,  number of elements in @models on success

> + */
> +int virConnectGetCPUModelNames(virConnectPtr conn,
> +                               const char *arch,
> +                               char ***models,
> +                               unsigned int flags);


> +int
> +cpuGetModels(const char *arch, char ***models)
> +{
> +    struct cpuGetModelsData data;
> +
> +    *models = data.data = NULL;
> +    data.len = 1;
> +
> +    if (VIR_ALLOC_N(data.data, data.len) < 0)
> +        goto error;
> +
> +    if (cpuGetArchModels(arch, &data) < 0)
> +        goto error;
> +
> +    *models = data.data;
> +    return 0;
> +
> +error:
> +    if (data.data) {
> +        char **it;
> +        for (it = data.data; *it; it++)
> +            VIR_FREE(*it);
> +        VIR_FREE(data.data);

virFreeStringList(data.data);  should do the trick.


>  /**
> + * virConnectGetCPUModelNames:
> + *
> + * @conn: virConnect connection
> + * @arch: Architecture
> + * @models: NULL terminated array of the CPU models supported for the specified
> + * architecture.  Each element and the array itself must be freed by the caller
> + * with free.
> + * @flags: extra flags; not used yet, so callers should always pass 0.
> + *
> + * Get the list of supported CPU models for a specific architecture.
> + *
> + * Returns -1 on error, 0 on success.
> + */
> +int
> +virConnectGetCPUModelNames(virConnectPtr conn, const char *arch, char ***models,
> +                           unsigned int flags)
> +{
> +    VIR_DEBUG("conn=%p, arch=%s, flags=%x", conn, arch, flags);
> +    virResetLastError();
> +
> +    if (!VIR_IS_CONNECT(conn)) {
> +        virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
> +        virDispatchError(NULL);
> +        return -1;
> +    }
> +
> +    if (arch == NULL) {
> +        virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__);
> +        goto error;
> +    }

This allows access to this API from readonly connections. I think this is ok,
but just wanted to mention it explicitly.

> +
> +    if (conn->driver->connectGetCPUModelNames) {
> +        if (conn->driver->connectGetCPUModelNames(conn, arch, models, flags) < 0)
> +            goto error;
> +
> +        return 0;
> +    }
> +
> +    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
> +
> +error:
> +    virDispatchError(conn);
> +    return -1;
> +}
> +
> +
> +/**
>   * virConnectBaselineCPU:
>   *
>   * @conn: virConnect connection


Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|


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