mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
vshExtractCPUDefXML: Accept domain capabilities XML
The domain capabilities XML contains host CPU model tailored to a specific hypervisor and since it's enclosed in <mode name='host-model'> element rather then the required <cpu> 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 <jdenemar@redhat.com> Reviewed-by: Collin Walling <walling@linux.ibm.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
95ef9ceea4
commit
d0ff5ce43b
@ -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
|
/* Extracts the CPU definition XML strings from a file which may contain either
|
||||||
* - just the CPU definitions,
|
* - just the CPU definitions,
|
||||||
* - domain XMLs, or
|
* - domain XMLs,
|
||||||
* - capabilities XMLs.
|
* - capabilities XMLs, or
|
||||||
|
* - domain capabilities XMLs.
|
||||||
*
|
*
|
||||||
* Returns NULL terminated string list.
|
* Returns NULL terminated string list.
|
||||||
*/
|
*/
|
||||||
@ -1143,20 +1144,37 @@ vshExtractCPUDefXMLs(vshControl *ctl,
|
|||||||
|
|
||||||
n = virXPathNodeSet("/container/cpu|"
|
n = virXPathNodeSet("/container/cpu|"
|
||||||
"/container/domain/cpu|"
|
"/container/domain/cpu|"
|
||||||
"/container/capabilities/host/cpu",
|
"/container/capabilities/host/cpu|"
|
||||||
|
"/container/domainCapabilities/cpu/"
|
||||||
|
"mode[@name='host-model' and @supported='yes']",
|
||||||
ctxt, &nodes);
|
ctxt, &nodes);
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
vshError(ctl, _("File '%s' does not contain any <cpu> element or "
|
vshError(ctl, _("File '%s' does not contain any <cpu> element or "
|
||||||
"valid domain or capabilities XML"), xmlFile);
|
"valid domain XML, host capabilities XML, or "
|
||||||
|
"domain capabilities XML"), xmlFile);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
cpus = vshCalloc(ctl, n + 1, sizeof(const char *));
|
cpus = vshCalloc(ctl, n + 1, sizeof(const char *));
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
|
/* If the user provided domain capabilities XML, we need to replace
|
||||||
|
* <mode ...> element with <cpu>. */
|
||||||
|
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]))) {
|
if (!(cpus[i] = virXMLNodeToString(xml, nodes[i]))) {
|
||||||
vshSaveLibvirtError();
|
vshSaveLibvirtError();
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -589,9 +589,11 @@ Compare CPU definition from XML <file> with host CPU. The XML <file> may
|
|||||||
contain either host or guest CPU definition. The host CPU definition is the
|
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
|
<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
|
guest CPU definition is the <cpu> element and its contents from domain XML
|
||||||
definition. In addition to the <cpu> element itself, this command accepts
|
definition or the CPU definition created from the host CPU model found in
|
||||||
full domain or capabilities XML containing the <cpu> element. For more
|
domain capabilities XML (printed by B<domcapabilities> command). In
|
||||||
information on guest CPU definition see:
|
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>. If I<--error> is
|
L<https://libvirt.org/formatdomain.html#elementsCPU>. If I<--error> is
|
||||||
specified, the command will return an error when the given CPU 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
|
incompatible with host CPU and a message providing more details about the
|
||||||
|
Loading…
Reference in New Issue
Block a user