From nobody Wed May 14 02:31:16 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 1526460010149308.2573282148617; Wed, 16 May 2018 01:40:10 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 43A643117B59; Wed, 16 May 2018 08:40:08 +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 F04F29935B; Wed, 16 May 2018 08:40:07 +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 8EEE3180B5B3; Wed, 16 May 2018 08:40:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4G8djUg018344 for ; Wed, 16 May 2018 04:39:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 13BCF2017D0D; Wed, 16 May 2018 08:39:45 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CA5E22024CBB for ; Wed, 16 May 2018 08:39:44 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id AE089102EDF; Wed, 16 May 2018 10:39:42 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 16 May 2018 10:39:25 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 06/22] vshExtractCPUDefXML: Accept domain capabilities XML 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.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Wed, 16 May 2018 08:40:09 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The domain capabilities XML contains host CPU model tailored to a specific hypervisor and since it's enclosed in element rather then the required it's impossible to directly use the host CPU model as an input to, e.g., cpu-compare command. To make this more convenient, vshExtractCPUDefXML now accepts full domain capabilities XML and automatically transforms the host CPU models into the form accepted by libvirt APIs. Signed-off-by: Jiri Denemark Reviewed-by: Collin Walling Reviewed-by: J=EF=BF=BDn Tomko --- tools/virsh-host.c | 26 ++++++++++++++++++++++---- tools/virsh.pod | 8 +++++--- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/tools/virsh-host.c b/tools/virsh-host.c index 51497db385..ea2c411c02 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -1109,8 +1109,9 @@ cmdURI(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_U= NUSED) =20 /* Extracts the CPU definition XML strings from a file which may contain e= ither * - just the CPU definitions, - * - domain XMLs, or - * - capabilities XMLs. + * - domain XMLs, + * - capabilities XMLs, or + * - domain capabilities XMLs. * * Returns NULL terminated string list. */ @@ -1138,20 +1139,37 @@ vshExtractCPUDefXMLs(vshControl *ctl, =20 n =3D virXPathNodeSet("/container/cpu|" "/container/domain/cpu|" - "/container/capabilities/host/cpu", + "/container/capabilities/host/cpu|" + "/container/domainCapabilities/cpu/" + "mode[@name=3D'host-model' and @supported=3D'y= es']", ctxt, &nodes); if (n < 0) goto error; =20 if (n =3D=3D 0) { vshError(ctl, _("File '%s' does not contain any element or " - "valid domain or capabilities XML"), xmlFile); + "valid domain XML, host capabilities XML, or " + "domain capabilities XML"), xmlFile); goto error; } =20 cpus =3D vshCalloc(ctl, n + 1, sizeof(const char *)); =20 for (i =3D 0; i < n; i++) { + /* If the user provided domain capabilities XML, we need to replace + * element with . */ + if (xmlStrEqual(nodes[i]->name, BAD_CAST "mode")) { + xmlNodeSetName(nodes[i], (const xmlChar *)"cpu"); + while (nodes[i]->properties) { + if (xmlRemoveProp(nodes[i]->properties) < 0) { + vshError(ctl, + _("Cannot extract CPU definition from domain " + "capabilities XML")); + goto error; + } + } + } + if (!(cpus[i] =3D virXMLNodeToString(xml, nodes[i]))) { vshSaveLibvirtError(); goto error; diff --git a/tools/virsh.pod b/tools/virsh.pod index 5fc8201893..ea10e1ad43 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -589,9 +589,11 @@ Compare CPU definition from XML with host CPU. = 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 -definition. In addition to the element itself, this command accepts -full domain or capabilities XML containing the element. For more -information on guest CPU definition see: +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. If I<--error> is specified, the command will return an error when the given CPU is incompatible with host CPU and a message providing more details about the --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list