From nobody Mon Feb 9 01:31:07 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1551860486968985.7660752049259; Wed, 6 Mar 2019 00:21:26 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3EA1181E08; Wed, 6 Mar 2019 08:21:25 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 00A9F5D78F; Wed, 6 Mar 2019 08:21:24 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id A8182181A26C; Wed, 6 Mar 2019 08:21:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x268LC6k032658 for ; Wed, 6 Mar 2019 03:21:12 -0500 Received: by smtp.corp.redhat.com (Postfix) id BB85A1A91B; Wed, 6 Mar 2019 08:21:12 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3FA511A267 for ; Wed, 6 Mar 2019 08:21:12 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 09:20:47 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 22/23] conf: Move XPath context node in descendants of virSysinfoParseXML X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 06 Mar 2019 08:21:25 +0000 (UTC) Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 45 ++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ea4fbf2280..bbeb1c1a8d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -14606,9 +14606,12 @@ virSysinfoBIOSParseXML(xmlNodePtr node, xmlXPathContextPtr ctxt, virSysinfoBIOSDefPtr *bios) { + VIR_XPATH_NODE_AUTORESTORE(ctxt); int ret =3D -1; virSysinfoBIOSDefPtr def; + ctxt->node =3D node; + if (!virXMLNodeNameEqual(node, "bios")) { virReportError(VIR_ERR_XML_ERROR, "%s", _("XML does not contain expected 'bios' element")); @@ -14666,10 +14669,13 @@ virSysinfoSystemParseXML(xmlNodePtr node, unsigned char *domUUID, bool uuid_generated) { + VIR_XPATH_NODE_AUTORESTORE(ctxt); int ret =3D -1; virSysinfoSystemDefPtr def; VIR_AUTOFREE(char *) tmpUUID =3D NULL; + ctxt->node =3D node; + if (!virXMLNodeNameEqual(node, "system")) { virReportError(VIR_ERR_XML_ERROR, "%s", _("XML does not contain expected 'system' element")= ); @@ -14786,15 +14792,19 @@ virSysinfoBaseBoardParseXML(xmlXPathContextPtr ct= xt, static int -virSysinfoOEMStringsParseXML(xmlXPathContextPtr ctxt, +virSysinfoOEMStringsParseXML(xmlNodePtr node, + xmlXPathContextPtr ctxt, virSysinfoOEMStringsDefPtr *oem) { + VIR_XPATH_NODE_AUTORESTORE(ctxt); int ret =3D -1; virSysinfoOEMStringsDefPtr def; int nstrings; size_t i; VIR_AUTOFREE(xmlNodePtr *) strings =3D NULL; + ctxt->node =3D node; + nstrings =3D virXPathNodeSet("./entry", ctxt, &strings); if (nstrings < 0) return -1; @@ -14824,9 +14834,12 @@ virSysinfoChassisParseXML(xmlNodePtr node, xmlXPathContextPtr ctxt, virSysinfoChassisDefPtr *chassisdef) { + VIR_XPATH_NODE_AUTORESTORE(ctxt); int ret =3D -1; virSysinfoChassisDefPtr def; + ctxt->node =3D node; + if (!xmlStrEqual(node->name, BAD_CAST "chassis")) { virReportError(VIR_ERR_XML_ERROR, "%s", _("XML does not contain expected 'chassis' element"= )); @@ -14868,7 +14881,7 @@ virSysinfoParseXML(xmlNodePtr node, bool uuid_generated) { virSysinfoDefPtr def; - xmlNodePtr oldnode, tmpnode; + xmlNodePtr tmpnode; VIR_AUTOFREE(char *) type =3D NULL; if (!virXMLNodeNameEqual(node, "sysinfo")) { @@ -14894,25 +14907,15 @@ virSysinfoParseXML(xmlNodePtr node, /* Extract BIOS related metadata */ if ((tmpnode =3D virXPathNode("./bios[1]", ctxt)) !=3D NULL) { - oldnode =3D ctxt->node; - ctxt->node =3D tmpnode; - if (virSysinfoBIOSParseXML(tmpnode, ctxt, &def->bios) < 0) { - ctxt->node =3D oldnode; + if (virSysinfoBIOSParseXML(tmpnode, ctxt, &def->bios) < 0) goto error; - } - ctxt->node =3D oldnode; } /* Extract system related metadata */ if ((tmpnode =3D virXPathNode("./system[1]", ctxt)) !=3D NULL) { - oldnode =3D ctxt->node; - ctxt->node =3D tmpnode; if (virSysinfoSystemParseXML(tmpnode, ctxt, &def->system, - domUUID, uuid_generated) < 0) { - ctxt->node =3D oldnode; + domUUID, uuid_generated) < 0) goto error; - } - ctxt->node =3D oldnode; } /* Extract system base board metadata */ @@ -14921,24 +14924,14 @@ virSysinfoParseXML(xmlNodePtr node, /* Extract chassis related metadata */ if ((tmpnode =3D virXPathNode("./chassis[1]", ctxt)) !=3D NULL) { - oldnode =3D ctxt->node; - ctxt->node =3D tmpnode; - if (virSysinfoChassisParseXML(tmpnode, ctxt, &def->chassis) < 0) { - ctxt->node =3D oldnode; + if (virSysinfoChassisParseXML(tmpnode, ctxt, &def->chassis) < 0) goto error; - } - ctxt->node =3D oldnode; } /* Extract system related metadata */ if ((tmpnode =3D virXPathNode("./oemStrings[1]", ctxt)) !=3D NULL) { - oldnode =3D ctxt->node; - ctxt->node =3D tmpnode; - if (virSysinfoOEMStringsParseXML(ctxt, &def->oemStrings) < 0) { - ctxt->node =3D oldnode; + if (virSysinfoOEMStringsParseXML(tmpnode, ctxt, &def->oemStrings) = < 0) goto error; - } - ctxt->node =3D oldnode; } cleanup: --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list