[libvirt] [PATCH v4 7/8] cpu_conf: xml to cpu definition parse helper

Collin Walling posted 8 patches 6 years, 6 months ago
There is a newer version of this series
[libvirt] [PATCH v4 7/8] cpu_conf: xml to cpu definition parse helper
Posted by Collin Walling 6 years, 6 months ago
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>
---
 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 7d16a05..c587aff 100644
--- a/src/conf/cpu_conf.c
+++ b/src/conf/cpu_conf.c
@@ -268,6 +268,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 19ce816..a0efac8 100644
--- a/src/conf/cpu_conf.h
+++ b/src/conf/cpu_conf.h
@@ -183,6 +183,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 b89462c..31ee887 100644
--- a/src/cpu/cpu.c
+++ b/src/cpu/cpu.c
@@ -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 (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 4e77cf5..ea5edab 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -90,6 +90,7 @@ virCPUDefIsEqual;
 virCPUDefListFree;
 virCPUDefListParse;
 virCPUDefParseXML;
+virCPUDefParseXMLHelper;
 virCPUDefStealModel;
 virCPUDefUpdateFeature;
 virCPUModeTypeToString;
-- 
2.7.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v4 7/8] cpu_conf: xml to cpu definition parse helper
Posted by Boris Fiuczynski 6 years, 6 months ago
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>

On 7/17/19 4:03 PM, Collin Walling wrote:
> 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>
> ---
>   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 7d16a05..c587aff 100644
> --- a/src/conf/cpu_conf.c
> +++ b/src/conf/cpu_conf.c
> @@ -268,6 +268,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 19ce816..a0efac8 100644
> --- a/src/conf/cpu_conf.h
> +++ b/src/conf/cpu_conf.h
> @@ -183,6 +183,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 b89462c..31ee887 100644
> --- a/src/cpu/cpu.c
> +++ b/src/cpu/cpu.c
> @@ -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 (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 4e77cf5..ea5edab 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -90,6 +90,7 @@ virCPUDefIsEqual;
>   virCPUDefListFree;
>   virCPUDefListParse;
>   virCPUDefParseXML;
> +virCPUDefParseXMLHelper;
>   virCPUDefStealModel;
>   virCPUDefUpdateFeature;
>   virCPUModeTypeToString;
> 


-- 
Mit freundlichen Grüßen/Kind regards
    Boris Fiuczynski

IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Matthias Hartmann
Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v4 7/8] cpu_conf: xml to cpu definition parse helper
Posted by Jiri Denemark 6 years, 5 months ago
On Wed, Jul 17, 2019 at 10:03:28 -0400, Collin Walling wrote:
> 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>
> ---
>  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 7d16a05..c587aff 100644
> --- a/src/conf/cpu_conf.c
> +++ b/src/conf/cpu_conf.c
> @@ -268,6 +268,36 @@ virCPUDefCopy(const virCPUDef *cpu)
>  }
>  
>  
> +int
> +virCPUDefParseXMLHelper(const char *xml,

I would call this virCPUDefParseXMLString for consistency with other
parsing functions. If there are several variants of the parsing function
with different input types, the String suffix is used for the variant
that parses an XML string.

> +                        const char *xpath,

And the callers of this function should not ever need the xpath
parameter. It should go away.

> +                        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 ".").
...

Jirka

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