[libvirt] [PATCH] conf: Add a function virDomainDefCputuneValidate

Suyang Chen dawson0xff at gmail.com
Tue Mar 12 21:32:40 UTC 2019


move all the def->cputune 'period must be in range' errors into
virDomainDefCputuneValidate function and have it called from
virDomainDefValidateInternal and virDomainDefParseXML function

Solve the bitsizedtask:
"Move validation checks out of domain XML parsing"

Resolves:
https://wiki.libvirt.org/page/BiteSizedTasks#Move_validation_checks_out_of_domain_XML_parsing

Signed-off-by: Suyang Chen <dawson0xff at gmail.com>
---
 src/conf/domain_conf.c | 75 ++++++++++++++++++++++++------------------
 1 file changed, 43 insertions(+), 32 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 995f87bcbe..e17ca0e0cb 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6589,6 +6589,45 @@ virDomainDefMemtuneValidate(const virDomainDef *def)
     return 0;
 }
 
+static int
+virDomainDefCputuneValidate(const virDomainDef *def)
+{
+    if (def->cputune.period > 0 &&
+        (def->cputune.period < 1000 || def->cputune.period > 1000000)) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("Value of cputune period must be in range "
+                         "[1000, 1000000]"));
+        return -1;
+    }
+
+    if (def->cputune.global_period > 0 &&
+        (def->cputune.global_period < 1000 || def->cputune.global_period > 1000000)) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("Value of cputune global 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_CONFIG_UNSUPPORTED, "%s",
+                       _("Value of cputune emulator_period must be in range "
+                         "[1000, 1000000]"));
+        return -1;
+    }
+
+    if (def->cputune.iothread_period > 0 &&
+        (def->cputune.iothread_period < 1000 ||
+         def->cputune.iothread_period > 1000000)) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("Value of cputune iothread_period must be in range "
+                         "[1000, 1000000]"));
+        return -1;
+    }
+
+    return 0;
+}
 
 static int
 virDomainDefValidateInternal(const virDomainDef *def)
@@ -6628,6 +6667,9 @@ virDomainDefValidateInternal(const virDomainDef *def)
     if (virDomainDefMemtuneValidate(def) < 0)
         return -1;
 
+    if (virDomainDefCputuneValidate(def) < 0)
+        return -1;
+
     return 0;
 }
 
@@ -19594,13 +19636,8 @@ virDomainDefParseXML(xmlDocPtr xml,
         goto error;
     }
 
-    if (def->cputune.period > 0 &&
-        (def->cputune.period < 1000 || def->cputune.period > 1000000)) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("Value of cputune period must be in range "
-                         "[1000, 1000000]"));
+    if (virDomainDefCputuneValidate(def) < 0)
         goto error;
-    }
 
     if (virXPathLongLong("string(./cputune/quota[1])", ctxt,
                          &def->cputune.quota) < -1) {
@@ -19625,14 +19662,6 @@ virDomainDefParseXML(xmlDocPtr xml,
         goto error;
     }
 
-    if (def->cputune.global_period > 0 &&
-        (def->cputune.global_period < 1000 || def->cputune.global_period > 1000000)) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("Value of cputune global period must be in range "
-                         "[1000, 1000000]"));
-        goto error;
-    }
-
     if (virXPathLongLong("string(./cputune/global_quota[1])", ctxt,
                          &def->cputune.global_quota) < -1) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
@@ -19656,15 +19685,6 @@ virDomainDefParseXML(xmlDocPtr xml,
         goto error;
     }
 
-    if (def->cputune.emulator_period > 0 &&
-        (def->cputune.emulator_period < 1000 ||
-         def->cputune.emulator_period > 1000000)) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("Value of cputune emulator_period must be in range "
-                         "[1000, 1000000]"));
-        goto error;
-    }
-
     if (virXPathLongLong("string(./cputune/emulator_quota[1])", ctxt,
                          &def->cputune.emulator_quota) < -1) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
@@ -19688,15 +19708,6 @@ virDomainDefParseXML(xmlDocPtr xml,
         goto error;
     }
 
-    if (def->cputune.iothread_period > 0 &&
-        (def->cputune.iothread_period < 1000 ||
-         def->cputune.iothread_period > 1000000)) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("Value of cputune iothread_period must be in range "
-                         "[1000, 1000000]"));
-        goto error;
-    }
-
     if (virXPathLongLong("string(./cputune/iothread_quota[1])", ctxt,
                          &def->cputune.iothread_quota) < -1) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
-- 
2.20.1




More information about the libvir-list mailing list