From d1e00f84c07903b46194097e68b4f2cd6897ec8a Mon Sep 17 00:00:00 2001 From: Collin Walling Date: Thu, 24 Sep 2020 20:22:39 -0400 Subject: [PATCH] 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 Reviewed-by: Jiri Denemark --- 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 5f2f267fb4..391596ba11 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -12423,6 +12423,7 @@ qemuConnectCPUModelBaseline(virQEMUCapsPtr qemuCaps, g_autoptr(qemuProcessQMP) proc = NULL; g_autoptr(virCPUDef) baseline = NULL; qemuMonitorCPUModelInfoPtr result = NULL; + qemuMonitorCPUModelExpansionType expansion_type; size_t i; for (i = 0; i < ncpus; i++) { @@ -12466,9 +12467,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.47.2