mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-28 22:32:19 +00:00
virsh: Warn when hypervisor-cpu-* is used with host CPU
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@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
71fe4b97a9
commit
2fb76aeae6
@ -1093,7 +1093,8 @@ cmdURI(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
|
|||||||
*/
|
*/
|
||||||
static char **
|
static char **
|
||||||
vshExtractCPUDefXMLs(vshControl *ctl,
|
vshExtractCPUDefXMLs(vshControl *ctl,
|
||||||
const char *xmlFile)
|
const char *xmlFile,
|
||||||
|
bool hostCPUWarning)
|
||||||
{
|
{
|
||||||
g_auto(GStrv) cpus = NULL;
|
g_auto(GStrv) cpus = NULL;
|
||||||
g_autofree char *buffer = NULL;
|
g_autofree char *buffer = NULL;
|
||||||
@ -1137,6 +1138,8 @@ vshExtractCPUDefXMLs(vshControl *ctl,
|
|||||||
cpus = g_new0(char *, n + 1);
|
cpus = g_new0(char *, n + 1);
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
|
ctxt->node = nodes[i];
|
||||||
|
|
||||||
/* If the user provided domain capabilities XML, we need to replace
|
/* If the user provided domain capabilities XML, we need to replace
|
||||||
* <mode ...> element with <cpu>. */
|
* <mode ...> element with <cpu>. */
|
||||||
if (xmlStrEqual(nodes[i]->name, BAD_CAST "mode")) {
|
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]))) {
|
if (!(cpus[i] = virXMLNodeToString(xml, nodes[i]))) {
|
||||||
vshSaveLibvirtError();
|
vshSaveLibvirtError();
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -1199,7 +1207,7 @@ cmdCPUCompare(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (vshCommandOptString(ctl, cmd, "file", &from) < 0)
|
if (vshCommandOptString(ctl, cmd, "file", &from) < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!(cpus = vshExtractCPUDefXMLs(ctl, from)))
|
if (!(cpus = vshExtractCPUDefXMLs(ctl, from, false)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
result = virConnectCompareCPU(priv->conn, cpus[0], flags);
|
result = virConnectCompareCPU(priv->conn, cpus[0], flags);
|
||||||
@ -1268,7 +1276,7 @@ cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (vshCommandOptString(ctl, cmd, "file", &from) < 0)
|
if (vshCommandOptString(ctl, cmd, "file", &from) < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!(list = vshExtractCPUDefXMLs(ctl, from)))
|
if (!(list = vshExtractCPUDefXMLs(ctl, from, false)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!(result = virConnectBaselineCPU(priv->conn, (const char **)list,
|
if (!(result = virConnectBaselineCPU(priv->conn, (const char **)list,
|
||||||
@ -1612,7 +1620,7 @@ cmdHypervisorCPUCompare(vshControl *ctl,
|
|||||||
vshCommandOptString(ctl, cmd, "machine", &machine) < 0)
|
vshCommandOptString(ctl, cmd, "machine", &machine) < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!(cpus = vshExtractCPUDefXMLs(ctl, from)))
|
if (!(cpus = vshExtractCPUDefXMLs(ctl, from, true)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
result = virConnectCompareHypervisorCPU(priv->conn, emulator, arch,
|
result = virConnectCompareHypervisorCPU(priv->conn, emulator, arch,
|
||||||
@ -1736,7 +1744,7 @@ cmdHypervisorCPUBaseline(vshControl *ctl,
|
|||||||
VSH_ALTERNATIVE_OPTIONS_EXPR("file", from, "model", model);
|
VSH_ALTERNATIVE_OPTIONS_EXPR("file", from, "model", model);
|
||||||
|
|
||||||
if (from) {
|
if (from) {
|
||||||
if (!(list = vshExtractCPUDefXMLs(ctl, from)))
|
if (!(list = vshExtractCPUDefXMLs(ctl, from, true)))
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
list = g_new0(char *, 2);
|
list = g_new0(char *, 2);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user