From nobody Fri Dec 19 19:19:33 2025 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=1678274182; cv=none; d=zohomail.com; s=zohoarc; b=GQY2ED2szkf6bSPiDQ37tAyDLscXa4Sn2B39chxS2HAv8aTQB1LRerJbShaLNVeGrX4fOZrlPGwWuCwHwZHsaFnVOJyferAeJAS1aLEmYxG984ZscxCEz2OudMrmA4jJh/C9BIDajb6gtwRBT+Tz5GYcc9+pejPcUug/zre9WGQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678274182; 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=f5MMbRqpQnJmBWYpBPWRis9mkUFaCF50Nt0W44dl1Jg=; b=PPuYChtEIYCyOdD8IwKfXKY0wSZMeiS9oaDsvOVnJMTt9QW9lzH1xY3cul0rU4ct0M+Ar56S5j45SXfdPKjtnQZoyVOjbiVvXGcoQGRH+NGHA+p6LfGbwzuPAkwCDJSUuaVcSEOuTQ5fdqRMJn/Vjo4vxa6pQsP9OYahYPzM1Yo= 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 1678274182125795.3805323504096; Wed, 8 Mar 2023 03:16:22 -0800 (PST) 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-626-SeLK-s8RPWO29whCiIgwXw-1; Wed, 08 Mar 2023 06:16:17 -0500 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 808253814585; Wed, 8 Mar 2023 11:16:15 +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 6E579492B04; Wed, 8 Mar 2023 11:16:15 +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 4EEDD19465B2; Wed, 8 Mar 2023 11:16:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id E828519465B1 for ; Wed, 8 Mar 2023 11:14:43 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id DC1E8112132D; Wed, 8 Mar 2023 11:14:43 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7E2F21121314 for ; Wed, 8 Mar 2023 11:14:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678274181; 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=f5MMbRqpQnJmBWYpBPWRis9mkUFaCF50Nt0W44dl1Jg=; b=I8OSsskvwzlbhkUMUYF8NLcqnad3YD/nUq8p9S/biLl8zn18eaxG3ktCu+rWvwCiKmbq1+ CSJHcvj2OsLstXotoKBnXy50qZD1v2QV5857RrBmVJNgeAXFPADUtAwD1aPYNmEj6EEAuv SzbgTNhBpY1lvyFRqgkfZaSmxE+Chds= X-MC-Unique: SeLK-s8RPWO29whCiIgwXw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 01/14] virnuma: Move virNumaNodesetToCPUset() our of WITH_NUMACTL Date: Wed, 8 Mar 2023 12:14:28 +0100 Message-Id: <9825d94033018f2873288cfbe520ba39f5271220.1678274036.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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.9 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: 1678274182472100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Technically, there's nothing libnuma specific about virNumaNodesetToCPUset(). It just implements a generic algorithm over virNumaGetNodeCPUs() (which is then libnuma dependant). Nevertheless, there's no need to have this function living inside WITH_NUMACTL block. Any error returned from virNumaGetNodeCPUs() (including the one that !WITH_NUMACTL stub returns) is propagated properly. Move the function out of the block into a generic one and drop the !WITH_NUMACTL stub. Signed-off-by: Michal Privoznik Reviewed-by: Andrea Bolognani Reviewed-by: Kristina Hanicova --- src/util/virnuma.c | 115 +++++++++++++++++++++------------------------ 1 file changed, 53 insertions(+), 62 deletions(-) diff --git a/src/util/virnuma.c b/src/util/virnuma.c index 43e299f4bb..dae0827c65 100644 --- a/src/util/virnuma.c +++ b/src/util/virnuma.c @@ -311,57 +311,6 @@ virNumaGetNodeCPUs(int node, # undef MASK_CPU_ISSET # undef n_bits =20 -/** - * virNumaNodesetToCPUset: - * @nodeset: bitmap containing a set of NUMA nodes - * @cpuset: return location for a bitmap containing a set of CPUs - * - * Convert a set of NUMA node to the set of CPUs they contain. - * - * Returns 0 on success, <0 on failure. - */ -int -virNumaNodesetToCPUset(virBitmap *nodeset, - virBitmap **cpuset) -{ - g_autoptr(virBitmap) allNodesCPUs =3D NULL; - size_t nodesetSize; - size_t i; - - *cpuset =3D NULL; - - if (!nodeset) - return 0; - - allNodesCPUs =3D virBitmapNew(0); - nodesetSize =3D virBitmapSize(nodeset); - - for (i =3D 0; i < nodesetSize; i++) { - g_autoptr(virBitmap) nodeCPUs =3D NULL; - int rc; - - if (!virBitmapIsBitSet(nodeset, i)) - continue; - - rc =3D virNumaGetNodeCPUs(i, &nodeCPUs); - if (rc < 0) { - /* Error is reported for cases other than non-existent NUMA no= de. */ - if (rc =3D=3D -2) { - virReportError(VIR_ERR_OPERATION_FAILED, - _("NUMA node %zu is not available"), - i); - } - return -1; - } - - virBitmapUnion(allNodesCPUs, nodeCPUs); - } - - *cpuset =3D g_steal_pointer(&allNodesCPUs); - - return 0; -} - #else /* !WITH_NUMACTL */ =20 int @@ -417,17 +366,6 @@ virNumaGetNodeCPUs(int node G_GNUC_UNUSED, return -1; } =20 -int -virNumaNodesetToCPUset(virBitmap *nodeset G_GNUC_UNUSED, - virBitmap **cpuset) -{ - *cpuset =3D NULL; - - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("NUMA isn't available on this host")); - return -1; -} - #endif /* !WITH_NUMACTL */ =20 /** @@ -1050,3 +988,56 @@ virNumaGetHostMemoryNodeset(void) =20 return nodeset; } + + +/** + * virNumaNodesetToCPUset: + * @nodeset: bitmap containing a set of NUMA nodes + * @cpuset: return location for a bitmap containing a set of CPUs + * + * Convert a set of NUMA node to the set of CPUs they contain. + * + * Returns 0 on success, + * -1 on failure (with error reported). + */ +int +virNumaNodesetToCPUset(virBitmap *nodeset, + virBitmap **cpuset) +{ + g_autoptr(virBitmap) allNodesCPUs =3D NULL; + size_t nodesetSize; + size_t i; + + *cpuset =3D NULL; + + if (!nodeset) + return 0; + + allNodesCPUs =3D virBitmapNew(0); + nodesetSize =3D virBitmapSize(nodeset); + + for (i =3D 0; i < nodesetSize; i++) { + g_autoptr(virBitmap) nodeCPUs =3D NULL; + int rc; + + if (!virBitmapIsBitSet(nodeset, i)) + continue; + + rc =3D virNumaGetNodeCPUs(i, &nodeCPUs); + if (rc < 0) { + /* Error is reported for cases other than non-existent NUMA no= de. */ + if (rc =3D=3D -2) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("NUMA node %zu is not available"), + i); + } + return -1; + } + + virBitmapUnion(allNodesCPUs, nodeCPUs); + } + + *cpuset =3D g_steal_pointer(&allNodesCPUs); + + return 0; +} --=20 2.39.2