From nobody Sun Sep 28 10:39:56 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1547600622983539.8269591404529; Tue, 15 Jan 2019 17:03:42 -0800 (PST) Received: from localhost ([127.0.0.1]:36699 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjZc9-0003o1-Dq for importer@patchew.org; Tue, 15 Jan 2019 20:03:29 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57795) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjZaC-0002j0-Bj for qemu-devel@nongnu.org; Tue, 15 Jan 2019 20:01:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gjZa4-0004X1-PJ for qemu-devel@nongnu.org; Tue, 15 Jan 2019 20:01:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56510) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gjZa3-0004Qt-88 for qemu-devel@nongnu.org; Tue, 15 Jan 2019 20:01:19 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9221BC0528B9; Wed, 16 Jan 2019 01:01:10 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-221.bos.redhat.com [10.18.17.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 039EA19C7C; Wed, 16 Jan 2019 01:01:09 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Date: Tue, 15 Jan 2019 20:00:59 -0500 Message-Id: <20190116010106.27626-2-jsnow@redhat.com> In-Reply-To: <20190116010106.27626-1-jsnow@redhat.com> References: <20190116010106.27626-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 16 Jan 2019 01:01:10 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 1/8] dirty-bitmap: improve bdrv_dirty_bitmap_next_zero X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Vladimir Sementsov-Ogievskiy , jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Add bytes parameter to the function, to limit searched range. Signed-off-by: Vladimir Sementsov-Ogievskiy Signed-off-by: John Snow --- block/backup.c | 3 ++- block/dirty-bitmap.c | 5 +++-- include/block/dirty-bitmap.h | 3 ++- include/qemu/hbitmap.h | 10 +++++++--- nbd/server.c | 2 +- tests/test-hbitmap.c | 2 +- util/hbitmap.c | 27 ++++++++++++++++++++++----- 7 files changed, 38 insertions(+), 14 deletions(-) diff --git a/block/backup.c b/block/backup.c index b829b251eb..9ffce5c183 100644 --- a/block/backup.c +++ b/block/backup.c @@ -422,7 +422,8 @@ static void backup_incremental_init_copy_bitmap(BackupB= lockJob *job) break; } =20 - offset =3D bdrv_dirty_bitmap_next_zero(job->sync_bitmap, offset); + offset =3D bdrv_dirty_bitmap_next_zero(job->sync_bitmap, offset, + UINT64_MAX); if (offset =3D=3D -1) { hbitmap_set(job->copy_bitmap, cluster, end - cluster); break; diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index 6b688394e4..b162f4ac22 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -781,9 +781,10 @@ char *bdrv_dirty_bitmap_sha256(const BdrvDirtyBitmap *= bitmap, Error **errp) return hbitmap_sha256(bitmap->bitmap, errp); } =20 -int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *bitmap, uint64_t offs= et) +int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *bitmap, uint64_t offs= et, + uint64_t bytes) { - return hbitmap_next_zero(bitmap->bitmap, offset); + return hbitmap_next_zero(bitmap->bitmap, offset, bytes); } =20 void bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, const BdrvDirtyBitmap = *src, diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index 8f38a3dec1..102ccdda32 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -99,7 +99,8 @@ bool bdrv_has_changed_persistent_bitmaps(BlockDriverState= *bs); BdrvDirtyBitmap *bdrv_dirty_bitmap_next(BlockDriverState *bs, BdrvDirtyBitmap *bitmap); char *bdrv_dirty_bitmap_sha256(const BdrvDirtyBitmap *bitmap, Error **errp= ); -int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *bitmap, uint64_t star= t); +int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *bitmap, uint64_t offs= et, + uint64_t bytes); BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap_locked(BlockDriverState *bs, BdrvDirtyBitmap *bitmap, Error **errp); diff --git a/include/qemu/hbitmap.h b/include/qemu/hbitmap.h index a7cb780592..135975530f 100644 --- a/include/qemu/hbitmap.h +++ b/include/qemu/hbitmap.h @@ -300,12 +300,16 @@ void hbitmap_iter_init(HBitmapIter *hbi, const HBitma= p *hb, uint64_t first); unsigned long hbitmap_iter_skip_words(HBitmapIter *hbi); =20 /* hbitmap_next_zero: + * + * Find next not dirty bit within selected range. If not found, return -1. + * * @hb: The HBitmap to operate on * @start: The bit to start from. - * - * Find next not dirty bit. + * @count: Number of bits to proceed. If @start+@count > bitmap size, the = whole + * bitmap is looked through. You can use UINT64_MAX as @count to search up= to + * the bitmap end. */ -int64_t hbitmap_next_zero(const HBitmap *hb, uint64_t start); +int64_t hbitmap_next_zero(const HBitmap *hb, uint64_t start, uint64_t coun= t); =20 /* hbitmap_create_meta: * Create a "meta" hbitmap to track dirtiness of the bits in this HBitmap. diff --git a/nbd/server.c b/nbd/server.c index e8c56607ef..6b136019f8 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -2014,7 +2014,7 @@ static unsigned int bitmap_to_extents(BdrvDirtyBitmap= *bitmap, uint64_t offset, bool next_dirty =3D !dirty; =20 if (dirty) { - end =3D bdrv_dirty_bitmap_next_zero(bitmap, begin); + end =3D bdrv_dirty_bitmap_next_zero(bitmap, begin, UINT64_MAX); } else { bdrv_set_dirty_iter(it, begin); end =3D bdrv_dirty_iter_next(it); diff --git a/tests/test-hbitmap.c b/tests/test-hbitmap.c index 5e67ac1d3a..b04a45a2de 100644 --- a/tests/test-hbitmap.c +++ b/tests/test-hbitmap.c @@ -939,7 +939,7 @@ static void test_hbitmap_iter_and_reset(TestHBitmapData= *data, =20 static void test_hbitmap_next_zero_check(TestHBitmapData *data, int64_t st= art) { - int64_t ret1 =3D hbitmap_next_zero(data->hb, start); + int64_t ret1 =3D hbitmap_next_zero(data->hb, start, UINT64_MAX); int64_t ret2 =3D start; for ( ; ret2 < data->size && hbitmap_get(data->hb, ret2); ret2++) { ; diff --git a/util/hbitmap.c b/util/hbitmap.c index 8d402c59d9..09b3719e44 100644 --- a/util/hbitmap.c +++ b/util/hbitmap.c @@ -53,6 +53,9 @@ */ =20 struct HBitmap { + /* Size of the bitmap, as requested in hbitmap_alloc. */ + uint64_t orig_size; + /* Number of total bits in the bottom level. */ uint64_t size; =20 @@ -192,16 +195,28 @@ void hbitmap_iter_init(HBitmapIter *hbi, const HBitma= p *hb, uint64_t first) } } =20 -int64_t hbitmap_next_zero(const HBitmap *hb, uint64_t start) +int64_t hbitmap_next_zero(const HBitmap *hb, uint64_t start, uint64_t coun= t) { size_t pos =3D (start >> hb->granularity) >> BITS_PER_LEVEL; unsigned long *last_lev =3D hb->levels[HBITMAP_LEVELS - 1]; - uint64_t sz =3D hb->sizes[HBITMAP_LEVELS - 1]; unsigned long cur =3D last_lev[pos]; - unsigned start_bit_offset =3D - (start >> hb->granularity) & (BITS_PER_LONG - 1); + unsigned start_bit_offset; + uint64_t end_bit, sz; int64_t res; =20 + if (start >=3D hb->orig_size || count =3D=3D 0) { + return -1; + } + + end_bit =3D count > hb->orig_size - start ? + hb->size : + ((start + count - 1) >> hb->granularity) + 1; + sz =3D (end_bit + BITS_PER_LONG - 1) >> BITS_PER_LEVEL; + + /* There may be some zero bits in @cur before @start. We are not inter= ested + * in them, let's set them. + */ + start_bit_offset =3D (start >> hb->granularity) & (BITS_PER_LONG - 1); cur |=3D (1UL << start_bit_offset) - 1; assert((start >> hb->granularity) < hb->size); =20 @@ -218,7 +233,7 @@ int64_t hbitmap_next_zero(const HBitmap *hb, uint64_t s= tart) } =20 res =3D (pos << BITS_PER_LEVEL) + ctol(cur); - if (res >=3D hb->size) { + if (res >=3D end_bit) { return -1; } =20 @@ -652,6 +667,8 @@ HBitmap *hbitmap_alloc(uint64_t size, int granularity) HBitmap *hb =3D g_new0(struct HBitmap, 1); unsigned i; =20 + hb->orig_size =3D size; + assert(granularity >=3D 0 && granularity < 64); size =3D (size + (1ULL << granularity) - 1) >> granularity; assert(size <=3D ((uint64_t)1 << HBITMAP_LOG_MAX_SIZE)); --=20 2.17.2 From nobody Sun Sep 28 10:39:56 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1547600788432930.7248768207073; Tue, 15 Jan 2019 17:06:28 -0800 (PST) Received: from localhost ([127.0.0.1]:37505 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjZf1-0006LO-6o for importer@patchew.org; Tue, 15 Jan 2019 20:06:27 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57800) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjZaC-0002j1-Br for qemu-devel@nongnu.org; Tue, 15 Jan 2019 20:01:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gjZa3-0004Vj-PE for qemu-devel@nongnu.org; Tue, 15 Jan 2019 20:01:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34534) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gjZa2-0004R2-BV for qemu-devel@nongnu.org; Tue, 15 Jan 2019 20:01:19 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 47C1B6445A; Wed, 16 Jan 2019 01:01:11 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-221.bos.redhat.com [10.18.17.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id AEC7519C7C; Wed, 16 Jan 2019 01:01:10 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Date: Tue, 15 Jan 2019 20:01:00 -0500 Message-Id: <20190116010106.27626-3-jsnow@redhat.com> In-Reply-To: <20190116010106.27626-1-jsnow@redhat.com> References: <20190116010106.27626-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 16 Jan 2019 01:01:11 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 2/8] tests: add tests for hbitmap_next_zero with specified end parameter X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Vladimir Sementsov-Ogievskiy , jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Signed-off-by: Vladimir Sementsov-Ogievskiy Signed-off-by: John Snow --- tests/test-hbitmap.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/tests/test-hbitmap.c b/tests/test-hbitmap.c index b04a45a2de..c0da31a6bd 100644 --- a/tests/test-hbitmap.c +++ b/tests/test-hbitmap.c @@ -937,31 +937,49 @@ static void test_hbitmap_iter_and_reset(TestHBitmapDa= ta *data, check_hbitmap_iter_next(&hbi); } =20 -static void test_hbitmap_next_zero_check(TestHBitmapData *data, int64_t st= art) +static void test_hbitmap_next_zero_check_range(TestHBitmapData *data, + uint64_t start, + uint64_t count) { - int64_t ret1 =3D hbitmap_next_zero(data->hb, start, UINT64_MAX); + int64_t ret1 =3D hbitmap_next_zero(data->hb, start, count); int64_t ret2 =3D start; - for ( ; ret2 < data->size && hbitmap_get(data->hb, ret2); ret2++) { + int64_t end =3D start >=3D data->size || data->size - start < count ? + data->size : start + count; + + for ( ; ret2 < end && hbitmap_get(data->hb, ret2); ret2++) { ; } - if (ret2 =3D=3D data->size) { + if (ret2 =3D=3D end) { ret2 =3D -1; } =20 g_assert_cmpint(ret1, =3D=3D, ret2); } =20 +static void test_hbitmap_next_zero_check(TestHBitmapData *data, int64_t st= art) +{ + test_hbitmap_next_zero_check_range(data, start, UINT64_MAX); +} + static void test_hbitmap_next_zero_do(TestHBitmapData *data, int granulari= ty) { hbitmap_test_init(data, L3, granularity); test_hbitmap_next_zero_check(data, 0); test_hbitmap_next_zero_check(data, L3 - 1); + test_hbitmap_next_zero_check_range(data, 0, 1); + test_hbitmap_next_zero_check_range(data, L3 - 1, 1); =20 hbitmap_set(data->hb, L2, 1); test_hbitmap_next_zero_check(data, 0); test_hbitmap_next_zero_check(data, L2 - 1); test_hbitmap_next_zero_check(data, L2); test_hbitmap_next_zero_check(data, L2 + 1); + test_hbitmap_next_zero_check_range(data, 0, 1); + test_hbitmap_next_zero_check_range(data, 0, L2); + test_hbitmap_next_zero_check_range(data, L2 - 1, 1); + test_hbitmap_next_zero_check_range(data, L2 - 1, 2); + test_hbitmap_next_zero_check_range(data, L2, 1); + test_hbitmap_next_zero_check_range(data, L2 + 1, 1); =20 hbitmap_set(data->hb, L2 + 5, L1); test_hbitmap_next_zero_check(data, 0); @@ -970,6 +988,10 @@ static void test_hbitmap_next_zero_do(TestHBitmapData = *data, int granularity) test_hbitmap_next_zero_check(data, L2 + 5); test_hbitmap_next_zero_check(data, L2 + L1 - 1); test_hbitmap_next_zero_check(data, L2 + L1); + test_hbitmap_next_zero_check_range(data, L2, 6); + test_hbitmap_next_zero_check_range(data, L2 + 1, 3); + test_hbitmap_next_zero_check_range(data, L2 + 4, L1); + test_hbitmap_next_zero_check_range(data, L2 + 5, L1); =20 hbitmap_set(data->hb, L2 * 2, L3 - L2 * 2); test_hbitmap_next_zero_check(data, L2 * 2 - L1); @@ -977,6 +999,8 @@ static void test_hbitmap_next_zero_do(TestHBitmapData *= data, int granularity) test_hbitmap_next_zero_check(data, L2 * 2 - 1); test_hbitmap_next_zero_check(data, L2 * 2); test_hbitmap_next_zero_check(data, L3 - 1); + test_hbitmap_next_zero_check_range(data, L2 * 2 - L1, L1 + 1); + test_hbitmap_next_zero_check_range(data, L2 * 2, L2); =20 hbitmap_set(data->hb, 0, L3); test_hbitmap_next_zero_check(data, 0); --=20 2.17.2 From nobody Sun Sep 28 10:39:56 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 154760062909394.51001406445243; Tue, 15 Jan 2019 17:03:49 -0800 (PST) Received: from localhost ([127.0.0.1]:36777 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjZcS-00043f-07 for importer@patchew.org; Tue, 15 Jan 2019 20:03:48 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57904) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjZaM-0002qI-Qf for qemu-devel@nongnu.org; Tue, 15 Jan 2019 20:01:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gjZaF-0004b2-9k for qemu-devel@nongnu.org; Tue, 15 Jan 2019 20:01:34 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45300) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gjZa8-0004RN-RJ for qemu-devel@nongnu.org; Tue, 15 Jan 2019 20:01:27 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 032717F3F4; Wed, 16 Jan 2019 01:01:12 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-221.bos.redhat.com [10.18.17.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 631FA19C7C; Wed, 16 Jan 2019 01:01:11 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Date: Tue, 15 Jan 2019 20:01:01 -0500 Message-Id: <20190116010106.27626-4-jsnow@redhat.com> In-Reply-To: <20190116010106.27626-1-jsnow@redhat.com> References: <20190116010106.27626-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 16 Jan 2019 01:01:12 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 3/8] dirty-bitmap: add bdrv_dirty_bitmap_next_dirty_area X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Vladimir Sementsov-Ogievskiy , jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy The function alters bdrv_dirty_iter_next_area(), which is wrong and less efficient (see further commit "block/mirror: fix and improve do_sync_target_write" for description). Signed-off-by: Vladimir Sementsov-Ogievskiy Signed-off-by: John Snow --- block/dirty-bitmap.c | 6 ++++++ include/block/dirty-bitmap.h | 2 ++ include/qemu/hbitmap.h | 16 +++++++++++++++ util/hbitmap.c | 39 ++++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+) diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index b162f4ac22..c1518373f9 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -787,6 +787,12 @@ int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *b= itmap, uint64_t offset, return hbitmap_next_zero(bitmap->bitmap, offset, bytes); } =20 +bool bdrv_dirty_bitmap_next_dirty_area(BdrvDirtyBitmap *bitmap, + uint64_t *offset, uint64_t *bytes) +{ + return hbitmap_next_dirty_area(bitmap->bitmap, offset, bytes); +} + void bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, const BdrvDirtyBitmap = *src, HBitmap **backup, Error **errp) { diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index 102ccdda32..4ef00ca6ba 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -101,6 +101,8 @@ BdrvDirtyBitmap *bdrv_dirty_bitmap_next(BlockDriverStat= e *bs, char *bdrv_dirty_bitmap_sha256(const BdrvDirtyBitmap *bitmap, Error **errp= ); int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *bitmap, uint64_t offs= et, uint64_t bytes); +bool bdrv_dirty_bitmap_next_dirty_area(BdrvDirtyBitmap *bitmap, + uint64_t *offset, uint64_t *bytes); BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap_locked(BlockDriverState *bs, BdrvDirtyBitmap *bitmap, Error **errp); diff --git a/include/qemu/hbitmap.h b/include/qemu/hbitmap.h index 135975530f..097dce31ee 100644 --- a/include/qemu/hbitmap.h +++ b/include/qemu/hbitmap.h @@ -311,6 +311,22 @@ unsigned long hbitmap_iter_skip_words(HBitmapIter *hbi= ); */ int64_t hbitmap_next_zero(const HBitmap *hb, uint64_t start, uint64_t coun= t); =20 +/* hbitmap_next_dirty_area: + * @hb: The HBitmap to operate on + * @start: in-out parameter. + * in: the offset to start from + * out: (if area found) start of found area + * @count: in-out parameter. + * in: length of requested region + * out: length of found area + * + * If dirty area found within [@start, @start + @count), returns true and = sets + * @offset and @bytes appropriately. Otherwise returns false and leaves @o= ffset + * and @bytes unchanged. + */ +bool hbitmap_next_dirty_area(const HBitmap *hb, uint64_t *start, + uint64_t *count); + /* hbitmap_create_meta: * Create a "meta" hbitmap to track dirtiness of the bits in this HBitmap. * The caller owns the created bitmap and must call hbitmap_free_meta(hb) = to diff --git a/util/hbitmap.c b/util/hbitmap.c index 09b3719e44..fa356522c4 100644 --- a/util/hbitmap.c +++ b/util/hbitmap.c @@ -246,6 +246,45 @@ int64_t hbitmap_next_zero(const HBitmap *hb, uint64_t = start, uint64_t count) return res; } =20 +bool hbitmap_next_dirty_area(const HBitmap *hb, uint64_t *start, + uint64_t *count) +{ + HBitmapIter hbi; + int64_t firt_dirty_off, area_end; + uint32_t granularity =3D 1UL << hb->granularity; + uint64_t end; + + if (*start >=3D hb->orig_size || *count =3D=3D 0) { + return false; + } + + end =3D *count > hb->orig_size - *start ? hb->orig_size : *start + *co= unt; + + hbitmap_iter_init(&hbi, hb, *start); + firt_dirty_off =3D hbitmap_iter_next(&hbi, false); + + if (firt_dirty_off < 0 || firt_dirty_off >=3D end) { + return false; + } + + if (firt_dirty_off + granularity >=3D end) { + area_end =3D end; + } else { + area_end =3D hbitmap_next_zero(hb, firt_dirty_off + granularity, + end - firt_dirty_off - granularity); + if (area_end < 0) { + area_end =3D end; + } + } + + if (firt_dirty_off > *start) { + *start =3D firt_dirty_off; + } + *count =3D area_end - *start; + + return true; +} + bool hbitmap_empty(const HBitmap *hb) { return hb->count =3D=3D 0; --=20 2.17.2 From nobody Sun Sep 28 10:39:56 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1547600622982735.5903867352813; Tue, 15 Jan 2019 17:03:42 -0800 (PST) Received: from localhost ([127.0.0.1]:36747 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjZcI-0003yM-Jp for importer@patchew.org; Tue, 15 Jan 2019 20:03:38 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57876) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjZaJ-0002nA-2A for qemu-devel@nongnu.org; Tue, 15 Jan 2019 20:01:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gjZa8-0004Y5-Hf for qemu-devel@nongnu.org; Tue, 15 Jan 2019 20:01:27 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60116) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gjZa4-0004Ra-42 for qemu-devel@nongnu.org; Tue, 15 Jan 2019 20:01:20 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B3B293290; Wed, 16 Jan 2019 01:01:12 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-221.bos.redhat.com [10.18.17.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1B10419940; Wed, 16 Jan 2019 01:01:12 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Date: Tue, 15 Jan 2019 20:01:02 -0500 Message-Id: <20190116010106.27626-5-jsnow@redhat.com> In-Reply-To: <20190116010106.27626-1-jsnow@redhat.com> References: <20190116010106.27626-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 16 Jan 2019 01:01:12 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 4/8] tests: add tests for hbitmap_next_dirty_area X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Vladimir Sementsov-Ogievskiy , jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Signed-off-by: Vladimir Sementsov-Ogievskiy Signed-off-by: John Snow --- tests/test-hbitmap.c | 107 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/tests/test-hbitmap.c b/tests/test-hbitmap.c index c0da31a6bd..4f312e9da3 100644 --- a/tests/test-hbitmap.c +++ b/tests/test-hbitmap.c @@ -1016,6 +1016,106 @@ static void test_hbitmap_next_zero_4(TestHBitmapDat= a *data, const void *unused) test_hbitmap_next_zero_do(data, 4); } =20 +static void test_hbitmap_next_dirty_area_check(TestHBitmapData *data, + uint64_t offset, + uint64_t count) +{ + uint64_t off1, off2; + uint64_t len1 =3D 0, len2; + bool ret1, ret2; + int64_t end; + + off1 =3D offset; + len1 =3D count; + ret1 =3D hbitmap_next_dirty_area(data->hb, &off1, &len1); + + end =3D offset > data->size || data->size - offset < count ? data->siz= e : + offset + co= unt; + + for (off2 =3D offset; off2 < end && !hbitmap_get(data->hb, off2); off2= ++) { + ; + } + + for (len2 =3D 1; off2 + len2 < end && hbitmap_get(data->hb, off2 + len= 2); + len2++) { + ; + } + + ret2 =3D off2 < end; + if (!ret2) { + /* leave unchanged */ + off2 =3D offset; + len2 =3D count; + } + + g_assert_cmpint(ret1, =3D=3D, ret2); + g_assert_cmpint(off1, =3D=3D, off2); + g_assert_cmpint(len1, =3D=3D, len2); +} + +static void test_hbitmap_next_dirty_area_do(TestHBitmapData *data, + int granularity) +{ + hbitmap_test_init(data, L3, granularity); + test_hbitmap_next_dirty_area_check(data, 0, UINT64_MAX); + test_hbitmap_next_dirty_area_check(data, 0, 1); + test_hbitmap_next_dirty_area_check(data, L3 - 1, 1); + + hbitmap_set(data->hb, L2, 1); + test_hbitmap_next_dirty_area_check(data, 0, 1); + test_hbitmap_next_dirty_area_check(data, 0, L2); + test_hbitmap_next_dirty_area_check(data, 0, UINT64_MAX); + test_hbitmap_next_dirty_area_check(data, L2 - 1, UINT64_MAX); + test_hbitmap_next_dirty_area_check(data, L2 - 1, 1); + test_hbitmap_next_dirty_area_check(data, L2 - 1, 2); + test_hbitmap_next_dirty_area_check(data, L2 - 1, 3); + test_hbitmap_next_dirty_area_check(data, L2, UINT64_MAX); + test_hbitmap_next_dirty_area_check(data, L2, 1); + test_hbitmap_next_dirty_area_check(data, L2 + 1, 1); + + hbitmap_set(data->hb, L2 + 5, L1); + test_hbitmap_next_dirty_area_check(data, 0, UINT64_MAX); + test_hbitmap_next_dirty_area_check(data, L2 - 2, 8); + test_hbitmap_next_dirty_area_check(data, L2 + 1, 5); + test_hbitmap_next_dirty_area_check(data, L2 + 1, 3); + test_hbitmap_next_dirty_area_check(data, L2 + 4, L1); + test_hbitmap_next_dirty_area_check(data, L2 + 5, L1); + test_hbitmap_next_dirty_area_check(data, L2 + 7, L1); + test_hbitmap_next_dirty_area_check(data, L2 + L1, L1); + test_hbitmap_next_dirty_area_check(data, L2, 0); + test_hbitmap_next_dirty_area_check(data, L2 + 1, 0); + + hbitmap_set(data->hb, L2 * 2, L3 - L2 * 2); + test_hbitmap_next_dirty_area_check(data, 0, UINT64_MAX); + test_hbitmap_next_dirty_area_check(data, L2, UINT64_MAX); + test_hbitmap_next_dirty_area_check(data, L2 + 1, UINT64_MAX); + test_hbitmap_next_dirty_area_check(data, L2 + 5 + L1 - 1, UINT64_MAX); + test_hbitmap_next_dirty_area_check(data, L2 + 5 + L1, 5); + test_hbitmap_next_dirty_area_check(data, L2 * 2 - L1, L1 + 1); + test_hbitmap_next_dirty_area_check(data, L2 * 2, L2); + + hbitmap_set(data->hb, 0, L3); + test_hbitmap_next_dirty_area_check(data, 0, UINT64_MAX); +} + +static void test_hbitmap_next_dirty_area_0(TestHBitmapData *data, + const void *unused) +{ + test_hbitmap_next_dirty_area_do(data, 0); +} + +static void test_hbitmap_next_dirty_area_1(TestHBitmapData *data, + const void *unused) +{ + test_hbitmap_next_dirty_area_do(data, 1); +} + +static void test_hbitmap_next_dirty_area_4(TestHBitmapData *data, + const void *unused) +{ + test_hbitmap_next_dirty_area_do(data, 4); +} + int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); @@ -1082,6 +1182,13 @@ int main(int argc, char **argv) hbitmap_test_add("/hbitmap/next_zero/next_zero_4", test_hbitmap_next_zero_4); =20 + hbitmap_test_add("/hbitmap/next_dirty_area/next_dirty_area_0", + test_hbitmap_next_dirty_area_0); + hbitmap_test_add("/hbitmap/next_dirty_area/next_dirty_area_1", + test_hbitmap_next_dirty_area_1); + hbitmap_test_add("/hbitmap/next_dirty_area/next_dirty_area_4", + test_hbitmap_next_dirty_area_4); + g_test_run(); =20 return 0; --=20 2.17.2 From nobody Sun Sep 28 10:39:56 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1547600621029378.63448757075537; Tue, 15 Jan 2019 17:03:41 -0800 (PST) Received: from localhost ([127.0.0.1]:36705 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjZcA-0003oe-Fl for importer@patchew.org; Tue, 15 Jan 2019 20:03:30 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57789) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjZaC-0002iz-BS for qemu-devel@nongnu.org; Tue, 15 Jan 2019 20:01:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gjZa3-0004Vf-Oy for qemu-devel@nongnu.org; Tue, 15 Jan 2019 20:01:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44608) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gjZa2-0004Ri-Ba for qemu-devel@nongnu.org; Tue, 15 Jan 2019 20:01:19 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 594FCC0587CE; Wed, 16 Jan 2019 01:01:13 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-221.bos.redhat.com [10.18.17.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id C499419C7C; Wed, 16 Jan 2019 01:01:12 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Date: Tue, 15 Jan 2019 20:01:03 -0500 Message-Id: <20190116010106.27626-6-jsnow@redhat.com> In-Reply-To: <20190116010106.27626-1-jsnow@redhat.com> References: <20190116010106.27626-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 16 Jan 2019 01:01:13 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 5/8] block/mirror: fix and improve do_sync_target_write X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Vladimir Sementsov-Ogievskiy , jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Use bdrv_dirty_bitmap_next_dirty_area() instead of bdrv_dirty_iter_next_area(), because of the following problems of bdrv_dirty_iter_next_area(): 1. Using HBitmap iterators we should carefully handle unaligned offset, as first call to hbitmap_iter_next() may return a value less than original offset (actually, it will be original offset rounded down to bitmap granularity). This handling is not done in do_sync_target_write(). 2. bdrv_dirty_iter_next_area() handles unaligned max_offset incorrectly: look at the code: if (max_offset =3D=3D iter->bitmap->size) { /* If max_offset points to the image end, round it up by the * bitmap granularity */ gran_max_offset =3D ROUND_UP(max_offset, granularity); } else { gran_max_offset =3D max_offset; } ret =3D hbitmap_iter_next(&iter->hbi, false); if (ret < 0 || ret + granularity > gran_max_offset) { return false; } and assume that max_offset !=3D iter->bitmap->size but still unaligned. if 0 < ret < max_offset we found dirty area, but the function can return false in this case (if ret + granularity > max_offset). 3. bdrv_dirty_iter_next_area() uses inefficient loop to find the end of the dirty area. Let's use more efficient hbitmap_next_zero instead (bdrv_dirty_bitmap_next_dirty_area() do so) Signed-off-by: Vladimir Sementsov-Ogievskiy Signed-off-by: John Snow --- block/mirror.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index f0b211a9c8..24ede6fdaa 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1185,25 +1185,23 @@ do_sync_target_write(MirrorBlockJob *job, MirrorMet= hod method, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int flags) { - BdrvDirtyBitmapIter *iter; QEMUIOVector target_qiov; - uint64_t dirty_offset; - int dirty_bytes; + uint64_t dirty_offset =3D offset; + uint64_t dirty_bytes; =20 if (qiov) { qemu_iovec_init(&target_qiov, qiov->niov); } =20 - iter =3D bdrv_dirty_iter_new(job->dirty_bitmap); - bdrv_set_dirty_iter(iter, offset); - while (true) { bool valid_area; int ret; =20 bdrv_dirty_bitmap_lock(job->dirty_bitmap); - valid_area =3D bdrv_dirty_iter_next_area(iter, offset + bytes, - &dirty_offset, &dirty_bytes= ); + dirty_bytes =3D MIN(offset + bytes - dirty_offset, INT_MAX); + valid_area =3D bdrv_dirty_bitmap_next_dirty_area(job->dirty_bitmap, + &dirty_offset, + &dirty_bytes); if (!valid_area) { bdrv_dirty_bitmap_unlock(job->dirty_bitmap); break; @@ -1259,9 +1257,10 @@ do_sync_target_write(MirrorBlockJob *job, MirrorMeth= od method, break; } } + + dirty_offset +=3D dirty_bytes; } =20 - bdrv_dirty_iter_free(iter); if (qiov) { qemu_iovec_destroy(&target_qiov); } --=20 2.17.2 From nobody Sun Sep 28 10:39:56 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1547600788321814.9503057787288; Tue, 15 Jan 2019 17:06:28 -0800 (PST) Received: from localhost ([127.0.0.1]:37502 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjZf0-0006Kq-ST for importer@patchew.org; Tue, 15 Jan 2019 20:06:27 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57867) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjZaJ-0002n9-1Z for qemu-devel@nongnu.org; Tue, 15 Jan 2019 20:01:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gjZa3-0004Vv-SZ for qemu-devel@nongnu.org; Tue, 15 Jan 2019 20:01:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34590) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gjZa3-0004Rx-4j for qemu-devel@nongnu.org; Tue, 15 Jan 2019 20:01:19 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 137666445C; Wed, 16 Jan 2019 01:01:14 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-221.bos.redhat.com [10.18.17.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7724B19C7C; Wed, 16 Jan 2019 01:01:13 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Date: Tue, 15 Jan 2019 20:01:04 -0500 Message-Id: <20190116010106.27626-7-jsnow@redhat.com> In-Reply-To: <20190116010106.27626-1-jsnow@redhat.com> References: <20190116010106.27626-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 16 Jan 2019 01:01:14 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 6/8] Revert "block/dirty-bitmap: Add bdrv_dirty_iter_next_area" X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Vladimir Sementsov-Ogievskiy , jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy This reverts commit 72d10a94213a954ad569095cb4491f2ae0853c40. The function is unused now. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: John Snow Signed-off-by: John Snow --- block/dirty-bitmap.c | 55 ------------------------------------ include/block/dirty-bitmap.h | 2 -- 2 files changed, 57 deletions(-) diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index c1518373f9..4d9a8af17d 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -518,61 +518,6 @@ int64_t bdrv_dirty_iter_next(BdrvDirtyBitmapIter *iter) return hbitmap_iter_next(&iter->hbi, true); } =20 -/** - * Return the next consecutively dirty area in the dirty bitmap - * belonging to the given iterator @iter. - * - * @max_offset: Maximum value that may be returned for - * *offset + *bytes - * @offset: Will contain the start offset of the next dirty area - * @bytes: Will contain the length of the next dirty area - * - * Returns: True if a dirty area could be found before max_offset - * (which means that *offset and *bytes then contain valid - * values), false otherwise. - * - * Note that @iter is never advanced if false is returned. If an area - * is found (which means that true is returned), it will be advanced - * past that area. - */ -bool bdrv_dirty_iter_next_area(BdrvDirtyBitmapIter *iter, uint64_t max_off= set, - uint64_t *offset, int *bytes) -{ - uint32_t granularity =3D bdrv_dirty_bitmap_granularity(iter->bitmap); - uint64_t gran_max_offset; - int64_t ret; - int size; - - if (max_offset =3D=3D iter->bitmap->size) { - /* If max_offset points to the image end, round it up by the - * bitmap granularity */ - gran_max_offset =3D ROUND_UP(max_offset, granularity); - } else { - gran_max_offset =3D max_offset; - } - - ret =3D hbitmap_iter_next(&iter->hbi, false); - if (ret < 0 || ret + granularity > gran_max_offset) { - return false; - } - - *offset =3D ret; - size =3D 0; - - assert(granularity <=3D INT_MAX); - - do { - /* Advance iterator */ - ret =3D hbitmap_iter_next(&iter->hbi, true); - size +=3D granularity; - } while (ret + granularity <=3D gran_max_offset && - hbitmap_iter_next(&iter->hbi, false) =3D=3D ret + granularity= && - size <=3D INT_MAX - granularity); - - *bytes =3D MIN(size, max_offset - *offset); - return true; -} - /* Called within bdrv_dirty_bitmap_lock..unlock */ void bdrv_set_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap, int64_t offset, int64_t bytes) diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index 4ef00ca6ba..04a117fc81 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -83,8 +83,6 @@ void bdrv_set_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap, void bdrv_reset_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap, int64_t offset, int64_t bytes); int64_t bdrv_dirty_iter_next(BdrvDirtyBitmapIter *iter); -bool bdrv_dirty_iter_next_area(BdrvDirtyBitmapIter *iter, uint64_t max_off= set, - uint64_t *offset, int *bytes); void bdrv_set_dirty_iter(BdrvDirtyBitmapIter *hbi, int64_t offset); int64_t bdrv_get_dirty_count(BdrvDirtyBitmap *bitmap); int64_t bdrv_get_meta_dirty_count(BdrvDirtyBitmap *bitmap); --=20 2.17.2 From nobody Sun Sep 28 10:39:56 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1547600907216169.21587437443827; Tue, 15 Jan 2019 17:08:27 -0800 (PST) Received: from localhost ([127.0.0.1]:38118 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjZgw-0007y2-8b for importer@patchew.org; Tue, 15 Jan 2019 20:08:26 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57920) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjZaQ-0002t9-4T for qemu-devel@nongnu.org; Tue, 15 Jan 2019 20:01:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gjZaF-0004al-9l for qemu-devel@nongnu.org; Tue, 15 Jan 2019 20:01:34 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54664) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gjZa4-0004SD-Po for qemu-devel@nongnu.org; Tue, 15 Jan 2019 20:01:24 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B248A3697F; Wed, 16 Jan 2019 01:01:14 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-221.bos.redhat.com [10.18.17.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2BAA119C7C; Wed, 16 Jan 2019 01:01:14 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Date: Tue, 15 Jan 2019 20:01:05 -0500 Message-Id: <20190116010106.27626-8-jsnow@redhat.com> In-Reply-To: <20190116010106.27626-1-jsnow@redhat.com> References: <20190116010106.27626-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 16 Jan 2019 01:01:14 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 7/8] Revert "test-hbitmap: Add non-advancing iter_next tests" X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Vladimir Sementsov-Ogievskiy , jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy This reverts commit 269576848ec3d57d2d958cf5ac69b08c44adf816. The functionality is unused. Drop tests. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: John Snow Signed-off-by: John Snow --- tests/test-hbitmap.c | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/tests/test-hbitmap.c b/tests/test-hbitmap.c index 4f312e9da3..6358f35359 100644 --- a/tests/test-hbitmap.c +++ b/tests/test-hbitmap.c @@ -30,18 +30,6 @@ typedef struct TestHBitmapData { } TestHBitmapData; =20 =20 -static int64_t check_hbitmap_iter_next(HBitmapIter *hbi) -{ - int next0, next1; - - next0 =3D hbitmap_iter_next(hbi, false); - next1 =3D hbitmap_iter_next(hbi, true); - - g_assert_cmpint(next0, =3D=3D, next1); - - return next0; -} - /* Check that the HBitmap and the shadow bitmap contain the same data, * ignoring the same "first" bits. */ @@ -58,7 +46,7 @@ static void hbitmap_test_check(TestHBitmapData *data, =20 i =3D first; for (;;) { - next =3D check_hbitmap_iter_next(&hbi); + next =3D hbitmap_iter_next(&hbi, true); if (next < 0) { next =3D data->size; } @@ -447,25 +435,25 @@ static void test_hbitmap_iter_granularity(TestHBitmap= Data *data, /* Note that hbitmap_test_check has to be invoked manually in this tes= t. */ hbitmap_test_init(data, 131072 << 7, 7); hbitmap_iter_init(&hbi, data->hb, 0); - g_assert_cmpint(check_hbitmap_iter_next(&hbi), <, 0); + g_assert_cmpint(hbitmap_iter_next(&hbi, true), <, 0); =20 hbitmap_test_set(data, ((L2 + L1 + 1) << 7) + 8, 8); hbitmap_iter_init(&hbi, data->hb, 0); - g_assert_cmpint(check_hbitmap_iter_next(&hbi), =3D=3D, (L2 + L1 + 1) <= < 7); - g_assert_cmpint(check_hbitmap_iter_next(&hbi), <, 0); + g_assert_cmpint(hbitmap_iter_next(&hbi, true), =3D=3D, (L2 + L1 + 1) <= < 7); + g_assert_cmpint(hbitmap_iter_next(&hbi, true), <, 0); =20 hbitmap_iter_init(&hbi, data->hb, (L2 + L1 + 2) << 7); g_assert_cmpint(hbitmap_iter_next(&hbi, true), <, 0); =20 hbitmap_test_set(data, (131072 << 7) - 8, 8); hbitmap_iter_init(&hbi, data->hb, 0); - g_assert_cmpint(check_hbitmap_iter_next(&hbi), =3D=3D, (L2 + L1 + 1) <= < 7); - g_assert_cmpint(check_hbitmap_iter_next(&hbi), =3D=3D, 131071 << 7); - g_assert_cmpint(check_hbitmap_iter_next(&hbi), <, 0); + g_assert_cmpint(hbitmap_iter_next(&hbi, true), =3D=3D, (L2 + L1 + 1) <= < 7); + g_assert_cmpint(hbitmap_iter_next(&hbi, true), =3D=3D, 131071 << 7); + g_assert_cmpint(hbitmap_iter_next(&hbi, true), <, 0); =20 hbitmap_iter_init(&hbi, data->hb, (L2 + L1 + 2) << 7); - g_assert_cmpint(check_hbitmap_iter_next(&hbi), =3D=3D, 131071 << 7); - g_assert_cmpint(check_hbitmap_iter_next(&hbi), <, 0); + g_assert_cmpint(hbitmap_iter_next(&hbi, true), =3D=3D, 131071 << 7); + g_assert_cmpint(hbitmap_iter_next(&hbi, true), <, 0); } =20 static void hbitmap_test_set_boundary_bits(TestHBitmapData *data, ssize_t = diff) @@ -905,7 +893,7 @@ static void test_hbitmap_serialize_zeroes(TestHBitmapDa= ta *data, for (i =3D 0; i < num_positions; i++) { hbitmap_deserialize_zeroes(data->hb, positions[i], min_l1, true); hbitmap_iter_init(&iter, data->hb, 0); - next =3D check_hbitmap_iter_next(&iter); + next =3D hbitmap_iter_next(&iter, true); if (i =3D=3D num_positions - 1) { g_assert_cmpint(next, =3D=3D, -1); } else { @@ -931,10 +919,10 @@ static void test_hbitmap_iter_and_reset(TestHBitmapDa= ta *data, =20 hbitmap_iter_init(&hbi, data->hb, BITS_PER_LONG - 1); =20 - check_hbitmap_iter_next(&hbi); + hbitmap_iter_next(&hbi, true); =20 hbitmap_reset_all(data->hb); - check_hbitmap_iter_next(&hbi); + hbitmap_iter_next(&hbi, true); } =20 static void test_hbitmap_next_zero_check_range(TestHBitmapData *data, --=20 2.17.2 From nobody Sun Sep 28 10:39:56 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1547600810693971.7805710662672; Tue, 15 Jan 2019 17:06:50 -0800 (PST) Received: from localhost ([127.0.0.1]:37584 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjZfN-0006bt-HD for importer@patchew.org; Tue, 15 Jan 2019 20:06:49 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57946) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjZaS-0002un-33 for qemu-devel@nongnu.org; Tue, 15 Jan 2019 20:01:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gjZaJ-0004cC-2W for qemu-devel@nongnu.org; Tue, 15 Jan 2019 20:01:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56576) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gjZa8-0004SR-RL for qemu-devel@nongnu.org; Tue, 15 Jan 2019 20:01:27 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6C579C04B948; Wed, 16 Jan 2019 01:01:15 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-221.bos.redhat.com [10.18.17.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id D1E5419C7C; Wed, 16 Jan 2019 01:01:14 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Date: Tue, 15 Jan 2019 20:01:06 -0500 Message-Id: <20190116010106.27626-9-jsnow@redhat.com> In-Reply-To: <20190116010106.27626-1-jsnow@redhat.com> References: <20190116010106.27626-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 16 Jan 2019 01:01:15 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 8/8] Revert "hbitmap: Add @advance param to hbitmap_iter_next()" X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Vladimir Sementsov-Ogievskiy , jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy This reverts commit a33fbb4f8b64226becf502a123733776ce319b24. The functionality is unused. Note: in addition to automatic revert, drop second parameter in hbitmap_iter_next() call from hbitmap_next_dirty_area() too. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: John Snow Signed-off-by: John Snow --- block/backup.c | 2 +- block/dirty-bitmap.c | 2 +- include/qemu/hbitmap.h | 5 +---- tests/test-hbitmap.c | 26 +++++++++++++------------- util/hbitmap.c | 12 ++++-------- 5 files changed, 20 insertions(+), 27 deletions(-) diff --git a/block/backup.c b/block/backup.c index 9ffce5c183..435414e964 100644 --- a/block/backup.c +++ b/block/backup.c @@ -385,7 +385,7 @@ static int coroutine_fn backup_run_incremental(BackupBl= ockJob *job) HBitmapIter hbi; =20 hbitmap_iter_init(&hbi, job->copy_bitmap, 0); - while ((cluster =3D hbitmap_iter_next(&hbi, true)) !=3D -1) { + while ((cluster =3D hbitmap_iter_next(&hbi)) !=3D -1) { do { if (yield_and_check(job)) { return 0; diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index 4d9a8af17d..00ea36f554 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -515,7 +515,7 @@ void bdrv_dirty_iter_free(BdrvDirtyBitmapIter *iter) =20 int64_t bdrv_dirty_iter_next(BdrvDirtyBitmapIter *iter) { - return hbitmap_iter_next(&iter->hbi, true); + return hbitmap_iter_next(&iter->hbi); } =20 /* Called within bdrv_dirty_bitmap_lock..unlock */ diff --git a/include/qemu/hbitmap.h b/include/qemu/hbitmap.h index 097dce31ee..4afbe6292e 100644 --- a/include/qemu/hbitmap.h +++ b/include/qemu/hbitmap.h @@ -351,14 +351,11 @@ void hbitmap_free_meta(HBitmap *hb); /** * hbitmap_iter_next: * @hbi: HBitmapIter to operate on. - * @advance: If true, advance the iterator. Otherwise, the next call - * of this function will return the same result (if that - * position is still dirty). * * Return the next bit that is set in @hbi's associated HBitmap, * or -1 if all remaining bits are zero. */ -int64_t hbitmap_iter_next(HBitmapIter *hbi, bool advance); +int64_t hbitmap_iter_next(HBitmapIter *hbi); =20 /** * hbitmap_iter_next_word: diff --git a/tests/test-hbitmap.c b/tests/test-hbitmap.c index 6358f35359..592d8219db 100644 --- a/tests/test-hbitmap.c +++ b/tests/test-hbitmap.c @@ -46,7 +46,7 @@ static void hbitmap_test_check(TestHBitmapData *data, =20 i =3D first; for (;;) { - next =3D hbitmap_iter_next(&hbi, true); + next =3D hbitmap_iter_next(&hbi); if (next < 0) { next =3D data->size; } @@ -435,25 +435,25 @@ static void test_hbitmap_iter_granularity(TestHBitmap= Data *data, /* Note that hbitmap_test_check has to be invoked manually in this tes= t. */ hbitmap_test_init(data, 131072 << 7, 7); hbitmap_iter_init(&hbi, data->hb, 0); - g_assert_cmpint(hbitmap_iter_next(&hbi, true), <, 0); + g_assert_cmpint(hbitmap_iter_next(&hbi), <, 0); =20 hbitmap_test_set(data, ((L2 + L1 + 1) << 7) + 8, 8); hbitmap_iter_init(&hbi, data->hb, 0); - g_assert_cmpint(hbitmap_iter_next(&hbi, true), =3D=3D, (L2 + L1 + 1) <= < 7); - g_assert_cmpint(hbitmap_iter_next(&hbi, true), <, 0); + g_assert_cmpint(hbitmap_iter_next(&hbi), =3D=3D, (L2 + L1 + 1) << 7); + g_assert_cmpint(hbitmap_iter_next(&hbi), <, 0); =20 hbitmap_iter_init(&hbi, data->hb, (L2 + L1 + 2) << 7); - g_assert_cmpint(hbitmap_iter_next(&hbi, true), <, 0); + g_assert_cmpint(hbitmap_iter_next(&hbi), <, 0); =20 hbitmap_test_set(data, (131072 << 7) - 8, 8); hbitmap_iter_init(&hbi, data->hb, 0); - g_assert_cmpint(hbitmap_iter_next(&hbi, true), =3D=3D, (L2 + L1 + 1) <= < 7); - g_assert_cmpint(hbitmap_iter_next(&hbi, true), =3D=3D, 131071 << 7); - g_assert_cmpint(hbitmap_iter_next(&hbi, true), <, 0); + g_assert_cmpint(hbitmap_iter_next(&hbi), =3D=3D, (L2 + L1 + 1) << 7); + g_assert_cmpint(hbitmap_iter_next(&hbi), =3D=3D, 131071 << 7); + g_assert_cmpint(hbitmap_iter_next(&hbi), <, 0); =20 hbitmap_iter_init(&hbi, data->hb, (L2 + L1 + 2) << 7); - g_assert_cmpint(hbitmap_iter_next(&hbi, true), =3D=3D, 131071 << 7); - g_assert_cmpint(hbitmap_iter_next(&hbi, true), <, 0); + g_assert_cmpint(hbitmap_iter_next(&hbi), =3D=3D, 131071 << 7); + g_assert_cmpint(hbitmap_iter_next(&hbi), <, 0); } =20 static void hbitmap_test_set_boundary_bits(TestHBitmapData *data, ssize_t = diff) @@ -893,7 +893,7 @@ static void test_hbitmap_serialize_zeroes(TestHBitmapDa= ta *data, for (i =3D 0; i < num_positions; i++) { hbitmap_deserialize_zeroes(data->hb, positions[i], min_l1, true); hbitmap_iter_init(&iter, data->hb, 0); - next =3D hbitmap_iter_next(&iter, true); + next =3D hbitmap_iter_next(&iter); if (i =3D=3D num_positions - 1) { g_assert_cmpint(next, =3D=3D, -1); } else { @@ -919,10 +919,10 @@ static void test_hbitmap_iter_and_reset(TestHBitmapDa= ta *data, =20 hbitmap_iter_init(&hbi, data->hb, BITS_PER_LONG - 1); =20 - hbitmap_iter_next(&hbi, true); + hbitmap_iter_next(&hbi); =20 hbitmap_reset_all(data->hb); - hbitmap_iter_next(&hbi, true); + hbitmap_iter_next(&hbi); } =20 static void test_hbitmap_next_zero_check_range(TestHBitmapData *data, diff --git a/util/hbitmap.c b/util/hbitmap.c index fa356522c4..7905212a8b 100644 --- a/util/hbitmap.c +++ b/util/hbitmap.c @@ -144,7 +144,7 @@ unsigned long hbitmap_iter_skip_words(HBitmapIter *hbi) return cur; } =20 -int64_t hbitmap_iter_next(HBitmapIter *hbi, bool advance) +int64_t hbitmap_iter_next(HBitmapIter *hbi) { unsigned long cur =3D hbi->cur[HBITMAP_LEVELS - 1] & hbi->hb->levels[HBITMAP_LEVELS - 1][hbi->pos]; @@ -157,12 +157,8 @@ int64_t hbitmap_iter_next(HBitmapIter *hbi, bool advan= ce) } } =20 - if (advance) { - /* The next call will resume work from the next bit. */ - hbi->cur[HBITMAP_LEVELS - 1] =3D cur & (cur - 1); - } else { - hbi->cur[HBITMAP_LEVELS - 1] =3D cur; - } + /* The next call will resume work from the next bit. */ + hbi->cur[HBITMAP_LEVELS - 1] =3D cur & (cur - 1); item =3D ((uint64_t)hbi->pos << BITS_PER_LEVEL) + ctzl(cur); =20 return item << hbi->granularity; @@ -261,7 +257,7 @@ bool hbitmap_next_dirty_area(const HBitmap *hb, uint64_= t *start, end =3D *count > hb->orig_size - *start ? hb->orig_size : *start + *co= unt; =20 hbitmap_iter_init(&hbi, hb, *start); - firt_dirty_off =3D hbitmap_iter_next(&hbi, false); + firt_dirty_off =3D hbitmap_iter_next(&hbi); =20 if (firt_dirty_off < 0 || firt_dirty_off >=3D end) { return false; --=20 2.17.2