From nobody Sun Sep 28 11:14:15 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