From nobody Wed Dec 17 04:18:35 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 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