From nobody Mon Feb 9 15:11:27 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1620919962; cv=none; d=zohomail.com; s=zohoarc; b=OMegwvBhwk8Kg9ZmOQ7e+l1/kJYu1i3/4hOCLKiHpHbLXlGiyLT/C5tBL0vFRFSpXaacYcJg2OfBTFsFvEBgwzVEWzd5YE4jxisiQGJ+hGTAT2Gt1OjH4FElSVRtpak2H5W9wEjmXJvo++VLpEDdvwG4xe7/1eguPSdEWgITd5U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620919962; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=H+GH/VwjeB+tAKs4e007Q6CCoM4eGSpkKtPjTqiakHE=; b=ZXQrEmtZt88uFnKXKfp3oLsncw2tRvPHq1cviHJbb5sB7Dv5cbItKvvm6dKWVDEtSKHo/l6FXf+5VU8d4Y71kSMySe/wpBJnedF2q/L3/8OUekY0uZO4RqDZvG+AP4tirrrf+d/qCbAp+sj2fdwcQiS+5UqDnoVo1dImftPGZW8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1620919962210687.0208029518046; Thu, 13 May 2021 08:32:42 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-271-PY7Gy9ZhOrKBopAgOcdBqg-1; Thu, 13 May 2021 11:32:38 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6F6BD1854E2A; Thu, 13 May 2021 15:32:32 +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 52E231ABE5; Thu, 13 May 2021 15:32:32 +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 19ACD55351; Thu, 13 May 2021 15:32:32 +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 14DFWG3m026218 for ; Thu, 13 May 2021 11:32:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2FE94189A5; Thu, 13 May 2021 15:32:16 +0000 (UTC) Received: from work.redhat.com (ovpn-112-97.ams2.redhat.com [10.36.112.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 78BD063BA7; Thu, 13 May 2021 15:32:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620919960; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=H+GH/VwjeB+tAKs4e007Q6CCoM4eGSpkKtPjTqiakHE=; b=gXZAqbE2YJZFrKeCqdACvG6WRYMoLd8sgBZel8OOgrCnxi5X58hVtJCn+ymDV/kz3qgD2+ EgGhtENSjNqhKpmJ69AtpXJpgQ5KwA6avWHQ6Ci5+/T5a376YRmzlLifrYq4utWX97bDYo y0LR3WiRYwwyliMSWXlxMwUjgLIjEsw= X-MC-Unique: PY7Gy9ZhOrKBopAgOcdBqg-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 5/6] virDomainNumaDefParseXML: Use virXMLProp* Date: Thu, 13 May 2021 17:32:00 +0200 Message-Id: <20210513153201.20407-6-twiederh@redhat.com> In-Reply-To: <20210513153201.20407-1-twiederh@redhat.com> References: <20210513153201.20407-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Tim Wiederhake --- src/conf/numa_conf.c | 128 +++++------------- .../hugepages-memaccess-invalid.err | 2 +- 2 files changed, 35 insertions(+), 95 deletions(-) diff --git a/src/conf/numa_conf.c b/src/conf/numa_conf.c index 60cd7767ef..9fe4998951 100644 --- a/src/conf/numa_conf.c +++ b/src/conf/numa_conf.c @@ -954,26 +954,23 @@ virDomainNumaDefParseXML(virDomainNuma *def, for (i =3D 0; i < n; i++) { VIR_XPATH_NODE_AUTORESTORE(ctxt) int rc; - unsigned int cur_cell =3D i; + unsigned int cur_cell; =20 - /* cells are in order of parsing or explicitly numbered */ - if ((tmp =3D virXMLPropString(nodes[i], "id"))) { - if (virStrToLong_uip(tmp, NULL, 10, &cur_cell) < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid 'id' attribute in NUMA cell: '%s= '"), - tmp); - goto cleanup; - } + if ((rc =3D virXMLPropUInt(nodes[i], "id", 10, VIR_XML_PROP_NONE, + &cur_cell)) < 0) + goto cleanup; =20 - if (cur_cell >=3D n) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Exactly one 'cell' element per guest " - "NUMA cell allowed, non-contiguous ranges= or " - "ranges not starting from 0 are not allow= ed")); - goto cleanup; - } + if (rc =3D=3D 0) + cur_cell =3D i; + + /* cells are in order of parsing or explicitly numbered */ + if (cur_cell >=3D n) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Exactly one 'cell' element per guest " + "NUMA cell allowed, non-contiguous ranges or " + "ranges not starting from 0 are not allowed")= ); + goto cleanup; } - VIR_FREE(tmp); =20 if (def->mem_nodes[cur_cell].mem) { virReportError(VIR_ERR_XML_ERROR, @@ -1013,29 +1010,15 @@ virDomainNumaDefParseXML(virDomainNuma *def, &def->mem_nodes[cur_cell].mem, true, fals= e) < 0) goto cleanup; =20 - if ((tmp =3D virXMLPropString(nodes[i], "memAccess"))) { - if ((rc =3D virDomainMemoryAccessTypeFromString(tmp)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Invalid 'memAccess' attribute value '%s'= "), - tmp); - goto cleanup; - } - - def->mem_nodes[cur_cell].memAccess =3D rc; - VIR_FREE(tmp); - } - - if ((tmp =3D virXMLPropString(nodes[i], "discard"))) { - if ((rc =3D virTristateBoolTypeFromString(tmp)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Invalid 'discard' attribute value '%s'"), - tmp); - goto cleanup; - } + if (virXMLPropEnum(nodes[i], "memAccess", + virDomainMemoryAccessTypeFromString, + VIR_XML_PROP_NONZERO, + &def->mem_nodes[cur_cell].memAccess) < 0) + goto cleanup; =20 - def->mem_nodes[cur_cell].discard =3D rc; - VIR_FREE(tmp); - } + if (virXMLPropTristateBool(nodes[i], "discard", VIR_XML_PROP_NONE, + &def->mem_nodes[cur_cell].discard) < 0) + goto cleanup; =20 /* Parse NUMA distances info */ if (virDomainNumaDefNodeDistanceParseXML(def, ctxt, cur_cell) < 0) @@ -1057,24 +1040,15 @@ virDomainNumaDefParseXML(virDomainNuma *def, unsigned int initiator; unsigned int target; unsigned int cache =3D 0; - int accessType; + virDomainMemoryLatency accessType; unsigned long long value; =20 if (virXMLNodeNameEqual(nodes[i], "latency")) { type =3D VIR_DOMAIN_NUMA_INTERCONNECT_TYPE_LATENCY; =20 - if (!(tmp =3D virXMLPropString(nodes[i], "value"))) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Missing 'value' attribute in NUMA interc= onnects")); - goto cleanup; - } - - if (virStrToLong_ullp(tmp, NULL, 10, &value) < 0) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Invalid 'value' attribute in NUMA interc= onnects")); + if (virXMLPropULongLong(nodes[i], "value", 10, + VIR_XML_PROP_REQUIRED, &value) < 0) goto cleanup; - } - VIR_FREE(tmp); } else if (virXMLNodeNameEqual(nodes[i], "bandwidth")) { VIR_XPATH_NODE_AUTORESTORE(ctxt) type =3D VIR_DOMAIN_NUMA_INTERCONNECT_TYPE_BANDWIDTH; @@ -1088,56 +1062,22 @@ virDomainNumaDefParseXML(virDomainNuma *def, continue; } =20 - if (!(tmp =3D virXMLPropString(nodes[i], "initiator"))) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Missing 'initiator' attribute in NUMA interc= onnects")); + if (virXMLPropUInt(nodes[i], "initiator", 10, VIR_XML_PROP_REQUIRE= D, + &initiator) < 0) goto cleanup; - } - - if (virStrToLong_uip(tmp, NULL, 10, &initiator) < 0) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Invalid 'initiator' attribute in NUMA interc= onnects")); - goto cleanup; - } - VIR_FREE(tmp); - - if (!(tmp =3D virXMLPropString(nodes[i], "target"))) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Missing 'target' attribute in NUMA interconn= ects")); - goto cleanup; - } =20 - if (virStrToLong_uip(tmp, NULL, 10, &target) < 0) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Invalid 'target' attribute in NUMA interconn= ects")); + if (virXMLPropUInt(nodes[i], "target", 10, VIR_XML_PROP_REQUIRED, + &target) < 0) goto cleanup; - } - VIR_FREE(tmp); - =20 - /* cache attribute is optional */ - if ((tmp =3D virXMLPropString(nodes[i], "cache"))) { - if (virStrToLong_uip(tmp, NULL, 10, &cache) < 0 || - cache =3D=3D 0) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Invalid 'cache' attribute in NUMA interc= onnects")); - goto cleanup; - } - } - VIR_FREE(tmp); - - if (!(tmp =3D virXMLPropString(nodes[i], "type"))) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Missing 'type' attribute in NUMA interconnec= ts")); + if (virXMLPropUInt(nodes[i], "cache", 10, VIR_XML_PROP_NONE, + &cache) < 0) goto cleanup; - } =20 - if ((accessType =3D virDomainMemoryLatencyTypeFromString(tmp)) <= =3D 0) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Invalid 'type' attribute in NUMA interconnec= ts")); + if (virXMLPropEnum(nodes[i], "type", virDomainMemoryLatencyTypeFro= mString, + VIR_XML_PROP_REQUIRED | VIR_XML_PROP_NONZERO, + &accessType) < 0) goto cleanup; - } - VIR_FREE(tmp); =20 def->interconnects[i] =3D (virDomainNumaInterconnect) {type, initi= ator, target, cache, access= Type, value}; diff --git a/tests/qemuxml2argvdata/hugepages-memaccess-invalid.err b/tests= /qemuxml2argvdata/hugepages-memaccess-invalid.err index 75ddd3e282..a1f07fb04d 100644 --- a/tests/qemuxml2argvdata/hugepages-memaccess-invalid.err +++ b/tests/qemuxml2argvdata/hugepages-memaccess-invalid.err @@ -1 +1 @@ -unsupported configuration: Invalid 'memAccess' attribute value 'invalid' +XML error: Invalid value for attribute 'memAccess' in element 'cell': 'inv= alid'. --=20 2.26.3