mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +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
|
* 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 ".").
|
* NULL, the current node of @ctxt is used (i.e., it is a shortcut to ".").
|
||||||
|
@ -182,6 +182,11 @@ virCPUDefCopy(const virCPUDef *cpu);
|
|||||||
virCPUDefPtr
|
virCPUDefPtr
|
||||||
virCPUDefCopyWithoutModel(const virCPUDef *cpu);
|
virCPUDefCopyWithoutModel(const virCPUDef *cpu);
|
||||||
|
|
||||||
|
int
|
||||||
|
virCPUDefParseXMLString(const char *xml,
|
||||||
|
virCPUType type,
|
||||||
|
virCPUDefPtr *cpu);
|
||||||
|
|
||||||
int
|
int
|
||||||
virCPUDefParseXML(xmlXPathContextPtr ctxt,
|
virCPUDefParseXML(xmlXPathContextPtr ctxt,
|
||||||
const char *xpath,
|
const char *xpath,
|
||||||
|
@ -111,31 +111,19 @@ virCPUCompareXML(virArch arch,
|
|||||||
const char *xml,
|
const char *xml,
|
||||||
bool failIncompatible)
|
bool failIncompatible)
|
||||||
{
|
{
|
||||||
xmlDocPtr doc = NULL;
|
|
||||||
xmlXPathContextPtr ctxt = NULL;
|
|
||||||
virCPUDefPtr cpu = NULL;
|
virCPUDefPtr cpu = NULL;
|
||||||
virCPUCompareResult ret = VIR_CPU_COMPARE_ERROR;
|
virCPUCompareResult ret = VIR_CPU_COMPARE_ERROR;
|
||||||
|
|
||||||
VIR_DEBUG("arch=%s, host=%p, xml=%s",
|
VIR_DEBUG("arch=%s, host=%p, xml=%s",
|
||||||
virArchToString(arch), host, NULLSTR(xml));
|
virArchToString(arch), host, NULLSTR(xml));
|
||||||
|
|
||||||
if (!xml) {
|
if (virCPUDefParseXMLString(xml, VIR_CPU_TYPE_AUTO, &cpu) < 0)
|
||||||
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)
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
ret = virCPUCompare(arch, host, cpu, failIncompatible);
|
ret = virCPUCompare(arch, host, cpu, failIncompatible);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virCPUDefFree(cpu);
|
virCPUDefFree(cpu);
|
||||||
xmlXPathFreeContext(ctxt);
|
|
||||||
xmlFreeDoc(doc);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -101,6 +101,7 @@ virCPUDefIsEqual;
|
|||||||
virCPUDefListFree;
|
virCPUDefListFree;
|
||||||
virCPUDefListParse;
|
virCPUDefListParse;
|
||||||
virCPUDefParseXML;
|
virCPUDefParseXML;
|
||||||
|
virCPUDefParseXMLString;
|
||||||
virCPUDefStealModel;
|
virCPUDefStealModel;
|
||||||
virCPUDefUpdateFeature;
|
virCPUDefUpdateFeature;
|
||||||
virCPUModeTypeToString;
|
virCPUModeTypeToString;
|
||||||
|
Loading…
Reference in New Issue
Block a user