From nobody Wed Nov 5 08:16:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1537196402189258.196597556181; Mon, 17 Sep 2018 08:00:02 -0700 (PDT) Received: from localhost ([::1]:35965 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g1v0E-0005KN-3N for importer@patchew.org; Mon, 17 Sep 2018 10:59:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52700) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g1uy6-00046M-07 for qemu-devel@nongnu.org; Mon, 17 Sep 2018 10:57:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g1uy2-0006NW-MZ for qemu-devel@nongnu.org; Mon, 17 Sep 2018 10:57:41 -0400 Received: from relay.sw.ru ([185.231.240.75]:57978) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g1uy2-0006Ff-BB; Mon, 17 Sep 2018 10:57:38 -0400 Received: from [10.28.8.145] (helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.90_1) (envelope-from ) id 1g1uxx-0006v1-SZ; Mon, 17 Sep 2018 17:57:33 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Mon, 17 Sep 2018 17:57:27 +0300 Message-Id: <20180917145732.48590-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180917145732.48590-1-vsementsov@virtuozzo.com> References: <20180917145732.48590-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 v4 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: kwolf@redhat.com, vsementsov@virtuozzo.com, famz@redhat.com, jcody@redhat.com, mreitz@redhat.com, den@openvz.org, pbonzini@redhat.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: John Snow --- include/block/dirty-bitmap.h | 2 ++ include/qemu/hbitmap.h | 16 +++++++++++++++ block/dirty-bitmap.c | 6 ++++++ util/hbitmap.c | 39 ++++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+) diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index 1a23c76862..7ad2a1357a 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -100,6 +100,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 8a399c1c9c..495a99e78e 100644 --- a/include/qemu/hbitmap.h +++ b/include/qemu/hbitmap.h @@ -304,6 +304,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/block/dirty-bitmap.c b/block/dirty-bitmap.c index a9ee814da7..7ee8b27368 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -791,6 +791,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, Error **errp) { diff --git a/util/hbitmap.c b/util/hbitmap.c index a18c68fb2f..5beca86740 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.18.0