Blob Blame History Raw
From adafaa880b67f1025c64515352e5e851daa62ae9 Mon Sep 17 00:00:00 2001
Message-Id: <adafaa880b67f1025c64515352e5e851daa62ae9@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Fri, 21 May 2021 14:16:05 +0200
Subject: [PATCH] conf: introduce virDomainDefParseBootInitOptions

Extract the code to it's own function.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
(cherry picked from commit b07116438c96fddfa00bdb57878a707240574b42)

Conflicts:
    src/conf/domain_conf.c
        - using VIR_ALLOC in downstream instead of g_new0

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

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <cb7f11437bdbc14b0791645c39c963118d0f9806.1621599207.git.phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/conf/domain_conf.c | 115 +++++++++++++++++++++++------------------
 1 file changed, 64 insertions(+), 51 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 444657c9a1..9eb418c7c0 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -19302,76 +19302,89 @@ virDomainVcpuParse(virDomainDefPtr def,
 
 
 static int
-virDomainDefParseBootOptions(virDomainDefPtr def,
-                             xmlXPathContextPtr ctxt)
+virDomainDefParseBootInitOptions(virDomainDefPtr def,
+                                 xmlXPathContextPtr ctxt)
 {
     char *name = NULL;
     size_t i;
     int n;
     g_autofree xmlNodePtr *nodes = NULL;
-    g_autofree char *tmp = NULL;
 
-    /*
-     * Booting options for different OS types....
-     *
-     *   - A bootloader (and optional kernel+initrd)  (xen)
-     *   - A kernel + initrd                          (xen)
-     *   - A boot device (and optional kernel+initrd) (hvm)
-     *   - An init script                             (exe)
-     */
+    def->os.init = virXPathString("string(./os/init[1])", ctxt);
+    def->os.cmdline = virXPathString("string(./os/cmdline[1])", ctxt);
+    def->os.initdir = virXPathString("string(./os/initdir[1])", ctxt);
+    def->os.inituser = virXPathString("string(./os/inituser[1])", ctxt);
+    def->os.initgroup = virXPathString("string(./os/initgroup[1])", ctxt);
 
-    if (def->os.type == VIR_DOMAIN_OSTYPE_EXE) {
-        def->os.init = virXPathString("string(./os/init[1])", ctxt);
-        def->os.cmdline = virXPathString("string(./os/cmdline[1])", ctxt);
-        def->os.initdir = virXPathString("string(./os/initdir[1])", ctxt);
-        def->os.inituser = virXPathString("string(./os/inituser[1])", ctxt);
-        def->os.initgroup = virXPathString("string(./os/initgroup[1])", ctxt);
+    if ((n = virXPathNodeSet("./os/initarg", ctxt, &nodes)) < 0)
+        return -1;
 
-        if ((n = virXPathNodeSet("./os/initarg", ctxt, &nodes)) < 0)
+    if (VIR_ALLOC_N(def->os.initargv, n+1) < 0)
+        return -1;
+    for (i = 0; i < n; i++) {
+        if (!nodes[i]->children ||
+            !nodes[i]->children->content) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("No data supplied for <initarg> element"));
             return -1;
+        }
+        def->os.initargv[i] = g_strdup((const char *)nodes[i]->children->content);
+    }
+    def->os.initargv[n] = NULL;
+    VIR_FREE(nodes);
 
-        if (VIR_ALLOC_N(def->os.initargv, n+1) < 0)
+    if ((n = virXPathNodeSet("./os/initenv", ctxt, &nodes)) < 0)
+        return -1;
+
+    if (VIR_ALLOC_N(def->os.initenv, n+1) < 0)
+        return -1;
+    for (i = 0; i < n; i++) {
+        if (!(name = virXMLPropString(nodes[i], "name"))) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("No name supplied for <initenv> element"));
             return -1;
-        for (i = 0; i < n; i++) {
-            if (!nodes[i]->children ||
-                !nodes[i]->children->content) {
-                virReportError(VIR_ERR_XML_ERROR, "%s",
-                               _("No data supplied for <initarg> element"));
-                return -1;
-            }
-            def->os.initargv[i] = g_strdup((const char *)nodes[i]->children->content);
         }
-        def->os.initargv[n] = NULL;
-        VIR_FREE(nodes);
 
-        if ((n = virXPathNodeSet("./os/initenv", ctxt, &nodes)) < 0)
+        if (!nodes[i]->children ||
+            !nodes[i]->children->content) {
+            virReportError(VIR_ERR_XML_ERROR,
+                           _("No value supplied for <initenv name='%s'> element"),
+                           name);
             return -1;
+        }
 
-        if (VIR_ALLOC_N(def->os.initenv, n+1) < 0)
+        if (VIR_ALLOC(def->os.initenv[i]) < 0)
             return -1;
-        for (i = 0; i < n; i++) {
-            if (!(name = virXMLPropString(nodes[i], "name"))) {
-                virReportError(VIR_ERR_XML_ERROR, "%s",
-                                _("No name supplied for <initenv> element"));
-                return -1;
-            }
 
-            if (!nodes[i]->children ||
-                !nodes[i]->children->content) {
-                virReportError(VIR_ERR_XML_ERROR,
-                               _("No value supplied for <initenv name='%s'> element"),
-                               name);
-                return -1;
-            }
+        def->os.initenv[i]->name = name;
+        def->os.initenv[i]->value = g_strdup((const char *)nodes[i]->children->content);
+    }
+    def->os.initenv[n] = NULL;
 
-            if (VIR_ALLOC(def->os.initenv[i]) < 0)
-                return -1;
+    return 0;
+}
 
-            def->os.initenv[i]->name = name;
-            def->os.initenv[i]->value = g_strdup((const char *)nodes[i]->children->content);
-        }
-        def->os.initenv[n] = NULL;
-        VIR_FREE(nodes);
+
+static int
+virDomainDefParseBootOptions(virDomainDefPtr def,
+                             xmlXPathContextPtr ctxt)
+{
+    int n;
+    g_autofree xmlNodePtr *nodes = NULL;
+    g_autofree char *tmp = NULL;
+
+    /*
+     * Booting options for different OS types....
+     *
+     *   - A bootloader (and optional kernel+initrd)  (xen)
+     *   - A kernel + initrd                          (xen)
+     *   - A boot device (and optional kernel+initrd) (hvm)
+     *   - An init script                             (exe)
+     */
+
+    if (def->os.type == VIR_DOMAIN_OSTYPE_EXE) {
+        if (virDomainDefParseBootInitOptions(def, ctxt) < 0)
+            return -1;
     }
 
     if (def->os.type == VIR_DOMAIN_OSTYPE_XEN ||
-- 
2.31.1