[libvirt PATCH 2/9] libvirt: introduce virConnectGetHypervisorCPUModelNames public API

Daniel P. Berrangé berrange at redhat.com
Mon Jul 18 10:05:13 UTC 2022


On Tue, Jun 28, 2022 at 06:09:39PM +0200, Tim Wiederhake wrote:
> Create a function to query the hypervisor for its list of known CPU model
> names. This is different from virConnectGetCPUModelNames, as this new
> function will determine the list of CPU models (and alias names) at
> runtime.

This is duplicating what we already report in the per-domain level
capabilities XML from virConnectGetDomainCapabilities.

The original virConnectGetCPUModelNames pre-dated the addition
of virConnectGetDomainCapabilities.

> Signed-off-by: Tim Wiederhake <twiederh at redhat.com>
> ---
>  include/libvirt/libvirt-host.h |  6 ++++
>  src/driver-hypervisor.h        |  8 +++++
>  src/libvirt-host.c             | 55 ++++++++++++++++++++++++++++++++++
>  src/libvirt_public.syms        |  1 +
>  4 files changed, 70 insertions(+)
> 
> diff --git a/include/libvirt/libvirt-host.h b/include/libvirt/libvirt-host.h
> index 3112f2b676..5aaa001adb 100644
> --- a/include/libvirt/libvirt-host.h
> +++ b/include/libvirt/libvirt-host.h
> @@ -962,6 +962,12 @@ int virConnectGetCPUModelNames(virConnectPtr conn,
>                                 char ***models,
>                                 unsigned int flags);
>  
> +int virConnectGetHypervisorCPUModelNames(virConnectPtr conn,
> +                                         const char *arch,
> +                                         char ***names,
> +                                         char ***aliases,
> +                                         unsigned int flags);

For virConnectCompareHypervisorCPU, virConnectBaselineHypervisorCPU,
and virConnectGetDomainCapabilities, we take more than just the 'arch'
value:

                                      const char *emulator,
                                      const char *arch,
                                      const char *machine,
                                      const char *virttype,

because we need all 4 of those pieces of information to accurately
determine what qemu-system-XXXX binary we're going to select.

If we do still want to add virConnectGetHypervisorCPUModelNames
despite having the info on virConnectGetDomainCapabilities, we
should take the full set of params.

I guess adding the new API isn't too costly

> +
>  /**
>   * virConnectBaselineCPUFlags:
>   *
> diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h
> index 016d5cec7c..c81e5d4c75 100644
> --- a/src/driver-hypervisor.h
> +++ b/src/driver-hypervisor.h
> @@ -732,6 +732,13 @@ typedef int
>                                   char ***models,
>                                   unsigned int flags);
>  
> +typedef int
> +(*virDrvConnectGetHypervisorCPUModelNames)(virConnectPtr conn,
> +                                           const char *archName,
> +                                           char ***names,
> +                                           char ***aliases,
> +                                           unsigned int flags);
> +
>  typedef int
>  (*virDrvDomainGetJobInfo)(virDomainPtr domain,
>                            virDomainJobInfoPtr info);
> @@ -1712,4 +1719,5 @@ struct _virHypervisorDriver {
>      virDrvDomainAuthorizedSSHKeysSet domainAuthorizedSSHKeysSet;
>      virDrvDomainGetMessages domainGetMessages;
>      virDrvDomainStartDirtyRateCalc domainStartDirtyRateCalc;
> +    virDrvConnectGetHypervisorCPUModelNames connectGetHypervisorCPUModelNames;
>  };
> diff --git a/src/libvirt-host.c b/src/libvirt-host.c
> index 2ee6370bce..6e734628c1 100644
> --- a/src/libvirt-host.c
> +++ b/src/libvirt-host.c
> @@ -1234,6 +1234,61 @@ virConnectGetCPUModelNames(virConnectPtr conn, const char *arch, char ***models,
>  }
>  
>  
> +/**
> + * virConnectGetHypervisorCPUModelNames:
> + *
> + * @conn: virConnect connection
> + * @arch: Architecture
> + * @names: Pointer to a variable to store the NULL-terminated array of the CPU
> + *         models supported by the hypervisor for the specified architecture.
> + *         Each element and the array itself must be freed by the caller.
> + * @aliases: Pointer to a variable to store the NULL-terminated array of alias
> + *           names for CPU model names. Each element and the array itself must
> + *           be freed by the caller.
> + * @flags: extra flags; not used yet, so callers should always pass 0.
> + *
> + * Get the list of CPU models supported by the hypervisor for a specific
> + * architecture.
> + *
> + * If @aliases[x] is not an empty string, @names[x] is an alias for that CPU
> + * model.
> + *
> + * Returns -1 on error, number of elements in @models on success.
> + *
> + * Since: 8.5.0
> + */
> +int
> +virConnectGetHypervisorCPUModelNames(virConnectPtr conn,
> +                                     const char *arch,
> +                                     char ***names,
> +                                     char ***aliases,
> +                                     unsigned int flags)
> +{
> +    VIR_DEBUG("conn=%p, arch=%s, flags=0x%x", conn, NULLSTR(arch), flags);
> +    virResetLastError();
> +
> +    virCheckConnectReturn(conn, -1);
> +    virCheckNonNullArgGoto(arch, error);
> +
> +    if (conn->driver->connectGetHypervisorCPUModelNames) {
> +        int ret;
> +
> +        ret = conn->driver->connectGetHypervisorCPUModelNames(conn, arch, names,
> +                                                              aliases, flags);
> +        if (ret < 0)
> +            goto error;
> +
> +        return ret;
> +    }
> +
> +    virReportUnsupportedError();
> +
> + error:
> +    virDispatchError(conn);
> +    return -1;
> +}
> +
> +
>  /**
>   * virConnectBaselineCPU:
>   *
> diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
> index 297a2c436a..c6a8e898ae 100644
> --- a/src/libvirt_public.syms
> +++ b/src/libvirt_public.syms
> @@ -924,6 +924,7 @@ LIBVIRT_8.4.0 {
>  
>  LIBVIRT_8.5.0 {
>      global:
> +        virConnectGetHypervisorCPUModelNames;
>          virDomainAbortJobFlags;
>  } LIBVIRT_8.4.0;
>  
> -- 
> 2.31.1
> 

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|


More information about the libvir-list mailing list