mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 11:22:23 +00:00
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:
parent
adb689bc2a
commit
d11c4ddbfb
@ -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 ".").
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -101,6 +101,7 @@ virCPUDefIsEqual;
|
||||
virCPUDefListFree;
|
||||
virCPUDefListParse;
|
||||
virCPUDefParseXML;
|
||||
virCPUDefParseXMLString;
|
||||
virCPUDefStealModel;
|
||||
virCPUDefUpdateFeature;
|
||||
virCPUModeTypeToString;
|
||||
|
Loading…
x
Reference in New Issue
Block a user