From nobody Mon Apr 29 00:14:19 2024 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=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1565794211; cv=none; d=zoho.com; s=zohoarc; b=WMr8+h83dgE+kwLe3Sg8vKqHcgG+QPSogMdhVS1HuOvwFWW+mXl6qEVBH9fub9n9Z95Z1Wcc8x2K8FcsheKdIyoGC6hISLPISAp0FFqSigumya0JoiFFBEJjTo0NexCYL1sIoZd9sa+0C4gwGq/qUrapRy63AfA8vO7HYlhg9P8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565794211; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=/0lKoiwD4G/oIb9BN+8dsUKNwEYyvODtYv0jD/cxgkA=; b=gvUxjIwPEdfK8dPpOgS5I7+qWYw4MoLK43bUlPuZUOdywydI063yqBbDjvDQbwqFlGQu1b7TPOurooVxOMzhYzZtFezisgzWutqRYsMD8ucAHAETvknttWApxR5hwsi250Em/YXnNEn3o3QTCkzW1msqfb1dC3a0bQFXKxo6dqI= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1565794211687894.099627009438; Wed, 14 Aug 2019 07:50:11 -0700 (PDT) Received: from localhost ([::1]:33042 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hxubK-0000aP-O3 for importer@patchew.org; Wed, 14 Aug 2019 10:50:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34190) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hxuUq-00045D-1k for qemu-devel@nongnu.org; Wed, 14 Aug 2019 10:43:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hxuUo-0002E1-B0 for qemu-devel@nongnu.org; Wed, 14 Aug 2019 10:43:27 -0400 Received: from relay.sw.ru ([185.231.240.75]:49614) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hxuUi-0002AG-NH; Wed, 14 Aug 2019 10:43:20 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hxuUe-0007hk-F4; Wed, 14 Aug 2019 17:43:16 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Date: Wed, 14 Aug 2019 17:43:12 +0300 Message-Id: <20190814144315.89729-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190814144315.89729-1-vsementsov@virtuozzo.com> References: <20190814144315.89729-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 1/4] block/dirty-bitmap: switch _next_dirty_area and _next_zero to int64_t X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: fam@euphon.net, kwolf@redhat.com, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, den@openvz.org, 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" It's very uncomfortable that we can't use same variable as result of bdrv_dirty_bitmap_next_zero and parameter of bdrv_dirty_bitmap_next_dirty_area. Signed-off-by: Vladimir Sementsov-Ogievskiy --- include/block/dirty-bitmap.h | 6 +++--- include/qemu/hbitmap.h | 5 ++--- block/dirty-bitmap.c | 6 +++--- block/mirror.c | 4 ++-- tests/test-hbitmap.c | 32 ++++++++++++++++---------------- util/hbitmap.c | 15 ++++++++++----- 6 files changed, 36 insertions(+), 32 deletions(-) diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index 4b4b731b46..493c4566d3 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -108,10 +108,10 @@ bool bdrv_has_changed_persistent_bitmaps(BlockDriverS= tate *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 offs= et, - uint64_t bytes); +int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *bitmap, int64_t offse= t, + int64_t bytes); bool bdrv_dirty_bitmap_next_dirty_area(BdrvDirtyBitmap *bitmap, - uint64_t *offset, uint64_t *bytes); + int64_t *offset, int64_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 4afbe6292e..5149ac7721 100644 --- a/include/qemu/hbitmap.h +++ b/include/qemu/hbitmap.h @@ -309,7 +309,7 @@ unsigned long hbitmap_iter_skip_words(HBitmapIter *hbi); * 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, uint64_t coun= t); +int64_t hbitmap_next_zero(const HBitmap *hb, int64_t start, int64_t count); =20 /* hbitmap_next_dirty_area: * @hb: The HBitmap to operate on @@ -324,8 +324,7 @@ int64_t hbitmap_next_zero(const HBitmap *hb, uint64_t s= tart, uint64_t count); * @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); +bool hbitmap_next_dirty_area(const HBitmap *hb, int64_t *start, int64_t *c= ount); =20 /* hbitmap_create_meta: * Create a "meta" hbitmap to track dirtiness of the bits in this HBitmap. diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index 134e0c9a0c..eeccdb48f5 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -802,14 +802,14 @@ 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, - uint64_t bytes) +int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *bitmap, int64_t offse= t, + int64_t bytes) { return hbitmap_next_zero(bitmap->bitmap, offset, bytes); } =20 bool bdrv_dirty_bitmap_next_dirty_area(BdrvDirtyBitmap *bitmap, - uint64_t *offset, uint64_t *bytes) + int64_t *offset, int64_t *bytes) { return hbitmap_next_dirty_area(bitmap->bitmap, offset, bytes); } diff --git a/block/mirror.c b/block/mirror.c index 56937ebe92..0d3b078f44 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1198,8 +1198,8 @@ do_sync_target_write(MirrorBlockJob *job, MirrorMetho= d method, QEMUIOVector *qiov, int flags) { QEMUIOVector target_qiov; - uint64_t dirty_offset =3D offset; - uint64_t dirty_bytes; + int64_t dirty_offset =3D offset; + int64_t dirty_bytes; =20 if (qiov) { qemu_iovec_init(&target_qiov, qiov->niov); diff --git a/tests/test-hbitmap.c b/tests/test-hbitmap.c index eed5d288cb..462a6c3f74 100644 --- a/tests/test-hbitmap.c +++ b/tests/test-hbitmap.c @@ -946,7 +946,7 @@ static void test_hbitmap_next_zero_check_range(TestHBit= mapData *data, =20 static void test_hbitmap_next_zero_check(TestHBitmapData *data, int64_t st= art) { - test_hbitmap_next_zero_check_range(data, start, UINT64_MAX); + test_hbitmap_next_zero_check_range(data, start, INT64_MAX); } =20 static void test_hbitmap_next_zero_do(TestHBitmapData *data, int granulari= ty) @@ -1014,11 +1014,11 @@ static void test_hbitmap_next_zero_after_truncate(T= estHBitmapData *data, } =20 static void test_hbitmap_next_dirty_area_check(TestHBitmapData *data, - uint64_t offset, - uint64_t count) + int64_t offset, + int64_t count) { - uint64_t off1, off2; - uint64_t len1 =3D 0, len2; + int64_t off1, off2; + int64_t len1 =3D 0, len2; bool ret1, ret2; int64_t end; =20 @@ -1054,24 +1054,24 @@ static void test_hbitmap_next_dirty_area_do(TestHBi= tmapData *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, INT64_MAX); test_hbitmap_next_dirty_area_check(data, 0, 1); test_hbitmap_next_dirty_area_check(data, L3 - 1, 1); =20 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, 0, INT64_MAX); + test_hbitmap_next_dirty_area_check(data, L2 - 1, INT64_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, INT64_MAX); test_hbitmap_next_dirty_area_check(data, L2, 1); test_hbitmap_next_dirty_area_check(data, L2 + 1, 1); =20 hbitmap_set(data->hb, L2 + 5, L1); - test_hbitmap_next_dirty_area_check(data, 0, UINT64_MAX); + test_hbitmap_next_dirty_area_check(data, 0, INT64_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); @@ -1083,16 +1083,16 @@ static void test_hbitmap_next_dirty_area_do(TestHBi= tmapData *data, test_hbitmap_next_dirty_area_check(data, L2 + 1, 0); =20 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, 0, INT64_MAX); + test_hbitmap_next_dirty_area_check(data, L2, INT64_MAX); + test_hbitmap_next_dirty_area_check(data, L2 + 1, INT64_MAX); + test_hbitmap_next_dirty_area_check(data, L2 + 5 + L1 - 1, INT64_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); =20 hbitmap_set(data->hb, 0, L3); - test_hbitmap_next_dirty_area_check(data, 0, UINT64_MAX); + test_hbitmap_next_dirty_area_check(data, 0, INT64_MAX); } =20 static void test_hbitmap_next_dirty_area_0(TestHBitmapData *data, @@ -1119,7 +1119,7 @@ static void test_hbitmap_next_dirty_area_after_trunca= te(TestHBitmapData *data, hbitmap_test_init(data, L1, 0); hbitmap_test_truncate_impl(data, L1 * 2); hbitmap_set(data->hb, L1 + 1, 1); - test_hbitmap_next_dirty_area_check(data, 0, UINT64_MAX); + test_hbitmap_next_dirty_area_check(data, 0, INT64_MAX); } =20 int main(int argc, char **argv) diff --git a/util/hbitmap.c b/util/hbitmap.c index fd44c897ab..c08751fb50 100644 --- a/util/hbitmap.c +++ b/util/hbitmap.c @@ -193,7 +193,7 @@ void hbitmap_iter_init(HBitmapIter *hbi, const HBitmap = *hb, uint64_t first) } } =20 -int64_t hbitmap_next_zero(const HBitmap *hb, uint64_t start, uint64_t coun= t) +int64_t hbitmap_next_zero(const HBitmap *hb, int64_t start, int64_t count) { size_t pos =3D (start >> hb->granularity) >> BITS_PER_LEVEL; unsigned long *last_lev =3D hb->levels[HBITMAP_LEVELS - 1]; @@ -202,6 +202,8 @@ int64_t hbitmap_next_zero(const HBitmap *hb, uint64_t s= tart, uint64_t count) uint64_t end_bit, sz; int64_t res; =20 + assert(start >=3D 0 && count >=3D 0); + if (start >=3D hb->orig_size || count =3D=3D 0) { return -1; } @@ -244,14 +246,15 @@ 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) +bool hbitmap_next_dirty_area(const HBitmap *hb, int64_t *start, int64_t *c= ount) { HBitmapIter hbi; int64_t firt_dirty_off, area_end; uint32_t granularity =3D 1UL << hb->granularity; uint64_t end; =20 + assert(*start >=3D 0 && *count >=3D 0); + if (*start >=3D hb->orig_size || *count =3D=3D 0) { return false; } @@ -704,6 +707,7 @@ HBitmap *hbitmap_alloc(uint64_t size, int granularity) HBitmap *hb =3D g_new0(struct HBitmap, 1); unsigned i; =20 + assert(size <=3D INT64_MAX); hb->orig_size =3D size; =20 assert(granularity >=3D 0 && granularity < 64); @@ -734,6 +738,7 @@ void hbitmap_truncate(HBitmap *hb, uint64_t size) uint64_t num_elements =3D size; uint64_t old; =20 + assert(size <=3D INT64_MAX); hb->orig_size =3D size; =20 /* Size comes in as logical elements, adjust for granularity. */ @@ -791,8 +796,8 @@ bool hbitmap_can_merge(const HBitmap *a, const HBitmap = *b) */ static void hbitmap_sparse_merge(HBitmap *dst, const HBitmap *src) { - uint64_t offset =3D 0; - uint64_t count =3D src->orig_size; + int64_t offset =3D 0; + int64_t count =3D src->orig_size; =20 while (hbitmap_next_dirty_area(src, &offset, &count)) { hbitmap_set(dst, offset, count); --=20 2.18.0 From nobody Mon Apr 29 00:14:19 2024 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=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1565793920; cv=none; d=zoho.com; s=zohoarc; b=merbHIBt+DcDMDneeLnzjz6RZXjGP1rIy9AnbtgTfdN3JIGTsWqULtuxpdqsPcYIjUUclA/eOiWRFXNiqoQ3EXcf0gC9Kre4rFinX8XzgsSSor6u6XsW1lpAijBFgqlPRuVsGL7HQ8/PtnVX+C86AxiWIByUyaVeRjjPkwGtUtc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565793920; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=SAmJNeUCpID3sMBtww9gv/I5Ky/QUa1x6CwzAKhkH20=; b=en7jemk1wZ/J/GnFk5/jU6XzDhRDiP+XenzE07sTiWzKc2kQD2myx3UyLJObm130Gm274eY7NHFntgnJfIPpFlP4weWHfcJq8Orv/k/8/qOUp0aa6hQWONa1iOW79h7NgvKnq49FKi+jxiROqr/N0e460oazg7BhLLibCGx9Zow= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1565793920160204.3285478795666; Wed, 14 Aug 2019 07:45:20 -0700 (PDT) Received: from localhost ([::1]:32988 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hxuWa-0005JB-GT for importer@patchew.org; Wed, 14 Aug 2019 10:45:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34165) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hxuUp-00043x-6r for qemu-devel@nongnu.org; Wed, 14 Aug 2019 10:43:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hxuUn-0002Db-ML for qemu-devel@nongnu.org; Wed, 14 Aug 2019 10:43:27 -0400 Received: from relay.sw.ru ([185.231.240.75]:49612) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hxuUi-0002AE-QL; Wed, 14 Aug 2019 10:43:20 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hxuUe-0007hk-VF; Wed, 14 Aug 2019 17:43:17 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Date: Wed, 14 Aug 2019 17:43:13 +0300 Message-Id: <20190814144315.89729-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190814144315.89729-1-vsementsov@virtuozzo.com> References: <20190814144315.89729-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 2/4] block/dirty-bitmap: add _next_dirty API X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: fam@euphon.net, kwolf@redhat.com, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, den@openvz.org, 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" We have bdrv_dirty_bitmap_next_zero, let's add corresponding bdrv_dirty_bitmap_next_dirty, which is more comfortable to use than bitmap iterators in some cases. It will be used in the following commit. Signed-off-by: Vladimir Sementsov-Ogievskiy --- include/block/dirty-bitmap.h | 2 ++ include/qemu/hbitmap.h | 13 ++++++++ block/dirty-bitmap.c | 6 ++++ util/hbitmap.c | 61 +++++++++++++++++++----------------- 4 files changed, 54 insertions(+), 28 deletions(-) diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index 493c4566d3..d1310ee76e 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -108,6 +108,8 @@ bool bdrv_has_changed_persistent_bitmaps(BlockDriverSta= te *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_dirty(BdrvDirtyBitmap *bitmap, int64_t offs= et, + int64_t bytes); int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *bitmap, int64_t offse= t, int64_t bytes); bool bdrv_dirty_bitmap_next_dirty_area(BdrvDirtyBitmap *bitmap, diff --git a/include/qemu/hbitmap.h b/include/qemu/hbitmap.h index 5149ac7721..80ecabe8e2 100644 --- a/include/qemu/hbitmap.h +++ b/include/qemu/hbitmap.h @@ -299,6 +299,19 @@ void hbitmap_iter_init(HBitmapIter *hbi, const HBitmap= *hb, uint64_t first); */ unsigned long hbitmap_iter_skip_words(HBitmapIter *hbi); =20 +/* + * hbitmap_next_dirty: + * + * Find next dirty bit within selected range. If not found, return -1. + * + * @hb: The HBitmap to operate on + * @start: The bit to start from. + * @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_dirty(const HBitmap *hb, int64_t start, int64_t count= ); + /* hbitmap_next_zero: * * Find next not dirty bit within selected range. If not found, return -1. diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index eeccdb48f5..efe3a39d49 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -802,6 +802,12 @@ char *bdrv_dirty_bitmap_sha256(const BdrvDirtyBitmap *= bitmap, Error **errp) return hbitmap_sha256(bitmap->bitmap, errp); } =20 +int64_t bdrv_dirty_bitmap_next_dirty(BdrvDirtyBitmap *bitmap, int64_t offs= et, + int64_t bytes) +{ + return hbitmap_next_zero(bitmap->bitmap, offset, bytes); +} + int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *bitmap, int64_t offse= t, int64_t bytes) { diff --git a/util/hbitmap.c b/util/hbitmap.c index c08751fb50..3f2d7451ce 100644 --- a/util/hbitmap.c +++ b/util/hbitmap.c @@ -193,6 +193,30 @@ void hbitmap_iter_init(HBitmapIter *hbi, const HBitmap= *hb, uint64_t first) } } =20 +int64_t hbitmap_next_dirty(const HBitmap *hb, int64_t start, int64_t count) +{ + HBitmapIter hbi; + int64_t firt_dirty_off; + uint64_t end; + + assert(start >=3D 0 && count >=3D 0); + + if (start >=3D hb->orig_size || count =3D=3D 0) { + return -1; + } + + end =3D count > hb->orig_size - start ? hb->orig_size : start + count; + + hbitmap_iter_init(&hbi, hb, start); + firt_dirty_off =3D hbitmap_iter_next(&hbi); + + if (firt_dirty_off < 0 || firt_dirty_off >=3D end) { + return -1; + } + + return MAX(start, firt_dirty_off); +} + int64_t hbitmap_next_zero(const HBitmap *hb, int64_t start, int64_t count) { size_t pos =3D (start >> hb->granularity) >> BITS_PER_LEVEL; @@ -248,40 +272,21 @@ int64_t hbitmap_next_zero(const HBitmap *hb, int64_t = start, int64_t count) =20 bool hbitmap_next_dirty_area(const HBitmap *hb, int64_t *start, int64_t *c= ount) { - HBitmapIter hbi; - int64_t firt_dirty_off, area_end; - uint32_t granularity =3D 1UL << hb->granularity; - uint64_t end; - - assert(*start >=3D 0 && *count >=3D 0); - - 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); + int64_t area_start, area_end; =20 - if (firt_dirty_off < 0 || firt_dirty_off >=3D end) { + area_start =3D hbitmap_next_dirty(hb, *start, *count); + if (area_start < 0) { return false; } =20 - 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; - } + area_end =3D QEMU_ALIGN_UP(area_start + 1, 1UL << hb->granularity); + area_end =3D hbitmap_next_zero(hb, area_end, *start + *count - area_en= d); + if (area_end < 0) { + area_end =3D MIN(hb->orig_size, *start + *count); } =20 - if (firt_dirty_off > *start) { - *start =3D firt_dirty_off; - } - *count =3D area_end - *start; + *start =3D area_start; + *count =3D area_end - area_start; =20 return true; } --=20 2.18.0 From nobody Mon Apr 29 00:14:19 2024 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=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1565793989; cv=none; d=zoho.com; s=zohoarc; b=J/TV0R4sLzvq70JIsRjSZ/Mhx6l2EIG2q8xlA/VESzJpQA0jz8qDOYUSb7SZINM8iXZkjsTuyKcoIsKnlZ79iPrEbFu32DwO9qTFkYFm1znqXHHC2xQLDq4DHjsJynN+nB7T7MW9SIVicLB142sqUFuODGZHUMdujZIiWKJqr8w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565793989; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=ZVJXTXUwabm5rmVal6uvqKxP7MD0NLkDVo3UcgosZaM=; b=bjGvkQWYLD6+sWXyoLQYqO80E2lfEJaXWv6BzxYu/WQ4aDXPEWAKkOO+hl+lvuYkOJWXGUzVfxP6b2du6gGiEOzvxOu022ZM6R7Q3TL4a/VFlHUxMDaZYADtZ+C37nCRcFLCbhR7H/RwV9uMr5uquM4ZvOh6GovAfRVS4UiPWDM= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1565793989622456.29851710283117; Wed, 14 Aug 2019 07:46:29 -0700 (PDT) Received: from localhost ([::1]:33002 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hxuXk-0005tX-MH for importer@patchew.org; Wed, 14 Aug 2019 10:46:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34156) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hxuUo-00043X-KF for qemu-devel@nongnu.org; Wed, 14 Aug 2019 10:43:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hxuUn-0002DN-E2 for qemu-devel@nongnu.org; Wed, 14 Aug 2019 10:43:26 -0400 Received: from relay.sw.ru ([185.231.240.75]:49604) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hxuUi-0002AF-Pv; Wed, 14 Aug 2019 10:43:20 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hxuUf-0007hk-8L; Wed, 14 Aug 2019 17:43:17 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Date: Wed, 14 Aug 2019 17:43:14 +0300 Message-Id: <20190814144315.89729-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190814144315.89729-1-vsementsov@virtuozzo.com> References: <20190814144315.89729-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 3/4] block/backup: use bdrv_dirty_bitmap_next_dirty X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: fam@euphon.net, kwolf@redhat.com, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, den@openvz.org, 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" Use more effective search for next dirty byte. Trace point is dropped to not introduce additional variable and logic only for trace point. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/backup.c | 7 +++---- block/trace-events | 1 - 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/block/backup.c b/block/backup.c index 07d751aea4..9bddea1b59 100644 --- a/block/backup.c +++ b/block/backup.c @@ -272,10 +272,9 @@ static int coroutine_fn backup_do_cow(BackupBlockJob *= job, while (start < end) { int64_t dirty_end; =20 - if (!bdrv_dirty_bitmap_get(job->copy_bitmap, start)) { - trace_backup_do_cow_skip(job, start); - start +=3D job->cluster_size; - continue; /* already copied */ + start =3D bdrv_dirty_bitmap_next_dirty(job->copy_bitmap, start, en= d); + if (start < 0) { + break; } =20 if (job->initializing_bitmap) { diff --git a/block/trace-events b/block/trace-events index 04209f058d..7e46f7e036 100644 --- a/block/trace-events +++ b/block/trace-events @@ -40,7 +40,6 @@ mirror_yield_in_flight(void *s, int64_t offset, int in_fl= ight) "s %p offset %" P # backup.c backup_do_cow_enter(void *job, int64_t start, int64_t offset, uint64_t byt= es) "job %p start %" PRId64 " offset %" PRId64 " bytes %" PRIu64 backup_do_cow_return(void *job, int64_t offset, uint64_t bytes, int ret) "= job %p offset %" PRId64 " bytes %" PRIu64 " ret %d" -backup_do_cow_skip(void *job, int64_t start) "job %p start %"PRId64 backup_do_cow_skip_range(void *job, int64_t start, uint64_t bytes) "job %p= start %"PRId64" bytes %"PRId64 backup_do_cow_process(void *job, int64_t start) "job %p start %"PRId64 backup_do_cow_read_fail(void *job, int64_t start, int ret) "job %p start %= "PRId64" ret %d" --=20 2.18.0 From nobody Mon Apr 29 00:14:19 2024 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=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1565794071; cv=none; d=zoho.com; s=zohoarc; b=iUZJzoglmVpMuaWEr6cubcgQxOFlm77AE8ixNiYkTj0M+oEHeCKQpvNFwMfc+nc7UfiqTYSy8NAQgQoWqYs459L2BvR51+zQ7iKTa0bq8UzoNqdxUJ6yWxcu4lgT4HO3V8HFJHymqdW/yImqNr+/MggJJBCYkyM/hmBf3c/AmHI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565794071; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=O2RFuspzmaYa/OcU5rwl2XHfiHvhYyBjrT7Q6owizvE=; b=cXp8YKehng2h31OD9PW9sWaq0oqCxqDaxc1NsXg6P15Pl1ttCx0jWnScyAsodbmFoFiuAzh5Fl3S55wD+4RtS0fw0KE8x/+MnA6MG/zWvFeNBkO0+8/TjEUphDl/ISqqexdqYrth/u/i/f9TAMR0oUrLQxZd9wNu4v/FY+BzaXQ= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1565794071436404.26151963905136; Wed, 14 Aug 2019 07:47:51 -0700 (PDT) Received: from localhost ([::1]:33004 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hxuYx-0006rb-PZ for importer@patchew.org; Wed, 14 Aug 2019 10:47:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34154) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hxuUo-00043U-Iy for qemu-devel@nongnu.org; Wed, 14 Aug 2019 10:43:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hxuUn-0002DA-Ce for qemu-devel@nongnu.org; Wed, 14 Aug 2019 10:43:26 -0400 Received: from relay.sw.ru ([185.231.240.75]:49608) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hxuUi-0002AH-Qn; Wed, 14 Aug 2019 10:43:22 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hxuUf-0007hk-JB; Wed, 14 Aug 2019 17:43:17 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Date: Wed, 14 Aug 2019 17:43:15 +0300 Message-Id: <20190814144315.89729-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190814144315.89729-1-vsementsov@virtuozzo.com> References: <20190814144315.89729-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 4/4] block/backup: fix and improve skipping unallocated in backup_do_cow X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: fam@euphon.net, kwolf@redhat.com, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, den@openvz.org, 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" 1. There is a bug: after detection an allocated area of skip_bytes length we ignore skip_bytes variable and my finish up by copying more than skip_bytes. 2. If request area is allocated we call block_status for each cluster on each loop iteration, even if after the first call we know that the whole request area is allocated. Solve all of this by handling resetting all unallocated bytes from requested area before copying loop. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/backup.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/block/backup.c b/block/backup.c index 9bddea1b59..d0815b21c8 100644 --- a/block/backup.c +++ b/block/backup.c @@ -257,7 +257,6 @@ static int coroutine_fn backup_do_cow(BackupBlockJob *j= ob, int ret =3D 0; int64_t start, end; /* bytes */ void *bounce_buffer =3D NULL; - int64_t skip_bytes; =20 qemu_co_rwlock_rdlock(&job->flush_rwlock); =20 @@ -269,6 +268,22 @@ static int coroutine_fn backup_do_cow(BackupBlockJob *= job, wait_for_overlapping_requests(job, start, end); cow_request_begin(&cow_request, job, start, end); =20 + if (job->initializing_bitmap) { + int64_t off =3D start; + int64_t count; + + while (off < end) { + off =3D bdrv_dirty_bitmap_next_dirty(job->copy_bitmap, + off, end - off); + if (off < 0) { + break; + } + + backup_bitmap_reset_unallocated(job, off, &count); + off +=3D count; + } + } + while (start < end) { int64_t dirty_end; =20 @@ -277,15 +292,6 @@ static int coroutine_fn backup_do_cow(BackupBlockJob *= job, break; } =20 - if (job->initializing_bitmap) { - ret =3D backup_bitmap_reset_unallocated(job, start, &skip_byte= s); - if (ret =3D=3D 0) { - trace_backup_do_cow_skip_range(job, start, skip_bytes); - start +=3D skip_bytes; - continue; - } - } - dirty_end =3D bdrv_dirty_bitmap_next_zero(job->copy_bitmap, start, (end - start)); if (dirty_end < 0) { --=20 2.18.0