While using host CPU definition from capabilities XML is allowed for
historical reasons, it will likely provide incorrect results and should
be avoided.
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
tools/virsh-host.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/tools/virsh-host.c b/tools/virsh-host.c
index f4e7324f42..418bd995da 100644
--- a/tools/virsh-host.c
+++ b/tools/virsh-host.c
@@ -1093,7 +1093,8 @@ cmdURI(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
*/
static char **
vshExtractCPUDefXMLs(vshControl *ctl,
- const char *xmlFile)
+ const char *xmlFile,
+ bool hostCPUWarning)
{
g_auto(GStrv) cpus = NULL;
g_autofree char *buffer = NULL;
@@ -1137,6 +1138,8 @@ vshExtractCPUDefXMLs(vshControl *ctl,
cpus = g_new0(char *, n + 1);
for (i = 0; i < n; i++) {
+ ctxt->node = nodes[i];
+
/* If the user provided domain capabilities XML, we need to replace
* <mode ...> element with <cpu>. */
if (xmlStrEqual(nodes[i]->name, BAD_CAST "mode")) {
@@ -1150,6 +1153,11 @@ vshExtractCPUDefXMLs(vshControl *ctl,
}
}
+ if (hostCPUWarning &&
+ virXPathBoolean("boolean(./feature[not(@policy)])", ctxt) == 1) {
+ vshWarn(ctl, "%s", _("using host CPU definition as input may
provide incorrect results"));
+ }
+
if (!(cpus[i] = virXMLNodeToString(xml, nodes[i]))) {
vshSaveLibvirtError();
return NULL;
@@ -1199,7 +1207,7 @@ cmdCPUCompare(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptString(ctl, cmd, "file", &from) < 0)
return false;
- if (!(cpus = vshExtractCPUDefXMLs(ctl, from)))
+ if (!(cpus = vshExtractCPUDefXMLs(ctl, from, false)))
return false;
result = virConnectCompareCPU(priv->conn, cpus[0], flags);
@@ -1268,7 +1276,7 @@ cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptString(ctl, cmd, "file", &from) < 0)
return false;
- if (!(list = vshExtractCPUDefXMLs(ctl, from)))
+ if (!(list = vshExtractCPUDefXMLs(ctl, from, false)))
return false;
if (!(result = virConnectBaselineCPU(priv->conn, (const char **)list,
@@ -1612,7 +1620,7 @@ cmdHypervisorCPUCompare(vshControl *ctl,
vshCommandOptString(ctl, cmd, "machine", &machine) < 0)
return false;
- if (!(cpus = vshExtractCPUDefXMLs(ctl, from)))
+ if (!(cpus = vshExtractCPUDefXMLs(ctl, from, true)))
return false;
result = virConnectCompareHypervisorCPU(priv->conn, emulator, arch,
@@ -1736,7 +1744,7 @@ cmdHypervisorCPUBaseline(vshControl *ctl,
VSH_ALTERNATIVE_OPTIONS_EXPR("file", from, "model", model);
if (from) {
- if (!(list = vshExtractCPUDefXMLs(ctl, from)))
+ if (!(list = vshExtractCPUDefXMLs(ctl, from, true)))
return false;
} else {
list = g_new0(char *, 2);
--
2.48.1