From d0ff5ce43bdccf9937ce9814eab4c39aac152b6d Mon Sep 17 00:00:00 2001 From: Jiri Denemark Date: Fri, 4 May 2018 23:46:55 +0200 Subject: [PATCH] vshExtractCPUDefXML: Accept domain capabilities XML MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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án 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 1e8cedd3bb..5ca0ae0cf7 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -1114,8 +1114,9 @@ cmdURI(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) /* Extracts the CPU definition XML strings from a file which may contain either * - just the CPU definitions, - * - domain XMLs, or - * - capabilities XMLs. + * - domain XMLs, + * - capabilities XMLs, or + * - domain capabilities XMLs. * * Returns NULL terminated string list. */ @@ -1143,20 +1144,37 @@ vshExtractCPUDefXMLs(vshControl *ctl, n = virXPathNodeSet("/container/cpu|" "/container/domain/cpu|" - "/container/capabilities/host/cpu", + "/container/capabilities/host/cpu|" + "/container/domainCapabilities/cpu/" + "mode[@name='host-model' and @supported='yes']", ctxt, &nodes); if (n < 0) goto error; if (n == 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; } cpus = vshCalloc(ctl, n + 1, sizeof(const char *)); for (i = 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] = virXMLNodeToString(xml, nodes[i]))) { vshSaveLibvirtError(); goto error; diff --git a/tools/virsh.pod b/tools/virsh.pod index 419c371d98..9badf47be8 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