render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
Blob Blame History Raw
From 0b93fb79af02a3b1913266d9ced819e07fb3627b Mon Sep 17 00:00:00 2001
Message-Id: <0b93fb79af02a3b1913266d9ced819e07fb3627b@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Mon, 10 Feb 2014 14:02:48 +0100
Subject: [PATCH] conf: Enforce supported options for certain timers

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

According to the documentation various timer options are only supported
by certain timer types. Add a post parse check to verify that the user
didn't specify invalid options.

Also fix the qemu command line parsing function to set correct default
values for the kvmclock timer so that it passes the new check.

(cherry picked from commit 8ffaa42d7bc42f110ea9015a1c8f5528c3eb3bbf)

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/conf/domain_conf.c  | 55 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_command.c |  1 +
 2 files changed, 56 insertions(+)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 99b505b..d6c5b3b 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2801,6 +2801,61 @@ virDomainDefPostParseInternal(virDomainDefPtr def,
 
     if (virDomainDefRejectDuplicateControllers(def) < 0)
         return -1;
+
+    /* verify settings of guest timers */
+    for (i = 0; i < def->clock.ntimers; i++) {
+        virDomainTimerDefPtr timer = def->clock.timers[i];
+
+        if (timer->name == VIR_DOMAIN_TIMER_NAME_KVMCLOCK) {
+            if (timer->tickpolicy != -1) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                               _("timer %s doesn't support setting of "
+                                 "timer tickpolicy"),
+                               virDomainTimerNameTypeToString(timer->name));
+                return -1;
+            }
+        }
+
+        if (timer->tickpolicy != VIR_DOMAIN_TIMER_TICKPOLICY_CATCHUP &&
+            (timer->catchup.threshold != 0 ||
+             timer->catchup.limit != 0 ||
+             timer->catchup.slew != 0)) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("setting of timer catchup policies is only "
+                             "supported with tickpolicy='catchup'"));
+            return -1;
+        }
+
+        if (timer->name != VIR_DOMAIN_TIMER_NAME_TSC) {
+            if (timer->frequency != 0) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                               _("timer %s doesn't support setting of "
+                                 "timer frequency"),
+                               virDomainTimerNameTypeToString(timer->name));
+                return -1;
+             }
+
+            if (timer->mode != -1) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                               _("timer %s doesn't support setting of "
+                                 "timer mode"),
+                               virDomainTimerNameTypeToString(timer->name));
+                return -1;
+             }
+        }
+
+        if (timer->name != VIR_DOMAIN_TIMER_NAME_PLATFORM &&
+            timer->name != VIR_DOMAIN_TIMER_NAME_RTC) {
+            if (timer->track != -1) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                               _("timer %s doesn't support setting of "
+                                 "timer track"),
+                               virDomainTimerNameTypeToString(timer->name));
+                return -1;
+            }
+        }
+    }
+
     return 0;
 }
 
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index d43fdc9..a0ae10c 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -10630,6 +10630,7 @@ qemuParseCommandLineCPU(virDomainDefPtr dom,
                     dom->clock.timers[j]->present = present;
                     dom->clock.timers[j]->tickpolicy = -1;
                     dom->clock.timers[j]->track = -1;
+                    dom->clock.timers[j]->mode = -1;
                     dom->clock.ntimers++;
                 } else if (dom->clock.timers[j]->present != -1 &&
                     dom->clock.timers[j]->present != present) {
-- 
1.8.5.4