[libvirt] [PATCH v3 1/9] Implement public API for virDomainGetIOThreadsInfo

Laine Stump laine at laine.org
Tue Feb 24 20:11:58 UTC 2015


On 02/17/2015 04:03 PM, John Ferlan wrote:
> Add virDomainGetIOThreadsInfo in order to return a list of
> virDomainIOThreadsInfoPtr structures which list the IOThread ID,
> the CPU Affinity map, and associated resources for each IOThread
> for the domain. For an active domain, the live data will be
> returned, while for an inactive domain, the config data will be
> returned. The resources data is expected to be the src path for
> the disks that have an assigned iothread.
>
> The API supports either the --live or --config flag, but not both.
>
> Also added virDomainIOThreadsInfoFree in order to free the cpumap,
> list of resources, and the array entry structure.
>
> Signed-off-by: John Ferlan <jferlan at redhat.com>
> ---
>  include/libvirt/libvirt-domain.h | 23 +++++++++++-
>  src/driver-hypervisor.h          |  8 +++-
>  src/libvirt-domain.c             | 80 +++++++++++++++++++++++++++++++++++++++-
>  src/libvirt_public.syms          |  6 +++
>  4 files changed, 114 insertions(+), 3 deletions(-)
>
> diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
> index 4dbd7f5..9dcc424 100644
> --- a/include/libvirt/libvirt-domain.h
> +++ b/include/libvirt/libvirt-domain.h
> @@ -4,7 +4,7 @@
>   * Description: Provides APIs for the management of domains
>   * Author: Daniel Veillard <veillard at redhat.com>
>   *
> - * Copyright (C) 2006-2014 Red Hat, Inc.
> + * Copyright (C) 2006-2015 Red Hat, Inc.
>   *
>   * This library is free software; you can redistribute it and/or
>   * modify it under the terms of the GNU Lesser General Public
> @@ -1568,6 +1568,27 @@ int                     virDomainGetEmulatorPinInfo (virDomainPtr domain,
>                                                       unsigned int flags);
>  
>  /**
> + * virIOThreadsInfo:
> + *
> + * The data structure for information about IOThreads in a domain
> + */
> +typedef struct _virDomainIOThreadsInfo virDomainIOThreadsInfo;
> +typedef virDomainIOThreadsInfo *virDomainIOThreadsInfoPtr;
> +struct _virDomainIOThreadsInfo {
> +    unsigned int iothread_id;          /* IOThread ID */
> +    unsigned char *cpumap;             /* CPU map for thread */
> +    int cpumaplen;                     /* cpumap size */
> +    size_t nresources;                 /* count of resources using IOThread */
> +    char **resources;                  /* array of resources using IOThread */
> +};

As an outsider, I'm left a bit uninformed about exactly what will be in
cpumap and resources. Is this information available elsewhere in the
documentation already?

