Change the commit message to:
qemu: allow hypervisor-cpu-baseline with single cpu
When executing the hypervisor-cpu-baseline command and if there is
only a single CPU definition present in the XML file, then the
baseline handler will exit early and 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
handler 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's feature set is sane if any were provided in
the file.
Signed-off-by: Collin Walling <walling(a)linux.ibm.com>
On 9/24/20 8:22 PM, Collin Walling wrote:
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;
--
Regards,
Collin
Stay safe and stay healthy