Extract the code to it's own function. Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx> --- src/conf/domain_conf.c | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 03985b6687..f6e8d5180a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19620,6 +19620,31 @@ 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; + + def->os.loader = g_new0(virDomainLoaderDef, 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) @@ -19646,7 +19671,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); @@ -19655,20 +19679,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; - - def->os.loader = g_new0(virDomainLoaderDef, 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.30.2