From nobody Wed May 14 02:45:30 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1526460011971901.9816847812875; Wed, 16 May 2018 01:40:11 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 76321CC9B3; Wed, 16 May 2018 08:40:10 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 320A730012C1; Wed, 16 May 2018 08:40:10 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B3138180BACD; Wed, 16 May 2018 08:40:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4G8dkL4018380 for ; Wed, 16 May 2018 04:39:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3489B6B59E; Wed, 16 May 2018 08:39:46 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EA354D1EA7 for ; Wed, 16 May 2018 08:39:44 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id BD8F6102EE4; Wed, 16 May 2018 10:39:42 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 16 May 2018 10:39:29 +0200 Message-Id: <47f68e079c68c1edceaaf6d534913615cf634fc8.1526459534.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 10/22] virsh: Introduce new hypervisor-cpu-compare command X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 16 May 2018 08:40:11 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This command is a virsh wrapper for virConnectCompareHypervisorCPU. Signed-off-by: Jiri Denemark Reviewed-by: Collin Walling Reviewed-by: J=EF=BF=BDn Tomko --- tools/virsh-host.c | 113 +++++++++++++++++++++++++++++++++++++++++++++ tools/virsh.pod | 29 +++++++++++- 2 files changed, 141 insertions(+), 1 deletion(-) diff --git a/tools/virsh-host.c b/tools/virsh-host.c index ea2c411c02..1e7cfcbd5e 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -1595,6 +1595,113 @@ cmdNodeMemoryTune(vshControl *ctl, const vshCmd *cm= d) goto cleanup; } =20 + +/* + * "hypervisor-cpu-compare" command + */ +static const vshCmdInfo info_hypervisor_cpu_compare[] =3D { + {.name =3D "help", + .data =3D N_("compare a CPU with the CPU created by a hypervisor on t= he host") + }, + {.name =3D "desc", + .data =3D N_("compare CPU with hypervisor CPU") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_hypervisor_cpu_compare[] =3D { + VIRSH_COMMON_OPT_FILE(N_("file containing an XML CPU description")), + {.name =3D "virttype", + .type =3D VSH_OT_STRING, + .help =3D N_("virtualization type (/domain/@type)"), + }, + {.name =3D "emulator", + .type =3D VSH_OT_STRING, + .help =3D N_("path to emulator binary (/domain/devices/emulator)"), + }, + {.name =3D "arch", + .type =3D VSH_OT_STRING, + .help =3D N_("domain architecture (/domain/os/type/@arch)"), + }, + {.name =3D "machine", + .type =3D VSH_OT_STRING, + .help =3D N_("machine type (/domain/os/type/@machine)"), + }, + {.name =3D "error", + .type =3D VSH_OT_BOOL, + .help =3D N_("report error if CPUs are incompatible") + }, + {.name =3D NULL} +}; + +static bool +cmdHypervisorCPUCompare(vshControl *ctl, + const vshCmd *cmd) +{ + const char *from =3D NULL; + const char *virttype =3D NULL; + const char *emulator =3D NULL; + const char *arch =3D NULL; + const char *machine =3D NULL; + bool ret =3D false; + int result; + char **cpus =3D NULL; + unsigned int flags =3D 0; + virshControlPtr priv =3D ctl->privData; + + if (vshCommandOptBool(cmd, "error")) + flags |=3D 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 =3D vshExtractCPUDefXMLs(ctl, from))) + return false; + + result =3D virConnectCompareHypervisorCPU(priv->conn, emulator, arch, + machine, virttype, cpus[0], fl= ags); + + switch (result) { + case VIR_CPU_COMPARE_INCOMPATIBLE: + vshPrint(ctl, + _("CPU described in %s is incompatible with the CPU provi= ded " + "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 b= y " + "hypervisor on the host\n"), + from); + break; + + case VIR_CPU_COMPARE_SUPERSET: + vshPrint(ctl, + _("The CPU provided by hypervisor on the host is a supers= et " + "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 =3D true; + + cleanup: + virStringListFree(cpus); + return ret; +} + + const vshCmdDef hostAndHypervisorCmds[] =3D { {.name =3D "allocpages", .handler =3D cmdAllocpages, @@ -1650,6 +1757,12 @@ const vshCmdDef hostAndHypervisorCmds[] =3D { .info =3D info_hostname, .flags =3D 0 }, + {.name =3D "hypervisor-cpu-compare", + .handler =3D cmdHypervisorCPUCompare, + .opts =3D opts_hypervisor_cpu_compare, + .info =3D info_hypervisor_cpu_compare, + .flags =3D 0 + }, {.name =3D "maxvcpus", .handler =3D cmdMaxvcpus, .opts =3D opts_maxvcpus, diff --git a/tools/virsh.pod b/tools/virsh.pod index ea10e1ad43..1a55092efd 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -585,7 +585,9 @@ features that block migration will not be included in t= he resulting CPU. =20 =3Ditem B I [I<--error>] =20 -Compare CPU definition from XML with host CPU. The XML may +Compare CPU definition from XML with host CPU. (See +B command for comparing the CPU definition with th= e CPU +which a specific hypervisor is able to provide on the host.) The XML may contain either host or guest CPU definition. The host CPU definition is the element and its contents as printed by B command. The guest CPU definition is the element and its contents from domain XML @@ -616,6 +618,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. =20 +=3Ditem B I [I] [I] [I] +[I] [I<--error>] + +Compare CPU definition from XML with the CPU the specified hypervis= or +is able to provide on the host. (This is different from B whi= ch +compares the CPU definition with the host CPU without considering any spec= ific +hypervisor and its abilities.) + +The XML I may contain either host or guest CPU definition. The host = CPU +definition is the element and its contents as printed by B +command. The guest CPU definition is the element and its contents fr= om +domain XML definition or the CPU definition created from the host CPU model +found in domain capabilities XML (printed by B command). = In +addition to the 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. + +The I option specifies the virtualization type (usable in the 't= ype' +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<--error> is specified, the com= mand +will return an error when the given CPU is incompatible with host CPU and a +message providing more details about the incompatibility will be printed o= ut. + =3Dback =20 =3Dhead1 DOMAIN COMMANDS --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list