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

Jiri Denemark jdenemar at redhat.com
Tue Aug 20 14:27:43 UTC 2019


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 at linux.ibm.com>
> Reviewed-by: Bjoern Walk <bwalk at linux.ibm.com>
> Reviewed-by: Daniel Henrique Barboza <danielh413 at 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




More information about the libvir-list mailing list