render / rpms / libvirt

Forked from rpms/libvirt 4 months ago
Clone
b35f2b
From adafaa880b67f1025c64515352e5e851daa62ae9 Mon Sep 17 00:00:00 2001
b35f2b
Message-Id: <adafaa880b67f1025c64515352e5e851daa62ae9@dist-git>
b35f2b
From: Pavel Hrdina <phrdina@redhat.com>
b35f2b
Date: Fri, 21 May 2021 14:16:05 +0200
b35f2b
Subject: [PATCH] conf: introduce virDomainDefParseBootInitOptions
b35f2b
b35f2b
Extract the code to it's own function.
b35f2b
b35f2b
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
b35f2b
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
b35f2b
(cherry picked from commit b07116438c96fddfa00bdb57878a707240574b42)
b35f2b
b35f2b
Conflicts:
b35f2b
    src/conf/domain_conf.c
b35f2b
        - using VIR_ALLOC in downstream instead of g_new0
b35f2b
b35f2b
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1929357
b35f2b
b35f2b
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
b35f2b
Message-Id: <cb7f11437bdbc14b0791645c39c963118d0f9806.1621599207.git.phrdina@redhat.com>
b35f2b
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
b35f2b
---
b35f2b
 src/conf/domain_conf.c | 115 +++++++++++++++++++++++------------------
b35f2b
 1 file changed, 64 insertions(+), 51 deletions(-)
