util/hbitmap: Add an API to reset all set bits in hbitmap

The function bdrv_clear_dirty_bitmap() is updated to use
faster hbitmap_reset_all() call.

Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
Signed-off-by: Gonglei <arei.gonglei@huawei.com>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: John Snow <jsnow@redhat.com>
Message-id: 555E868A.60506@cn.fujitsu.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
Wen Congyang 2015-05-22 09:29:46 +08:00 committed by Stefan Hajnoczi
parent 6e40b3bfc7
commit c6a8c3283f
4 changed files with 60 additions and 1 deletions

View file

@ -356,6 +356,19 @@ void hbitmap_reset(HBitmap *hb, uint64_t start, uint64_t count)
hb_reset_between(hb, HBITMAP_LEVELS - 1, start, last);
}
void hbitmap_reset_all(HBitmap *hb)
{
unsigned int i;
/* Same as hbitmap_alloc() except for memset() instead of malloc() */
for (i = HBITMAP_LEVELS; --i >= 1; ) {
memset(hb->levels[i], 0, hb->sizes[i] * sizeof(unsigned long));
}
hb->levels[0][0] = 1UL << (BITS_PER_LONG - 1);
hb->count = 0;
}
bool hbitmap_get(const HBitmap *hb, uint64_t item)
{
/* Compute position and bit in the last layer. */