From nobody Mon Apr 29 01:14:34 2024 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 15028872572989.070412321896015; Wed, 16 Aug 2017 05:40:57 -0700 (PDT) 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 5BC1A4022C; Wed, 16 Aug 2017 12:40:55 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F16C36FE4D; Wed, 16 Aug 2017 12:40:54 +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 A6CE03FACE; Wed, 16 Aug 2017 12:40:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v7GCepxa021693 for ; Wed, 16 Aug 2017 08:40:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9CFFA7DB2D; Wed, 16 Aug 2017 12:40:51 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 22CA67DB20 for ; Wed, 16 Aug 2017 12:40:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5BC1A4022C Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Date: Wed, 16 Aug 2017 14:40:38 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 01/10] util: introduce virXMLPropStringLimit 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 16 Aug 2017 12:40:55 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The virXMLPropStringLimit is an equivalent of virXPathStringLimit which should be preferred if you already have a XML dom node or if you need to parse more than one property. Signed-off-by: Pavel Hrdina --- src/libvirt_private.syms | 1 + src/util/virxml.c | 52 +++++++++++++++++++++++++++++++++++++++-----= ---- src/util/virxml.h | 3 +++ 3 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 6e4c3e83b9..7646998aef 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2939,6 +2939,7 @@ virXMLNodeToString; virXMLParseHelper; virXMLPickShellSafeComment; virXMLPropString; +virXMLPropStringLimit; virXMLSaveFile; virXMLValidateAgainstSchema; virXMLValidatorFree; diff --git a/src/util/virxml.c b/src/util/virxml.c index b42358a08c..2904fc16c9 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -92,6 +92,24 @@ virXPathString(const char *xpath, return ret; } =20 + +static char * +virXMLStringLimitInternal(char *value, + size_t maxlen, + const char *name) +{ + if (value !=3D NULL && strlen(value) >=3D maxlen) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("'%s' value longer than '%zu' bytes"), + name, maxlen); + VIR_FREE(value); + return NULL; + } + + return value; +} + + /** * virXPathStringLimit: * @xpath: the XPath string to evaluate @@ -111,15 +129,7 @@ virXPathStringLimit(const char *xpath, { char *tmp =3D virXPathString(xpath, ctxt); =20 - if (tmp !=3D NULL && strlen(tmp) >=3D maxlen) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("\'%s\' value longer than %zu bytes"), - xpath, maxlen); - VIR_FREE(tmp); - return NULL; - } - - return tmp; + return virXMLStringLimitInternal(tmp, maxlen, xpath); } =20 /** @@ -506,6 +516,30 @@ virXMLPropString(xmlNodePtr node, return (char *)xmlGetProp(node, BAD_CAST name); } =20 + +/** + * virXMLPropStringLimit: + * @node: XML dom node pointer + * @name: Name of the property (attribute) to get + * @maxlen: maximum length permitted string + * + * Wrapper for virXMLPropString, which validates the length of the returned + * string. + * + * Returns a new string which must be deallocated by the caller or NULL if + * the evaluation failed. + */ +char * +virXMLPropStringLimit(xmlNodePtr node, + const char *name, + size_t maxlen) +{ + char *tmp =3D (char *)xmlGetProp(node, BAD_CAST name); + + return virXMLStringLimitInternal(tmp, maxlen, name); +} + + /** * virXPathBoolean: * @xpath: the XPath string to evaluate diff --git a/src/util/virxml.h b/src/util/virxml.h index 2f953a6d44..1ecc6b0a61 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -73,6 +73,9 @@ int virXPathNodeSet(const char *xpath, xmlNodePtr **list); char * virXMLPropString(xmlNodePtr node, const char *name); +char * virXMLPropStringLimit(xmlNodePtr node, + const char *name, + size_t maxlen); long virXMLChildElementCount(xmlNodePtr node); =20 /* Internal function; prefer the macros below. */ --=20 2.13.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 01:14:34 2024 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 150288725703563.825160698952345; Wed, 16 Aug 2017 05:40:57 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 41A9FC062EB2; Wed, 16 Aug 2017 12:40:55 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EC7EB60627; Wed, 16 Aug 2017 12:40:54 +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 931963FACF; Wed, 16 Aug 2017 12:40:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v7GCeqFQ021706 for ; Wed, 16 Aug 2017 08:40:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id 997F57DB38; Wed, 16 Aug 2017 12:40:52 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 203DE7DB51 for ; Wed, 16 Aug 2017 12:40:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 41A9FC062EB2 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Date: Wed, 16 Aug 2017 14:40:39 +0200 Message-Id: <963f2fc75daa0f1874d2fbf8a863fbcfa1000748.1502887192.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 02/10] util: introduce virXMLNodeContentString 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 16 Aug 2017 12:40:55 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" It's equivalent of calling virXPahtString("string(.)", ctxt) but it doesn't have to use the XPath resolving and parsing. Signed-off-by: Pavel Hrdina --- src/libvirt_private.syms | 1 + src/util/virxml.c | 16 ++++++++++++++++ src/util/virxml.h | 1 + 3 files changed, 18 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 7646998aef..f0e1e3eb6e 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2933,6 +2933,7 @@ virVHBAPathExists; virXMLCheckIllegalChars; virXMLChildElementCount; virXMLExtractNamespaceXML; +virXMLNodeContentString; virXMLNodeNameEqual; virXMLNodeSanitizeNamespaces; virXMLNodeToString; diff --git a/src/util/virxml.c b/src/util/virxml.c index 2904fc16c9..cf9122f261 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -541,6 +541,22 @@ virXMLPropStringLimit(xmlNodePtr node, =20 =20 /** + * virXMLNodeContentString: + * @node: XML dom node pointer + * + * Convenience function to return copy of content of an XML node. + * + * Returns the content value as string or NULL in case of failure. + * The caller is responsible for freeing the returned buffer. + */ +char * +virXMLNodeContentString(xmlNodePtr node) +{ + return (char *)xmlNodeGetContent(node); +} + + +/** * virXPathBoolean: * @xpath: the XPath string to evaluate * @ctxt: an XPath context diff --git a/src/util/virxml.h b/src/util/virxml.h index 1ecc6b0a61..86baeb37a7 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -76,6 +76,7 @@ char * virXMLPropString(xmlNodePtr node, char * virXMLPropStringLimit(xmlNodePtr node, const char *name, size_t maxlen); +char * virXMLNodeContentString(xmlNodePtr node); long virXMLChildElementCount(xmlNodePtr node); =20 /* Internal function; prefer the macros below. */ --=20 2.13.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 01:14:34 2024 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 1502887271515459.99247881531574; Wed, 16 Aug 2017 05:41:11 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CD497CAA6F; Wed, 16 Aug 2017 12:41: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 9C8725C542; Wed, 16 Aug 2017 12:41: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 4A54F1806105; Wed, 16 Aug 2017 12:41:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v7GCerM8021714 for ; Wed, 16 Aug 2017 08:40:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 71D527D971; Wed, 16 Aug 2017 12:40:53 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id E63F77D57E for ; Wed, 16 Aug 2017 12:40:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CD497CAA6F Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Date: Wed, 16 Aug 2017 14:40:40 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 03/10] conf: use virXMLPropString for virDomainVirtioOptionsParseXML 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 16 Aug 2017 12:41: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 | 49 ++++++++++++++++++++++++++++------------------= --- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 281dc68f0e..ec4fbf36b3 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1114,7 +1114,7 @@ virDomainXMLOptionGetNamespace(virDomainXMLOptionPtr = xmlopt) } =20 static int -virDomainVirtioOptionsParseXML(xmlXPathContextPtr ctxt, +virDomainVirtioOptionsParseXML(xmlNodePtr driver, virDomainVirtioOptionsPtr *virtio) { char *str =3D NULL; @@ -1122,12 +1122,15 @@ virDomainVirtioOptionsParseXML(xmlXPathContextPtr c= txt, int val; virDomainVirtioOptionsPtr res; =20 + if (*virtio || !driver) + return 0; + if (VIR_ALLOC(*virtio) < 0) return -1; =20 res =3D *virtio; =20 - if ((str =3D virXPathString("string(./driver/@iommu)", ctxt))) { + if ((str =3D virXMLPropString(driver, "iommu"))) { if ((val =3D virTristateSwitchTypeFromString(str)) <=3D 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("invalid iommu value")); @@ -1137,7 +1140,7 @@ virDomainVirtioOptionsParseXML(xmlXPathContextPtr ctx= t, } VIR_FREE(str); =20 - if ((str =3D virXPathString("string(./driver/@ats)", ctxt))) { + if ((str =3D virXMLPropString(driver, "ats"))) { if ((val =3D virTristateSwitchTypeFromString(str)) <=3D 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("invalid ats value")); @@ -8406,6 +8409,9 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, } } else if (!def->src->driverName && virXMLNodeNameEqual(cur, "driver")) { + if (virDomainVirtioOptionsParseXML(cur, &def->virtio) < 0) + goto error; + if (virDomainDiskDefDriverParseXML(def, cur) < 0) goto error; } else if (!def->mirror && @@ -8491,9 +8497,6 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, } } =20 - if (virDomainVirtioOptionsParseXML(ctxt, &def->virtio) < 0) - goto error; - /* Disk volume types will have authentication information handled in * virStorageTranslateDiskSourcePool */ @@ -9078,6 +9081,9 @@ virDomainControllerDefParseXML(xmlNodePtr node, max_sectors =3D virXMLPropString(cur, "max_sectors"); ioeventfd =3D virXMLPropString(cur, "ioeventfd"); iothread =3D virXMLPropString(cur, "iothread"); + + if (virDomainVirtioOptionsParseXML(cur, &def->virtio) < 0) + goto error; } else if (virXMLNodeNameEqual(cur, "model")) { if (processedModel) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -9105,9 +9111,6 @@ virDomainControllerDefParseXML(xmlNodePtr node, cur =3D cur->next; } =20 - if (virDomainVirtioOptionsParseXML(ctxt, &def->virtio) < 0) - goto error; - /* node is parsed differently from target attributes because * someone thought it should be a subelement instead... */ @@ -9483,6 +9486,9 @@ virDomainFSDefParseXML(xmlNodePtr node, wrpolicy =3D virXMLPropString(cur, "wrpolicy"); if (!format) format =3D virXMLPropString(cur, "format"); + + if (virDomainVirtioOptionsParseXML(cur, &def->virtio) < 0) + goto error; } } cur =3D cur->next; @@ -9544,9 +9550,6 @@ virDomainFSDefParseXML(xmlNodePtr node, goto error; } =20 - if (virDomainVirtioOptionsParseXML(ctxt, &def->virtio) < 0) - goto error; - def->src->path =3D source; source =3D NULL; def->dst =3D target; @@ -9986,6 +9989,9 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt, queues =3D virXMLPropString(cur, "queues"); rx_queue_size =3D virXMLPropString(cur, "rx_queue_size"); tx_queue_size =3D virXMLPropString(cur, "tx_queue_size"); + + if (virDomainVirtioOptionsParseXML(cur, &def->virtio) < 0) + goto error; } else if (virXMLNodeNameEqual(cur, "filterref")) { if (filter) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -10563,9 +10569,6 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlop= t, goto error; } =20 - if (virDomainVirtioOptionsParseXML(ctxt, &def->virtio) < 0) - goto error; - cleanup: ctxt->node =3D oldnode; VIR_FREE(macaddr); @@ -11689,7 +11692,8 @@ virDomainInputDefParseXML(const virDomainDef *dom, goto error; } =20 - if (virDomainVirtioOptionsParseXML(ctxt, &def->virtio) < 0) + if (virDomainVirtioOptionsParseXML(virXPathNode("./driver", ctxt), + &def->virtio) < 0) goto error; =20 cleanup: @@ -13028,7 +13032,8 @@ virDomainRNGDefParseXML(virDomainXMLOptionPtr xmlop= t, if (virDomainDeviceInfoParseXML(node, NULL, &def->info, flags) < 0) goto error; =20 - if (virDomainVirtioOptionsParseXML(ctxt, &def->virtio) < 0) + if (virDomainVirtioOptionsParseXML(virXPathNode("./driver", ctxt), + &def->virtio) < 0) goto error; =20 cleanup: @@ -13096,7 +13101,8 @@ virDomainMemballoonDefParseXML(xmlNodePtr node, else if (virDomainDeviceInfoParseXML(node, NULL, &def->info, flags) < = 0) goto error; =20 - if (virDomainVirtioOptionsParseXML(ctxt, &def->virtio) < 0) + if (virDomainVirtioOptionsParseXML(virXPathNode("./driver", ctxt), + &def->virtio) < 0) goto error; =20 cleanup: @@ -13681,6 +13687,10 @@ virDomainVideoDefParseXML(xmlNodePtr node, =20 def->accel =3D virDomainVideoAccelDefParseXML(cur); } + if (virXMLNodeNameEqual(cur, "driver")) { + if (virDomainVirtioOptionsParseXML(cur, &def->virtio) < 0) + goto error; + } } cur =3D cur->next; } @@ -13759,9 +13769,6 @@ virDomainVideoDefParseXML(xmlNodePtr node, if (virDomainDeviceInfoParseXML(node, NULL, &def->info, flags) < 0) goto error; =20 - if (virDomainVirtioOptionsParseXML(ctxt, &def->virtio) < 0) - goto error; - def->driver =3D virDomainVideoDriverDefParseXML(node); =20 cleanup: --=20 2.13.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 01:14:34 2024 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 1502887273869463.56263874525314; Wed, 16 Aug 2017 05:41:13 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EE82479754; Wed, 16 Aug 2017 12:41:11 +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 C8C4B7E38D; Wed, 16 Aug 2017 12:41:11 +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 4B9AA1806107; Wed, 16 Aug 2017 12:41:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v7GCesfO021726 for ; Wed, 16 Aug 2017 08:40:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id 697937D57E; Wed, 16 Aug 2017 12:40:54 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id E60527DB27 for ; Wed, 16 Aug 2017 12:40:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com EE82479754 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: Wed, 16 Aug 2017 14:40:41 +0200 Message-Id: <2094fd9e7e605590eb6f900c040756832da14965.1502887192.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 04/10] conf: use virXMLPropString for IOMMU 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 16 Aug 2017 12:41:12 +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 --- Notes: hint: review with -b src/conf/domain_conf.c | 57 ++++++++++++++++++++++++++--------------------= ---- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ec4fbf36b3..4138a87f8b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -14429,6 +14429,7 @@ virDomainIOMMUDefParseXML(xmlNodePtr node, { virDomainIOMMUDefPtr iommu =3D NULL, ret =3D NULL; xmlNodePtr save =3D ctxt->node; + xmlNodePtr driver; char *tmp =3D NULL; int val; =20 @@ -14450,39 +14451,41 @@ virDomainIOMMUDefParseXML(xmlNodePtr node, =20 iommu->model =3D val; =20 - VIR_FREE(tmp); - if ((tmp =3D virXPathString("string(./driver/@intremap)", ctxt))) { - if ((val =3D virTristateSwitchTypeFromString(tmp)) < 0) { - virReportError(VIR_ERR_XML_ERROR, _("unknown intremap value: %= s"), tmp); - goto cleanup; + if ((driver =3D virXPathNode("./driver", ctxt))) { + VIR_FREE(tmp); + if ((tmp =3D virXMLPropString(driver, "intremap"))) { + if ((val =3D virTristateSwitchTypeFromString(tmp)) < 0) { + virReportError(VIR_ERR_XML_ERROR, _("unknown intremap valu= e: %s"), tmp); + goto cleanup; + } + iommu->intremap =3D val; } - iommu->intremap =3D val; - } =20 - VIR_FREE(tmp); - if ((tmp =3D virXPathString("string(./driver/@caching_mode)", ctxt))) { - if ((val =3D virTristateSwitchTypeFromString(tmp)) < 0) { - virReportError(VIR_ERR_XML_ERROR, _("unknown caching_mode valu= e: %s"), tmp); - goto cleanup; + VIR_FREE(tmp); + if ((tmp =3D virXMLPropString(driver, "caching_mode"))) { + if ((val =3D virTristateSwitchTypeFromString(tmp)) < 0) { + virReportError(VIR_ERR_XML_ERROR, _("unknown caching_mode = value: %s"), tmp); + goto cleanup; + } + iommu->caching_mode =3D val; } - iommu->caching_mode =3D val; - } - VIR_FREE(tmp); - if ((tmp =3D virXPathString("string(./driver/@iotlb)", ctxt))) { - if ((val =3D virTristateSwitchTypeFromString(tmp)) < 0) { - virReportError(VIR_ERR_XML_ERROR, _("unknown iotlb value: %s")= , tmp); - goto cleanup; + VIR_FREE(tmp); + if ((tmp =3D virXMLPropString(driver, "iotlb"))) { + if ((val =3D virTristateSwitchTypeFromString(tmp)) < 0) { + virReportError(VIR_ERR_XML_ERROR, _("unknown iotlb value: = %s"), tmp); + goto cleanup; + } + iommu->iotlb =3D val; } - iommu->iotlb =3D val; - } =20 - VIR_FREE(tmp); - if ((tmp =3D virXPathString("string(./driver/@eim)", ctxt))) { - if ((val =3D virTristateSwitchTypeFromString(tmp)) < 0) { - virReportError(VIR_ERR_XML_ERROR, _("unknown eim value: %s"), = tmp); - goto cleanup; + VIR_FREE(tmp); + if ((tmp =3D virXMLPropString(driver, "eim"))) { + if ((val =3D virTristateSwitchTypeFromString(tmp)) < 0) { + virReportError(VIR_ERR_XML_ERROR, _("unknown eim value: %s= "), tmp); + goto cleanup; + } + iommu->eim =3D val; } - iommu->eim =3D val; } =20 ret =3D iommu; --=20 2.13.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 01:14:34 2024 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 1502887277705733.4500877446561; Wed, 16 Aug 2017 05:41:17 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C0A667790C; Wed, 16 Aug 2017 12:41:15 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 97AB06062D; Wed, 16 Aug 2017 12:41:15 +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 62D753FAD7; Wed, 16 Aug 2017 12:41:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v7GCetR5021734 for ; Wed, 16 Aug 2017 08:40:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3DD537D57E; Wed, 16 Aug 2017 12:40:55 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id B673B7D971 for ; Wed, 16 Aug 2017 12:40:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C0A667790C 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: Wed, 16 Aug 2017 14:40:42 +0200 Message-Id: <2288dbf47616df0d9007f67c2b5076e21c1af413.1502887192.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 05/10] conf: use virXMLPropString for network 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 16 Aug 2017 12:41:16 +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 --- Notes: hint: review with -b src/conf/domain_conf.c | 223 +++++++++++++++++++++++++--------------------= ---- 1 file changed, 116 insertions(+), 107 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 4138a87f8b..90f3f55f25 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -9793,6 +9793,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt, virDomainNetDefPtr def; virDomainHostdevDefPtr hostdev; xmlNodePtr cur; + xmlNodePtr tmpNode; char *macaddr =3D NULL; char *type =3D NULL; char *network =3D NULL; @@ -9952,8 +9953,10 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt, if (!localaddr && def->type =3D=3D VIR_DOMAIN_NET_TYPE_UDP= ) { xmlNodePtr tmpnode =3D ctxt->node; ctxt->node =3D cur; - localaddr =3D virXPathString("string(./local/@address)= ", ctxt); - localport =3D virXPathString("string(./local/@port)", = ctxt); + if ((tmpNode =3D virXPathNode("./local", ctxt))) { + localaddr =3D virXMLPropString(tmpNode, "address"); + localport =3D virXMLPropString(tmpNode, "port"); + } ctxt->node =3D tmpnode; } } else if (!ifname && @@ -10399,124 +10402,130 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr x= mlopt, } def->driver.virtio.tx_queue_size =3D q; } - if ((str =3D virXPathString("string(./driver/host/@csum)", ctxt)))= { - if ((val =3D virTristateSwitchTypeFromString(str)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown host csum mode '%s'"), - str); - goto error; + + if ((tmpNode =3D virXPathNode("./driver/host", ctxt))) { + if ((str =3D virXMLPropString(tmpNode, "csum"))) { + if ((val =3D virTristateSwitchTypeFromString(str)) <=3D 0)= { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown host csum mode '%s'"), + str); + goto error; + } + def->driver.virtio.host.csum =3D val; } - def->driver.virtio.host.csum =3D val; - } - VIR_FREE(str); - if ((str =3D virXPathString("string(./driver/host/@gso)", ctxt))) { - if ((val =3D virTristateSwitchTypeFromString(str)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown host gso mode '%s'"), - str); - goto error; + VIR_FREE(str); + if ((str =3D virXMLPropString(tmpNode, "gso"))) { + if ((val =3D virTristateSwitchTypeFromString(str)) <=3D 0)= { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown host gso mode '%s'"), + str); + goto error; + } + def->driver.virtio.host.gso =3D val; } - def->driver.virtio.host.gso =3D val; - } - VIR_FREE(str); - if ((str =3D virXPathString("string(./driver/host/@tso4)", ctxt)))= { - if ((val =3D virTristateSwitchTypeFromString(str)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown host tso4 mode '%s'"), - str); - goto error; + VIR_FREE(str); + if ((str =3D virXMLPropString(tmpNode, "tso4"))) { + if ((val =3D virTristateSwitchTypeFromString(str)) <=3D 0)= { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown host tso4 mode '%s'"), + str); + goto error; + } + def->driver.virtio.host.tso4 =3D val; } - def->driver.virtio.host.tso4 =3D val; - } - VIR_FREE(str); - if ((str =3D virXPathString("string(./driver/host/@tso6)", ctxt)))= { - if ((val =3D virTristateSwitchTypeFromString(str)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown host tso6 mode '%s'"), - str); - goto error; + VIR_FREE(str); + if ((str =3D virXMLPropString(tmpNode, "tso6"))) { + if ((val =3D virTristateSwitchTypeFromString(str)) <=3D 0)= { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown host tso6 mode '%s'"), + str); + goto error; + } + def->driver.virtio.host.tso6 =3D val; } - def->driver.virtio.host.tso6 =3D val; - } - VIR_FREE(str); - if ((str =3D virXPathString("string(./driver/host/@ecn)", ctxt))) { - if ((val =3D virTristateSwitchTypeFromString(str)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown host ecn mode '%s'"), - str); - goto error; + VIR_FREE(str); + if ((str =3D virXMLPropString(tmpNode, "ecn"))) { + if ((val =3D virTristateSwitchTypeFromString(str)) <=3D 0)= { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown host ecn mode '%s'"), + str); + goto error; + } + def->driver.virtio.host.ecn =3D val; } - def->driver.virtio.host.ecn =3D val; - } - VIR_FREE(str); - if ((str =3D virXPathString("string(./driver/host/@ufo)", ctxt))) { - if ((val =3D virTristateSwitchTypeFromString(str)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown host ufo mode '%s'"), - str); - goto error; + VIR_FREE(str); + if ((str =3D virXMLPropString(tmpNode, "ufo"))) { + if ((val =3D virTristateSwitchTypeFromString(str)) <=3D 0)= { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown host ufo mode '%s'"), + str); + goto error; + } + def->driver.virtio.host.ufo =3D val; } - def->driver.virtio.host.ufo =3D val; - } - VIR_FREE(str); - if ((str =3D virXPathString("string(./driver/host/@mrg_rxbuf)", ct= xt))) { - if ((val =3D virTristateSwitchTypeFromString(str)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown host mrg_rxbuf mode '%s'"), - str); - goto error; + VIR_FREE(str); + if ((str =3D virXMLPropString(tmpNode, "mrg_rxbuf"))) { + if ((val =3D virTristateSwitchTypeFromString(str)) <=3D 0)= { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown host mrg_rxbuf mode '%s'"), + str); + goto error; + } + def->driver.virtio.host.mrg_rxbuf =3D val; } - def->driver.virtio.host.mrg_rxbuf =3D val; + VIR_FREE(str); } - VIR_FREE(str); - if ((str =3D virXPathString("string(./driver/guest/@csum)", ctxt))= ) { - if ((val =3D virTristateSwitchTypeFromString(str)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown guest csum mode '%s'"), - str); - goto error; + + if ((tmpNode =3D virXPathNode("./driver/guest", ctxt))) { + if ((str =3D virXMLPropString(tmpNode, "csum"))) { + if ((val =3D virTristateSwitchTypeFromString(str)) <=3D 0)= { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown guest csum mode '%s'"), + str); + goto error; + } + def->driver.virtio.guest.csum =3D val; } - def->driver.virtio.guest.csum =3D val; - } - VIR_FREE(str); - if ((str =3D virXPathString("string(./driver/guest/@tso4)", ctxt))= ) { - if ((val =3D virTristateSwitchTypeFromString(str)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown guest tso4 mode '%s'"), - str); - goto error; + VIR_FREE(str); + if ((str =3D virXMLPropString(tmpNode, "tso4"))) { + if ((val =3D virTristateSwitchTypeFromString(str)) <=3D 0)= { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown guest tso4 mode '%s'"), + str); + goto error; + } + def->driver.virtio.guest.tso4 =3D val; } - def->driver.virtio.guest.tso4 =3D val; - } - VIR_FREE(str); - if ((str =3D virXPathString("string(./driver/guest/@tso6)", ctxt))= ) { - if ((val =3D virTristateSwitchTypeFromString(str)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown guest tso6 mode '%s'"), - str); - goto error; + VIR_FREE(str); + if ((str =3D virXMLPropString(tmpNode, "tso6"))) { + if ((val =3D virTristateSwitchTypeFromString(str)) <=3D 0)= { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown guest tso6 mode '%s'"), + str); + goto error; + } + def->driver.virtio.guest.tso6 =3D val; } - def->driver.virtio.guest.tso6 =3D val; - } - VIR_FREE(str); - if ((str =3D virXPathString("string(./driver/guest/@ecn)", ctxt)))= { - if ((val =3D virTristateSwitchTypeFromString(str)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown guest ecn mode '%s'"), - str); - goto error; + VIR_FREE(str); + if ((str =3D virXMLPropString(tmpNode, "ecn"))) { + if ((val =3D virTristateSwitchTypeFromString(str)) <=3D 0)= { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown guest ecn mode '%s'"), + str); + goto error; + } + def->driver.virtio.guest.ecn =3D val; } - def->driver.virtio.guest.ecn =3D val; - } - VIR_FREE(str); - if ((str =3D virXPathString("string(./driver/guest/@ufo)", ctxt)))= { - if ((val =3D virTristateSwitchTypeFromString(str)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown guest ufo mode '%s'"), - str); - goto error; + VIR_FREE(str); + if ((str =3D virXMLPropString(tmpNode, "ufo"))) { + if ((val =3D virTristateSwitchTypeFromString(str)) <=3D 0)= { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown guest ufo mode '%s'"), + str); + goto error; + } + def->driver.virtio.guest.ufo =3D val; } - def->driver.virtio.guest.ufo =3D val; } def->backend.vhost =3D vhost_path; vhost_path =3D NULL; --=20 2.13.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 01:14:34 2024 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 15028872719761010.6216577324967; Wed, 16 Aug 2017 05:41:11 -0700 (PDT) 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 2197774EE3; Wed, 16 Aug 2017 12:41:10 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EFB2A7DFC0; Wed, 16 Aug 2017 12:41: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 B38A83FAD3; Wed, 16 Aug 2017 12:41:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v7GCeuGB021751 for ; Wed, 16 Aug 2017 08:40:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0D4A57D978; Wed, 16 Aug 2017 12:40:56 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8809B7FA5B for ; Wed, 16 Aug 2017 12:40:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2197774EE3 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Date: Wed, 16 Aug 2017 14:40:43 +0200 Message-Id: <7b7f23d166f2e80dc79ecd12db17c48da02300f1.1502887192.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 06/10] conf: use virXMLPropString for boot 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 16 Aug 2017 12:41: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 --- Notes: hint: review with -b src/conf/domain_conf.c | 95 ++++++++++++++++++++++++++--------------------= ---- 1 file changed, 50 insertions(+), 45 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 90f3f55f25..917ea004e5 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -16039,6 +16039,7 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt, virDomainDefPtr def) { xmlNodePtr *nodes =3D NULL; + xmlNodePtr node; size_t i; int n; char *tmp =3D NULL; @@ -16088,62 +16089,66 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt, def->os.bootDevs[0] =3D VIR_DOMAIN_BOOT_DISK; } =20 - tmp =3D virXPathString("string(./os/bootmenu[1]/@enable)", ctxt); - if (tmp) { - def->os.bootmenu =3D virTristateBoolTypeFromString(tmp); - if (def->os.bootmenu <=3D 0) { - /* In order not to break misconfigured machines, this - * should not emit an error, but rather set the bootmenu - * to disabled */ - VIR_WARN("disabling bootmenu due to unknown option '%s'", - tmp); - def->os.bootmenu =3D VIR_TRISTATE_BOOL_NO; - } - VIR_FREE(tmp); - } - - tmp =3D virXPathString("string(./os/bootmenu[1]/@timeout)", ctxt); - if (tmp && def->os.bootmenu =3D=3D VIR_TRISTATE_BOOL_YES) { - if (virStrToLong_uip(tmp, NULL, 0, &def->os.bm_timeout) < 0 || - def->os.bm_timeout > 65535) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("invalid value for boot menu timeout, " - "must be in range [0,65535]")); - goto cleanup; + if ((node =3D virXPathNode("./os/bootmenu[1]", ctxt))) { + tmp =3D virXMLPropString(node, "enable"); + if (tmp) { + def->os.bootmenu =3D virTristateBoolTypeFromString(tmp); + if (def->os.bootmenu <=3D 0) { + /* In order not to break misconfigured machines, this + * should not emit an error, but rather set the bootmenu + * to disabled */ + VIR_WARN("disabling bootmenu due to unknown option '%s'", + tmp); + def->os.bootmenu =3D VIR_TRISTATE_BOOL_NO; + } + VIR_FREE(tmp); } - def->os.bm_timeout_set =3D true; - } - VIR_FREE(tmp); =20 - tmp =3D virXPathString("string(./os/bios[1]/@useserial)", ctxt); - if (tmp) { - if (STREQ(tmp, "yes")) { - if (virXPathULong("count(./devices/serial)", - ctxt, &serialPorts) < 0) { + tmp =3D virXMLPropString(node, "timeout"); + if (tmp && def->os.bootmenu =3D=3D VIR_TRISTATE_BOOL_YES) { + if (virStrToLong_uip(tmp, NULL, 0, &def->os.bm_timeout) < 0 || + def->os.bm_timeout > 65535) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("need at least one serial port " - "for useserial")); + _("invalid value for boot menu timeout, " + "must be in range [0,65535]")); goto cleanup; } - def->os.bios.useserial =3D VIR_TRISTATE_BOOL_YES; - } else { - def->os.bios.useserial =3D VIR_TRISTATE_BOOL_NO; + def->os.bm_timeout_set =3D true; } VIR_FREE(tmp); } =20 - tmp =3D virXPathString("string(./os/bios[1]/@rebootTimeout)", ctxt); - if (tmp) { - /* that was really just for the check if it is there */ + if ((node =3D virXPathNode("./os/bios[1]", ctxt))) { + tmp =3D virXMLPropString(node, "useserial"); + if (tmp) { + if (STREQ(tmp, "yes")) { + if (virXPathULong("count(./devices/serial)", + ctxt, &serialPorts) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("need at least one serial port " + "for useserial")); + goto cleanup; + } + def->os.bios.useserial =3D VIR_TRISTATE_BOOL_YES; + } else { + def->os.bios.useserial =3D VIR_TRISTATE_BOOL_NO; + } + VIR_FREE(tmp); + } + + tmp =3D virXMLPropString(node, "rebootTimeout"); + if (tmp) { + /* that was really just for the check if it is there */ =20 - if (virStrToLong_i(tmp, NULL, 0, &def->os.bios.rt_delay) < 0 || - def->os.bios.rt_delay < -1 || def->os.bios.rt_delay > 65535) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("invalid value for rebootTimeout, " - "must be in range [-1,65535]")); - goto cleanup; + if (virStrToLong_i(tmp, NULL, 0, &def->os.bios.rt_delay) < 0 || + def->os.bios.rt_delay < -1 || def->os.bios.rt_delay > 6553= 5) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("invalid value for rebootTimeout, " + "must be in range [-1,65535]")); + goto cleanup; + } + def->os.bios.rt_set =3D true; } - def->os.bios.rt_set =3D true; } =20 ret =3D 0; --=20 2.13.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 01:14:34 2024 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 15028872818821004.6045901252305; Wed, 16 Aug 2017 05:41:21 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EE8457CB8B; Wed, 16 Aug 2017 12:41:19 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CAFD67DB51; Wed, 16 Aug 2017 12:41:19 +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 D69883FAEB; Wed, 16 Aug 2017 12:41:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v7GCeuGg021757 for ; Wed, 16 Aug 2017 08:40:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id D26E17DB24; Wed, 16 Aug 2017 12:40:56 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 59CAD7D57E for ; Wed, 16 Aug 2017 12:40:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com EE8457CB8B 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: Wed, 16 Aug 2017 14:40:44 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 07/10] conf: use virXMLPropString for actual network 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 16 Aug 2017 12:41:20 +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 --- Notes: hint: review with -b src/conf/domain_conf.c | 61 ++++++++++++++++++++++++++++------------------= ---- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 917ea004e5..83432fa5b0 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -9656,18 +9656,22 @@ virDomainActualNetDefParseXML(xmlNodePtr node, } =20 if (actual->type =3D=3D VIR_DOMAIN_NET_TYPE_DIRECT) { - actual->data.direct.linkdev =3D virXPathString("string(./source[1]= /@dev)", ctxt); + xmlNodePtr sourceNode =3D virXPathNode("./source[1]", ctxt); =20 - mode =3D virXPathString("string(./source[1]/@mode)", ctxt); - if (mode) { - int m; - if ((m =3D virNetDevMacVLanModeTypeFromString(mode)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unknown mode '%s' in interface = element"), - mode); - goto error; + if (sourceNode) { + actual->data.direct.linkdev =3D virXMLPropString(sourceNode, "= dev"); + + mode =3D virXMLPropString(sourceNode, "mode"); + if (mode) { + int m; + if ((m =3D virNetDevMacVLanModeTypeFromString(mode)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Unknown mode '%s' in interface element"), + mode); + goto error; + } + actual->data.direct.mode =3D m; } - actual->data.direct.mode =3D m; } } else if (actual->type =3D=3D VIR_DOMAIN_NET_TYPE_HOSTDEV) { virDomainHostdevDefPtr hostdev =3D &actual->data.hostdev.def; @@ -9703,24 +9707,27 @@ virDomainActualNetDefParseXML(xmlNodePtr node, } if (actual->type =3D=3D VIR_DOMAIN_NET_TYPE_BRIDGE || actual->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { - char *brname =3D virXPathString("string(./source/@bridge)", ctxt); + xmlNodePtr sourceNode =3D virXPathNode("./source", ctxt); + if (sourceNode) { + char *brname =3D virXMLPropString(sourceNode, "bridge"); =20 - if (!brname && actual->type =3D=3D VIR_DOMAIN_NET_TYPE_BRIDGE) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Missing element with bridge name in= " - "interface's element")); - goto error; - } - actual->data.bridge.brname =3D brname; - macTableManager =3D virXPathString("string(./source/@macTableManag= er)", ctxt); - if (macTableManager && - (actual->data.bridge.macTableManager - =3D virNetworkBridgeMACTableManagerTypeFromString(macTableMan= ager)) <=3D 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid macTableManager setting '%s' " - "in domain interface's element"), - macTableManager); - goto error; + if (!brname && actual->type =3D=3D VIR_DOMAIN_NET_TYPE_BRIDGE)= { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Missing element with bridge nam= e in " + "interface's element")); + goto error; + } + actual->data.bridge.brname =3D brname; + macTableManager =3D virXMLPropString(sourceNode, "macTableMana= ger"); + if (macTableManager && + (actual->data.bridge.macTableManager + =3D virNetworkBridgeMACTableManagerTypeFromString(macTabl= eManager)) <=3D 0) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid macTableManager setting '%s' " + "in domain interface's element"), + macTableManager); + goto error; + } } } =20 --=20 2.13.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 01:14:34 2024 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 1502887275239151.24626850247307; Wed, 16 Aug 2017 05:41:15 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0CA6069069; Wed, 16 Aug 2017 12:41:13 +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 DBFE27E391; Wed, 16 Aug 2017 12:41:12 +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 5C99F1806108; Wed, 16 Aug 2017 12:41:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v7GCev4k021763 for ; Wed, 16 Aug 2017 08:40:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id A28F77D57E; Wed, 16 Aug 2017 12:40:57 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2ADAB7DB20 for ; Wed, 16 Aug 2017 12:40:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0CA6069069 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Date: Wed, 16 Aug 2017 14:40:45 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 08/10] conf: use virXMLPropStringLimit where it makes sense 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 16 Aug 2017 12:41:13 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The XPath call for these cases is more expensive than accessing the XML dom node directly. Signed-off-by: Pavel Hrdina --- src/conf/domain_conf.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 83432fa5b0..ea293b9f02 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7227,8 +7227,8 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt, char *p; virSecurityLabelDefPtr seclabel =3D NULL; =20 - p =3D virXPathStringLimit("string(./@model)", - VIR_SECURITY_MODEL_BUFLEN - 1, ctxt); + p =3D virXMLPropStringLimit(ctxt->node, "model", + VIR_SECURITY_MODEL_BUFLEN - 1); =20 if (!(seclabel =3D virSecurityLabelDefNew(p))) goto error; @@ -7237,8 +7237,8 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt, /* set default value */ seclabel->type =3D VIR_DOMAIN_SECLABEL_DYNAMIC; =20 - p =3D virXPathStringLimit("string(./@type)", - VIR_SECURITY_LABEL_BUFLEN - 1, ctxt); + p =3D virXMLPropStringLimit(ctxt->node, "type", + VIR_SECURITY_LABEL_BUFLEN - 1); if (p) { seclabel->type =3D virDomainSeclabelTypeFromString(p); if (seclabel->type <=3D 0) { @@ -7253,8 +7253,8 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt, seclabel->relabel =3D false; =20 VIR_FREE(p); - p =3D virXPathStringLimit("string(./@relabel)", - VIR_SECURITY_LABEL_BUFLEN-1, ctxt); + p =3D virXMLPropStringLimit(ctxt->node, "relabel", + VIR_SECURITY_LABEL_BUFLEN-1); if (p) { if (STREQ(p, "yes")) { seclabel->relabel =3D true; --=20 2.13.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 01:14:34 2024 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 150288727834927.336807302511602; Wed, 16 Aug 2017 05:41:18 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 731077790E; Wed, 16 Aug 2017 12:41:16 +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 4D55E60631; Wed, 16 Aug 2017 12:41:16 +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 F0990180610F; Wed, 16 Aug 2017 12:41:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v7GCew9l021777 for ; Wed, 16 Aug 2017 08:40:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id 741687D971; Wed, 16 Aug 2017 12:40:58 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF6467D57E for ; Wed, 16 Aug 2017 12:40:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 731077790E 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: Wed, 16 Aug 2017 14:40:46 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 09/10] conf: use virXMLNodeContentString for boot options 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 16 Aug 2017 12:41:16 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Using XPath here doesn't add any benefit. Signed-off-by: Pavel Hrdina --- src/conf/domain_conf.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ea293b9f02..db042e5dc1 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -17062,7 +17062,6 @@ virDomainDefParseBootOptions(virDomainDefPtr def, virHashTablePtr *bootHash) { xmlNodePtr *nodes =3D NULL; - xmlNodePtr oldnode; char *tmp =3D NULL; char *name =3D NULL; int ret =3D -1; @@ -17169,8 +17168,6 @@ virDomainDefParseBootOptions(virDomainDefPtr def, } =20 if (n =3D=3D 1) { - oldnode =3D ctxt->node; - ctxt->node =3D nodes[0]; tmp =3D virXMLPropString(nodes[0], "type"); =20 if (!tmp) { @@ -17181,7 +17178,7 @@ virDomainDefParseBootOptions(virDomainDefPtr def, =20 if (STREQ_NULLABLE(tmp, "slic")) { VIR_FREE(tmp); - tmp =3D virXPathString("string(.)", ctxt); + tmp =3D virXMLNodeContentString(nodes[0]); def->os.slic_table =3D virFileSanitizePath(tmp); VIR_FREE(tmp); } else { @@ -17190,7 +17187,6 @@ virDomainDefParseBootOptions(virDomainDefPtr def, tmp); goto error; } - ctxt->node =3D oldnode; } =20 if (virDomainDefParseBootXML(ctxt, def) < 0) --=20 2.13.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 01:14:34 2024 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 1502887277037508.7671438022328; Wed, 16 Aug 2017 05:41:17 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 205F569073; Wed, 16 Aug 2017 12:41:15 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F383268D61; Wed, 16 Aug 2017 12:41:14 +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 BCBE33FAD0; Wed, 16 Aug 2017 12:41:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v7GCexBP021793 for ; Wed, 16 Aug 2017 08:40:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4D3297DB24; Wed, 16 Aug 2017 12:40:59 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id C0F047D57E for ; Wed, 16 Aug 2017 12:40:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 205F569073 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Date: Wed, 16 Aug 2017 14:40:47 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 10/10] conf: use virXMLPropString and virXMLNodeContentString for vcpu 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 16 Aug 2017 12:41:15 +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 --- Notes: hint: review with -b src/conf/domain_conf.c | 98 ++++++++++++++++++++++++++--------------------= ---- 1 file changed, 51 insertions(+), 47 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index db042e5dc1..3db56ffb7a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -16914,66 +16914,70 @@ virDomainVcpuParse(virDomainDefPtr def, { int n; xmlNodePtr *nodes =3D NULL; + xmlNodePtr vcpuNode; size_t i; char *tmp =3D NULL; unsigned int maxvcpus; unsigned int vcpus; int ret =3D -1; =20 - if ((n =3D virXPathUInt("string(./vcpu[1])", ctxt, &maxvcpus)) < 0) { - if (n =3D=3D -2) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("maximum vcpus count must be an integer")); - goto cleanup; + vcpus =3D maxvcpus =3D 1; + + if ((vcpuNode =3D virXPathNode("./vcpu[1]", ctxt))) { + if ((tmp =3D virXMLNodeContentString(vcpuNode))) { + if (virStrToLong_ui(tmp, NULL, 10, &maxvcpus) < 0) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("maximum vcpus count must be an integer")= ); + goto cleanup; + } + VIR_FREE(tmp); + } + + if ((tmp =3D virXMLPropString(vcpuNode, "current"))) { + if (virStrToLong_ui(tmp, NULL, 10, &vcpus) < 0) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("current vcpus count must be an integer")= ); + goto cleanup; + } + VIR_FREE(tmp); + } else { + vcpus =3D maxvcpus; + } + + tmp =3D virXMLPropString(vcpuNode, "placement"); + if (tmp) { + if ((def->placement_mode =3D + virDomainCpuPlacementModeTypeFromString(tmp)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Unsupported CPU placement mode '%s'"), + tmp); + goto cleanup; + } + VIR_FREE(tmp); + } else { + def->placement_mode =3D VIR_DOMAIN_CPU_PLACEMENT_MODE_STATIC; } =20 - maxvcpus =3D 1; + if (def->placement_mode !=3D VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO) { + tmp =3D virXMLPropString(vcpuNode, "cpuset"); + if (tmp) { + if (virBitmapParse(tmp, &def->cpumask, VIR_DOMAIN_CPUMASK_= LEN) < 0) + goto cleanup; + + if (virBitmapIsAllClear(def->cpumask)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Invalid value of 'cpuset': %s"), tmp= ); + goto cleanup; + } + + VIR_FREE(tmp); + } + } } =20 if (virDomainDefSetVcpusMax(def, maxvcpus, xmlopt) < 0) goto cleanup; =20 - if ((n =3D virXPathUInt("string(./vcpu[1]/@current)", ctxt, &vcpus)) <= 0) { - if (n =3D=3D -2) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("current vcpus count must be an integer")); - goto cleanup; - } - - vcpus =3D maxvcpus; - } - - - tmp =3D virXPathString("string(./vcpu[1]/@placement)", ctxt); - if (tmp) { - if ((def->placement_mode =3D - virDomainCpuPlacementModeTypeFromString(tmp)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unsupported CPU placement mode '%s'"), - tmp); - goto cleanup; - } - VIR_FREE(tmp); - } else { - def->placement_mode =3D VIR_DOMAIN_CPU_PLACEMENT_MODE_STATIC; - } - - if (def->placement_mode !=3D VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO) { - tmp =3D virXPathString("string(./vcpu[1]/@cpuset)", ctxt); - if (tmp) { - if (virBitmapParse(tmp, &def->cpumask, VIR_DOMAIN_CPUMASK_LEN)= < 0) - goto cleanup; - - if (virBitmapIsAllClear(def->cpumask)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Invalid value of 'cpuset': %s"), tmp); - goto cleanup; - } - - VIR_FREE(tmp); - } - } - if ((n =3D virXPathNodeSet("./vcpus/vcpu", ctxt, &nodes)) < 0) goto cleanup; =20 --=20 2.13.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list