b35f2b
b35f2b
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
b35f2b
index 444657c9a1..9eb418c7c0 100644
b35f2b
--- a/src/conf/domain_conf.c
b35f2b
+++ b/src/conf/domain_conf.c
b35f2b
@@ -19302,76 +19302,89 @@ virDomainVcpuParse(virDomainDefPtr def,
b35f2b
 
b35f2b
 
b35f2b
 static int
b35f2b
-virDomainDefParseBootOptions(virDomainDefPtr def,
b35f2b
-                             xmlXPathContextPtr ctxt)
b35f2b
+virDomainDefParseBootInitOptions(virDomainDefPtr def,
b35f2b
+                                 xmlXPathContextPtr ctxt)
b35f2b
 {
b35f2b
     char *name = NULL;
b35f2b
     size_t i;
b35f2b
     int n;
b35f2b
     g_autofree xmlNodePtr *nodes = NULL;
b35f2b
-    g_autofree char *tmp = NULL;
b35f2b
 
b35f2b
-    /*
b35f2b
-     * Booting options for different OS types....
b35f2b
-     *
b35f2b
-     *   - A bootloader (and optional kernel+initrd)  (xen)
b35f2b
-     *   - A kernel + initrd                          (xen)
b35f2b
-     *   - A boot device (and optional kernel+initrd) (hvm)
b35f2b
-     *   - An init script                             (exe)
b35f2b
-     */
b35f2b
+    def->os.init = virXPathString("string(./os/init[1])", ctxt);
b35f2b
+    def->os.cmdline = virXPathString("string(./os/cmdline[1])", ctxt);
b35f2b
+    def->os.initdir = virXPathString("string(./os/initdir[1])", ctxt);
b35f2b
+    def->os.inituser = virXPathString("string(./os/inituser[1])", ctxt);
b35f2b
+    def->os.initgroup = virXPathString("string(./os/initgroup[1])", ctxt);
b35f2b
 
b35f2b
-    if (def->os.type == VIR_DOMAIN_OSTYPE_EXE) {
b35f2b
-        def->os.init = virXPathString("string(./os/init[1])", ctxt);
b35f2b
-        def->os.cmdline = virXPathString("string(./os/cmdline[1])", ctxt);
b35f2b
-        def->os.initdir = virXPathString("string(./os/initdir[1])", ctxt);
b35f2b
-        def->os.inituser = virXPathString("string(./os/inituser[1])", ctxt);
b35f2b
-        def->os.initgroup = virXPathString("string(./os/initgroup[1])", ctxt);
b35f2b
+    if ((n = virXPathNodeSet("./os/initarg", ctxt, &nodes)) < 0)
b35f2b
+        return -1;
b35f2b
 
b35f2b
-        if ((n = virXPathNodeSet("./os/initarg", ctxt, &nodes)) < 0)
b35f2b
+    if (VIR_ALLOC_N(def->os.initargv, n+1) < 0)
b35f2b
+        return -1;
b35f2b
+    for (i = 0; i < n; i++) {
b35f2b
+        if (!nodes[i]->children ||
b35f2b
+            !nodes[i]->children->content) {
b35f2b
+            virReportError(VIR_ERR_XML_ERROR, "%s",
b35f2b
+                           _("No data supplied for <initarg> element"));
b35f2b
             return -1;
b35f2b
+        }
b35f2b
+        def->os.initargv[i] = g_strdup((const char *)nodes[i]->children->content);
b35f2b
+    }
b35f2b
+    def->os.initargv[n] = NULL;
b35f2b
+    VIR_FREE(nodes);
b35f2b
 
b35f2b
-        if (VIR_ALLOC_N(def->os.initargv, n+1) < 0)
b35f2b
+    if ((n = virXPathNodeSet("./os/initenv", ctxt, &nodes)) < 0)
b35f2b
+        return -1;
b35f2b
+
b35f2b
+    if (VIR_ALLOC_N(def->os.initenv, n+1) < 0)
b35f2b
+        return -1;
b35f2b
+    for (i = 0; i < n; i++) {
b35f2b
+        if (!(name = virXMLPropString(nodes[i], "name"))) {
b35f2b
+            virReportError(VIR_ERR_XML_ERROR, "%s",
b35f2b
+                           _("No name supplied for <initenv> element"));
b35f2b
             return -1;
b35f2b
-        for (i = 0; i < n; i++) {
b35f2b
-            if (!nodes[i]->children ||
b35f2b
-                !nodes[i]->children->content) {
b35f2b
-                virReportError(VIR_ERR_XML_ERROR, "%s",
b35f2b
-                               _("No data supplied for <initarg> element"));
b35f2b
-                return -1;
b35f2b
-            }
b35f2b
-            def->os.initargv[i] = g_strdup((const char *)nodes[i]->children->content);
b35f2b
         }
b35f2b
-        def->os.initargv[n] = NULL;
b35f2b
-        VIR_FREE(nodes);
b35f2b
 
b35f2b
-        if ((n = virXPathNodeSet("./os/initenv", ctxt, &nodes)) < 0)
b35f2b
+        if (!nodes[i]->children ||
b35f2b
+            !nodes[i]->children->content) {
b35f2b
+            virReportError(VIR_ERR_XML_ERROR,
b35f2b
+                           _("No value supplied for <initenv name='%s'> element"),
b35f2b
+                           name);
b35f2b
             return -1;
b35f2b
+        }
b35f2b
 
b35f2b
-        if (VIR_ALLOC_N(def->os.initenv, n+1) < 0)
b35f2b
+        if (VIR_ALLOC(def->os.initenv[i]) < 0)
b35f2b
             return -1;
b35f2b
-        for (i = 0; i < n; i++) {
b35f2b
-            if (!(name = virXMLPropString(nodes[i], "name"))) {
b35f2b
-                virReportError(VIR_ERR_XML_ERROR, "%s",
b35f2b
-                                _("No name supplied for <initenv> element"));
b35f2b
-                return -1;
b35f2b
-            }
b35f2b
 
b35f2b
-            if (!nodes[i]->children ||
b35f2b
-                !nodes[i]->children->content) {
b35f2b
-                virReportError(VIR_ERR_XML_ERROR,
b35f2b
-                               _("No value supplied for <initenv name='%s'> element"),
b35f2b
-                               name);
b35f2b
-                return -1;
b35f2b
-            }
b35f2b
+        def->os.initenv[i]->name = name;
b35f2b
+        def->os.initenv[i]->value = g_strdup((const char *)nodes[i]->children->content);
b35f2b
+    }
b35f2b
+    def->os.initenv[n] = NULL;
b35f2b
 
b35f2b
-            if (VIR_ALLOC(def->os.initenv[i]) < 0)
b35f2b
-                return -1;
b35f2b
+    return 0;
b35f2b
+}
b35f2b
 
b35f2b
-            def->os.initenv[i]->name = name;
b35f2b
-            def->os.initenv[i]->value = g_strdup((const char *)nodes[i]->children->content);
b35f2b
-        }
b35f2b
-        def->os.initenv[n] = NULL;
b35f2b
-        VIR_FREE(nodes);
b35f2b
+
b35f2b
+static int
b35f2b
+virDomainDefParseBootOptions(virDomainDefPtr def,
b35f2b
+                             xmlXPathContextPtr ctxt)
b35f2b
+{
b35f2b
+    int n;
b35f2b
+    g_autofree xmlNodePtr *nodes = NULL;
b35f2b
+    g_autofree char *tmp = NULL;
b35f2b
+
b35f2b
+    /*
b35f2b
+     * Booting options for different OS types....
b35f2b
+     *
b35f2b
+     *   - A bootloader (and optional kernel+initrd)  (xen)
b35f2b
+     *   - A kernel + initrd                          (xen)
b35f2b
+     *   - A boot device (and optional kernel+initrd) (hvm)
b35f2b
+     *   - An init script                             (exe)
b35f2b
+     */
b35f2b
+
b35f2b
+    if (def->os.type == VIR_DOMAIN_OSTYPE_EXE) {
b35f2b
+        if (virDomainDefParseBootInitOptions(def, ctxt) < 0)
b35f2b
+            return -1;
b35f2b
     }
b35f2b
 
b35f2b
     if (def->os.type == VIR_DOMAIN_OSTYPE_XEN ||
b35f2b
-- 
b35f2b
2.31.1
b35f2b