From c6a8c3283f1d53e360073bdb32f87a97e78e2880 Mon Sep 17 00:00:00 2001 From: Wen Congyang Date: Fri, 22 May 2015 09:29:46 +0800 Subject: 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 Signed-off-by: zhanghailiang Signed-off-by: Gonglei Acked-by: Paolo Bonzini Reviewed-by: Eric Blake Reviewed-by: John Snow Message-id: 555E868A.60506@cn.fujitsu.com Signed-off-by: Stefan Hajnoczi --- util/hbitmap.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'util/hbitmap.c') diff --git a/util/hbitmap.c b/util/hbitmap.c index a10c7ae..50b888f 100644 --- a/util/hbitmap.c +++ b/util/hbitmap.c @@ -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. */ -- cgit v1.1