]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu_capabilities.c: add virQEMUCapsValidateArch()
authorDaniel Henrique Barboza <danielhb413@gmail.com>
Thu, 18 Nov 2021 18:41:19 +0000 (15:41 -0300)
committerDaniel Henrique Barboza <danielhb413@gmail.com>
Fri, 19 Nov 2021 16:32:58 +0000 (13:32 -0300)
Create a new helper to remove the arch validation logic from the
body of virQEMUCapsLoadCache().

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
src/qemu/qemu_capabilities.c

index a18074d5ad04c40265214888945014c5b38a4c29..4d431623aba5eeef44e1c51ae2e0e6a700c503e2 100644 (file)
@@ -4234,6 +4234,26 @@ virQEMUCapsValidateEmulator(virQEMUCaps *qemuCaps, xmlXPathContextPtr ctxt)
 }
 
 
+static int
+virQEMUCapsValidateArch(virQEMUCaps *qemuCaps, xmlXPathContextPtr ctxt)
+{
+    g_autofree char *str = NULL;
+
+    if (!(str = virXPathString("string(./arch)", ctxt))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("missing arch in QEMU capabilities cache"));
+        return -1;
+    }
+    if (!(qemuCaps->arch = virArchFromString(str))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("unknown arch %s in QEMU capabilities cache"), str);
+        return -1;
+    }
+
+    return 0;
+}
+
+
 /*
  * Parsing a doc that looks like
  *
@@ -4357,17 +4377,8 @@ virQEMUCapsLoadCache(virArch hostArch,
             goto cleanup;
     }
 
-    if (!(str = virXPathString("string(./arch)", ctxt))) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("missing arch in QEMU capabilities cache"));
+    if (virQEMUCapsValidateArch(qemuCaps, ctxt) < 0)
         goto cleanup;
-    }
-    if (!(qemuCaps->arch = virArchFromString(str))) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("unknown arch %s in QEMU capabilities cache"), str);
-        goto cleanup;
-    }
-    VIR_FREE(str);
 
     if (virXPathBoolean("boolean(./cpudata)", ctxt) > 0) {
         qemuCaps->cpuData = virCPUDataParseNode(virXPathNode("./cpudata", ctxt));