From 6d27148ae189c4e80248099c7c2f9636435799ee Mon Sep 17 00:00:00 2001 From: Jiri Denemark Date: Mon, 7 May 2018 15:10:52 +0200 Subject: [PATCH] virsh: Introduce new hypervisor-cpu-baseline command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This command is a virsh wrapper for virConnectBaselineHypervisorCPU. Signed-off-by: Jiri Denemark Reviewed-by: Ján Tomko --- tools/virsh-host.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++ tools/virsh.pod | 47 ++++++++++++++++++++--- 2 files changed, 137 insertions(+), 6 deletions(-) diff --git a/tools/virsh-host.c b/tools/virsh-host.c index 56e238d1a8..16f504bafe 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -1707,6 +1707,96 @@ cmdHypervisorCPUCompare(vshControl *ctl, } +/* + * "hypervisor-cpu-baseline" command + */ +static const vshCmdInfo info_hypervisor_cpu_baseline[] = { + {.name = "help", + .data = N_("compute baseline CPU usable by a specific hypervisor") + }, + {.name = "desc", + .data = N_("Compute baseline CPU for a set of given CPUs. The result " + "will be tailored to the specified hypervisor.") + }, + {.name = NULL} +}; + +static const vshCmdOptDef opts_hypervisor_cpu_baseline[] = { + VIRSH_COMMON_OPT_FILE(N_("file containing XML CPU descriptions")), + {.name = "virttype", + .type = VSH_OT_STRING, + .help = N_("virtualization type (/domain/@type)"), + }, + {.name = "emulator", + .type = VSH_OT_STRING, + .help = N_("path to emulator binary (/domain/devices/emulator)"), + }, + {.name = "arch", + .type = VSH_OT_STRING, + .help = N_("CPU architecture (/domain/os/type/@arch)"), + }, + {.name = "machine", + .type = VSH_OT_STRING, + .help = N_("machine type (/domain/os/type/@machine)"), + }, + {.name = "features", + .type = VSH_OT_BOOL, + .help = N_("Show features that are part of the CPU model type") + }, + {.name = "migratable", + .type = VSH_OT_BOOL, + .help = N_("Do not include features that block migration") + }, + {.name = NULL} +}; + +static bool +cmdHypervisorCPUBaseline(vshControl *ctl, + const vshCmd *cmd) +{ + const char *from = NULL; + const char *virttype = NULL; + const char *emulator = NULL; + const char *arch = NULL; + const char *machine = NULL; + bool ret = false; + char *result = NULL; + char **list = NULL; + unsigned int flags = 0; + virshControlPtr priv = ctl->privData; + + if (vshCommandOptBool(cmd, "features")) + flags |= VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES; + if (vshCommandOptBool(cmd, "migratable")) + flags |= VIR_CONNECT_BASELINE_CPU_MIGRATABLE; + + if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0 || + vshCommandOptStringReq(ctl, cmd, "virttype", &virttype) < 0 || + vshCommandOptStringReq(ctl, cmd, "emulator", &emulator) < 0 || + vshCommandOptStringReq(ctl, cmd, "arch", &arch) < 0 || + vshCommandOptStringReq(ctl, cmd, "machine", &machine) < 0) + return false; + + if (!(list = vshExtractCPUDefXMLs(ctl, from))) + return false; + + result = virConnectBaselineHypervisorCPU(priv->conn, emulator, arch, + machine, virttype, + (const char **)list, + virStringListLength((const char **)list), + flags); + + if (result) { + vshPrint(ctl, "%s", result); + ret = true; + } + + VIR_FREE(result); + virStringListFree(list); + return ret; +} + + const vshCmdDef hostAndHypervisorCmds[] = { {.name = "allocpages", .handler = cmdAllocpages, @@ -1762,6 +1852,12 @@ const vshCmdDef hostAndHypervisorCmds[] = { .info = info_hostname, .flags = 0 }, + {.name = "hypervisor-cpu-baseline", + .handler = cmdHypervisorCPUBaseline, + .opts = opts_hypervisor_cpu_baseline, + .info = info_hypervisor_cpu_baseline, + .flags = 0 + }, {.name = "hypervisor-cpu-compare", .handler = cmdHypervisorCPUCompare, .opts = opts_hypervisor_cpu_compare, diff --git a/tools/virsh.pod b/tools/virsh.pod index a561c31c41..3f3314a87e 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -574,12 +574,13 @@ I<--all> which executes the modification on all NUMA cells. =item B I [I<--features>] [I<--migratable>] Compute baseline CPU which will be supported by all host CPUs given in . -The list of host CPUs is built by extracting all elements from the -. Thus, the can contain either a set of elements separated -by new lines or even a set of complete elements printed by -B command. If I<--features> is specified then the -resulting XML description will explicitly include all features that make -up the CPU, without this option features that are part of the CPU model +(See B command to get a CPU which can be provided by a +specific hypervisor.) The list of host CPUs is built by extracting all +elements from the . Thus, the can contain either a set of +elements separated by new lines or even a set of complete +elements printed by B command. If I<--features> is specified, +then the resulting XML description will explicitly include all features that +make up the CPU, without this option features that are part of the CPU model will not be listed in the XML description. If I<--migratable> is specified, features that block migration will not be included in the resulting CPU. @@ -644,6 +645,40 @@ I specifies the machine type. If I<--error> is specified, the command will return an error when the given CPU is incompatible with the host CPU and a message providing more details about the incompatibility will be printed out. +=item B I [I] [I] [I] +[I] [I<--features>] [I<--migratable>] + +Compute a baseline CPU which will be compatible with all CPUs defined in an XML +I and with the CPU the hypervisor is able to provide on the host. (This +is different from B which does not consider any hypervisor +abilities when computing the baseline CPU.) + +The XML I may contain either host or guest CPU definitions describing the +host CPU model. The host CPU definition is the element and its contents +as printed by B command. The guest CPU definition may be created +from the host CPU model found in domain capabilities XML (printed by +B command). In addition to the elements, this command +accepts full capabilities XMLs, or domain capabilities XMLs containing the CPU +definitions. For best results, use only the CPU definitions from domain +capabilities. + +When I contains only a single CPU definition, the command will print the +same CPU with restrictions imposed by the capabilities of the hypervisor. +Specifically, running th B command with no +additional options on the result of B will transform the +host CPU model from domain capabilities XML to a form directly usable in domain +XML. + +The I option specifies the virtualization type (usable in the 'type' +attribute of the top level element from the domain XML). I +specifies the path to the emulator, I specifies the CPU architecture, and +I specifies the machine type. If I<--features> is specified, then the +resulting XML description will explicitly include all features that make up the +CPU, without this option features that are part of the CPU model will not be +listed in the XML description. If I<--migratable> is specified, features that +block migration will not be included in the resulting CPU. + + =back =head1 DOMAIN COMMANDS