From nobody Tue Nov 4 18:50:17 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 1530615328411441.40398453011016; Tue, 3 Jul 2018 03:55:28 -0700 (PDT) Received: from localhost ([::1]:39601 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1faIxz-0004Oz-PF for importer@patchew.org; Tue, 03 Jul 2018 06:55:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52901) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1faIvp-000389-BG for qemu-devel@nongnu.org; Tue, 03 Jul 2018 06:53:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1faIvl-0004lN-GG for qemu-devel@nongnu.org; Tue, 03 Jul 2018 06:53:13 -0400 Received: from relay.sw.ru ([185.231.240.75]:47656) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1faIvl-0004k5-82; Tue, 03 Jul 2018 06:53:09 -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 1faIvh-0006Ql-JN; Tue, 03 Jul 2018 13:53:05 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Tue, 3 Jul 2018 13:53:04 +0300 Message-Id: <20180703105305.45398-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20180703105305.45398-1-vsementsov@virtuozzo.com> References: <20180703105305.45398-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 1/2] drity-bitmap: refactor merge: separte can_merge 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, armbru@redhat.com, mreitz@redhat.com, den@openvz.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Separate can_merge, to reuse it for transaction support for merge command. Also, switch some asserts to errors. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Reviewed-by: John Snow --- include/block/dirty-bitmap.h | 3 +++ include/qemu/hbitmap.h | 8 ++++++++ block/dirty-bitmap.c | 32 +++++++++++++++++++++++++++----- blockdev.c | 10 ---------- util/hbitmap.c | 6 +++++- 5 files changed, 43 insertions(+), 16 deletions(-) diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index 288dc6adb6..412a333c02 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -71,6 +71,9 @@ void bdrv_dirty_bitmap_set_persistance(BdrvDirtyBitmap *b= itmap, void bdrv_dirty_bitmap_set_qmp_locked(BdrvDirtyBitmap *bitmap, bool qmp_lo= cked); void bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, const BdrvDirtyBitmap = *src, Error **errp); +bool bdrv_can_merge_dirty_bitmap(BdrvDirtyBitmap *dst, + const BdrvDirtyBitmap *src, + Error **errp); =20 /* Functions that require manual locking. */ void bdrv_dirty_bitmap_lock(BdrvDirtyBitmap *bitmap); diff --git a/include/qemu/hbitmap.h b/include/qemu/hbitmap.h index ddca52c48e..d08bc20ea3 100644 --- a/include/qemu/hbitmap.h +++ b/include/qemu/hbitmap.h @@ -85,6 +85,14 @@ void hbitmap_truncate(HBitmap *hb, uint64_t size); bool hbitmap_merge(HBitmap *a, const HBitmap *b); =20 /** + * hbitmap_can_merge: + * + * Returns same value as hbitmap_merge, but do not do actual merge. + * + */ +bool hbitmap_can_merge(HBitmap *a, const HBitmap *b); + +/** * hbitmap_empty: * @hb: HBitmap to operate on. * diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index db1782ec1f..1137224aaa 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -784,6 +784,30 @@ int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *b= itmap, uint64_t offset) return hbitmap_next_zero(bitmap->bitmap, offset); } =20 +bool bdrv_can_merge_dirty_bitmap(BdrvDirtyBitmap *dst, + const BdrvDirtyBitmap *src, + Error **errp) +{ + if (bdrv_dirty_bitmap_frozen(dst)) { + error_setg(errp, "Bitmap '%s' is frozen and cannot be modified", + dst->name); + return false; + } + + if (bdrv_dirty_bitmap_readonly(dst)) { + error_setg(errp, "Bitmap '%s' is readonly and cannot be modified", + dst->name); + return false; + } + + if (!hbitmap_can_merge(dst->bitmap, src->bitmap)) { + error_setg(errp, "Bitmaps are incompatible and can't be merged"); + return false; + } + + return true; +} + void bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, const BdrvDirtyBitmap = *src, Error **errp) { @@ -792,11 +816,9 @@ void bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, co= nst BdrvDirtyBitmap *src, =20 qemu_mutex_lock(dest->mutex); =20 - assert(bdrv_dirty_bitmap_enabled(dest)); - assert(!bdrv_dirty_bitmap_readonly(dest)); - - if (!hbitmap_merge(dest->bitmap, src->bitmap)) { - error_setg(errp, "Bitmaps are incompatible and can't be merged"); + if (bdrv_can_merge_dirty_bitmap(dest, src, errp)) { + bool ret =3D hbitmap_merge(dest->bitmap, src->bitmap); + assert(ret); } =20 qemu_mutex_unlock(dest->mutex); diff --git a/blockdev.c b/blockdev.c index 58d7570932..63c4d33124 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2955,16 +2955,6 @@ void qmp_x_block_dirty_bitmap_merge(const char *node= , const char *dst_name, return; } =20 - if (bdrv_dirty_bitmap_frozen(dst)) { - error_setg(errp, "Bitmap '%s' is frozen and cannot be modified", - dst_name); - return; - } else if (bdrv_dirty_bitmap_readonly(dst)) { - error_setg(errp, "Bitmap '%s' is readonly and cannot be modified", - dst_name); - return; - } - src =3D bdrv_find_dirty_bitmap(bs, src_name); if (!src) { error_setg(errp, "Dirty bitmap '%s' not found", src_name); diff --git a/util/hbitmap.c b/util/hbitmap.c index bcd304041a..b56377b043 100644 --- a/util/hbitmap.c +++ b/util/hbitmap.c @@ -723,6 +723,10 @@ void hbitmap_truncate(HBitmap *hb, uint64_t size) } } =20 +bool hbitmap_can_merge(HBitmap *a, const HBitmap *b) +{ + return (a->size =3D=3D b->size) && (a->granularity =3D=3D b->granulari= ty); +} =20 /** * Given HBitmaps A and B, let A :=3D A (BITOR) B. @@ -736,7 +740,7 @@ bool hbitmap_merge(HBitmap *a, const HBitmap *b) int i; uint64_t j; =20 - if ((a->size !=3D b->size) || (a->granularity !=3D b->granularity)) { + if (!hbitmap_can_merge(a, b)) { return false; } =20 --=20 2.11.1