cpu_conf: xml to cpu definition parse helper

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>
This commit is contained in:
Collin Walling 2019-09-19 16:25:04 -04:00 committed by Jiri Denemark
parent adb689bc2a
commit d11c4ddbfb
4 changed files with 36 additions and 13 deletions

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

View 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,

View 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;
}

View File

@ -101,6 +101,7 @@ virCPUDefIsEqual;
virCPUDefListFree;
virCPUDefListParse;
virCPUDefParseXML;
virCPUDefParseXMLString;
virCPUDefStealModel;
virCPUDefUpdateFeature;
virCPUModeTypeToString;