> +
> +void                 virDomainIOThreadsInfoFree(virDomainIOThreadsInfoPtr info);
> +
> +int                  virDomainGetIOThreadsInfo(virDomainPtr domain,
> +                                               virDomainIOThreadsInfoPtr **info,
> +                                               unsigned int flags);
> +
> +/**
>   * VIR_USE_CPU:
>   * @cpumap: pointer to a bit map of real CPUs (in 8-bit bytes) (IN/OUT)
>   * @cpu: the physical CPU number
> diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h
> index a1198ad..2ce1a51 100644
> --- a/src/driver-hypervisor.h
> +++ b/src/driver-hypervisor.h
> @@ -1,7 +1,7 @@
>  /*
>   * driver-hypervisor.h: entry points for hypervisor drivers
>   *
> - * Copyright (C) 2006-2014 Red Hat, Inc.
> + * Copyright (C) 2006-2015 Red Hat, Inc.
>   *
>   * This library is free software; you can redistribute it and/or
>   * modify it under the terms of the GNU Lesser General Public
> @@ -381,6 +381,11 @@ typedef int
>  (*virDrvDomainGetMaxVcpus)(virDomainPtr domain);
>  
>  typedef int
> +(*virDrvDomainGetIOThreadsInfo)(virDomainPtr domain,
> +                                virDomainIOThreadsInfoPtr **info,
> +                                unsigned int flags);
> +
> +typedef int
>  (*virDrvDomainGetSecurityLabel)(virDomainPtr domain,
>                                  virSecurityLabelPtr seclabel);
>  
> @@ -1254,6 +1259,7 @@ struct _virHypervisorDriver {
>      virDrvDomainGetEmulatorPinInfo domainGetEmulatorPinInfo;
>      virDrvDomainGetVcpus domainGetVcpus;
>      virDrvDomainGetMaxVcpus domainGetMaxVcpus;
> +    virDrvDomainGetIOThreadsInfo domainGetIOThreadsInfo;
>      virDrvDomainGetSecurityLabel domainGetSecurityLabel;
>      virDrvDomainGetSecurityLabelList domainGetSecurityLabelList;
>      virDrvNodeGetSecurityModel nodeGetSecurityModel;
> diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
> index 492e90a..f893b35 100644
> --- a/src/libvirt-domain.c
> +++ b/src/libvirt-domain.c
> @@ -1,7 +1,7 @@
>  /*
>   * libvirt-domain.c: entry points for virDomainPtr APIs
>   *
> - * Copyright (C) 2006-2014 Red Hat, Inc.
> + * Copyright (C) 2006-2015 Red Hat, Inc.
>   *
>   * This library is free software; you can redistribute it and/or
>   * modify it under the terms of the GNU Lesser General Public
> @@ -7891,6 +7891,84 @@ virDomainGetMaxVcpus(virDomainPtr domain)
>  
>  
>  /**
> + * virDomainGetIOThreadsInfo:
> + * @dom: a domain object
> + * @info: pointer to an array of virDomainIOThreadsInfo structures (OUT)
> + * @flags: bitwise-OR of virDomainModificationImpact
> + *     Must not be VIR_DOMAIN_AFFECT_LIVE and
> + *     VIR_DOMAIN_AFFECT_CONFIG concurrently.
> + *
> + * Fetch IOThreads of an active domain including the cpumap information to
> + * determine on which CPU the IOThread has affinity to run.
> + *
> + * Returns the number of IOThreads or -1 in case of error.
> + * On success, the array of information is stored into @info. The caller is
> + * responsible for calling virDomainIOThreadsInfoFree() on each array element,
> + * then calling free() on @info. On error, @info is set to NULL.
> + */
> +int
> +virDomainGetIOThreadsInfo(virDomainPtr dom,
> +                          virDomainIOThreadsInfoPtr **info,
> +                          unsigned int flags)
> +{
> +    VIR_DOMAIN_DEBUG(dom, "info=%p flags=%x", info, flags);
> +
> +    virResetLastError();
> +
> +    virCheckDomainReturn(dom, -1);
> +    virCheckReadOnlyGoto(dom->conn->flags, error);
> +    virCheckNonNullArgGoto(info, error);
> +    *info = NULL;
> +
> +    /* At most one of these two flags should be set.  */
> +    if ((flags & VIR_DOMAIN_AFFECT_LIVE) &&
> +        (flags & VIR_DOMAIN_AFFECT_CONFIG)) {
> +        virReportInvalidArg(flags,
> +                            _("flags 'affect live' and 'affect config' in %s "
> +                              "are mutually exclusive"),
> +                            __FUNCTION__);
> +        goto error;
> +    }
> +
> +    if (dom->conn->driver->domainGetIOThreadsInfo) {
> +        int ret;
> +        ret = dom->conn->driver->domainGetIOThreadsInfo(dom, info, flags);
> +        if (ret < 0)
> +            goto error;
> +        return ret;
> +    }
> +
> +    virReportUnsupportedError();
> +
> + error:
> +    virDispatchError(dom->conn);
> +    return -1;
> +}
> +
> +
> +/**
> + * virDomainIOThreadsInfoFree:
> + * @info: pointer to a virDomainIOThreadsInfo object
> + *
> + * Frees the memory used by @info.
> + */
> +void
> +virDomainIOThreadsInfoFree(virDomainIOThreadsInfoPtr info)
> +{
> +    size_t i;
> +
> +    if (!info)
> +        return;
> +
> +    VIR_FREE(info->cpumap);
> +    for (i = 0; i < info->nresources; i++)
> +        VIR_FREE(info->resources[i]);
> +    VIR_FREE(info->resources);
> +    VIR_FREE(info);
> +}
> +
> +
> +/**
>   * virDomainGetSecurityLabel:
>   * @domain: a domain object
>   * @seclabel: pointer to a virSecurityLabel structure
> diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
> index 4ea5cff..d3ddd24 100644
> --- a/src/libvirt_public.syms
> +++ b/src/libvirt_public.syms
> @@ -695,4 +695,10 @@ LIBVIRT_1.2.12 {
>          virDomainDefineXMLFlags;
>  } LIBVIRT_1.2.11;
>  
> +LIBVIRT_1.2.13 {

Of course this will now have to change.

> +    global:
> +        virDomainIOThreadsInfoFree;
> +        virDomainGetIOThreadsInfo;
> +} LIBVIRT_1.2.12;
> +
>  # .... define new API here using predicted next version number ....

I haven't added any new API in a long time, but everything I see here
seems in order, as long as there are no other comments from the peanut
gallery about exactly what should be in the info (I see you've removed
the pid as suggested by danpb). So ACK assuming that better
documentation on the fields of the info is already available elsewhere.

(Anybody else feel free to jump in and point out anything missing from
the "new API checklist" that I didn't see).




More information about the libvir-list mailing list