Re: [PATCH 1/3] util: Add a helper to check if all bits of a bitmap are clear

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Attachment: signature.asc
Description: OpenPGP digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]