From nobody Thu May 15 10:08:39 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1510563077645802.6312641946548; Mon, 13 Nov 2017 00:51:17 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 669571A4064; Mon, 13 Nov 2017 08:51:15 +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 3704E78410; Mon, 13 Nov 2017 08:51:15 +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 F36A71802130; Mon, 13 Nov 2017 08:51:14 +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 vAD8omJO016341 for ; Mon, 13 Nov 2017 03:50:48 -0500 Received: by smtp.corp.redhat.com (Postfix) id E057F5E278; Mon, 13 Nov 2017 08:50:48 +0000 (UTC) Received: from caroline.localdomain (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B2F695E27A for ; Mon, 13 Nov 2017 08:50:46 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.brq.redhat.com [127.0.0.1]) by caroline.localdomain (Postfix) with ESMTP id 82A6A123A7E for ; Mon, 13 Nov 2017 09:50:41 +0100 (CET) From: Martin Kletzander To: libvir-list@redhat.com Date: Mon, 13 Nov 2017 09:50:24 +0100 Message-Id: <716e610108257d1d1a103f9adedc935459dcdb4e.1510560300.git.mkletzan@redhat.com> 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 Subject: [libvirt] [PATCH 09/21] util: Introduce 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 13 Nov 2017 08:51:15 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Sometimes the size of the bitmap matters and it might not be guessed correc= tly when parsing from some type of input. For example virBitmapNewData() has B= yte granularity, virBitmapNewString() has nibble granularity and so on. virBitmapParseUnlimited() can be tricked into creating huge bitmap that's n= ot needed (e.g.: "0-2,^99999999"). This function provides a way to shrink the bitmap. It is not supposed to free any memory. Signed-off-by: Martin Kletzander Reviewed-by: John Ferlan --- src/libvirt_private.syms | 1 + src/util/virbitmap.c | 19 +++++++++++++++++++ src/util/virbitmap.h | 2 ++ 3 files changed, 22 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 0b78a0681c5e..3986cc523e39 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1369,6 +1369,7 @@ virBitmapParseUnlimited; virBitmapSetAll; virBitmapSetBit; virBitmapSetBitExpand; +virBitmapShrink; virBitmapSize; virBitmapSubtract; virBitmapToData; diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index ac6ff4f6d26d..95b1f8656907 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -176,6 +176,25 @@ int virBitmapSetBit(virBitmapPtr bitmap, size_t b) return 0; } =20 + +/** + * virBitmapShrink: + * @map: Pointer to bitmap + * @b: last bit position to be excluded from bitmap + * + * Resizes the bitmap so that no more than @b bits will fit into it. Noth= ing + * will change if the size is already smaller than @b. + */ +void virBitmapShrink(virBitmapPtr map, size_t b) +{ + if (!map) + return; + + if (map->max_bit >=3D b) + map->max_bit =3D b; +} + + /** * virBitmapExpand: * @map: Pointer to bitmap diff --git a/src/util/virbitmap.h b/src/util/virbitmap.h index 7b2bea8b534c..2464814055de 100644 --- a/src/util/virbitmap.h +++ b/src/util/virbitmap.h @@ -153,4 +153,6 @@ void virBitmapIntersect(virBitmapPtr a, virBitmapPtr b) void virBitmapSubtract(virBitmapPtr a, virBitmapPtr b) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); =20 +void virBitmapShrink(virBitmapPtr map, size_t b); + #endif --=20 2.15.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list