From nobody Mon Dec 15 01:55:43 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1517836728567506.4782912130772; Mon, 5 Feb 2018 05:18:48 -0800 (PST) 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 mx1.redhat.com (Postfix) with ESMTPS id A53BD49024; Mon, 5 Feb 2018 13:18:47 +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 7DE8B6B262; Mon, 5 Feb 2018 13:18:47 +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 30AFF18033DE; Mon, 5 Feb 2018 13:18:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w15DIcsg000332 for ; Mon, 5 Feb 2018 08:18:38 -0500 Received: by smtp.corp.redhat.com (Postfix) id 33C58659E7; Mon, 5 Feb 2018 13:18:38 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7F26A5D9CB; Mon, 5 Feb 2018 13:18:36 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Mon, 5 Feb 2018 14:17:46 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 5/6] util: bitmap: Use VIR_SHRINK_N in virBitmapShrink 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 05 Feb 2018 13:18:48 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The function only reduces the size of the bitmap thus we can use the appropriate shrinking function which also does not have any return value. Since virBitmapShrink now does not return any value callers need to be fixed as well. --- src/conf/domain_conf.c | 3 +-- src/util/virbitmap.c | 20 ++++++++++---------- src/util/virbitmap.h | 2 +- src/util/virresctrl.c | 3 +-- tests/virbitmaptest.c | 6 ++---- 5 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index e827b2a810..34aae82f15 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18453,8 +18453,7 @@ virDomainCachetuneDefParse(virDomainDefPtr def, /* We need to limit the bitmap to number of vCPUs. If there's nothing= left, * then we can just clean up and return 0 immediately */ - if (virBitmapShrink(vcpus, def->maxvcpus) < 0) - goto cleanup; + virBitmapShrink(vcpus, def->maxvcpus); if (virBitmapIsAllClear(vcpus)) { ret =3D 0; diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index d1e5a9d1ea..82b1f76427 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -1292,15 +1292,16 @@ virBitmapSubtract(virBitmapPtr a, * Reduces the bitmap to size @b. Nothing will change if the size is alre= ady * smaller than or equal to @b. */ -int +void virBitmapShrink(virBitmapPtr map, size_t b) { + size_t toremove; size_t nl =3D 0; size_t nb =3D 0; if (!map) - return 0; + return; if (map->nbits >=3D b) map->nbits =3D b; @@ -1309,14 +1310,13 @@ virBitmapShrink(virBitmapPtr map, nb =3D map->nbits % VIR_BITMAP_BITS_PER_UNIT; map->map[nl] &=3D ((1UL << nb) - 1); - nl++; - if (nl =3D=3D map->map_len) - return 0; + toremove =3D map->map_alloc - (nl + 1); - if (VIR_REALLOC_N(map->map, nl) < 0) - return -1; + if (toremove =3D=3D 0) + return; - map->map_len =3D nl; - map->map_alloc =3D nl; - return 0; + VIR_SHRINK_N(map->map, map->map_alloc, toremove); + + /* length needs to be fixed as well */ + map->map_len =3D map->map_alloc; } diff --git a/src/util/virbitmap.h b/src/util/virbitmap.h index 5a3362a19f..2464814055 100644 --- a/src/util/virbitmap.h +++ b/src/util/virbitmap.h @@ -153,6 +153,6 @@ void virBitmapIntersect(virBitmapPtr a, virBitmapPtr b) void virBitmapSubtract(virBitmapPtr a, virBitmapPtr b) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); -int virBitmapShrink(virBitmapPtr map, size_t b); +void virBitmapShrink(virBitmapPtr map, size_t b); #endif diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index ef388757a7..70426199ce 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -941,8 +941,7 @@ virResctrlAllocParseProcessCache(virResctrlInfoPtr resc= trl, if (!mask) return -1; - if (virBitmapShrink(mask, resctrl->levels[level]->types[type]->bits) <= 0) - goto cleanup; + virBitmapShrink(mask, resctrl->levels[level]->types[type]->bits); if (virResctrlAllocUpdateMask(alloc, level, type, cache_id, mask) < 0) goto cleanup; diff --git a/tests/virbitmaptest.c b/tests/virbitmaptest.c index fffecdf1f6..2fbafc0a76 100644 --- a/tests/virbitmaptest.c +++ b/tests/virbitmaptest.c @@ -656,12 +656,10 @@ test12(const void *opaque ATTRIBUTE_UNUSED) TEST_MAP(1024, "34,1023"); - if (virBitmapShrink(map, 35) < 0) - goto cleanup; + virBitmapShrink(map, 35); TEST_MAP(35, "34"); - if (virBitmapShrink(map, 34) < 0) - goto cleanup; + virBitmapShrink(map, 34); TEST_MAP(34, ""); ret =3D 0; --=20 2.15.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list