]> xenbits.xensource.com Git - libvirt.git/commitdiff
virsh: Introduce new hypervisor-cpu-compare command
authorJiri Denemark <jdenemar@redhat.com>
Mon, 30 Apr 2018 12:48:03 +0000 (14:48 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Mon, 28 May 2018 13:58:05 +0000 (15:58 +0200)
This command is a virsh wrapper for virConnectCompareHypervisorCPU.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Collin Walling <walling@linux.ibm.com>
tools/virsh-host.c
tools/virsh.pod

index 5ca0ae0cf78cb4f156cdfd4ce3a4c02f18200b93..56e238d1a8c34b09c43bde03b822d1c89155d558 100644 (file)
@@ -1600,6 +1600,113 @@ cmdNodeMemoryTune(vshControl *ctl, const vshCmd *cmd)
     goto cleanup;
 }
 
+
+/*
+ * "hypervisor-cpu-compare" command
+ */
+static const vshCmdInfo info_hypervisor_cpu_compare[] = {
+    {.name = "help",
+     .data = N_("compare a CPU with the CPU created by a hypervisor on the host")
+    },
+    {.name = "desc",
+     .data = N_("compare CPU with hypervisor CPU")
+    },
+    {.name = NULL}
+};
+
+static const vshCmdOptDef opts_hypervisor_cpu_compare[] = {
+    VIRSH_COMMON_OPT_FILE(N_("file containing an XML CPU description")),
+    {.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 = "error",
+     .type = VSH_OT_BOOL,
+     .help = N_("report error if CPUs are incompatible")
+    },
+    {.name = NULL}
+};
+
+static bool
+cmdHypervisorCPUCompare(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;
+    int result;
+    char **cpus = NULL;
+    unsigned int flags = 0;
+    virshControlPtr priv = ctl->privData;
+
+    if (vshCommandOptBool(cmd, "error"))
+        flags |= VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE;
+
+    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 (!(cpus = vshExtractCPUDefXMLs(ctl, from)))
+        return false;
+
+    result = virConnectCompareHypervisorCPU(priv->conn, emulator, arch,
+                                            machine, virttype, cpus[0], flags);
+
+    switch (result) {
+    case VIR_CPU_COMPARE_INCOMPATIBLE:
+        vshPrint(ctl,
+                 _("CPU described in %s is incompatible with the CPU provided "
+                   "by hypervisor on the host\n"),
+                 from);
+        goto cleanup;
+        break;
+
+    case VIR_CPU_COMPARE_IDENTICAL:
+        vshPrint(ctl,
+                 _("CPU described in %s is identical to the CPU provided by "
+                   "hypervisor on the host\n"),
+                 from);
+        break;
+
+    case VIR_CPU_COMPARE_SUPERSET:
+        vshPrint(ctl,
+                 _("The CPU provided by hypervisor on the host is a superset "
+                   "of CPU described in %s\n"),
+                 from);
+        break;
+
+    case VIR_CPU_COMPARE_ERROR:
+    default:
+        vshError(ctl, _("Failed to compare hypervisor CPU with %s"), from);
+        goto cleanup;
+    }
+
+    ret = true;
+
+ cleanup:
+    virStringListFree(cpus);
+    return ret;
+}
+
+
 const vshCmdDef hostAndHypervisorCmds[] = {
     {.name = "allocpages",
      .handler = cmdAllocpages,
@@ -1655,6 +1762,12 @@ const vshCmdDef hostAndHypervisorCmds[] = {
      .info = info_hostname,
      .flags = 0
     },
+    {.name = "hypervisor-cpu-compare",
+     .handler = cmdHypervisorCPUCompare,
+     .opts = opts_hypervisor_cpu_compare,
+     .info = info_hypervisor_cpu_compare,
+     .flags = 0
+    },
     {.name = "maxvcpus",
      .handler = cmdMaxvcpus,
      .opts = opts_maxvcpus,
index 9badf47be8507d2e4a9f5a072fc2b1ed03a31741..a561c31c41000645dd7977c1be9b20740e7e7eda 100644 (file)
@@ -585,7 +585,9 @@ features that block migration will not be included in the resulting CPU.
 
 =item B<cpu-compare> I<FILE> [I<--error>]
 
-Compare CPU definition from XML <file> with host CPU. The XML <file> may
+Compare CPU definition from XML <file> with host CPU. (See
+B<hypervisor-cpu-compare> command for comparing the CPU definition with the CPU
+which a specific hypervisor is able to provide on the host.) The XML <file> may
 contain either host or guest CPU definition. The host CPU definition is the
 <cpu> element and its contents as printed by B<capabilities> command. The
 guest CPU definition is the <cpu> element and its contents from domain XML
@@ -617,6 +619,31 @@ specified, then the output will be single-quoted where needed, so that
 it is suitable for reuse in a shell context.  If I<--xml> is
 specified, then the output will be escaped for use in XML.
 
+=item B<hypervisor-cpu-compare> I<FILE> [I<virttype>] [I<emulator>] [I<arch>]
+[I<machine>] [I<--error>]
+
+Compare CPU definition from XML <file> with the CPU the hypervisor is able to
+provide on the host. (This is different from B<cpu-compare> which compares the
+CPU definition with the host CPU without considering any specific hypervisor
+and its abilities.)
+
+The XML I<FILE> may contain either a host or guest CPU definition. The host CPU
+definition is the <cpu> element and its contents as printed by the
+B<capabilities> command. The guest CPU definition is the <cpu> element and its
+contents from the domain XML definition or the CPU definition created from the
+host CPU model found in the domain capabilities XML (printed by the
+B<domcapabilities> command). In addition to the <cpu> element itself, this
+command accepts full domain XML, capabilities XML, or domain capabilities XML
+containing the CPU definition. For more information on guest CPU definition
+see: L<https://libvirt.org/formatdomain.html#elementsCPU>.
+
+The I<virttype> option specifies the virtualization type (usable in the 'type'
+attribute of the <domain> top level element from the domain XML). I<emulator>
+specifies the path to the emulator, I<arch> specifies the CPU architecture, and
+I<machine> 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.
+
 =back
 
 =head1 DOMAIN COMMANDS