From patchwork Tue Aug 14 12:14:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 957480 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=virtuozzo.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41qWsR4Qz4z9s9l for ; Tue, 14 Aug 2018 22:20:59 +1000 (AEST) Received: from localhost ([::1]:44058 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fpYJl-00010x-AF for incoming@patchwork.ozlabs.org; Tue, 14 Aug 2018 08:20:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37586) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fpYDs-0002eA-UN for qemu-devel@nongnu.org; Tue, 14 Aug 2018 08:14:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fpYDn-00052W-SE for qemu-devel@nongnu.org; Tue, 14 Aug 2018 08:14:52 -0400 Received: from relay.sw.ru ([185.231.240.75]:51106) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fpYDn-000519-HK; Tue, 14 Aug 2018 08:14:47 -0400 Received: from vz-out.virtuozzo.com ([185.231.240.5] helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.90_1) (envelope-from ) id 1fpYDk-0007K0-D1; Tue, 14 Aug 2018 15:14:44 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Tue, 14 Aug 2018 15:14:38 +0300 Message-Id: <20180814121443.33114-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20180814121443.33114-1-vsementsov@virtuozzo.com> References: <20180814121443.33114-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 v3 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 | 3 +++ include/qemu/hbitmap.h | 15 +++++++++++++++ block/dirty-bitmap.c | 7 +++++++ util/hbitmap.c | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+) diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index 27f5299c4e..cb9162fa7e 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -100,6 +100,9 @@ BdrvDirtyBitmap *bdrv_dirty_bitmap_next(BlockDriverState *bs, char *bdrv_dirty_bitmap_sha256(const BdrvDirtyBitmap *bitmap, Error **errp); int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *bitmap, uint64_t start, int64_t end); +bool bdrv_dirty_bitmap_next_dirty_area(BdrvDirtyBitmap *bitmap, + uint64_t *offset, uint64_t end, + uint64_t *length); 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 fe4dfde27a..7800317bf3 100644 --- a/include/qemu/hbitmap.h +++ b/include/qemu/hbitmap.h @@ -306,6 +306,21 @@ unsigned long hbitmap_iter_skip_words(HBitmapIter *hbi); */ int64_t hbitmap_next_zero(const HBitmap *hb, uint64_t start, int64_t end); +/* hbitmap_next_dirty_area: + * @hb: The HBitmap to operate on + * @offset: in-out parameter. + * in: the offset to start from + * out: (if area found) start of found area + * @end: end of requested region. (*@offset + *@length) will be <= @end + * @length: length of found area + * + * If dirty area found within [@offset, @end), returns true and sets @offset + * and @length appropriately. Otherwise returns true and leaves @offset and + * @length unchanged. + */ +bool hbitmap_next_dirty_area(const HBitmap *hb, uint64_t *offset, + uint64_t end, uint64_t *length); + /* 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 037ae62726..4af20a1beb 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -791,6 +791,13 @@ int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *bitmap, uint64_t offset, return hbitmap_next_zero(bitmap->bitmap, offset, end); } +bool bdrv_dirty_bitmap_next_dirty_area(BdrvDirtyBitmap *bitmap, + uint64_t *offset, uint64_t end, + uint64_t *length) +{ + return hbitmap_next_dirty_area(bitmap->bitmap, offset, end, length); +} + void bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, const BdrvDirtyBitmap *src, Error **errp) { diff --git a/util/hbitmap.c b/util/hbitmap.c index 1687372504..bf88c1223e 100644 --- a/util/hbitmap.c +++ b/util/hbitmap.c @@ -244,6 +244,44 @@ int64_t hbitmap_next_zero(const HBitmap *hb, uint64_t start, int64_t end) return res; } +bool hbitmap_next_dirty_area(const HBitmap *hb, uint64_t *offset, + uint64_t end, uint64_t *length) +{ + HBitmapIter hbi; + int64_t off1, off0; + uint32_t granularity = 1UL << hb->granularity; + + if (end == 0) { + end = hb->orig_size; + } + + hbitmap_iter_init(&hbi, hb, *offset); + off1 = hbitmap_iter_next(&hbi, true); + + if (off1 < 0 || off1 >= end) { + return false; + } + + if (off1 + granularity >= end) { + if (off1 > *offset) { + *offset = off1; + } + *length = end - *offset; + return true; + } + + off0 = hbitmap_next_zero(hb, off1 + granularity, end); + if (off0 < 0) { + off0 = end; + } + + if (off1 > *offset) { + *offset = off1; + } + *length = off0 - *offset; + return true; +} + bool hbitmap_empty(const HBitmap *hb) { return hb->count == 0;