When executing the hypervisor-cpu-baseline command and if there is
only a single CPU definition present in the XML file, then libvirt
will print an unhelpful message:
"error: An error occurred, but the cause is unknown"
This is due to no CPU definition ever being "baselined", since the
API expects at least two CPU models.
Let's fix this by performing a CPU model expansion on the single CPU
definition and returning the result to the caller. This will also
ensure the CPU model is sane.
Signed-off-by: Collin Walling <walling(a)linux.ibm.com>
---
src/qemu/qemu_driver.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index fe572b13e1..bc823fc585 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12459,6 +12459,7 @@ qemuConnectCPUModelBaseline(virQEMUCapsPtr qemuCaps,
g_autoptr(qemuProcessQMP) proc = NULL;
g_autoptr(virCPUDef) baseline = NULL;
qemuMonitorCPUModelInfoPtr result = NULL;
+ qemuMonitorCPUModelExpansionType expansion_type;
size_t i, j;
for (i = 0; i < ncpus; i++) {
@@ -12506,9 +12507,11 @@ qemuConnectCPUModelBaseline(virQEMUCapsPtr qemuCaps,
return NULL;
}
- if (expand_features) {
- if (qemuMonitorGetCPUModelExpansion(proc->mon,
- QEMU_MONITOR_CPU_MODEL_EXPANSION_FULL,
+ if (expand_features || ncpus == 1) {
+ expansion_type = expand_features ? QEMU_MONITOR_CPU_MODEL_EXPANSION_FULL
+ : QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC;
+
+ if (qemuMonitorGetCPUModelExpansion(proc->mon, expansion_type,
baseline, true, false, &result) < 0)
return NULL;
--
2.26.2