1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

conf: Move XPath context node in descendants of virSysinfoParseXML

Rather than moving the XPath root node in the caller and then still
passing it down, make sure that the callees move the node themselves.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2019-03-05 15:38:26 +01:00
parent 8f6ac3b740
commit 933f136844

View File

@ -14606,9 +14606,12 @@ virSysinfoBIOSParseXML(xmlNodePtr node,
xmlXPathContextPtr ctxt, xmlXPathContextPtr ctxt,
virSysinfoBIOSDefPtr *bios) virSysinfoBIOSDefPtr *bios)
{ {
VIR_XPATH_NODE_AUTORESTORE(ctxt);
int ret = -1; int ret = -1;
virSysinfoBIOSDefPtr def; virSysinfoBIOSDefPtr def;
ctxt->node = node;
if (!virXMLNodeNameEqual(node, "bios")) { if (!virXMLNodeNameEqual(node, "bios")) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("XML does not contain expected 'bios' element")); _("XML does not contain expected 'bios' element"));
@ -14666,10 +14669,13 @@ virSysinfoSystemParseXML(xmlNodePtr node,
unsigned char *domUUID, unsigned char *domUUID,
bool uuid_generated) bool uuid_generated)
{ {
VIR_XPATH_NODE_AUTORESTORE(ctxt);
int ret = -1; int ret = -1;
virSysinfoSystemDefPtr def; virSysinfoSystemDefPtr def;
VIR_AUTOFREE(char *) tmpUUID = NULL; VIR_AUTOFREE(char *) tmpUUID = NULL;
ctxt->node = node;
if (!virXMLNodeNameEqual(node, "system")) { if (!virXMLNodeNameEqual(node, "system")) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("XML does not contain expected 'system' element")); _("XML does not contain expected 'system' element"));
@ -14786,15 +14792,19 @@ virSysinfoBaseBoardParseXML(xmlXPathContextPtr ctxt,
static int static int
virSysinfoOEMStringsParseXML(xmlXPathContextPtr ctxt, virSysinfoOEMStringsParseXML(xmlNodePtr node,
xmlXPathContextPtr ctxt,
virSysinfoOEMStringsDefPtr *oem) virSysinfoOEMStringsDefPtr *oem)
{ {
VIR_XPATH_NODE_AUTORESTORE(ctxt);
int ret = -1; int ret = -1;
virSysinfoOEMStringsDefPtr def; virSysinfoOEMStringsDefPtr def;
int nstrings; int nstrings;
size_t i; size_t i;
VIR_AUTOFREE(xmlNodePtr *) strings = NULL; VIR_AUTOFREE(xmlNodePtr *) strings = NULL;
ctxt->node = node;
nstrings = virXPathNodeSet("./entry", ctxt, &strings); nstrings = virXPathNodeSet("./entry", ctxt, &strings);
if (nstrings < 0) if (nstrings < 0)
return -1; return -1;
@ -14824,9 +14834,12 @@ virSysinfoChassisParseXML(xmlNodePtr node,
xmlXPathContextPtr ctxt, xmlXPathContextPtr ctxt,
virSysinfoChassisDefPtr *chassisdef) virSysinfoChassisDefPtr *chassisdef)
{ {
VIR_XPATH_NODE_AUTORESTORE(ctxt);
int ret = -1; int ret = -1;
virSysinfoChassisDefPtr def; virSysinfoChassisDefPtr def;
ctxt->node = node;
if (!xmlStrEqual(node->name, BAD_CAST "chassis")) { if (!xmlStrEqual(node->name, BAD_CAST "chassis")) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("XML does not contain expected 'chassis' element")); _("XML does not contain expected 'chassis' element"));
@ -14868,7 +14881,7 @@ virSysinfoParseXML(xmlNodePtr node,
bool uuid_generated) bool uuid_generated)
{ {
virSysinfoDefPtr def; virSysinfoDefPtr def;
xmlNodePtr oldnode, tmpnode; xmlNodePtr tmpnode;
VIR_AUTOFREE(char *) type = NULL; VIR_AUTOFREE(char *) type = NULL;
if (!virXMLNodeNameEqual(node, "sysinfo")) { if (!virXMLNodeNameEqual(node, "sysinfo")) {
@ -14894,25 +14907,15 @@ virSysinfoParseXML(xmlNodePtr node,
/* Extract BIOS related metadata */ /* Extract BIOS related metadata */
if ((tmpnode = virXPathNode("./bios[1]", ctxt)) != NULL) { if ((tmpnode = virXPathNode("./bios[1]", ctxt)) != NULL) {
oldnode = ctxt->node; if (virSysinfoBIOSParseXML(tmpnode, ctxt, &def->bios) < 0)
ctxt->node = tmpnode;
if (virSysinfoBIOSParseXML(tmpnode, ctxt, &def->bios) < 0) {
ctxt->node = oldnode;
goto error; goto error;
}
ctxt->node = oldnode;
} }
/* Extract system related metadata */ /* Extract system related metadata */
if ((tmpnode = virXPathNode("./system[1]", ctxt)) != NULL) { if ((tmpnode = virXPathNode("./system[1]", ctxt)) != NULL) {
oldnode = ctxt->node;
ctxt->node = tmpnode;
if (virSysinfoSystemParseXML(tmpnode, ctxt, &def->system, if (virSysinfoSystemParseXML(tmpnode, ctxt, &def->system,
domUUID, uuid_generated) < 0) { domUUID, uuid_generated) < 0)
ctxt->node = oldnode;
goto error; goto error;
}
ctxt->node = oldnode;
} }
/* Extract system base board metadata */ /* Extract system base board metadata */
@ -14921,24 +14924,14 @@ virSysinfoParseXML(xmlNodePtr node,
/* Extract chassis related metadata */ /* Extract chassis related metadata */
if ((tmpnode = virXPathNode("./chassis[1]", ctxt)) != NULL) { if ((tmpnode = virXPathNode("./chassis[1]", ctxt)) != NULL) {
oldnode = ctxt->node; if (virSysinfoChassisParseXML(tmpnode, ctxt, &def->chassis) < 0)
ctxt->node = tmpnode;
if (virSysinfoChassisParseXML(tmpnode, ctxt, &def->chassis) < 0) {
ctxt->node = oldnode;
goto error; goto error;
}
ctxt->node = oldnode;
} }
/* Extract system related metadata */ /* Extract system related metadata */
if ((tmpnode = virXPathNode("./oemStrings[1]", ctxt)) != NULL) { if ((tmpnode = virXPathNode("./oemStrings[1]", ctxt)) != NULL) {
oldnode = ctxt->node; if (virSysinfoOEMStringsParseXML(tmpnode, ctxt, &def->oemStrings) < 0)
ctxt->node = tmpnode;
if (virSysinfoOEMStringsParseXML(ctxt, &def->oemStrings) < 0) {
ctxt->node = oldnode;
goto error; goto error;
}
ctxt->node = oldnode;
} }
cleanup: cleanup: