[PATCH v1 2/4] cpu_conf: xml to cpu definition parse helper

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Implement an xml to virCPUDefPtr helper that handles
the ctxt prerequisite for virCPUDefParseXML.

Signed-off-by: Collin Walling <walling@xxxxxxxxxxxxx>
---
 src/conf/cpu_conf.c      | 30 ++++++++++++++++++++++++++++++
 src/conf/cpu_conf.h      |  6 ++++++
 src/cpu/cpu.c            | 14 +-------------
 src/libvirt_private.syms |  1 +
 4 files changed, 38 insertions(+), 13 deletions(-)

diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c
index 43a3ab5..b2e726a 100644
--- a/src/conf/cpu_conf.c
+++ b/src/conf/cpu_conf.c
@@ -250,6 +250,36 @@ virCPUDefCopy(const virCPUDef *cpu)
 }
 
 
+int
+virCPUDefParseXMLHelper(const char *xml,
+                        const char *xpath,
+                        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, xpath, 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 ".").
diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h
index 9f2e7ee..f8f57fa 100644
--- a/src/conf/cpu_conf.h
+++ b/src/conf/cpu_conf.h
@@ -184,6 +184,12 @@ virCPUDefPtr
 virCPUDefCopyWithoutModel(const virCPUDef *cpu);
 
 int
+virCPUDefParseXMLHelper(const char *xml,
+                        const char *xpath,
+                        virCPUType type,
+                        virCPUDefPtr *cpu);
+
+int
 virCPUDefParseXML(xmlXPathContextPtr ctxt,
                   const char *xpath,
                   virCPUType mode,
diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c
index 047e3b1..8b829a3 100644
--- a/src/cpu/cpu.c
+++ b/src/cpu/cpu.c
@@ -114,31 +114,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 (virCPUDefParseXMLHelper(xml, NULL, VIR_CPU_TYPE_AUTO, &cpu) < 0)
         goto cleanup;
 
     ret = virCPUCompare(arch, host, cpu, failIncompatible);
 
  cleanup:
     virCPUDefFree(cpu);
-    xmlXPathFreeContext(ctxt);
-    xmlFreeDoc(doc);
 
     return ret;
 }
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index cab324c..502fe48 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -86,6 +86,7 @@ virCPUDefIsEqual;
 virCPUDefListFree;
 virCPUDefListParse;
 virCPUDefParseXML;
+virCPUDefParseXMLHelper;
 virCPUDefStealModel;
 virCPUDefUpdateFeature;
 virCPUModeTypeToString;
-- 
2.7.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux