]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
cpu_conf: xml to cpu definition parse helper
authorCollin Walling <walling@linux.ibm.com>
Thu, 19 Sep 2019 20:25:04 +0000 (16:25 -0400)
committerJiri Denemark <jdenemar@redhat.com>
Mon, 7 Oct 2019 08:10:17 +0000 (10:10 +0200)
Implement an XML to virCPUDefPtr helper that handles the ctxt
prerequisite for virCPUDefParseXML.

This does not alter any functionality.

Signed-off-by: Collin Walling <walling@linux.ibm.com>
Reviewed-by: Bjoern Walk <bwalk@linux.ibm.com>
Reviewed-by: Daniel Henrique Barboza <danielh413@gmail.com>
Message-Id: <1568924706-2311-14-git-send-email-walling@linux.ibm.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
src/conf/cpu_conf.c
src/conf/cpu_conf.h
src/cpu/cpu.c
src/libvirt_private.syms

index 7d16a05283fe2473f5349b251e50613fc32729ca..a6bb9ea263c6f5f4984d39f18d39223e927ca7b0 100644 (file)
@@ -268,6 +268,35 @@ virCPUDefCopy(const virCPUDef *cpu)
 }
 
 
+int
+virCPUDefParseXMLString(const char *xml,
+                        virCPUType type,
+                        virCPUDefPtr *cpu)
+{
+    xmlDocPtr doc = NULL;
+    xmlXPathContextPtr ctxt = NULL;
+    int ret = -1;
+
+    if (!xml) {
+        virReportError(VIR_ERR_INVALID_ARG, "%s", _("missing CPU definition"));
+        goto cleanup;
+    }
+
+    if (!(doc = virXMLParseStringCtxt(xml, _("(CPU_definition)"), &ctxt)))
+        goto cleanup;
+
+    if (virCPUDefParseXML(ctxt, NULL, type, cpu) < 0)
+        goto cleanup;
+
+    ret = 0;
+
+ cleanup:
+    xmlFreeDoc(doc);
+    xmlXPathFreeContext(ctxt);
+    return ret;
+}
+
+
 /*
  * Parses CPU definition XML from a node pointed to by @xpath. If @xpath is
  * NULL, the current node of @ctxt is used (i.e., it is a shortcut to ".").
index 19ce816ec28ef9518480115b52d2fa33ce87978d..30904fab95c2034f8135d97a2734831d4fd362e9 100644 (file)
@@ -182,6 +182,11 @@ virCPUDefCopy(const virCPUDef *cpu);
 virCPUDefPtr
 virCPUDefCopyWithoutModel(const virCPUDef *cpu);
 
+int
+virCPUDefParseXMLString(const char *xml,
+                        virCPUType type,
+                        virCPUDefPtr *cpu);
+
 int
 virCPUDefParseXML(xmlXPathContextPtr ctxt,
                   const char *xpath,
index b89462cc0c74ce66f5a2c831bf2296e9b4de5e2e..2278d79a774aae0518c36e401ce78ac4ff26718f 100644 (file)
@@ -111,31 +111,19 @@ virCPUCompareXML(virArch arch,
                  const char *xml,
                  bool failIncompatible)
 {
-    xmlDocPtr doc = NULL;
-    xmlXPathContextPtr ctxt = NULL;
     virCPUDefPtr cpu = NULL;
     virCPUCompareResult ret = VIR_CPU_COMPARE_ERROR;
 
     VIR_DEBUG("arch=%s, host=%p, xml=%s",
               virArchToString(arch), host, NULLSTR(xml));
 
-    if (!xml) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s", _("missing CPU definition"));
-        goto cleanup;
-    }
-
-    if (!(doc = virXMLParseStringCtxt(xml, _("(CPU_definition)"), &ctxt)))
-        goto cleanup;
-
-    if (virCPUDefParseXML(ctxt, NULL, VIR_CPU_TYPE_AUTO, &cpu) < 0)
+    if (virCPUDefParseXMLString(xml, VIR_CPU_TYPE_AUTO, &cpu) < 0)
         goto cleanup;
 
     ret = virCPUCompare(arch, host, cpu, failIncompatible);
 
  cleanup:
     virCPUDefFree(cpu);
-    xmlXPathFreeContext(ctxt);
-    xmlFreeDoc(doc);
 
     return ret;
 }
index 7b681fac643136b03537d949447922f08e834480..eeab820ecab00ce8a396b9222a558f0c8d6297c2 100644 (file)
@@ -101,6 +101,7 @@ virCPUDefIsEqual;
 virCPUDefListFree;
 virCPUDefListParse;
 virCPUDefParseXML;
+virCPUDefParseXMLString;
 virCPUDefStealModel;
 virCPUDefUpdateFeature;
 virCPUModeTypeToString;