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