diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 5d630d5d1b..d3ca6b2ec4 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1375,6 +1375,7 @@ virBitmapParseUnlimited; virBitmapSetAll; virBitmapSetBit; virBitmapSetBitExpand; +virBitmapShrink; virBitmapSize; virBitmapSubtract; virBitmapToData; diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index 7338f0255a..b2c5c7a6a5 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -1196,3 +1196,26 @@ virBitmapSubtract(virBitmapPtr a, for (i = 0; i < max; i++) a->map[i] &= ~b->map[i]; } + + +/** + * 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. Nothing + * will change if the size is already smaller than @b. + * + * NB: Does not adjust the map->map_len so that a subsequent virBitmapExpand + * doesn't necessarily need to reallocate. + */ +void +virBitmapShrink(virBitmapPtr map, + size_t b) +{ + if (!map) + return; + + if (map->max_bit >= b) + map->max_bit = b; +} diff --git a/src/util/virbitmap.h b/src/util/virbitmap.h index 7b2bea8b53..2464814055 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); +void virBitmapShrink(virBitmapPtr map, size_t b); + #endif