qemu: capabilities: Convert virQEMUCapsLoadCache to virXMLParse

Use virXMLParse so that the code doesn't have to explicitly allocate
an XPath context and validate the root element.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2022-09-23 14:47:12 +02:00
parent 5d2f69aa68
commit 9b3828e263

View File

@ -4351,22 +4351,9 @@ virQEMUCapsLoadCache(virArch hostArch,
long long int l;
unsigned long lu;
if (!(doc = virXMLParseFile(filename)))
if (!(doc = virXMLParse(filename, NULL, NULL, "qemuCaps", &ctxt, NULL, false)))
return -1;
if (!(ctxt = virXMLXPathContextNew(doc)))
return -1;
ctxt->node = xmlDocGetRootElement(doc);
if (STRNEQ((const char *)ctxt->node->name, "qemuCaps")) {
virReportError(VIR_ERR_XML_ERROR,
_("unexpected root element <%s>, "
"expecting <qemuCaps>"),
ctxt->node->name);
return -1;
}
if (virXPathLongLong("string(./selfctime)", ctxt, &l) < 0) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing selfctime in QEMU capabilities XML"));