diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2017-12-19 17:44:42 +0000 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2017-12-19 17:44:42 +0000 |
commit | 03c1c09d56bb242696fa07f9842b3a8f9fbcd46f (patch) | |
tree | 52ae405d1af375cee2d9b074366eddb71a2ca99c /util | |
parent | 062fcb27c4c1af6902f497ec9316c1c0ead90e81 (diff) | |
parent | 996922de45299878cdc4c15b72b19edf2bc618a4 (diff) |
Merge remote-tracking branch 'remotes/cody/tags/block-pull-request' into staging
# gpg: Signature made Mon 18 Dec 2017 21:05:53 GMT
# gpg: using RSA key 0xBDBE7B27C0DE3057
# gpg: Good signature from "Jeffrey Cody <jcody@redhat.com>"
# gpg: aka "Jeffrey Cody <jeff@codyprime.org>"
# gpg: aka "Jeffrey Cody <codyprime@gmail.com>"
# Primary key fingerprint: 9957 4B4D 3474 90E7 9D98 D624 BDBE 7B27 C0DE 3057
* remotes/cody/tags/block-pull-request:
block/curl: fix minor memory leaks
block/curl: check error return of curl_global_init()
block/sheepdog: code beautification
block/sheepdog: remove spurious NULL check
blockjob: kick jobs on set-speed
backup: use copy_bitmap in incremental backup
backup: simplify non-dirty bits progress processing
backup: init copy_bitmap from sync_bitmap for incremental
backup: move from done_bitmap to copy_bitmap
hbitmap: add next_zero function
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'util')
-rw-r--r-- | util/hbitmap.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/util/hbitmap.c b/util/hbitmap.c index 2f9d0fdbd0..289778a55c 100644 --- a/util/hbitmap.c +++ b/util/hbitmap.c @@ -188,6 +188,45 @@ void hbitmap_iter_init(HBitmapIter *hbi, const HBitmap *hb, uint64_t first) } } +int64_t hbitmap_next_zero(const HBitmap *hb, uint64_t start) +{ + size_t pos = (start >> hb->granularity) >> BITS_PER_LEVEL; + unsigned long *last_lev = hb->levels[HBITMAP_LEVELS - 1]; + uint64_t sz = hb->sizes[HBITMAP_LEVELS - 1]; + unsigned long cur = last_lev[pos]; + unsigned start_bit_offset = + (start >> hb->granularity) & (BITS_PER_LONG - 1); + int64_t res; + + cur |= (1UL << start_bit_offset) - 1; + assert((start >> hb->granularity) < hb->size); + + if (cur == (unsigned long)-1) { + do { + pos++; + } while (pos < sz && last_lev[pos] == (unsigned long)-1); + + if (pos >= sz) { + return -1; + } + + cur = last_lev[pos]; + } + + res = (pos << BITS_PER_LEVEL) + ctol(cur); + if (res >= hb->size) { + return -1; + } + + res = res << hb->granularity; + if (res < start) { + assert(((start - res) >> hb->granularity) == 0); + return start; + } + + return res; +} + bool hbitmap_empty(const HBitmap *hb) { return hb->count == 0; |