Re: [libvirt PATCH 5/9] tools: Report hypervisor cpu model names

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

 



On Tue, Jun 28, 2022 at 06:09:42PM +0200, Tim Wiederhake wrote:
> $ virsh hypervisor-cpu-models --arch x86_64
>  Name                        Alias
> ----------------------------------------------------
>  max
>  host
>  base
>  qemu64-v1
>  qemu64                      qemu64-v1
>  qemu32-v1
>  qemu32                      qemu32-v1
>  phenom-v1
>  phenom                      phenom-v1
> (...)
> 
> Note that this includes alias names and cpu models that currently
> do not exist in libvirt, e.g. Denverton and Knights Mill.
> 
> Signed-off-by: Tim Wiederhake <twiederh@xxxxxxxxxx>
> ---
>  docs/manpages/virsh.rst | 14 +++++++++
>  tools/virsh-host.c      | 67 +++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 81 insertions(+)
> 
> diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst
> index 45469f2f35..a55792b0e2 100644
> --- a/docs/manpages/virsh.rst
> +++ b/docs/manpages/virsh.rst
> @@ -955,6 +955,20 @@ If *--validate* is specified, validates the format of the XML document against
>  an internal RNG schema.
>  
>  
> +hypervisor-cpu-models
> +---------------------
> +
> +**Syntax:**
> +
> +::
> +
> +   hypervisor-cpu-models [arch]
> +
> +List the names of cpu models known to the hypervisor. A hypervisor may define
> +alias names for some or all cpu models. Note that the cpu models may differ
> +from libvirt, even if named identically.
> +
> +
>  hypervisor-cpu-baseline
>  -----------------------
>  
> diff --git a/tools/virsh-host.c b/tools/virsh-host.c
> index ead966b500..cb8e1e8c6d 100644
> --- a/tools/virsh-host.c
> +++ b/tools/virsh-host.c
> @@ -32,6 +32,7 @@
>  #include "virstring.h"
>  #include "virfile.h"
>  #include "virenum.h"
> +#include "vsh-table.h"
>  
>  /*
>   * "capabilities" command
> @@ -1674,6 +1675,65 @@ cmdHypervisorCPUCompare(vshControl *ctl,
>  }
>  
>  
> +/*
> + * "hypervisor-cpu-models" command
> + */
> +static const vshCmdInfo info_hypervisor_cpu_models[] = {
> +    {.name = "help",
> +     .data = N_("return list of CPU models supported by a specific hypervisor")
> +    },
> +    {.name = "desc",
> +     .data = N_("Return list of CPU models supported by a specific hypervisor")
> +    },
> +    {.name = NULL}
> +};
> +
> +static const vshCmdOptDef opts_hypervisor_cpu_models[] = {
> +    {.name = "arch",
> +     .type = VSH_OT_STRING,
> +     .completer = virshArchCompleter,
> +     .help = N_("CPU architecture (/domain/os/type/@arch)"),
> +    },
> +    {.name = NULL}
> +};

This will need to be expanded to  add machine, virttype and
emulator to match the API params.


> +    nresults = virConnectGetHypervisorCPUModelNames(priv->conn, arch, &name,
> +                                                    &alias, 0);

Should we do sorting here or somewhere earlier in the flow ?

I notice the existing 'cpu-models' doesn't do sorting just returning
stuff in a pretty horrible random order.

I think both this new API and the old one should sort case insensitive.

> +    if (nresults >= 0) {
> +        size_t index;
> +        for (index = 0; index < nresults; ++index) {
> +            if (vshTableRowAppend(table, name[index], alias[index], NULL) < 0)
> +                return ret;
> +            g_free(name[index]);
> +            g_free(alias[index]);
> +        }
> +        ret = true;
> +    }
> +    vshTablePrintToStdout(table, ctl);
> +    g_free(name);
> +    g_free(alias);
> +
> +    return ret;
> +}
> +
>  /*
>   * "hypervisor-cpu-baseline" command
>   */
> @@ -1819,6 +1879,13 @@ const vshCmdDef hostAndHypervisorCmds[] = {
>       .info = info_hostname,
>       .flags = 0
>      },
> +    {
> +     .name = "hypervisor-cpu-models",
> +     .handler = cmdHypervisorCPUModels,
> +     .opts = opts_hypervisor_cpu_models,
> +     .info = info_hypervisor_cpu_models,
> +     .flags = 0
> +    },
>      {.name = "hypervisor-cpu-baseline",
>       .handler = cmdHypervisorCPUBaseline,
>       .opts = opts_hypervisor_cpu_baseline,
> -- 
> 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 :|




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux