[libvirt] [PATCH 1/3] util: Add a helper to check if all bits of a bitmap are clear
Eric Blake
eblake at redhat.com
Tue Apr 2 12:05:24 UTC 2013
On 04/01/2013 11:42 PM, Osier Yang wrote:
> ---
> src/libvirt_private.syms | 1 +
> src/util/virbitmap.c | 30 ++++++++++++++++++++++++++++++
> src/util/virbitmap.h | 3 +++
> 3 files changed, 34 insertions(+)
>
> +bool virBitmapIsAllClear(virBitmapPtr bitmap)
> +{
> + int i;
> + int unusedBits;
> + size_t sz;
> +
> + unusedBits = bitmap->map_len * VIR_BITMAP_BITS_PER_UNIT - bitmap->max_bit;
> +
> + sz = bitmap->map_len;
> + if (unusedBits > 0)
> + sz--;
> +
> + for (i = 0; i < sz; i++)
> + if (bitmap->map[i] != 0)
> + return false;
> +
> + if (unusedBits > 0) {
> + if ((bitmap->map[sz] & ((1UL << (VIR_BITMAP_BITS_PER_UNIT - unusedBits)) - 1)))
> + return false;
You are being careful to avoid assuming any state about the bits in the
tail beyond the bitmap size. But I thought our code was already careful
to ensure that the tail bits are always 0. Therefore, you should be
able to just check that the entire bitmap->map is 0, without
special-casing the tail.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 621 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20130402/220d9630/attachment-0001.sig>
More information about the libvir-list
mailing list