render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
c480ed
From b3f714b0907ff1a906d8725efb26733caa913b01 Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <b3f714b0907ff1a906d8725efb26733caa913b01@dist-git>
c480ed
From: Jiri Denemark <jdenemar@redhat.com>
c480ed
Date: Fri, 21 Jun 2019 09:25:47 +0200
c480ed
Subject: [PATCH] qemu_command: Use consistent syntax for CPU features
c480ed
MIME-Version: 1.0
c480ed
Content-Type: text/plain; charset=UTF-8
c480ed
Content-Transfer-Encoding: 8bit
c480ed
c480ed
Normal CPU features use modern -cpu ...,feature=on|off syntax when
c480ed
available, but kvm features kept using the old +feature or -feature.
c480ed
c480ed
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
(cherry picked from commit e1ba4073961091522b1560472c5559124bd3c034)
c480ed
c480ed
https://bugzilla.redhat.com/show_bug.cgi?id=1697627
c480ed
c480ed
Conflicts:
c480ed
	tests/qemuxml2argvdata/eoi-disabled.x86_64-latest.args
c480ed
	tests/qemuxml2argvdata/eoi-enabled.x86_64-latest.args
c480ed
	tests/qemuxml2argvdata/kvmclock+eoi-disabled.x86_64-latest.args
c480ed
	tests/qemuxml2argvdata/pv-spinlock-disabled.x86_64-latest.args
c480ed
	tests/qemuxml2argvdata/pv-spinlock-enabled.x86_64-latest.args
c480ed
            - not backported
c480ed
c480ed
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c480ed
Message-Id: <da608f8dcef1eeb3e62d4c1d921c8182c1b4d533.1561068591.git.jdenemar@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
---
c480ed
 src/qemu/qemu_command.c | 46 +++++++++++++++++++----------------------
c480ed
 1 file changed, 21 insertions(+), 25 deletions(-)
c480ed
c480ed
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
c480ed
index 7ffc4358e3..bea9a208e5 100644
c480ed
--- a/src/qemu/qemu_command.c
c480ed
+++ b/src/qemu/qemu_command.c
c480ed
@@ -6813,6 +6813,19 @@ qemuBuildGlobalControllerCommandLine(virCommandPtr cmd,
c480ed
 }
c480ed
 
c480ed
 
c480ed
+static void
c480ed
+qemuBuildCpuFeature(virQEMUCapsPtr qemuCaps,
c480ed
+                    virBufferPtr buf,
c480ed
+                    const char *name,
c480ed
+                    bool state)
c480ed
+{
c480ed
+    if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_MODEL_EXPANSION))
c480ed
+        virBufferAsprintf(buf, ",%s=%s", name, state ? "on" : "off");
c480ed
+    else
c480ed
+        virBufferAsprintf(buf, ",%c%s", state ? '+' : '-', name);
c480ed
+}
c480ed
+
c480ed
+
c480ed
 static int
c480ed
 qemuBuildCpuModelArgStr(virQEMUDriverPtr driver,
c480ed
                         const virDomainDef *def,
c480ed
@@ -6890,18 +6903,12 @@ qemuBuildCpuModelArgStr(virQEMUDriverPtr driver,
c480ed
         switch ((virCPUFeaturePolicy) cpu->features[i].policy) {
c480ed
         case VIR_CPU_FEATURE_FORCE:
c480ed
         case VIR_CPU_FEATURE_REQUIRE:
c480ed
-            if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_MODEL_EXPANSION))
c480ed
-                virBufferAsprintf(buf, ",%s=on", cpu->features[i].name);
c480ed
-            else
c480ed
-                virBufferAsprintf(buf, ",+%s", cpu->features[i].name);
c480ed
+            qemuBuildCpuFeature(qemuCaps, buf, cpu->features[i].name, true);
c480ed
             break;
c480ed
 
c480ed
         case VIR_CPU_FEATURE_DISABLE:
c480ed
         case VIR_CPU_FEATURE_FORBID:
c480ed
-            if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_MODEL_EXPANSION))
c480ed
-                virBufferAsprintf(buf, ",%s=off", cpu->features[i].name);
c480ed
-            else
c480ed
-                virBufferAsprintf(buf, ",-%s", cpu->features[i].name);
c480ed
+            qemuBuildCpuFeature(qemuCaps, buf, cpu->features[i].name, false);
c480ed
             break;
c480ed
 
c480ed
         case VIR_CPU_FEATURE_OPTIONAL:
c480ed
@@ -6982,8 +6989,8 @@ qemuBuildCpuCommandLine(virCommandPtr cmd,
c480ed
 
c480ed
         if (timer->name == VIR_DOMAIN_TIMER_NAME_KVMCLOCK &&
c480ed
             timer->present != -1) {
c480ed
-            virBufferAsprintf(&buf, ",%ckvmclock",
c480ed
-                              timer->present ? '+' : '-');
c480ed
+            qemuBuildCpuFeature(qemuCaps, &buf, "kvmclock",
c480ed
+                                !!timer->present);
c480ed
         } else if (timer->name == VIR_DOMAIN_TIMER_NAME_HYPERVCLOCK &&
c480ed
                    timer->present == 1) {
c480ed
             virBufferAddLit(&buf, ",hv_time");
c480ed
@@ -6994,24 +7001,13 @@ qemuBuildCpuCommandLine(virCommandPtr cmd,
c480ed
     }
c480ed
 
c480ed
     if (def->apic_eoi) {
c480ed
-        char sign;
c480ed
-        if (def->apic_eoi == VIR_TRISTATE_SWITCH_ON)
c480ed
-            sign = '+';
c480ed
-        else
c480ed
-            sign = '-';
c480ed
-
c480ed
-        virBufferAsprintf(&buf, ",%ckvm_pv_eoi", sign);
c480ed
+        qemuBuildCpuFeature(qemuCaps, &buf, "kvm_pv_eoi",
c480ed
+                            def->apic_eoi == VIR_TRISTATE_SWITCH_ON);
c480ed
     }
c480ed
 
c480ed
     if (def->features[VIR_DOMAIN_FEATURE_PVSPINLOCK]) {
c480ed
-        char sign;
c480ed
-        if (def->features[VIR_DOMAIN_FEATURE_PVSPINLOCK] ==
c480ed
-            VIR_TRISTATE_SWITCH_ON)
c480ed
-            sign = '+';
c480ed
-        else
c480ed
-            sign = '-';
c480ed
-
c480ed
-        virBufferAsprintf(&buf, ",%ckvm_pv_unhalt", sign);
c480ed
+        qemuBuildCpuFeature(qemuCaps, &buf, "kvm_pv_unhalt",
c480ed
+                            def->features[VIR_DOMAIN_FEATURE_PVSPINLOCK] == VIR_TRISTATE_SWITCH_ON);
c480ed
     }
c480ed
 
c480ed
     if (def->features[VIR_DOMAIN_FEATURE_HYPERV] == VIR_TRISTATE_SWITCH_ON) {
c480ed
-- 
c480ed
2.22.0
c480ed