render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From 67198a38ee3bce9ff19a8c80a593724d684d966e Mon Sep 17 00:00:00 2001
Message-Id: <67198a38ee3bce9ff19a8c80a593724d684d966e@dist-git>
From: Andrea Bolognani <abologna@redhat.com>
Date: Fri, 14 Feb 2020 13:12:33 +0100
Subject: [PATCH] qemu: Use switch statement in qemuBuildCpuCommandLine()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Make sure we are taking all possible virDomainTimerNameType values
into account. This will make upcoming changes easier.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
(cherry picked from commit f8e923c1ba70d7be53ea18d9b4de040763347f9e)

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

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Message-Id: <20200214121237.623948-3-abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/qemu/qemu_command.c | 34 ++++++++++++++++++++++++----------
 1 file changed, 24 insertions(+), 10 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index d144855b0d..0ad09baa1d 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -6616,16 +6616,30 @@ qemuBuildCpuCommandLine(virCommandPtr cmd,
     for (i = 0; i < def->clock.ntimers; i++) {
         virDomainTimerDefPtr timer = def->clock.timers[i];
 
-        if (timer->name == VIR_DOMAIN_TIMER_NAME_KVMCLOCK &&
-            timer->present != -1) {
-            qemuBuildCpuFeature(qemuCaps, &buf, "kvmclock",
-                                !!timer->present);
-        } else if (timer->name == VIR_DOMAIN_TIMER_NAME_HYPERVCLOCK &&
-                   timer->present == 1) {
-            virBufferAddLit(&buf, ",hv-time");
-        } else if (timer->name == VIR_DOMAIN_TIMER_NAME_TSC &&
-                   timer->frequency > 0) {
-            virBufferAsprintf(&buf, ",tsc-frequency=%lu", timer->frequency);
+        switch ((virDomainTimerNameType)timer->name) {
+        case VIR_DOMAIN_TIMER_NAME_KVMCLOCK:
+            if (timer->present != -1) {
+                qemuBuildCpuFeature(qemuCaps, &buf, "kvmclock",
+                                    !!timer->present);
+            }
+            break;
+        case VIR_DOMAIN_TIMER_NAME_HYPERVCLOCK:
+            if (timer->present == 1)
+                virBufferAddLit(&buf, ",hv-time");
+            break;
+        case VIR_DOMAIN_TIMER_NAME_TSC:
+            if (timer->frequency > 0)
+                virBufferAsprintf(&buf, ",tsc-frequency=%lu", timer->frequency);
+            break;
+        case VIR_DOMAIN_TIMER_NAME_PLATFORM:
+        case VIR_DOMAIN_TIMER_NAME_PIT:
+        case VIR_DOMAIN_TIMER_NAME_RTC:
+        case VIR_DOMAIN_TIMER_NAME_HPET:
+            break;
+        case VIR_DOMAIN_TIMER_NAME_LAST:
+        default:
+            virReportEnumRangeError(virDomainTimerNameType, timer->name);
+            return -1;
         }
     }
 
-- 
2.25.0