render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
Blob Blame History Raw
From b3f714b0907ff1a906d8725efb26733caa913b01 Mon Sep 17 00:00:00 2001
Message-Id: <b3f714b0907ff1a906d8725efb26733caa913b01@dist-git>
From: Jiri Denemark <jdenemar@redhat.com>
Date: Fri, 21 Jun 2019 09:25:47 +0200
Subject: [PATCH] qemu_command: Use consistent syntax for CPU features
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Normal CPU features use modern -cpu ...,feature=on|off syntax when
available, but kvm features kept using the old +feature or -feature.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
(cherry picked from commit e1ba4073961091522b1560472c5559124bd3c034)

https://bugzilla.redhat.com/show_bug.cgi?id=1697627

Conflicts:
	tests/qemuxml2argvdata/eoi-disabled.x86_64-latest.args
	tests/qemuxml2argvdata/eoi-enabled.x86_64-latest.args
	tests/qemuxml2argvdata/kvmclock+eoi-disabled.x86_64-latest.args
	tests/qemuxml2argvdata/pv-spinlock-disabled.x86_64-latest.args
	tests/qemuxml2argvdata/pv-spinlock-enabled.x86_64-latest.args
            - not backported

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Message-Id: <da608f8dcef1eeb3e62d4c1d921c8182c1b4d533.1561068591.git.jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/qemu/qemu_command.c | 46 +++++++++++++++++++----------------------
 1 file changed, 21 insertions(+), 25 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 7ffc4358e3..bea9a208e5 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -6813,6 +6813,19 @@ qemuBuildGlobalControllerCommandLine(virCommandPtr cmd,
 }
 
 
+static void
+qemuBuildCpuFeature(virQEMUCapsPtr qemuCaps,
+                    virBufferPtr buf,
+                    const char *name,
+                    bool state)
+{
+    if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_MODEL_EXPANSION))
+        virBufferAsprintf(buf, ",%s=%s", name, state ? "on" : "off");
+    else
+        virBufferAsprintf(buf, ",%c%s", state ? '+' : '-', name);
+}
+
+
 static int
 qemuBuildCpuModelArgStr(virQEMUDriverPtr driver,
                         const virDomainDef *def,
@@ -6890,18 +6903,12 @@ qemuBuildCpuModelArgStr(virQEMUDriverPtr driver,
         switch ((virCPUFeaturePolicy) cpu->features[i].policy) {
         case VIR_CPU_FEATURE_FORCE:
         case VIR_CPU_FEATURE_REQUIRE:
-            if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_MODEL_EXPANSION))
-                virBufferAsprintf(buf, ",%s=on", cpu->features[i].name);
-            else
-                virBufferAsprintf(buf, ",+%s", cpu->features[i].name);
+            qemuBuildCpuFeature(qemuCaps, buf, cpu->features[i].name, true);
             break;
 
         case VIR_CPU_FEATURE_DISABLE:
         case VIR_CPU_FEATURE_FORBID:
-            if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_MODEL_EXPANSION))
-                virBufferAsprintf(buf, ",%s=off", cpu->features[i].name);
-            else
-                virBufferAsprintf(buf, ",-%s", cpu->features[i].name);
+            qemuBuildCpuFeature(qemuCaps, buf, cpu->features[i].name, false);
             break;
 
         case VIR_CPU_FEATURE_OPTIONAL:
@@ -6982,8 +6989,8 @@ qemuBuildCpuCommandLine(virCommandPtr cmd,
 
         if (timer->name == VIR_DOMAIN_TIMER_NAME_KVMCLOCK &&
             timer->present != -1) {
-            virBufferAsprintf(&buf, ",%ckvmclock",
-                              timer->present ? '+' : '-');
+            qemuBuildCpuFeature(qemuCaps, &buf, "kvmclock",
+                                !!timer->present);
         } else if (timer->name == VIR_DOMAIN_TIMER_NAME_HYPERVCLOCK &&
                    timer->present == 1) {
             virBufferAddLit(&buf, ",hv_time");
@@ -6994,24 +7001,13 @@ qemuBuildCpuCommandLine(virCommandPtr cmd,
     }
 
     if (def->apic_eoi) {
-        char sign;
-        if (def->apic_eoi == VIR_TRISTATE_SWITCH_ON)
-            sign = '+';
-        else
-            sign = '-';
-
-        virBufferAsprintf(&buf, ",%ckvm_pv_eoi", sign);
+        qemuBuildCpuFeature(qemuCaps, &buf, "kvm_pv_eoi",
+                            def->apic_eoi == VIR_TRISTATE_SWITCH_ON);
     }
 
     if (def->features[VIR_DOMAIN_FEATURE_PVSPINLOCK]) {
-        char sign;
-        if (def->features[VIR_DOMAIN_FEATURE_PVSPINLOCK] ==
-            VIR_TRISTATE_SWITCH_ON)
-            sign = '+';
-        else
-            sign = '-';
-
-        virBufferAsprintf(&buf, ",%ckvm_pv_unhalt", sign);
+        qemuBuildCpuFeature(qemuCaps, &buf, "kvm_pv_unhalt",
+                            def->features[VIR_DOMAIN_FEATURE_PVSPINLOCK] == VIR_TRISTATE_SWITCH_ON);
     }
 
     if (def->features[VIR_DOMAIN_FEATURE_HYPERV] == VIR_TRISTATE_SWITCH_ON) {
-- 
2.22.0