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

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 b8dd70db4ee2f3a5edcbbeb8515830db9652cb59)

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: <e9d0f563b055b415deb7718d33f7661a797a48f1.1621599207.git.phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/conf/domain_conf.c | 44 +++++++++++++++++++++++++++---------------
 1 file changed, 28 insertions(+), 16 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index bb484a57c6..493700ed6b 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -19402,6 +19402,32 @@ virDomainDefParseBootFirmwareOptions(virDomainDefPtr def,
 }
 
 
+static int
+virDomainDefParseBootLoaderOptions(virDomainDefPtr def,
+                                   xmlXPathContextPtr ctxt)
+{
+    xmlNodePtr loader_node = virXPathNode("./os/loader[1]", ctxt);
+    const bool fwAutoSelect = def->os.firmware != VIR_DOMAIN_OS_DEF_FIRMWARE_NONE;
+
+    if (!loader_node)
+        return 0;
+
+    if (VIR_ALLOC(def->os.loader) < 0)
+        return -1;
+
+    if (virDomainLoaderDefParseXML(loader_node,
+                                   def->os.loader,
+                                   fwAutoSelect) < 0)
+        return -1;
+
+    def->os.loader->nvram = virXPathString("string(./os/nvram[1])", ctxt);
+    if (!fwAutoSelect)
+        def->os.loader->templt = virXPathString("string(./os/nvram[1]/@template)", ctxt);
+
+    return 0;
+}
+
+
 static int
 virDomainDefParseBootOptions(virDomainDefPtr def,
                              xmlXPathContextPtr ctxt)
@@ -19428,7 +19454,6 @@ virDomainDefParseBootOptions(virDomainDefPtr def,
         def->os.type == VIR_DOMAIN_OSTYPE_XENPVH ||
         def->os.type == VIR_DOMAIN_OSTYPE_HVM ||
         def->os.type == VIR_DOMAIN_OSTYPE_UML) {
-        xmlNodePtr loader_node;
 
         virDomainDefParseBootKernelOptions(def, ctxt);
 
@@ -19437,21 +19462,8 @@ virDomainDefParseBootOptions(virDomainDefPtr def,
                 return -1;
         }
 
-        if ((loader_node = virXPathNode("./os/loader[1]", ctxt))) {
-            const bool fwAutoSelect = def->os.firmware != VIR_DOMAIN_OS_DEF_FIRMWARE_NONE;
-
-            if (VIR_ALLOC(def->os.loader) < 0)
-                return -1;
-
-            if (virDomainLoaderDefParseXML(loader_node,
-                                           def->os.loader,
-                                           fwAutoSelect) < 0)
-                return -1;
-
-            def->os.loader->nvram = virXPathString("string(./os/nvram[1])", ctxt);
-            if (!fwAutoSelect)
-                def->os.loader->templt = virXPathString("string(./os/nvram[1]/@template)", ctxt);
-        }
+        if (virDomainDefParseBootLoaderOptions(def, ctxt) < 0)
+            return -1;
     }
 
     if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
-- 
2.31.1