From nobody Sun Feb 8 13:53:33 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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=1596812374; cv=none; d=zohomail.com; s=zohoarc; b=XgUZ3i+IsyJhA6siKJnDSXeFYv6vOt+JXtpqfvb7kiZJ+bcxSpwG+fBNs/wfb+LwWQoCswZ74t0blVcisirHZd18vGtyAh5udWGtISSqBi7nlCoEYiI3eYRL+yIoypI7UDRHqri8rMYdFIPVVZUoT5oS4B400hs59z3ansYrGz4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1596812374; 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=i8iP18pmMiUUIKOAoSjsvIog1NJQlFYArygrE6KZDPA=; b=VTwHkVqzl4uRj8aptTDboTqbtXvS9y2vDh2UcjfsIwRm3VMWMKcBp0uh4XETLb5xnvd3veI79KGwidijo9hw1O9YI+5IG45jzrzLDZyC6TdPFCTFeGSB7vYKNICSGU5JhlwmlDihKM3C0E39O+2FH7mzVdDVWmxYAbF0MgFO4X8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1596812374049420.3442922904926; Fri, 7 Aug 2020 07:59:34 -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-245-BXhylyCCMwW7Mr-SAZkBhg-1; Fri, 07 Aug 2020 10:59:30 -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 10CFC107BF11; Fri, 7 Aug 2020 14:59:25 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E12B165C9E; Fri, 7 Aug 2020 14:59:24 +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 C6D191809554; Fri, 7 Aug 2020 14:59:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 077ExK86022550 for ; Fri, 7 Aug 2020 10:59:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2858365C99; Fri, 7 Aug 2020 14:59:20 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.40.192.28]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6A1EA65C9E for ; Fri, 7 Aug 2020 14:59:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1596812372; 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=i8iP18pmMiUUIKOAoSjsvIog1NJQlFYArygrE6KZDPA=; b=U8EBsKtTLumCtGiDEEmsHMFdl1Bg63/BMfxiIzwodQ7GeE4V2ckkr6rCo52/jNSCfvHdN4 kr5NwNwnasLAYF85yJTBRofTsckiE2MRZ18XrlfKxcBfmdGbWfAMk9bAqHo2tcTxmbc0Uh RA6FcRkR2uOZAOG8UOzWpiX8NTKCw8A= X-MC-Unique: BXhylyCCMwW7Mr-SAZkBhg-1 From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH 1/3] conf: fix detection of available host CPUs for vcpupin Date: Fri, 7 Aug 2020 16:59:12 +0200 Message-Id: <5445263db50db12a3e315e97e87e917f75b2f7a7.1596812211.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com 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" Commit <2020c6af8a8e4bb04acb629d089142be984484c8> fixed an issue with QEMU driver by reporting offline CPUs as well. However, doing so it introduced a regression into libxl and test drivers by completely ignoring the passed `hostcpus` variable. Move the virHostCPUGetAvailableCPUsBitmap() out of the helper into QEMU driver so it will not affect other drivers which gets the number of host CPUs differently. This was uncovered by running libvirt-dbus test suite which counts on the fact that test driver has hard-coded host definition and must not depend on the host at all. Signed-off-by: Pavel Hrdina Reviewed-by: Daniel P. Berrang=C3=A9 --- src/conf/domain_conf.c | 18 +++++------------- src/conf/domain_conf.h | 4 ++-- src/libxl/libxl_driver.c | 7 ++++++- src/qemu/qemu_driver.c | 6 +++++- src/test/test_driver.c | 8 ++++++-- 5 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ef67efa1da..8e7981bf25 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2090,33 +2090,25 @@ virDomainDefHasVcpuPin(const virDomainDef *def) * @maplen: length of one cpumap passed from caller (@cpumaps) * @ncpumaps: count of cpumaps of @maplen length in @cpumaps * @cpumaps: array of pinning information bitmaps to be filled - * @hostcpus: number of cpus in the host + * @hostcpus: default CPU pinning bitmap based on host CPUs * @autoCpuset: Cpu pinning bitmap used in case of automatic cpu pinning * * Fills the @cpumaps array as documented by the virDomainGetVcpuPinInfo A= PI. * In case when automatic cpu pinning is supported, the bitmap should be p= assed - * as @autoCpuset. If @hostcpus is < 0 no error is reported (to pass throu= gh - * error message). + * as @autoCpuset. * - * Returns number of filled entries or -1 on error. + * Returns number of filled entries. */ int virDomainDefGetVcpuPinInfoHelper(virDomainDefPtr def, int maplen, int ncpumaps, unsigned char *cpumaps, - int hostcpus, + virBitmapPtr hostcpus, virBitmapPtr autoCpuset) { int maxvcpus =3D virDomainDefGetVcpusMax(def); size_t i; - g_autoptr(virBitmap) allcpumap =3D NULL; - - if (hostcpus < 0) - return -1; - - if (!(allcpumap =3D virHostCPUGetAvailableCPUsBitmap())) - return -1; =20 for (i =3D 0; i < maxvcpus && i < ncpumaps; i++) { virDomainVcpuDefPtr vcpu =3D virDomainDefGetVcpu(def, i); @@ -2130,7 +2122,7 @@ virDomainDefGetVcpuPinInfoHelper(virDomainDefPtr def, else if (def->cpumask) bitmap =3D def->cpumask; else - bitmap =3D allcpumap; + bitmap =3D hostcpus; =20 virBitmapToDataBuf(bitmap, VIR_GET_CPUMAP(cpumaps, maplen, i), map= len); } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 011bf66cb4..68be32614c 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3741,9 +3741,9 @@ int virDomainDefGetVcpuPinInfoHelper(virDomainDefPtr = def, int maplen, int ncpumaps, unsigned char *cpumaps, - int hostcpus, + virBitmapPtr hostcpus, virBitmapPtr autoCpuset) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4) G_GNUC_WARN_UNUSED_RESULT; + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4) ATTRIBUTE_NONNULL(5) G_GNUC_= WARN_UNUSED_RESULT; =20 bool virDomainDefHasMemballoon(const virDomainDef *def) ATTRIBUTE_NONNULL(= 1); =20 diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 4db3c0782e..dc602ea162 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -2547,6 +2547,7 @@ libxlDomainGetVcpuPinInfo(virDomainPtr dom, int ncpum= aps, libxlDriverConfigPtr cfg =3D libxlDriverConfigGet(driver); virDomainObjPtr vm =3D NULL; virDomainDefPtr targetDef =3D NULL; + g_autoptr(virBitmap) hostcpus =3D NULL; int ret =3D -1; =20 virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | @@ -2568,8 +2569,12 @@ libxlDomainGetVcpuPinInfo(virDomainPtr dom, int ncpu= maps, /* Make sure coverity knows targetDef is valid at this point. */ sa_assert(targetDef); =20 + if (!(hostcpus =3D virBitmapNew(libxl_get_max_cpus(cfg->ctx)))) + goto cleanup; + virBitmapSetAll(hostcpus); + ret =3D virDomainDefGetVcpuPinInfoHelper(targetDef, maplen, ncpumaps, = cpumaps, - libxl_get_max_cpus(cfg->ctx), N= ULL); + hostcpus, NULL); =20 cleanup: virDomainObjEndAPI(&vm); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 0f98243fe4..9eaea8d613 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -5288,6 +5288,7 @@ qemuDomainGetVcpuPinInfo(virDomainPtr dom, virDomainDefPtr def; bool live; int ret =3D -1; + g_autoptr(virBitmap) hostcpus =3D NULL; virBitmapPtr autoCpuset =3D NULL; =20 virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | @@ -5302,11 +5303,14 @@ qemuDomainGetVcpuPinInfo(virDomainPtr dom, if (!(def =3D virDomainObjGetOneDefState(vm, flags, &live))) goto cleanup; =20 + if (!(hostcpus =3D virHostCPUGetAvailableCPUsBitmap())) + goto cleanup; + if (live) autoCpuset =3D QEMU_DOMAIN_PRIVATE(vm)->autoCpuset; =20 ret =3D virDomainDefGetVcpuPinInfoHelper(def, maplen, ncpumaps, cpumap= s, - virHostCPUGetCount(), autoCpuse= t); + hostcpus, autoCpuset); cleanup: virDomainObjEndAPI(&vm); return ret; diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 01c4675c30..a75c992af1 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -3072,6 +3072,7 @@ testDomainGetVcpuPinInfo(virDomainPtr dom, testDriverPtr driver =3D dom->conn->privateData; virDomainObjPtr privdom; virDomainDefPtr def; + g_autoptr(virBitmap) hostcpus =3D NULL; int ret =3D -1; =20 if (!(privdom =3D testDomObjFromDomain(dom))) @@ -3080,9 +3081,12 @@ testDomainGetVcpuPinInfo(virDomainPtr dom, if (!(def =3D virDomainObjGetOneDef(privdom, flags))) goto cleanup; =20 + if (!(hostcpus =3D virBitmapNew(VIR_NODEINFO_MAXCPUS(driver->nodeInfo)= ))) + goto cleanup; + virBitmapSetAll(hostcpus); + ret =3D virDomainDefGetVcpuPinInfoHelper(def, maplen, ncpumaps, cpumap= s, - VIR_NODEINFO_MAXCPUS(driver->no= deInfo), - NULL); + hostcpus, NULL); =20 cleanup: virDomainObjEndAPI(&privdom); --=20 2.26.2