[PATCH v2 1/9] domain_conf.c: move boot related timeouts check to validate callback

Daniel Henrique Barboza danielhb413 at gmail.com
Mon Dec 7 13:54:27 UTC 2020


This patch creates a new function, virDomainDefBootValidate(), to host
the validation of boot menu timeout and rebootTimeout outside of parse
time. The checks in virDomainDefParseBootXML() were changed to throw
VIR_ERR_XML_ERROR in case of parse error of those values.

Signed-off-by: Daniel Henrique Barboza <danielhb413 at gmail.com>
---
 src/conf/domain_conf.c   | 41 ++++++++++++++++++++++++++++++----------
 tests/qemuxml2argvtest.c |  3 ++-
 2 files changed, 33 insertions(+), 11 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 66ee658e7b..e53a7372fc 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -7299,6 +7299,28 @@ virDomainDefOSValidate(const virDomainDef *def,
 }
 
 
+static int
+virDomainDefBootValidate(const virDomainDef *def)
+{
+    if (def->os.bm_timeout_set && def->os.bm_timeout > 65535) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("invalid value for boot menu timeout, "
+                         "must be in range [0,65535]"));
+        return -1;
+    }
+
+    if (def->os.bios.rt_set &&
+        (def->os.bios.rt_delay < -1 || def->os.bios.rt_delay > 65535)) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("invalid value for rebootTimeout, "
+                         "must be in range [-1,65535]"));
+        return -1;
+    }
+
+    return 0;
+}
+
+
 static int
 virDomainDefValidateInternal(const virDomainDef *def,
                              virDomainXMLOptionPtr xmlopt)
@@ -7344,6 +7366,9 @@ virDomainDefValidateInternal(const virDomainDef *def,
     if (virDomainDefCputuneValidate(def) < 0)
         return -1;
 
+    if (virDomainDefBootValidate(def) < 0)
+        return -1;
+
     if (virDomainNumaDefValidate(def->numa) < 0)
         return -1;
 
@@ -18867,11 +18892,9 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt,
 
         tmp = virXMLPropString(node, "timeout");
         if (tmp && def->os.bootmenu == VIR_TRISTATE_BOOL_YES) {
-            if (virStrToLong_uip(tmp, NULL, 0, &def->os.bm_timeout) < 0 ||
-                def->os.bm_timeout > 65535) {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                               _("invalid value for boot menu timeout, "
-                                 "must be in range [0,65535]"));
+            if (virStrToLong_uip(tmp, NULL, 0, &def->os.bm_timeout) < 0) {
+                virReportError(VIR_ERR_XML_ERROR, "%s",
+                               _("invalid value for boot menu timeout"));
                 return -1;
             }
             def->os.bm_timeout_set = true;
@@ -18892,11 +18915,9 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt,
         if (tmp) {
             /* that was really just for the check if it is there */
 
-            if (virStrToLong_i(tmp, NULL, 0, &def->os.bios.rt_delay) < 0 ||
-                def->os.bios.rt_delay < -1 || def->os.bios.rt_delay > 65535) {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                               _("invalid value for rebootTimeout, "
-                                 "must be in range [-1,65535]"));
+            if (virStrToLong_i(tmp, NULL, 0, &def->os.bios.rt_delay) < 0) {
+                virReportError(VIR_ERR_XML_ERROR, "%s",
+                               _("invalid value for rebootTimeout"));
                 return -1;
             }
             def->os.bios.rt_set = true;
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 7c9dc0e641..202fc83ccf 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -1006,7 +1006,8 @@ mymain(void)
     DO_TEST("boot-menu-enable-with-timeout",
             QEMU_CAPS_SPLASH_TIMEOUT);
     DO_TEST_PARSE_ERROR("boot-menu-enable-with-timeout", NONE);
-    DO_TEST_PARSE_ERROR("boot-menu-enable-with-timeout-invalid", NONE);
+    DO_TEST_PARSE_ERROR("boot-menu-enable-with-timeout-invalid",
+                        QEMU_CAPS_SPLASH_TIMEOUT);
     DO_TEST("boot-menu-disable", NONE);
     DO_TEST("boot-menu-disable-drive", NONE);
     DO_TEST_PARSE_ERROR("boot-dev+order",
-- 
2.26.2




More information about the libvir-list mailing list