]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu_capabilities.c: add virQEMUCapsValidateEmulator()
authorDaniel Henrique Barboza <danielhb413@gmail.com>
Thu, 18 Nov 2021 18:37:06 +0000 (15:37 -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 emulator validation logic from the
body of virQEMUCapsLoadCache().

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

index 4329a880d92fc443ee0efeb5b9fecfc63db013ed..a18074d5ad04c40265214888945014c5b38a4c29 100644 (file)
@@ -4212,6 +4212,28 @@ virQEMUCapsParseGIC(virQEMUCaps *qemuCaps, xmlXPathContextPtr ctxt)
 }
 
 
+static int
+virQEMUCapsValidateEmulator(virQEMUCaps *qemuCaps, xmlXPathContextPtr ctxt)
+{
+    g_autofree char *str = NULL;
+
+    if (!(str = virXPathString("string(./emulator)", ctxt))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("missing emulator in QEMU capabilities cache"));
+        return -1;
+    }
+
+    if (STRNEQ(str, qemuCaps->binary)) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Expected caps for '%s' but saw '%s'"),
+                       qemuCaps->binary, str);
+        return -1;
+    }
+
+    return 0;
+}
+
+
 /*
  * Parsing a doc that looks like
  *
@@ -4286,18 +4308,9 @@ virQEMUCapsLoadCache(virArch hostArch,
         goto cleanup;
     }
 
-    if (!(str = virXPathString("string(./emulator)", ctxt))) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("missing emulator in QEMU capabilities cache"));
-        goto cleanup;
-    }
-    if (STRNEQ(str, qemuCaps->binary)) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Expected caps for '%s' but saw '%s'"),
-                       qemuCaps->binary, str);
+    if (virQEMUCapsValidateEmulator(qemuCaps, ctxt) < 0)
         goto cleanup;
-    }
-    VIR_FREE(str);
+
     if (virXPathLongLong("string(./qemuctime)", ctxt, &l) < 0) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
                        _("missing qemuctime in QEMU capabilities XML"));