From nobody Fri May 16 01:35:52 2025 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1502713991783195.9633997266708; Mon, 14 Aug 2017 05:33:11 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C5A137972A; Mon, 14 Aug 2017 12:33:09 +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 9533C7900F; Mon, 14 Aug 2017 12:33:09 +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 43FAA180BA88; Mon, 14 Aug 2017 12:33:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v7ECWwoP015602 for ; Mon, 14 Aug 2017 08:32:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9C2E768733; Mon, 14 Aug 2017 12:32:58 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 23F8468710 for ; Mon, 14 Aug 2017 12:32:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C5A137972A Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Date: Mon, 14 Aug 2017 14:32:47 +0200 Message-Id: <6379914e4785602d23a489393090927d06902f5b.1502713940.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 8/8] conf: use virXMLPropString for Domain def parsing 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: , MIME-Version: 1.0 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 14 Aug 2017 12:33:10 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" XPath is good for random search of elements, not for accessing attributes of one node. Signed-off-by: Pavel Hrdina --- src/conf/domain_conf.c | 46 +++++++++++++--------------------------------- 1 file changed, 13 insertions(+), 33 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 23ef46dc79..281dc68f0e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -17140,7 +17140,7 @@ virDomainDefParseBootOptions(virDomainDefPtr def, if (n =3D=3D 1) { oldnode =3D ctxt->node; ctxt->node =3D nodes[0]; - tmp =3D virXPathString("string(./@type)", ctxt); + tmp =3D virXMLPropString(nodes[0], "type"); =20 if (!tmp) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -17221,7 +17221,7 @@ virDomainDefParseXML(xmlDocPtr xml, def->id =3D (int)id; =20 /* Find out what type of virtualization to use */ - if (!(tmp =3D virXPathString("string(./@type)", ctxt))) { + if (!(tmp =3D virXMLPropString(ctxt->node, "type"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing domain type attribute")); goto error; @@ -17812,9 +17812,7 @@ virDomainDefParseXML(xmlDocPtr xml, break; =20 case VIR_DOMAIN_FEATURE_CAPABILITIES: - node =3D ctxt->node; - ctxt->node =3D nodes[i]; - if ((tmp =3D virXPathString("string(./@policy)", ctxt))) { + if ((tmp =3D virXMLPropString(nodes[i], "policy"))) { if ((def->features[val] =3D virDomainCapabilitiesPolicyTyp= eFromString(tmp)) =3D=3D -1) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown state attribute '%s' of feat= ure '%s'"), @@ -17825,7 +17823,6 @@ virDomainDefParseXML(xmlDocPtr xml, } else { def->features[val] =3D VIR_TRISTATE_SWITCH_ABSENT; } - ctxt->node =3D node; break; =20 case VIR_DOMAIN_FEATURE_HAP: @@ -17833,9 +17830,7 @@ virDomainDefParseXML(xmlDocPtr xml, case VIR_DOMAIN_FEATURE_PVSPINLOCK: case VIR_DOMAIN_FEATURE_VMPORT: case VIR_DOMAIN_FEATURE_SMM: - node =3D ctxt->node; - ctxt->node =3D nodes[i]; - if ((tmp =3D virXPathString("string(./@state)", ctxt))) { + if ((tmp =3D virXMLPropString(nodes[i], "state"))) { if ((def->features[val] =3D virTristateSwitchTypeFromStrin= g(tmp)) =3D=3D -1) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown state attribute '%s' of feat= ure '%s'"), @@ -17846,13 +17841,10 @@ virDomainDefParseXML(xmlDocPtr xml, } else { def->features[val] =3D VIR_TRISTATE_SWITCH_ON; } - ctxt->node =3D node; break; =20 case VIR_DOMAIN_FEATURE_GIC: - node =3D ctxt->node; - ctxt->node =3D nodes[i]; - if ((tmp =3D virXPathString("string(./@version)", ctxt))) { + if ((tmp =3D virXMLPropString(nodes[i], "version"))) { gic_version =3D virGICVersionTypeFromString(tmp); if (gic_version < 0 || gic_version =3D=3D VIR_GIC_VERSION_= NONE) { virReportError(VIR_ERR_XML_ERROR, @@ -17863,13 +17855,10 @@ virDomainDefParseXML(xmlDocPtr xml, VIR_FREE(tmp); } def->features[val] =3D VIR_TRISTATE_SWITCH_ON; - ctxt->node =3D node; break; =20 case VIR_DOMAIN_FEATURE_IOAPIC: - node =3D ctxt->node; - ctxt->node =3D nodes[i]; - tmp =3D virXPathString("string(./@driver)", ctxt); + tmp =3D virXMLPropString(nodes[i], "driver"); if (tmp) { int value =3D virDomainIOAPICTypeFromString(tmp); if (value < 0) { @@ -17882,7 +17871,6 @@ virDomainDefParseXML(xmlDocPtr xml, def->features[val] =3D VIR_TRISTATE_SWITCH_ON; VIR_FREE(tmp); } - ctxt->node =3D node; break; =20 /* coverity[dead_error_begin] */ @@ -17910,7 +17898,7 @@ virDomainDefParseXML(xmlDocPtr xml, =20 ctxt->node =3D nodes[i]; =20 - if (!(tmp =3D virXPathString("string(./@state)", ctxt))) { + if (!(tmp =3D virXMLPropString(nodes[i], "state"))) { virReportError(VIR_ERR_XML_ERROR, _("missing 'state' attribute for " "HyperV Enlightenment feature '%s'"), @@ -17962,8 +17950,8 @@ virDomainDefParseXML(xmlDocPtr xml, if (value !=3D VIR_TRISTATE_SWITCH_ON) break; =20 - if (!(def->hyperv_vendor_id =3D virXPathString("string(./@= value)", - ctxt))) { + if (!(def->hyperv_vendor_id =3D virXMLPropString(nodes[i], + "value"))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing 'value' attribute for " "HyperV feature 'vendor_id'")); @@ -17997,7 +17985,6 @@ virDomainDefParseXML(xmlDocPtr xml, if (def->features[VIR_DOMAIN_FEATURE_KVM] =3D=3D VIR_TRISTATE_SWITCH_O= N) { int feature; int value; - node =3D ctxt->node; if ((n =3D virXPathNodeSet("./features/kvm/*", ctxt, &nodes)) < 0) goto error; =20 @@ -18010,11 +17997,9 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } =20 - ctxt->node =3D nodes[i]; - switch ((virDomainKVM) feature) { case VIR_DOMAIN_KVM_HIDDEN: - if (!(tmp =3D virXPathString("string(./@state)", ctxt)= )) { + if (!(tmp =3D virXMLPropString(nodes[i], "state"))) { virReportError(VIR_ERR_XML_ERROR, _("missing 'state' attribute for " "KVM feature '%s'"), @@ -18040,7 +18025,6 @@ virDomainDefParseXML(xmlDocPtr xml, } } VIR_FREE(nodes); - ctxt->node =3D node; } =20 if ((n =3D virXPathNodeSet("./features/capabilities/*", ctxt, &nodes))= < 0) @@ -18055,10 +18039,7 @@ virDomainDefParseXML(xmlDocPtr xml, } =20 if (val >=3D 0 && val < VIR_DOMAIN_CAPS_FEATURE_LAST) { - node =3D ctxt->node; - ctxt->node =3D nodes[i]; - - if ((tmp =3D virXPathString("string(./@state)", ctxt))) { + if ((tmp =3D virXMLPropString(nodes[i], "state"))) { if ((def->caps_features[val] =3D virTristateSwitchTypeFrom= String(tmp)) =3D=3D -1) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown state attribute '%s' of feat= ure capability '%s'"), @@ -18069,7 +18050,6 @@ virDomainDefParseXML(xmlDocPtr xml, } else { def->caps_features[val] =3D VIR_TRISTATE_SWITCH_ON; } - ctxt->node =3D node; } } VIR_FREE(nodes); @@ -18914,7 +18894,7 @@ virDomainObjParseXML(xmlDocPtr xml, if (!obj->def) goto error; =20 - if (!(tmp =3D virXPathString("string(./@state)", ctxt))) { + if (!(tmp =3D virXMLPropString(ctxt->node, "state"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing domain state")); goto error; @@ -18927,7 +18907,7 @@ virDomainObjParseXML(xmlDocPtr xml, } VIR_FREE(tmp); =20 - if ((tmp =3D virXPathString("string(./@reason)", ctxt))) { + if ((tmp =3D virXMLPropString(ctxt->node, "reason"))) { if ((reason =3D virDomainStateReasonFromString(state, tmp)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("invalid domain state reason '%s'"), tmp); --=20 2.13.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list