From nobody Mon Feb 9 18:19:19 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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 170.10.129.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=1666620982; cv=none; d=zohomail.com; s=zohoarc; b=Qj35DHxX2McO5GiUbPznagpzIaOQknJYCSmSpPgxE2IPDwVUSo52DB4Pa4WhLZhNJcpjCU4PGNkrTzmeYPqr+UXxzQw+cYsLtf/v79QHsb9autPU46/uEZJHdyMqSxVSwaNRKs7uNJtr7eNGpaIYvTxUQ0pNg42gaubtGHYLiZY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666620982; h=Content-Type:Content-Transfer-Encoding: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=T3BWaNQRHnMGlL7kyXTxu7hGtPJGf7GglJ0DgmAl2CQ=; b=htsWUnaO5r+wkOjC5g3tUL2cbsbCMBLOjo7S3kE3nInY/FS/3OFH95dSRDuquh61qJNiuOOq4VSVFtxI2D137bzDBdRt+X9lBsK34BMq2c6nj7uPSDuLiY7T2RnUe43ImnHpUXxpFyYTVQ5NO8U8GILfkWMj/flV+mrVm9aXrZI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1666620982916544.5705341183387; Mon, 24 Oct 2022 07:16:22 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-205-__KctGW7NtKiV98h6gEs2g-1; Mon, 24 Oct 2022 10:16:12 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 864451C07557; Mon, 24 Oct 2022 14:15:21 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 73944112132C; Mon, 24 Oct 2022 14:15:21 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 6446D194658F; Mon, 24 Oct 2022 14:15:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 69A3919465A4 for ; Mon, 24 Oct 2022 14:15:19 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 5EE7740C2064; Mon, 24 Oct 2022 14:15:19 +0000 (UTC) Received: from speedmetal.lan (ovpn-208-27.brq.redhat.com [10.40.208.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id BDA7740C2089 for ; Mon, 24 Oct 2022 14:15:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666620981; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=T3BWaNQRHnMGlL7kyXTxu7hGtPJGf7GglJ0DgmAl2CQ=; b=dv+87P2nESQaPey/zW/JgRb9ir7q9S4yra4NTL9psWJgafJoUoJ3BcunvzF14Ge8ryg7Ft sgcXfxS/+/PnlcMJ7Uugw0wmkiKSeRM01zxcv5Dxj++Cj2B0iTdLwWVx7u5U7HLNtQLYBF qWdiCbLSDrjbRUX5sjnwwQRZbBvwlng= X-MC-Unique: __KctGW7NtKiV98h6gEs2g-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 17/43] conf: cpu: Extract and refactor parsing of cache from virCPUDefParseXML Date: Mon, 24 Oct 2022 16:14:22 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666620984504100001 Content-Type: text/plain; charset="utf-8" Move the parser into a helper function named 'virCPUDefParseXMLCache' and use the virXMLProp* helpers instead of multiple XPath lookups. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/cpu_conf.c | 58 ++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index fdbb564cc8..a33f39ef31 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -312,6 +312,34 @@ virCPUDefParseXMLString(const char *xml, } +static int +virCPUDefParseXMLCache(virCPUDef *def, + xmlNodePtr node) +{ + int rc; + + def->cache =3D g_new0(virCPUCacheDef, 1); + + if ((rc =3D virXMLPropInt(node, "level", 10, VIR_XML_PROP_NONNEGATIVE, + &def->cache->level, -1)) < 0) + return -1; + + if (rc =3D=3D 1) { + if (def->cache->level < 1 || def->cache->level > 3) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("invalid CPU cache level, must be in range [1= ,3]")); + return -1; + } + } + + if (virXMLPropEnum(node, "mode", virCPUCacheModeTypeFromString, + VIR_XML_PROP_REQUIRED, &def->cache->mode) < 0) + return -1; + + return 0; +} + + /* * Parses CPU definition XML from a node pointed to by @xpath. If @xpath is * NULL, the current node of @ctxt is used (i.e., it is a shortcut to "."). @@ -335,6 +363,8 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt, g_autofree xmlNodePtr *nodes =3D NULL; xmlNodePtr topology =3D NULL; xmlNodePtr maxphysaddrNode =3D NULL; + g_autofree xmlNodePtr *cacheNodes =3D NULL; + ssize_t ncacheNodes =3D 0; VIR_XPATH_NODE_AUTORESTORE(ctxt) int n; int rv; @@ -626,35 +656,15 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt, def->features[i].policy =3D policy; } - if (virXPathInt("count(./cache)", ctxt, &n) < 0) { - return -1; - } else if (n > 1) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("at most one CPU cache element may be specified")= ); - return -1; - } else if (n =3D=3D 1) { - int level =3D -1; - g_autofree char *strmode =3D NULL; - int mode; - - if (virXPathBoolean("boolean(./cache[1]/@level)", ctxt) =3D=3D 1 && - (virXPathInt("string(./cache[1]/@level)", ctxt, &level) < 0 || - level < 1 || level > 3)) { + if ((ncacheNodes =3D virXPathNodeSet("./cache", ctxt, &cacheNodes)) > = 0) { + if (ncacheNodes > 1) { virReportError(VIR_ERR_XML_ERROR, "%s", - _("invalid CPU cache level, must be in range [1= ,3]")); + _("at most one CPU cache element may be specifi= ed")); return -1; } - if (!(strmode =3D virXPathString("string(./cache[1]/@mode)", ctxt)= ) || - (mode =3D virCPUCacheModeTypeFromString(strmode)) < 0) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("missing or invalid CPU cache mode")); + if (virCPUDefParseXMLCache(def, cacheNodes[0]) < 0) return -1; - } - - def->cache =3D g_new0(virCPUCacheDef, 1); - def->cache->level =3D level; - def->cache->mode =3D mode; } if ((maxphysaddrNode =3D virXPathNode("./maxphysaddr[1]", ctxt))) { --=20 2.37.3