]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: allow hypervisor-cpu-baseline with single cpu
authorCollin Walling <walling@linux.ibm.com>
Fri, 25 Sep 2020 00:22:39 +0000 (20:22 -0400)
committerJiri Denemark <jdenemar@redhat.com>
Tue, 24 Nov 2020 20:04:07 +0000 (21:04 +0100)
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@linux.ibm.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
src/qemu/qemu_driver.c

index 5f2f267fb4c1f9f653dd57c4ce9f7060972d5f36..391596ba11d2c5040152257afc2cd055c939e698 100644 (file)
@@ -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;