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

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

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

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

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 432ad938f9..bb484a57c6 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -19377,6 +19377,31 @@ virDomainDefParseBootKernelOptions(virDomainDefPtr def,
 }
 
 
+static int
+virDomainDefParseBootFirmwareOptions(virDomainDefPtr def,
+                                     xmlXPathContextPtr ctxt)
+{
+    g_autofree char *firmware = virXPathString("string(./os/@firmware)", ctxt);
+    int fw = 0;
+
+    if (!firmware)
+        return 0;
+
+    fw = virDomainOsDefFirmwareTypeFromString(firmware);
+
+    if (fw <= 0) {
+        virReportError(VIR_ERR_XML_ERROR,
+                       _("unknown firmware value %s"),
+                       firmware);
+        return -1;
+    }
+
+    def->os.firmware = fw;
+
+    return 0;
+}
+
+
 static int
 virDomainDefParseBootOptions(virDomainDefPtr def,
                              xmlXPathContextPtr ctxt)
@@ -19403,23 +19428,13 @@ virDomainDefParseBootOptions(virDomainDefPtr def,
         def->os.type == VIR_DOMAIN_OSTYPE_XENPVH ||
         def->os.type == VIR_DOMAIN_OSTYPE_HVM ||
         def->os.type == VIR_DOMAIN_OSTYPE_UML) {
-        g_autofree char *firmware = NULL;
         xmlNodePtr loader_node;
 
         virDomainDefParseBootKernelOptions(def, ctxt);
 
-        if (def->os.type == VIR_DOMAIN_OSTYPE_HVM &&
-            (firmware = virXPathString("string(./os/@firmware)", ctxt))) {
-            int fw = virDomainOsDefFirmwareTypeFromString(firmware);
-
-            if (fw <= 0) {
-                virReportError(VIR_ERR_XML_ERROR,
-                               _("unknown firmware value %s"),
-                               firmware);
+        if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
+            if (virDomainDefParseBootFirmwareOptions(def, ctxt) < 0)
                 return -1;
-            }
-
-            def->os.firmware = fw;
         }
 
         if ((loader_node = virXPathNode("./os/loader[1]", ctxt))) {
-- 
2.31.1