From nobody Sun Apr 28 22:47:04 2024 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 1517836713480584.6721324396283; Mon, 5 Feb 2018 05:18:33 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 954AC28203; Mon, 5 Feb 2018 13:18:32 +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 684FC18BAA; Mon, 5 Feb 2018 13:18:32 +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 2BF1241FAE; Mon, 5 Feb 2018 13:18:32 +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 w15DIV5O032742 for ; Mon, 5 Feb 2018 08:18:31 -0500 Received: by smtp.corp.redhat.com (Postfix) id B37FF18BA8; Mon, 5 Feb 2018 13:18:31 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 10EAC659EC; Mon, 5 Feb 2018 13:18:28 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Mon, 5 Feb 2018 14:17:42 +0100 Message-Id: <7ae883863e7d20aef8d2e3bde6350a45a7612518.1517836057.git.pkrempa@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 Cc: Peter Krempa Subject: [libvirt] [PATCH 1/6] util: bitmap: Rename 'max_bit' to 'nbits' 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 05 Feb 2018 13:18:33 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 'max_bit' is misleading as the value is set to the first invalid bit as it's used as the number of bits in the bitmap. Rename it to a more descriptive name. --- src/util/virbitmap.c | 54 ++++++++++++++++++++++++++----------------------= ---- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index 33cae2f305..c1b97d90fb 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -42,7 +42,7 @@ #define VIR_FROM_THIS VIR_FROM_NONE struct _virBitmap { - size_t max_bit; + size_t nbits; size_t map_len; size_t map_alloc; unsigned long *map; @@ -83,7 +83,7 @@ virBitmapNewQuiet(size_t size) return NULL; } - bitmap->max_bit =3D size; + bitmap->nbits =3D size; bitmap->map_len =3D sz; bitmap->map_alloc =3D sz; return bitmap; @@ -147,7 +147,7 @@ void virBitmapFree(virBitmapPtr bitmap) int virBitmapCopy(virBitmapPtr dst, virBitmapPtr src) { - if (dst->max_bit !=3D src->max_bit) { + if (dst->nbits !=3D src->nbits) { errno =3D EINVAL; return -1; } @@ -169,7 +169,7 @@ int virBitmapCopy(virBitmapPtr dst, virBitmapPtr src) */ int virBitmapSetBit(virBitmapPtr bitmap, size_t b) { - if (bitmap->max_bit <=3D b) + if (bitmap->nbits <=3D b) return -1; bitmap->map[VIR_BITMAP_UNIT_OFFSET(b)] |=3D VIR_BITMAP_BIT(b); @@ -197,7 +197,7 @@ static int virBitmapExpand(virBitmapPtr map, size_t b) return -1; } - map->max_bit =3D b + 1; + map->nbits =3D b + 1; map->map_len =3D new_len; return 0; @@ -216,7 +216,7 @@ static int virBitmapExpand(virBitmapPtr map, size_t b) */ int virBitmapSetBitExpand(virBitmapPtr bitmap, size_t b) { - if (bitmap->max_bit <=3D b && virBitmapExpand(bitmap, b) < 0) + if (bitmap->nbits <=3D b && virBitmapExpand(bitmap, b) < 0) return -1; bitmap->map[VIR_BITMAP_UNIT_OFFSET(b)] |=3D VIR_BITMAP_BIT(b); @@ -235,7 +235,7 @@ int virBitmapSetBitExpand(virBitmapPtr bitmap, size_t b) */ int virBitmapClearBit(virBitmapPtr bitmap, size_t b) { - if (bitmap->max_bit <=3D b) + if (bitmap->nbits <=3D b) return -1; bitmap->map[VIR_BITMAP_UNIT_OFFSET(b)] &=3D ~VIR_BITMAP_BIT(b); @@ -255,7 +255,7 @@ int virBitmapClearBit(virBitmapPtr bitmap, size_t b) */ int virBitmapClearBitExpand(virBitmapPtr bitmap, size_t b) { - if (bitmap->max_bit <=3D b) { + if (bitmap->nbits <=3D b) { if (virBitmapExpand(bitmap, b) < 0) return -1; } else { @@ -266,7 +266,7 @@ int virBitmapClearBitExpand(virBitmapPtr bitmap, size_t= b) } -/* Helper function. caller must ensure b < bitmap->max_bit */ +/* Helper function. caller must ensure b < bitmap->nbits */ static bool virBitmapIsSet(virBitmapPtr bitmap, size_t b) { return !!(bitmap->map[VIR_BITMAP_UNIT_OFFSET(b)] & VIR_BITMAP_BIT(b)); @@ -284,7 +284,7 @@ static bool virBitmapIsSet(virBitmapPtr bitmap, size_t = b) */ bool virBitmapIsBitSet(virBitmapPtr bitmap, size_t b) { - if (bitmap->max_bit <=3D b) + if (bitmap->nbits <=3D b) return false; return virBitmapIsSet(bitmap, b); @@ -303,7 +303,7 @@ bool virBitmapIsBitSet(virBitmapPtr bitmap, size_t b) */ int virBitmapGetBit(virBitmapPtr bitmap, size_t b, bool *result) { - if (bitmap->max_bit <=3D b) + if (bitmap->nbits <=3D b) return -1; *result =3D virBitmapIsSet(bitmap, b); @@ -350,14 +350,14 @@ virBitmapToString(virBitmapPtr bitmap, if (!trim) return ret; - if (bitmap->max_bit !=3D bitmap->map_len * VIR_BITMAP_BITS_PER_UNIT) { + if (bitmap->nbits !=3D bitmap->map_len * VIR_BITMAP_BITS_PER_UNIT) { char *tmp =3D ret; if (prefix) tmp +=3D 2; len =3D strlen(tmp); - sz =3D VIR_DIV_UP(bitmap->max_bit, 4); + sz =3D VIR_DIV_UP(bitmap->nbits, 4); diff =3D len - sz; if (diff) @@ -692,7 +692,7 @@ virBitmapPtr virBitmapNewCopy(virBitmapPtr src) { virBitmapPtr dst; - if ((dst =3D virBitmapNew(src->max_bit)) =3D=3D NULL) + if ((dst =3D virBitmapNew(src->nbits)) =3D=3D NULL) return NULL; if (virBitmapCopy(dst, src) !=3D 0) { @@ -818,7 +818,7 @@ bool virBitmapEqual(virBitmapPtr b1, virBitmapPtr b2) if (!b1 || !b2) return false; - if (b1->max_bit > b2->max_bit) { + if (b1->nbits > b2->nbits) { tmp =3D b1; b1 =3D b2; b2 =3D tmp; @@ -841,7 +841,7 @@ bool virBitmapEqual(virBitmapPtr b1, virBitmapPtr b2) size_t virBitmapSize(virBitmapPtr bitmap) { - return bitmap->max_bit; + return bitmap->nbits; } /** @@ -852,7 +852,7 @@ size_t virBitmapSize(virBitmapPtr bitmap) */ void virBitmapSetAll(virBitmapPtr bitmap) { - int tail =3D bitmap->max_bit % VIR_BITMAP_BITS_PER_UNIT; + int tail =3D bitmap->nbits % VIR_BITMAP_BITS_PER_UNIT; memset(bitmap->map, 0xff, bitmap->map_len * (VIR_BITMAP_BITS_PER_UNIT / CHAR_BIT)); @@ -887,7 +887,7 @@ bool virBitmapIsAllSet(virBitmapPtr bitmap) int unusedBits; size_t sz; - unusedBits =3D bitmap->map_len * VIR_BITMAP_BITS_PER_UNIT - bitmap->ma= x_bit; + unusedBits =3D bitmap->map_len * VIR_BITMAP_BITS_PER_UNIT - bitmap->nb= its; sz =3D bitmap->map_len; if (unusedBits > 0) @@ -946,7 +946,7 @@ virBitmapNextSetBit(virBitmapPtr bitmap, ssize_t pos) pos++; - if (pos >=3D bitmap->max_bit) + if (pos >=3D bitmap->nbits) return -1; nl =3D pos / VIR_BITMAP_BITS_PER_UNIT; @@ -983,7 +983,7 @@ virBitmapLastSetBit(virBitmapPtr bitmap) if (bitmap->map_len =3D=3D 0) return -1; - unusedBits =3D bitmap->map_len * VIR_BITMAP_BITS_PER_UNIT - bitmap->ma= x_bit; + unusedBits =3D bitmap->map_len * VIR_BITMAP_BITS_PER_UNIT - bitmap->nb= its; sz =3D bitmap->map_len - 1; if (unusedBits > 0) { @@ -1035,7 +1035,7 @@ virBitmapNextClearBit(virBitmapPtr bitmap, ssize_t po= s) pos++; - if (pos >=3D bitmap->max_bit) + if (pos >=3D bitmap->nbits) return -1; nl =3D pos / VIR_BITMAP_BITS_PER_UNIT; @@ -1048,7 +1048,7 @@ virBitmapNextClearBit(virBitmapPtr bitmap, ssize_t po= s) if (nl =3D=3D bitmap->map_len - 1) { /* Ensure tail bits are ignored. */ - int tail =3D bitmap->max_bit % VIR_BITMAP_BITS_PER_UNIT; + int tail =3D bitmap->nbits % VIR_BITMAP_BITS_PER_UNIT; if (tail) bits &=3D -1UL >> (VIR_BITMAP_BITS_PER_UNIT - tail); @@ -1140,7 +1140,7 @@ virBitmapOverlaps(virBitmapPtr b1, { size_t i; - if (b1->max_bit > b2->max_bit) { + if (b1->nbits > b2->nbits) { virBitmapPtr tmp =3D b1; b1 =3D b2; b2 =3D tmp; @@ -1216,11 +1216,11 @@ virBitmapShrink(virBitmapPtr map, if (!map) return 0; - if (map->max_bit >=3D b) - map->max_bit =3D b; + if (map->nbits >=3D b) + map->nbits =3D b; - nl =3D map->max_bit / VIR_BITMAP_BITS_PER_UNIT; - nb =3D map->max_bit % VIR_BITMAP_BITS_PER_UNIT; + nl =3D map->nbits / VIR_BITMAP_BITS_PER_UNIT; + nb =3D map->nbits % VIR_BITMAP_BITS_PER_UNIT; map->map[nl] &=3D ((1UL << nb) - 1); nl++; --=20 2.15.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 22:47:04 2024 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 1517836717944279.39738757923976; Mon, 5 Feb 2018 05:18:37 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E497F81239; Mon, 5 Feb 2018 13:18:36 +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 BAE96691C2; Mon, 5 Feb 2018 13:18:36 +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 7F31A18033DA; Mon, 5 Feb 2018 13:18:36 +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 w15DIWtV032754 for ; Mon, 5 Feb 2018 08:18:32 -0500 Received: by smtp.corp.redhat.com (Postfix) id B15B918E57; Mon, 5 Feb 2018 13:18:32 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0D86D5D9CB; Mon, 5 Feb 2018 13:18:31 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Mon, 5 Feb 2018 14:17:43 +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 2/6] util: bitmap: Fix function formatting and spacing 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 05 Feb 2018 13:18:37 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" --- src/util/virbitmap.c | 107 +++++++++++++++++++++++++++++++++++++++--------= ---- 1 file changed, 83 insertions(+), 24 deletions(-) diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index c1b97d90fb..4229aa286e 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -136,7 +136,8 @@ virBitmapNewEmpty(void) * * Free @bitmap previously allocated by virBitmapNew. */ -void virBitmapFree(virBitmapPtr bitmap) +void +virBitmapFree(virBitmapPtr bitmap) { if (bitmap) { VIR_FREE(bitmap->map); @@ -145,7 +146,9 @@ void virBitmapFree(virBitmapPtr bitmap) } -int virBitmapCopy(virBitmapPtr dst, virBitmapPtr src) +int +virBitmapCopy(virBitmapPtr dst, + virBitmapPtr src) { if (dst->nbits !=3D src->nbits) { errno =3D EINVAL; @@ -167,7 +170,9 @@ int virBitmapCopy(virBitmapPtr dst, virBitmapPtr src) * * Returns 0 on if bit is successfully set, -1 on error. */ -int virBitmapSetBit(virBitmapPtr bitmap, size_t b) +int +virBitmapSetBit(virBitmapPtr bitmap, + size_t b) { if (bitmap->nbits <=3D b) return -1; @@ -176,6 +181,7 @@ int virBitmapSetBit(virBitmapPtr bitmap, size_t b) return 0; } + /** * virBitmapExpand: * @map: Pointer to bitmap @@ -186,7 +192,9 @@ int virBitmapSetBit(virBitmapPtr bitmap, size_t b) * * Returns 0 on success, -1 on error. */ -static int virBitmapExpand(virBitmapPtr map, size_t b) +static int +virBitmapExpand(virBitmapPtr map, + size_t b) { size_t new_len =3D VIR_DIV_UP(b + 1, VIR_BITMAP_BITS_PER_UNIT); @@ -214,7 +222,9 @@ static int virBitmapExpand(virBitmapPtr map, size_t b) * * Returns 0 on if bit is successfully set, -1 on error. */ -int virBitmapSetBitExpand(virBitmapPtr bitmap, size_t b) +int +virBitmapSetBitExpand(virBitmapPtr bitmap, + size_t b) { if (bitmap->nbits <=3D b && virBitmapExpand(bitmap, b) < 0) return -1; @@ -233,7 +243,9 @@ int virBitmapSetBitExpand(virBitmapPtr bitmap, size_t b) * * Returns 0 on if bit is successfully clear, -1 on error. */ -int virBitmapClearBit(virBitmapPtr bitmap, size_t b) +int +virBitmapClearBit(virBitmapPtr bitmap, + size_t b) { if (bitmap->nbits <=3D b) return -1; @@ -253,7 +265,9 @@ int virBitmapClearBit(virBitmapPtr bitmap, size_t b) * * Returns 0 on if bit is successfully cleared, -1 on error. */ -int virBitmapClearBitExpand(virBitmapPtr bitmap, size_t b) +int +virBitmapClearBitExpand(virBitmapPtr bitmap, + size_t b) { if (bitmap->nbits <=3D b) { if (virBitmapExpand(bitmap, b) < 0) @@ -267,11 +281,13 @@ int virBitmapClearBitExpand(virBitmapPtr bitmap, size= _t b) /* Helper function. caller must ensure b < bitmap->nbits */ -static bool virBitmapIsSet(virBitmapPtr bitmap, size_t b) +static bool +virBitmapIsSet(virBitmapPtr bitmap, size_t b) { return !!(bitmap->map[VIR_BITMAP_UNIT_OFFSET(b)] & VIR_BITMAP_BIT(b)); } + /** * virBitmapIsBitSet: * @bitmap: Pointer to bitmap @@ -282,7 +298,9 @@ static bool virBitmapIsSet(virBitmapPtr bitmap, size_t = b) * If @b is in the range of @bitmap, returns the value of the bit. * Otherwise false is returned. */ -bool virBitmapIsBitSet(virBitmapPtr bitmap, size_t b) +bool +virBitmapIsBitSet(virBitmapPtr bitmap, + size_t b) { if (bitmap->nbits <=3D b) return false; @@ -290,6 +308,7 @@ bool virBitmapIsBitSet(virBitmapPtr bitmap, size_t b) return virBitmapIsSet(bitmap, b); } + /** * virBitmapGetBit: * @bitmap: Pointer to bitmap @@ -301,7 +320,10 @@ bool virBitmapIsBitSet(virBitmapPtr bitmap, size_t b) * On success, @result will contain the setting of @b and 0 is * returned. On failure, -1 is returned and @result is unchanged. */ -int virBitmapGetBit(virBitmapPtr bitmap, size_t b, bool *result) +int +virBitmapGetBit(virBitmapPtr bitmap, + size_t b, + bool *result) { if (bitmap->nbits <=3D b) return -1; @@ -310,6 +332,7 @@ int virBitmapGetBit(virBitmapPtr bitmap, size_t b, bool= *result) return 0; } + /** * virBitmapToString: * @bitmap: Pointer to bitmap @@ -367,6 +390,7 @@ virBitmapToString(virBitmapPtr bitmap, return ret; } + /** * virBitmapFormat: * @bitmap: the bitmap @@ -381,7 +405,8 @@ virBitmapToString(virBitmapPtr bitmap, * Returns the string on success or NULL otherwise. Caller should call * VIR_FREE to free the string. */ -char *virBitmapFormat(virBitmapPtr bitmap) +char * +virBitmapFormat(virBitmapPtr bitmap) { virBuffer buf =3D VIR_BUFFER_INITIALIZER; bool first =3D true; @@ -426,6 +451,7 @@ char *virBitmapFormat(virBitmapPtr bitmap) return virBufferContentAndReset(&buf); } + /** * virBitmapParseSeparator: * @str: points to a string representing a human-readable bitmap @@ -546,6 +572,7 @@ virBitmapParseSeparator(const char *str, return -1; } + /** * virBitmapParse: * @str: points to a string representing a human-readable bitmap @@ -569,6 +596,7 @@ virBitmapParse(const char *str, return virBitmapParseSeparator(str, '\0', bitmap, bitmapSize); } + /** * virBitmapParseUnlimited: * @str: points to a string representing a human-readable bitmap @@ -679,6 +707,7 @@ virBitmapParseUnlimited(const char *str) return NULL; } + /** * virBitmapNewCopy: * @src: the source bitmap. @@ -688,7 +717,8 @@ virBitmapParseUnlimited(const char *str) * returns the copied bitmap on success, or NULL otherwise. Caller * should call virBitmapFree to free the returned bitmap. */ -virBitmapPtr virBitmapNewCopy(virBitmapPtr src) +virBitmapPtr +virBitmapNewCopy(virBitmapPtr src) { virBitmapPtr dst; @@ -703,6 +733,7 @@ virBitmapPtr virBitmapNewCopy(virBitmapPtr src) return dst; } + /** * virBitmapNewData: * @data: the data @@ -714,7 +745,9 @@ virBitmapPtr virBitmapNewCopy(virBitmapPtr src) * Returns a pointer to the allocated bitmap or NULL if * memory cannot be allocated. */ -virBitmapPtr virBitmapNewData(const void *data, int len) +virBitmapPtr +virBitmapNewData(const void *data, + int len) { virBitmapPtr bitmap; size_t i, j; @@ -738,6 +771,7 @@ virBitmapPtr virBitmapNewData(const void *data, int len) return bitmap; } + /** * virBitmapToData: * @data: the data @@ -749,7 +783,10 @@ virBitmapPtr virBitmapNewData(const void *data, int le= n) * * Returns 0 on success, -1 otherwise. */ -int virBitmapToData(virBitmapPtr bitmap, unsigned char **data, int *dataLe= n) +int +virBitmapToData(virBitmapPtr bitmap, + unsigned char **data, + int *dataLen) { ssize_t len; @@ -768,6 +805,7 @@ int virBitmapToData(virBitmapPtr bitmap, unsigned char = **data, int *dataLen) return 0; } + /** * virBitmapToDataBuf: * @bytes: pointer to memory to fill @@ -777,9 +815,10 @@ int virBitmapToData(virBitmapPtr bitmap, unsigned char= **data, int *dataLen) * Data consists of sequential bytes, with lower bytes containing * lower bits. */ -void virBitmapToDataBuf(virBitmapPtr bitmap, - unsigned char *bytes, - size_t len) +void +virBitmapToDataBuf(virBitmapPtr bitmap, + unsigned char *bytes, + size_t len) { unsigned long *l; size_t i, j; @@ -797,6 +836,7 @@ void virBitmapToDataBuf(virBitmapPtr bitmap, } } + /** * virBitmapEqual: * @b1: bitmap 1 @@ -807,7 +847,9 @@ void virBitmapToDataBuf(virBitmapPtr bitmap, * Returns true if two bitmaps have exactly the same set of bits set, * otherwise false. */ -bool virBitmapEqual(virBitmapPtr b1, virBitmapPtr b2) +bool +virBitmapEqual(virBitmapPtr b1, + virBitmapPtr b2) { virBitmapPtr tmp; size_t i; @@ -839,11 +881,14 @@ bool virBitmapEqual(virBitmapPtr b1, virBitmapPtr b2) return true; } -size_t virBitmapSize(virBitmapPtr bitmap) + +size_t +virBitmapSize(virBitmapPtr bitmap) { return bitmap->nbits; } + /** * virBitmapSetAll: * @bitmap: the bitmap @@ -863,25 +908,29 @@ void virBitmapSetAll(virBitmapPtr bitmap) -1UL >> (VIR_BITMAP_BITS_PER_UNIT - tail); } + /** * virBitmapClearAll: * @bitmap: the bitmap * * clear all bits in @bitmap. */ -void virBitmapClearAll(virBitmapPtr bitmap) +void +virBitmapClearAll(virBitmapPtr bitmap) { memset(bitmap->map, 0, bitmap->map_len * (VIR_BITMAP_BITS_PER_UNIT / CHAR_BIT)); } + /** * virBitmapIsAllSet: * @bitmap: the bitmap to check * * check if all bits in @bitmap are set. */ -bool virBitmapIsAllSet(virBitmapPtr bitmap) +bool +virBitmapIsAllSet(virBitmapPtr bitmap) { size_t i; int unusedBits; @@ -906,13 +955,15 @@ bool virBitmapIsAllSet(virBitmapPtr bitmap) return true; } + /** * virBitmapIsAllClear: * @bitmap: the bitmap to check * * check if all bits in @bitmap are clear */ -bool virBitmapIsAllClear(virBitmapPtr bitmap) +bool +virBitmapIsAllClear(virBitmapPtr bitmap) { size_t i; @@ -923,6 +974,7 @@ bool virBitmapIsAllClear(virBitmapPtr bitmap) return true; } + /** * virBitmapNextSetBit: * @bitmap: the bitmap @@ -935,7 +987,8 @@ bool virBitmapIsAllClear(virBitmapPtr bitmap) * Returns the position of the found bit, or -1 if no bit found. */ ssize_t -virBitmapNextSetBit(virBitmapPtr bitmap, ssize_t pos) +virBitmapNextSetBit(virBitmapPtr bitmap, + ssize_t pos) { size_t nl; size_t nb; @@ -963,6 +1016,7 @@ virBitmapNextSetBit(virBitmapPtr bitmap, ssize_t pos) return ffsl(bits) - 1 + nl * VIR_BITMAP_BITS_PER_UNIT; } + /** * virBitmapLastSetBit: * @bitmap: the bitmap @@ -1012,6 +1066,7 @@ virBitmapLastSetBit(virBitmapPtr bitmap) return -1; } + /** * virBitmapNextClearBit: * @bitmap: the bitmap @@ -1024,7 +1079,8 @@ virBitmapLastSetBit(virBitmapPtr bitmap) * Returns the position of the found bit, or -1 if no bit found. */ ssize_t -virBitmapNextClearBit(virBitmapPtr bitmap, ssize_t pos) +virBitmapNextClearBit(virBitmapPtr bitmap, + ssize_t pos) { size_t nl; size_t nb; @@ -1059,6 +1115,7 @@ virBitmapNextClearBit(virBitmapPtr bitmap, ssize_t po= s) return ffsl(bits) - 1 + nl * VIR_BITMAP_BITS_PER_UNIT; } + /* Return the number of bits currently set in the map. */ size_t virBitmapCountBits(virBitmapPtr bitmap) @@ -1134,6 +1191,7 @@ virBitmapDataFormat(const void *data, return ret; } + bool virBitmapOverlaps(virBitmapPtr b1, virBitmapPtr b2) @@ -1154,6 +1212,7 @@ virBitmapOverlaps(virBitmapPtr b1, return false; } + /** * virBitmapIntersect: * @a: bitmap, modified to contain result --=20 2.15.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 22:47:04 2024 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 1517836722227871.9180279025813; Mon, 5 Feb 2018 05:18:42 -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 16A3C883B0; Mon, 5 Feb 2018 13:18:41 +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 E671F19F1F; Mon, 5 Feb 2018 13:18:40 +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 AAD824EBD7; Mon, 5 Feb 2018 13:18:40 +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 w15DIYII000306 for ; Mon, 5 Feb 2018 08:18:34 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0A90D18BAA; Mon, 5 Feb 2018 13:18:34 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5CAB05D9CB; Mon, 5 Feb 2018 13:18:32 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Mon, 5 Feb 2018 14:17:44 +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 3/6] util: bitmap: Add comments for functions which don't have them 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.26]); Mon, 05 Feb 2018 13:18:41 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" virBitmap code is thoroughly documented. Add docs for the few functions missing them. --- src/util/virbitmap.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index 4229aa286e..0973731e3a 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -146,6 +146,14 @@ virBitmapFree(virBitmapPtr bitmap) } +/** + * virBitmapCopy: + * @dst: destination bitmap + * @src: source bitmap + * + * Copies contents of @src to @dst. @dst must have the same size as @src. + * Returns -1 if the size is not the same or 0 on success. + */ int virBitmapCopy(virBitmapPtr dst, virBitmapPtr src) @@ -882,6 +890,12 @@ virBitmapEqual(virBitmapPtr b1, } +/** + * virBitmapSize: + * @bitmap: virBitmap to inspect + * + * Returns number of bits @bitmap can store. + */ size_t virBitmapSize(virBitmapPtr bitmap) { @@ -1116,7 +1130,12 @@ virBitmapNextClearBit(virBitmapPtr bitmap, } -/* Return the number of bits currently set in the map. */ +/** + * virBitmapCountBits: + * @bitmap: bitmap to inspect + * + * Return the number of bits currently set in @bitmap. + */ size_t virBitmapCountBits(virBitmapPtr bitmap) { @@ -1192,6 +1211,14 @@ virBitmapDataFormat(const void *data, } +/** + * virBitmapOverlaps: + * @b1: virBitmap to inspect + * @b2: virBitmap to inspect + * + * Returns true if at least one bit with the same index is set both in @b1= and + * @b2. + */ bool virBitmapOverlaps(virBitmapPtr b1, virBitmapPtr b2) --=20 2.15.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 22:47:04 2024 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 1517836725367989.9216283576634; Mon, 5 Feb 2018 05:18:45 -0800 (PST) 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 mx1.redhat.com (Postfix) with ESMTPS id 613E461471; Mon, 5 Feb 2018 13:18:44 +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 210ED5EE15; Mon, 5 Feb 2018 13:18:44 +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 C983F5FBD7; Mon, 5 Feb 2018 13:18:43 +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 w15DIa3H000319 for ; Mon, 5 Feb 2018 08:18:36 -0500 Received: by smtp.corp.redhat.com (Postfix) id 30CEB5D9CB; Mon, 5 Feb 2018 13:18:36 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9A43F18E5B; Mon, 5 Feb 2018 13:18:34 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Mon, 5 Feb 2018 14:17:45 +0100 Message-Id: <7b8592cd6aaf105a1a9d08888e76ae2b4d391e5b.1517836057.git.pkrempa@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 Cc: Peter Krempa Subject: [libvirt] [PATCH 4/6] util: bitmap: Fix value of 'map_alloc' when shrinking bitmap 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 05 Feb 2018 13:18:44 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The virBitmap code uses VIR_RESIZE_N to do quadratic scaling, which means that along with the number of requested map elements we also need to keep the number of actually allocated elements for the scaling algorithm to work properly. The shrinking code did not fix 'map_alloc' thus virResizeN might actually not expand the bitmap properly after called on a previously shrunk bitmap. --- src/util/virbitmap.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index 0973731e3a..d1e5a9d1ea 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -1317,5 +1317,6 @@ virBitmapShrink(virBitmapPtr map, return -1; map->map_len =3D nl; + map->map_alloc =3D nl; return 0; } --=20 2.15.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 22:47:04 2024 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 From nobody Sun Apr 28 22:47:04 2024 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 1517836722157312.9108854739534; Mon, 5 Feb 2018 05:18:42 -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 4DE6281E03; Mon, 5 Feb 2018 13:18:41 +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 155B6608F0; Mon, 5 Feb 2018 13:18:41 +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 CEAC94ED37; Mon, 5 Feb 2018 13:18:40 +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 w15DIdCj000338 for ; Mon, 5 Feb 2018 08:18:39 -0500 Received: by smtp.corp.redhat.com (Postfix) id 80C8C18E5C; Mon, 5 Feb 2018 13:18:39 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id D2D60659E7; Mon, 5 Feb 2018 13:18:38 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Mon, 5 Feb 2018 14:17:47 +0100 Message-Id: <1f0c27393ee6bee14954d290c11e10e15c47b5e6.1517836057.git.pkrempa@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 Cc: Peter Krempa Subject: [libvirt] [PATCH 6/6] util: bitmap: Note that shrinking the bitmap requires clearing of unused bits 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.25]); Mon, 05 Feb 2018 13:18:41 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Note the fact that the unused portion of the last element in the bitmap needs to be cleared, since we use functions which process only full-size elements and don't really deal with individual bits. --- src/util/virbitmap.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index 82b1f76427..0cc5292d8c 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -45,6 +45,10 @@ struct _virBitmap { size_t nbits; size_t map_len; size_t map_alloc; + + /* Note that code below depends on the fact that unused bits of the bi= tmap + * are not set. Any function decreasing the size of the map needs clear + * bits which don't belong to the bitmap any more. */ unsigned long *map; }; --=20 2.15.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list