render / rpms / libvirt

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