[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCHv3 27/27] conf: Enforce ranges on cputune variables



The limits are documented at
http://libvirt.org/formatdomain.html#elementsCPUTuning . Enforce them
when going through XML parsing in addition to being enforced by the API.
---
 src/conf/domain_conf.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index fbdab9a..be3bf1a 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2493,6 +2493,43 @@ virDomainDefVerifyInternal(virDomainDefPtr def,
         return -1;
     }

+    /* enforce range checks for cputune values */
+    /* these are not represented in the XML schema, but are documented */
+    if (def->cputune.period > 0 &&
+        (def->cputune.period < 1000 || def->cputune.period > 1000000)) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("Value of cputune period must be in range "
+                         "[1000, 1000000]"));
+        return -1;
+    }
+
+    if (def->cputune.emulator_period > 0 &&
+        (def->cputune.emulator_period < 1000 ||
+         def->cputune.emulator_period > 1000000)) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("Value of cputune emulator_period must be in range "
+                         "[1000, 1000000]"));
+        return -1;
+    }
+
+    if (def->cputune.quota > 0 &&
+        (def->cputune.quota < 1000 ||
+         def->cputune.quota > 18446744073709551)) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("Value of cputune quota must be in range "
+                         "[1000, 18446744073709551]"));
+        return -1;
+    }
+
+    if (def->cputune.emulator_quota > 0 &&
+        (def->cputune.emulator_quota < 1000 ||
+         def->cputune.emulator_quota > 18446744073709551)) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("Value of cputune emulator_quota must be in range "
+                         "[1000, 18446744073709551]"));
+        return -1;
+    }
+
     return 0;
 }

-- 
1.8.1.5


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]