render / rpms / libvirt

Forked from rpms/libvirt 11 months ago
Clone
ab145e
From 2a019bfa26e697c60893afd09fcc2f0c3218691b Mon Sep 17 00:00:00 2001
ab145e
Message-Id: <2a019bfa26e697c60893afd09fcc2f0c3218691b@dist-git>
ab145e
From: Pavel Hrdina <phrdina@redhat.com>
ab145e
Date: Fri, 21 May 2021 14:16:07 +0200
ab145e
Subject: [PATCH] conf: introduce virDomainDefParseBootFirmwareOptions
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 bcf97abfc6b45694f0d789ae2bdf87c8d082fddf)
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: <9a090d9f2a43b261ed1b6db608779a01a7594f4a.1621599207.git.phrdina@redhat.com>
ab145e
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
ab145e
---
ab145e
 src/conf/domain_conf.c | 39 +++++++++++++++++++++++++++------------
ab145e
 1 file changed, 27 insertions(+), 12 deletions(-)
ab145e
ab145e
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
ab145e
index 432ad938f9..bb484a57c6 100644
ab145e
--- a/src/conf/domain_conf.c
ab145e
+++ b/src/conf/domain_conf.c
ab145e
@@ -19377,6 +19377,31 @@ virDomainDefParseBootKernelOptions(virDomainDefPtr def,
ab145e
 }
ab145e
 
ab145e
 
ab145e
+static int
ab145e
+virDomainDefParseBootFirmwareOptions(virDomainDefPtr def,
ab145e
+                                     xmlXPathContextPtr ctxt)
ab145e
+{
ab145e
+    g_autofree char *firmware = virXPathString("string(./os/@firmware)", ctxt);
ab145e
+    int fw = 0;
ab145e
+
ab145e
+    if (!firmware)
ab145e
+        return 0;
ab145e
+
ab145e
+    fw = virDomainOsDefFirmwareTypeFromString(firmware);
ab145e
+
ab145e
+    if (fw <= 0) {
ab145e
+        virReportError(VIR_ERR_XML_ERROR,
ab145e
+                       _("unknown firmware value %s"),
ab145e
+                       firmware);
ab145e
+        return -1;
ab145e
+    }
ab145e
+
ab145e
+    def->os.firmware = fw;
ab145e
+
ab145e
+    return 0;
ab145e
+}
ab145e
+
ab145e
+
ab145e
 static int
ab145e
 virDomainDefParseBootOptions(virDomainDefPtr def,
ab145e
                              xmlXPathContextPtr ctxt)
ab145e
@@ -19403,23 +19428,13 @@ virDomainDefParseBootOptions(virDomainDefPtr def,
ab145e
         def->os.type == VIR_DOMAIN_OSTYPE_XENPVH ||
ab145e
         def->os.type == VIR_DOMAIN_OSTYPE_HVM ||
ab145e
         def->os.type == VIR_DOMAIN_OSTYPE_UML) {
ab145e
-        g_autofree char *firmware = NULL;
ab145e
         xmlNodePtr loader_node;
ab145e
 
ab145e
         virDomainDefParseBootKernelOptions(def, ctxt);
ab145e
 
ab145e
-        if (def->os.type == VIR_DOMAIN_OSTYPE_HVM &&
ab145e
-            (firmware = virXPathString("string(./os/@firmware)", ctxt))) {
ab145e
-            int fw = virDomainOsDefFirmwareTypeFromString(firmware);
ab145e
-
ab145e
-            if (fw <= 0) {
ab145e
-                virReportError(VIR_ERR_XML_ERROR,
ab145e
-                               _("unknown firmware value %s"),
ab145e
-                               firmware);
ab145e
+        if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
ab145e
+            if (virDomainDefParseBootFirmwareOptions(def, ctxt) < 0)
ab145e
                 return -1;
ab145e
-            }
ab145e
-
ab145e
-            def->os.firmware = fw;
ab145e
         }
ab145e
 
ab145e
         if ((loader_node = virXPathNode("./os/loader[1]", ctxt))) {
ab145e
-- 
ab145e
2.31.1
ab145e