提交 d11c4ddb 编写于 作者: C Collin Walling 提交者: Jiri Denemark

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: NCollin Walling <walling@linux.ibm.com>
Reviewed-by: NBjoern Walk <bwalk@linux.ibm.com>
Reviewed-by: NDaniel Henrique Barboza <danielh413@gmail.com>
Message-Id: <1568924706-2311-14-git-send-email-walling@linux.ibm.com>
Reviewed-by: NJiri Denemark <jdenemar@redhat.com>
上级 adb689bc
...@@ -268,6 +268,35 @@ virCPUDefCopy(const virCPUDef *cpu) ...@@ -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); ...@@ -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, ...@@ -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; ...@@ -101,6 +101,7 @@ virCPUDefIsEqual;
virCPUDefListFree; virCPUDefListFree;
virCPUDefListParse; virCPUDefListParse;
virCPUDefParseXML; virCPUDefParseXML;
virCPUDefParseXMLString;
virCPUDefStealModel; virCPUDefStealModel;
virCPUDefUpdateFeature; virCPUDefUpdateFeature;
virCPUModeTypeToString; virCPUModeTypeToString;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册