From nobody Sun Feb 8 16:34:30 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1636043260; cv=none; d=zohomail.com; s=zohoarc; b=jjKhbvLisom94cCzCdS7JdQU2cd449HY1myXEKi9iuUTTpLUMMiSqeB4b6lTQFkR4xvcVP44wNXsoVF/2EZwgcVcw58rimFYHk8/gfx0EqX7xWcgvVZBoZpKqmwA7gr8uuM36mVnxE4AXscBGm2dirNxGKwabAmlu5eEgliEC0k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1636043260; 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=OO79J1BSd4A8IaIU2xrdumL9N4e5H4cj/oKlQ3w5wn4=; b=K9wlZe6+d5JRaaH1wfRX7v76FaumlE0VrbKV6pWiAPbw+erUmPJ9V/ULOTdu1jJrlahYSav0GY6rLwy0ZXQoU+g6XY8j9XrBpFQ8VygMQVQA3kJCHHh/zgoBMEFSt7A3BYbRnR0dyW2JWKFxZPqd/C89LusXbwBQ2tdWCvq7R6Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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.133.124]) by mx.zohomail.com with SMTPS id 1636043260458464.4797775756108; Thu, 4 Nov 2021 09:27:40 -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-378-T4gyflAnOwuaz1cYAUzw4A-1; Thu, 04 Nov 2021 12:27:36 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 33B9A8AF849; Thu, 4 Nov 2021 16:27:31 +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 1FD0360BD8; Thu, 4 Nov 2021 16:27:30 +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 43C4A4EA2A; Thu, 4 Nov 2021 16:27:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1A4GROZ9026352 for ; Thu, 4 Nov 2021 12:27:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id C5DCA19D9F; Thu, 4 Nov 2021 16:27:24 +0000 (UTC) Received: from work.speedport.ip (unknown [10.39.193.164]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1B89519C79; Thu, 4 Nov 2021 16:27:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636043259; 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=OO79J1BSd4A8IaIU2xrdumL9N4e5H4cj/oKlQ3w5wn4=; b=UhoQK8XhytMq9AFzhh6da52GHbfWm7RiPNdlQpddTpsfObfRl1YixnTIj+bHoQDicOlXNO Fq2ZB87RDtsHw/HyMoGFKBYpKZjYWGX7c5oIB3xIDA3BUtmO8Cwri7DRVX4w61ihbZG9bN TSzhXgWMzGApcufXCooKTVh7skc0bac= X-MC-Unique: T4gyflAnOwuaz1cYAUzw4A-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 03/20] cpu_x86: Add x86ParseDataItemList Date: Thu, 4 Nov 2021 17:27:03 +0100 Message-Id: <20211104162720.108973-4-twiederh@redhat.com> In-Reply-To: <20211104162720.108973-1-twiederh@redhat.com> References: <20211104162720.108973-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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.11 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) X-ZM-MESSAGEID: 1636043260744100001 Content-Type: text/plain; charset="utf-8" Factor out duplicated code from x86FeatureParse and virCPUx86DataParse. This also consolidates error messages. Signed-off-by: Tim Wiederhake --- src/cpu/cpu_x86.c | 106 ++++++++++++++++++---------------------------- 1 file changed, 41 insertions(+), 65 deletions(-) diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index 006221215a..29b4df1f79 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -1068,17 +1068,51 @@ x86ParseMSR(xmlNodePtr node, } =20 =20 +static int +x86ParseDataItemList(virCPUx86Data *cpudata, + xmlNodePtr node) +{ + size_t i; + + if (xmlChildElementCount(node) <=3D 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("no x86 CPU data fo= und")); + return -1; + } + + node =3D xmlFirstElementChild(node); + for (i =3D 0; node; ++i) { + virCPUx86DataItem item; + + if (virXMLNodeNameEqual(node, "cpuid")) { + if (x86ParseCPUID(node, &item) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Invalid cpuid[%zu]"), i); + return -1; + } + } else { + if (x86ParseMSR(node, &item) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Invalid msr[%zu]"), i); + return -1; + } + } + + if (virCPUx86DataAddItem(cpudata, &item) < 0) + return -1; + + node =3D xmlNextElementSibling(node); + } + + return 0; +} + static int x86FeatureParse(xmlXPathContextPtr ctxt, const char *name, void *data) { virCPUx86Map *map =3D data; - g_autofree xmlNodePtr *nodes =3D NULL; g_autoptr(virCPUx86Feature) feature =3D NULL; - virCPUx86DataItem item; - size_t i; - int n; g_autofree char *str =3D NULL; =20 feature =3D g_new0(virCPUx86Feature, 1); @@ -1095,38 +1129,8 @@ x86FeatureParse(xmlXPathContextPtr ctxt, if (STREQ_NULLABLE(str, "no")) feature->migratable =3D false; =20 - n =3D virXPathNodeSet("./cpuid|./msr", ctxt, &nodes); - if (n < 0) - return -1; - - if (n =3D=3D 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Missing cpuid or msr element in feature %s"), - feature->name); + if (x86ParseDataItemList(&feature->data, ctxt->node) < 0) return -1; - } - - for (i =3D 0; i < n; i++) { - ctxt->node =3D nodes[i]; - if (virXMLNodeNameEqual(nodes[i], "cpuid")) { - if (x86ParseCPUID(ctxt->node, &item) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Invalid cpuid[%zu] in %s feature"), - i, feature->name); - return -1; - } - } else { - if (x86ParseMSR(ctxt->node, &item) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Invalid msr[%zu] in %s feature"), - i, feature->name); - return -1; - } - } - - if (virCPUx86DataAddItem(&feature->data, &item)) - return -1; - } =20 if (!feature->migratable) VIR_APPEND_ELEMENT_COPY(map->migrate_blockers, map->nblockers, fea= ture); @@ -1780,41 +1784,13 @@ virCPUx86DataFormat(const virCPUData *data) static virCPUData * virCPUx86DataParse(xmlXPathContextPtr ctxt) { - g_autofree xmlNodePtr *nodes =3D NULL; g_autoptr(virCPUData) cpuData =3D NULL; - virCPUx86DataItem item; - size_t i; - int n; - - n =3D virXPathNodeSet("/cpudata/cpuid|/cpudata/msr", ctxt, &nodes); - if (n <=3D 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("no x86 CPU data found")); - return NULL; - } =20 if (!(cpuData =3D virCPUDataNew(VIR_ARCH_X86_64))) return NULL; =20 - for (i =3D 0; i < n; i++) { - ctxt->node =3D nodes[i]; - if (virXMLNodeNameEqual(nodes[i], "cpuid")) { - if (x86ParseCPUID(ctxt->node, &item) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("failed to parse cpuid[%zu]"), i); - return NULL; - } - } else { - if (x86ParseMSR(ctxt->node, &item) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("failed to parse msr[%zu]"), i); - return NULL; - } - } - - if (virCPUx86DataAdd(cpuData, &item) < 0) - return NULL; - } + if (x86ParseDataItemList(&cpuData->data.x86, ctxt->node) < 0) + return NULL; =20 return g_steal_pointer(&cpuData); } --=20 2.31.1