From nobody Sun Nov 9 11:36:03 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 155088150616523.245812981338645; Fri, 22 Feb 2019 16:25:06 -0800 (PST) Received: from localhost ([127.0.0.1]:58959 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxL7n-0001pT-4M for importer@patchew.org; Fri, 22 Feb 2019 19:25:03 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34740) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxL5B-0000CG-3m for qemu-devel@nongnu.org; Fri, 22 Feb 2019 19:22:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gxL5A-0004Ps-11 for qemu-devel@nongnu.org; Fri, 22 Feb 2019 19:22:21 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42410) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gxL57-0004Mg-EG; Fri, 22 Feb 2019 19:22:17 -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 9FAB980F81; Sat, 23 Feb 2019 00:22:16 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-206.bos.redhat.com [10.18.17.206]) by smtp.corp.redhat.com (Postfix) with ESMTP id 713F619C58; Sat, 23 Feb 2019 00:22:15 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Fri, 22 Feb 2019 19:22:06 -0500 Message-Id: <20190223002209.23084-2-jsnow@redhat.com> In-Reply-To: <20190223002209.23084-1-jsnow@redhat.com> References: <20190223002209.23084-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.27]); Sat, 23 Feb 2019 00:22:16 +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] [PATCH v2 1/4] block/dirty-bitmaps: add inconsistent bit 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: Kevin Wolf , Fam Zheng , vsementsov@virtuozzo.com, Juan Quintela , Markus Armbruster , "Dr. David Alan Gilbert" , Max Reitz , John Snow , Stefan Hajnoczi 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" Add an inconsistent bit to dirty-bitmaps that allows us to report a bitmap = as persistent but potentially inconsistent, i.e. if we find bitmaps on a qcow2 that have been marked as "in use". Signed-off-by: John Snow Reviewed-by: Eric Blake --- block/dirty-bitmap.c | 19 +++++++++++++++++++ include/block/dirty-bitmap.h | 2 ++ qapi/block-core.json | 8 ++++++-- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index 86c3b87ab9..9042c04788 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -46,6 +46,9 @@ struct BdrvDirtyBitmap { and this bitmap must remain unchanged w= hile this flag is set. */ bool persistent; /* bitmap must be saved to owner disk imag= e */ + bool inconsistent; /* bitmap is persistent, but not owned by = QEMU. + * It cannot be used at all in any way, ex= cept + * a QMP user can remove it. */ bool migration; /* Bitmap is selected for migration, it sh= ould not be stored on the next inactivation (persistent flag doesn't matter until n= ext @@ -462,6 +465,8 @@ BlockDirtyInfoList *bdrv_query_dirty_bitmaps(BlockDrive= rState *bs) info->recording =3D bdrv_dirty_bitmap_recording(bm); info->busy =3D bdrv_dirty_bitmap_busy(bm); info->persistent =3D bm->persistent; + info->has_inconsistent =3D bm->inconsistent; + info->inconsistent =3D bm->inconsistent; entry->value =3D info; *plist =3D entry; plist =3D &entry->next; @@ -709,6 +714,15 @@ void bdrv_dirty_bitmap_set_persistance(BdrvDirtyBitmap= *bitmap, bool persistent) qemu_mutex_unlock(bitmap->mutex); } =20 +/* Called with BQL taken. */ +void bdrv_dirty_bitmap_set_inconsistent(BdrvDirtyBitmap *bitmap) +{ + qemu_mutex_lock(bitmap->mutex); + bitmap->inconsistent =3D true; + bitmap->disabled =3D true; + qemu_mutex_unlock(bitmap->mutex); +} + /* Called with BQL taken. */ void bdrv_dirty_bitmap_set_migration(BdrvDirtyBitmap *bitmap, bool migrati= on) { @@ -722,6 +736,11 @@ bool bdrv_dirty_bitmap_get_persistance(BdrvDirtyBitmap= *bitmap) return bitmap->persistent && !bitmap->migration; } =20 +bool bdrv_dirty_bitmap_inconsistent(BdrvDirtyBitmap *bitmap) +{ + return bitmap->inconsistent; +} + bool bdrv_has_changed_persistent_bitmaps(BlockDriverState *bs) { BdrvDirtyBitmap *bm; diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index ba8477b73f..b270773f7e 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -68,6 +68,7 @@ void bdrv_dirty_bitmap_deserialize_finish(BdrvDirtyBitmap= *bitmap); void bdrv_dirty_bitmap_set_readonly(BdrvDirtyBitmap *bitmap, bool value); void bdrv_dirty_bitmap_set_persistance(BdrvDirtyBitmap *bitmap, bool persistent); +void bdrv_dirty_bitmap_set_inconsistent(BdrvDirtyBitmap *bitmap); void bdrv_dirty_bitmap_set_busy(BdrvDirtyBitmap *bitmap, bool busy); void bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, const BdrvDirtyBitmap = *src, HBitmap **backup, Error **errp); @@ -91,6 +92,7 @@ bool bdrv_dirty_bitmap_readonly(const BdrvDirtyBitmap *bi= tmap); bool bdrv_has_readonly_bitmaps(BlockDriverState *bs); bool bdrv_dirty_bitmap_get_autoload(const BdrvDirtyBitmap *bitmap); bool bdrv_dirty_bitmap_get_persistance(BdrvDirtyBitmap *bitmap); +bool bdrv_dirty_bitmap_inconsistent(BdrvDirtyBitmap *bitmap); bool bdrv_dirty_bitmap_busy(BdrvDirtyBitmap *bitmap); bool bdrv_has_changed_persistent_bitmaps(BlockDriverState *bs); BdrvDirtyBitmap *bdrv_dirty_bitmap_next(BlockDriverState *bs, diff --git a/qapi/block-core.json b/qapi/block-core.json index 6e543594b3..a7209fce22 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -470,12 +470,16 @@ # @persistent: true if the bitmap will eventually be flushed to persistent # storage (since 4.0) # +# @inconsistent: true if this is a persistent bitmap that QEMU does not ow= n. +# Implies @recording and @busy to be false. To reclaim +# ownership, use @block-dirty-bitmap-remove. (since 4.0) +# # Since: 1.3 ## { 'struct': 'BlockDirtyInfo', 'data': {'*name': 'str', 'count': 'int', 'granularity': 'uint32', - 'recording': 'bool', 'busy': 'bool', - 'status': 'DirtyBitmapStatus', 'persistent': 'bool' } } + 'recording': 'bool', 'busy': 'bool', 'status': 'DirtyBitmapStat= us', + 'persistent': 'bool', '*inconsistent': 'bool' } } =20 ## # @Qcow2BitmapInfoFlags: --=20 2.17.2 From nobody Sun Nov 9 11:36:03 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 1550881460712265.92549236937407; Fri, 22 Feb 2019 16:24:20 -0800 (PST) Received: from localhost ([127.0.0.1]:58957 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxL72-0001EH-Ni for importer@patchew.org; Fri, 22 Feb 2019 19:24:16 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34773) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxL5B-0000D1-QF for qemu-devel@nongnu.org; Fri, 22 Feb 2019 19:22:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gxL5B-0004Qu-1P for qemu-devel@nongnu.org; Fri, 22 Feb 2019 19:22:21 -0500 Received: from mx1.redhat.com ([209.132.183.28]:14385) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gxL58-0004OD-N5; Fri, 22 Feb 2019 19:22:18 -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 F18AC3099D38; Sat, 23 Feb 2019 00:22:17 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-206.bos.redhat.com [10.18.17.206]) by smtp.corp.redhat.com (Postfix) with ESMTP id BF84919C58; Sat, 23 Feb 2019 00:22:16 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Fri, 22 Feb 2019 19:22:07 -0500 Message-Id: <20190223002209.23084-3-jsnow@redhat.com> In-Reply-To: <20190223002209.23084-1-jsnow@redhat.com> References: <20190223002209.23084-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.41]); Sat, 23 Feb 2019 00:22:18 +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] [PATCH v2 2/4] block/dirty-bitmap: add inconsistent status 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: Kevin Wolf , Fam Zheng , vsementsov@virtuozzo.com, Juan Quintela , Markus Armbruster , "Dr. David Alan Gilbert" , Max Reitz , John Snow , Stefan Hajnoczi 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" Even though the status field is deprecated, we still have to support it for a few more releases. Since this is a very new kind of bitmap state, it makes sense for it to have its own status field. Signed-off-by: John Snow Reviewed-by: Eric Blake --- block/dirty-bitmap.c | 7 ++++++- qapi/block-core.json | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index 9042c04788..4e8f931659 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -209,10 +209,15 @@ bool bdrv_dirty_bitmap_enabled(BdrvDirtyBitmap *bitma= p) * or it can be Disabled and not recording writes. * (4) Locked: Whether Active or Disabled, the user cannot modify this b= itmap * in any way from the monitor. + * (5) Inconsistent: This is a persistent bitmap whose "in use" bit is set= , and + * is unusable by QEMU. It can be deleted to remove it f= rom + * the qcow2. */ DirtyBitmapStatus bdrv_dirty_bitmap_status(BdrvDirtyBitmap *bitmap) { - if (bdrv_dirty_bitmap_has_successor(bitmap)) { + if (bdrv_dirty_bitmap_inconsistent(bitmap)) { + return DIRTY_BITMAP_STATUS_INCONSISTENT; + } else if (bdrv_dirty_bitmap_has_successor(bitmap)) { return DIRTY_BITMAP_STATUS_FROZEN; } else if (bdrv_dirty_bitmap_busy(bitmap)) { return DIRTY_BITMAP_STATUS_LOCKED; diff --git a/qapi/block-core.json b/qapi/block-core.json index a7209fce22..b25ca6a6c1 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -442,10 +442,15 @@ # recording new writes. If the bitmap was @disabled, it is not # recording new writes. (Since 2.12) # +# @inconsistent: This is a persistent dirty bitmap that was marked in-use = on +# disk, and is unusable by QEMU. It can only be deleted. +# Please rely on the inconsistent field in @BlockDirtyInfo +# instead, as the status field is deprecated. (Since 4.0) +# # Since: 2.4 ## { 'enum': 'DirtyBitmapStatus', - 'data': ['active', 'disabled', 'frozen', 'locked'] } + 'data': ['active', 'disabled', 'frozen', 'locked', 'inconsistent'] } =20 ## # @BlockDirtyInfo: --=20 2.17.2 From nobody Sun Nov 9 11:36:03 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 1550881588992797.8660410508315; Fri, 22 Feb 2019 16:26:28 -0800 (PST) Received: from localhost ([127.0.0.1]:59005 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxL97-0002rJ-Uc for importer@patchew.org; Fri, 22 Feb 2019 19:26:25 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34825) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxL5E-0000F6-Ny for qemu-devel@nongnu.org; Fri, 22 Feb 2019 19:22:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gxL5D-0004VP-8h for qemu-devel@nongnu.org; Fri, 22 Feb 2019 19:22:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34870) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gxL5A-0004PX-1T; Fri, 22 Feb 2019 19:22:20 -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 4B9C7307DAC2; Sat, 23 Feb 2019 00:22:19 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-206.bos.redhat.com [10.18.17.206]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1C16219C58; Sat, 23 Feb 2019 00:22:18 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Fri, 22 Feb 2019 19:22:08 -0500 Message-Id: <20190223002209.23084-4-jsnow@redhat.com> In-Reply-To: <20190223002209.23084-1-jsnow@redhat.com> References: <20190223002209.23084-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.42]); Sat, 23 Feb 2019 00:22:19 +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] [PATCH v2 3/4] block/dirty-bitmaps: add block_dirty_bitmap_check function 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: Kevin Wolf , Fam Zheng , vsementsov@virtuozzo.com, Juan Quintela , Markus Armbruster , "Dr. David Alan Gilbert" , Max Reitz , John Snow , Stefan Hajnoczi 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" Instead of checking against busy, inconsistent, or read only directly, use a check function with permissions bits that let us streamline the checks without reproducing them in many places. As a side effect, this adds consistency checks to all the QMP interfaces for bitmap manipulation. Signed-off-by: John Snow --- block/dirty-bitmap.c | 39 ++++++++++++++++++++------- blockdev.c | 49 +++++++--------------------------- include/block/dirty-bitmap.h | 13 ++++++++- migration/block-dirty-bitmap.c | 12 +++------ nbd/server.c | 3 +-- 5 files changed, 54 insertions(+), 62 deletions(-) diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index 4e8f931659..2e7fd81866 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -174,7 +174,7 @@ bool bdrv_dirty_bitmap_has_successor(BdrvDirtyBitmap *b= itmap) return bitmap->successor; } =20 -bool bdrv_dirty_bitmap_busy(BdrvDirtyBitmap *bitmap) { +static bool bdrv_dirty_bitmap_busy(BdrvDirtyBitmap *bitmap) { return bitmap->busy; } =20 @@ -235,6 +235,33 @@ static bool bdrv_dirty_bitmap_recording(BdrvDirtyBitma= p *bitmap) !bitmap->successor->disabled); } =20 +int bdrv_dirty_bitmap_check(BdrvDirtyBitmap *bitmap, uint32_t flags, + Error **errp) +{ + if ((flags & BDRV_BITMAP_BUSY) && bdrv_dirty_bitmap_busy(bitmap)) { + error_setg(errp, "Bitmap '%s' is currently in use by another" + " operation and cannot be used", bitmap->name); + return -1; + } + + if ((flags & BDRV_BITMAP_RO) && bdrv_dirty_bitmap_readonly(bitmap)) { + error_setg(errp, "Bitmap '%s' is readonly and cannot be modified", + bitmap->name); + return -1; + } + + if ((flags & BDRV_BITMAP_INCONSISTENT) && + bdrv_dirty_bitmap_inconsistent(bitmap)) { + error_setg(errp, "Bitmap '%s' is inconsistent and cannot be used", + bitmap->name); + error_append_hint(errp, "Try block-dirty-bitmap-remove to delete " + "this bitmap from disk"); + return -1; + } + + return 0; +} + /** * Create a successor bitmap destined to replace this bitmap after an oper= ation. * Requires that the bitmap is not user_locked and has no successor. @@ -792,15 +819,7 @@ void bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, co= nst BdrvDirtyBitmap *src, =20 qemu_mutex_lock(dest->mutex); =20 - if (bdrv_dirty_bitmap_busy(dest)) { - error_setg(errp, "Bitmap '%s' is currently in use by another" - " operation and cannot be modified", dest->name); - goto out; - } - - if (bdrv_dirty_bitmap_readonly(dest)) { - error_setg(errp, "Bitmap '%s' is readonly and cannot be modified", - dest->name); + if (bdrv_dirty_bitmap_check(dest, BDRV_BITMAP_DEFAULT, errp)) { goto out; } =20 diff --git a/blockdev.c b/blockdev.c index cbce44877d..5d74479ba7 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2007,11 +2007,7 @@ static void block_dirty_bitmap_clear_prepare(BlkActi= onState *common, return; } =20 - if (bdrv_dirty_bitmap_busy(state->bitmap)) { - error_setg(errp, "Cannot modify a bitmap in use by another operati= on"); - return; - } else if (bdrv_dirty_bitmap_readonly(state->bitmap)) { - error_setg(errp, "Cannot clear a readonly bitmap"); + if (bdrv_dirty_bitmap_check(state->bitmap, BDRV_BITMAP_DEFAULT, errp))= { return; } =20 @@ -2056,10 +2052,7 @@ static void block_dirty_bitmap_enable_prepare(BlkAct= ionState *common, return; } =20 - if (bdrv_dirty_bitmap_busy(state->bitmap)) { - error_setg(errp, - "Bitmap '%s' is currently in use by another operation" - " and cannot be enabled", action->name); + if (bdrv_dirty_bitmap_check(state->bitmap, BDRV_BITMAP_ALLOW_RO, errp)= ) { return; } =20 @@ -2097,10 +2090,7 @@ static void block_dirty_bitmap_disable_prepare(BlkAc= tionState *common, return; } =20 - if (bdrv_dirty_bitmap_busy(state->bitmap)) { - error_setg(errp, - "Bitmap '%s' is currently in use by another operation" - " and cannot be disabled", action->name); + if (bdrv_dirty_bitmap_check(state->bitmap, BDRV_BITMAP_ALLOW_RO, errp)= ) { return; } =20 @@ -2891,10 +2881,7 @@ void qmp_block_dirty_bitmap_remove(const char *node,= const char *name, return; } =20 - if (bdrv_dirty_bitmap_busy(bitmap)) { - error_setg(errp, - "Bitmap '%s' is currently in use by another operation a= nd" - " cannot be removed", name); + if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_BUSY, errp)) { return; } =20 @@ -2930,13 +2917,7 @@ void qmp_block_dirty_bitmap_clear(const char *node, = const char *name, return; } =20 - if (bdrv_dirty_bitmap_busy(bitmap)) { - error_setg(errp, - "Bitmap '%s' is currently in use by another operation" - " and cannot be cleared", name); - return; - } else if (bdrv_dirty_bitmap_readonly(bitmap)) { - error_setg(errp, "Bitmap '%s' is readonly and cannot be cleared", = name); + if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_DEFAULT, errp)) { return; } =20 @@ -2954,10 +2935,7 @@ void qmp_block_dirty_bitmap_enable(const char *node,= const char *name, return; } =20 - if (bdrv_dirty_bitmap_busy(bitmap)) { - error_setg(errp, - "Bitmap '%s' is currently in use by another operation" - " and cannot be enabled", name); + if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_ALLOW_RO, errp)) { return; } =20 @@ -2975,10 +2953,7 @@ void qmp_block_dirty_bitmap_disable(const char *node= , const char *name, return; } =20 - if (bdrv_dirty_bitmap_busy(bitmap)) { - error_setg(errp, - "Bitmap '%s' is currently in use by another operation" - " and cannot be disabled", name); + if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_ALLOW_RO, errp)) { return; } =20 @@ -3551,10 +3526,7 @@ static BlockJob *do_drive_backup(DriveBackup *backup= , JobTxn *txn, bdrv_unref(target_bs); goto out; } - if (bdrv_dirty_bitmap_busy(bmap)) { - error_setg(errp, - "Bitmap '%s' is currently in use by another operati= on" - " and cannot be used for backup", backup->bitmap); + if (bdrv_dirty_bitmap_check(bmap, BDRV_BITMAP_ALLOW_RO, errp)) { goto out; } } @@ -3664,10 +3636,7 @@ BlockJob *do_blockdev_backup(BlockdevBackup *backup,= JobTxn *txn, error_setg(errp, "Bitmap '%s' could not be found", backup->bit= map); goto out; } - if (bdrv_dirty_bitmap_busy(bmap)) { - error_setg(errp, - "Bitmap '%s' is currently in use by another operati= on" - " and cannot be used for backup", backup->bitmap); + if (bdrv_dirty_bitmap_check(bmap, BDRV_BITMAP_ALLOW_RO, errp)) { goto out; } } diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index b270773f7e..ee98b5014b 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -5,6 +5,16 @@ #include "qapi/qapi-types-block-core.h" #include "qemu/hbitmap.h" =20 +typedef enum BitmapCheckFlags { + BDRV_BITMAP_BUSY =3D 1, + BDRV_BITMAP_RO =3D 2, + BDRV_BITMAP_INCONSISTENT =3D 4, +} BitmapCheckFlags; + +#define BDRV_BITMAP_DEFAULT (BDRV_BITMAP_BUSY | BDRV_BITMAP_RO | \ + BDRV_BITMAP_INCONSISTENT) +#define BDRV_BITMAP_ALLOW_RO (BDRV_BITMAP_BUSY | BDRV_BITMAP_INCONSISTENT) + BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs, uint32_t granularity, const char *name, @@ -24,6 +34,8 @@ BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BlockDriverSta= te *bs, void bdrv_dirty_bitmap_enable_successor(BdrvDirtyBitmap *bitmap); BdrvDirtyBitmap *bdrv_find_dirty_bitmap(BlockDriverState *bs, const char *name); +int bdrv_dirty_bitmap_check(BdrvDirtyBitmap *bitmap, uint32_t flags, + Error **errp); void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitm= ap); void bdrv_release_named_dirty_bitmaps(BlockDriverState *bs); void bdrv_remove_persistent_dirty_bitmap(BlockDriverState *bs, @@ -93,7 +105,6 @@ bool bdrv_has_readonly_bitmaps(BlockDriverState *bs); bool bdrv_dirty_bitmap_get_autoload(const BdrvDirtyBitmap *bitmap); bool bdrv_dirty_bitmap_get_persistance(BdrvDirtyBitmap *bitmap); bool bdrv_dirty_bitmap_inconsistent(BdrvDirtyBitmap *bitmap); -bool bdrv_dirty_bitmap_busy(BdrvDirtyBitmap *bitmap); bool bdrv_has_changed_persistent_bitmaps(BlockDriverState *bs); BdrvDirtyBitmap *bdrv_dirty_bitmap_next(BlockDriverState *bs, BdrvDirtyBitmap *bitmap); diff --git a/migration/block-dirty-bitmap.c b/migration/block-dirty-bitmap.c index 7057fff242..0fcf897f32 100644 --- a/migration/block-dirty-bitmap.c +++ b/migration/block-dirty-bitmap.c @@ -274,6 +274,7 @@ static int init_dirty_bitmap_migration(void) BdrvDirtyBitmap *bitmap; DirtyBitmapMigBitmapState *dbms; BdrvNextIterator it; + Error *local_err =3D NULL; =20 dirty_bitmap_mig_state.bulk_completed =3D false; dirty_bitmap_mig_state.prev_bs =3D NULL; @@ -301,15 +302,8 @@ static int init_dirty_bitmap_migration(void) goto fail; } =20 - if (bdrv_dirty_bitmap_busy(bitmap)) { - error_report("Can't migrate a bitmap that is in use by ano= ther operation: '%s'", - bdrv_dirty_bitmap_name(bitmap)); - goto fail; - } - - if (bdrv_dirty_bitmap_readonly(bitmap)) { - error_report("Can't migrate read-only dirty bitmap: '%s", - bdrv_dirty_bitmap_name(bitmap)); + if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_DEFAULT, &loca= l_err)) { + error_report_err(local_err); goto fail; } =20 diff --git a/nbd/server.c b/nbd/server.c index 02773e2836..9b87c7f243 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1510,8 +1510,7 @@ NBDExport *nbd_export_new(BlockDriverState *bs, uint6= 4_t dev_offset, goto fail; } =20 - if (bdrv_dirty_bitmap_busy(bm)) { - error_setg(errp, "Bitmap '%s' is in use", bitmap); + if (bdrv_dirty_bitmap_check(bm, BDRV_BITMAP_ALLOW_RO, errp)) { goto fail; } =20 --=20 2.17.2 From nobody Sun Nov 9 11:36:03 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 1550881628833901.2174573972839; Fri, 22 Feb 2019 16:27:08 -0800 (PST) Received: from localhost ([127.0.0.1]:59009 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxL9l-0003GF-Qf for importer@patchew.org; Fri, 22 Feb 2019 19:27:05 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34850) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxL5F-0000Fy-QK for qemu-devel@nongnu.org; Fri, 22 Feb 2019 19:22:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gxL5E-0004X0-Ov for qemu-devel@nongnu.org; Fri, 22 Feb 2019 19:22:25 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49232) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gxL5B-0004Qe-C7; Fri, 22 Feb 2019 19:22:21 -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 9A764C057F48; Sat, 23 Feb 2019 00:22:20 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-206.bos.redhat.com [10.18.17.206]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6CC1119C58; Sat, 23 Feb 2019 00:22:19 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Fri, 22 Feb 2019 19:22:09 -0500 Message-Id: <20190223002209.23084-5-jsnow@redhat.com> In-Reply-To: <20190223002209.23084-1-jsnow@redhat.com> References: <20190223002209.23084-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.32]); Sat, 23 Feb 2019 00:22:20 +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] [PATCH v2 4/4] block/dirty-bitmaps: implement inconsistent bit 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: Kevin Wolf , Fam Zheng , vsementsov@virtuozzo.com, Juan Quintela , Markus Armbruster , "Dr. David Alan Gilbert" , Max Reitz , John Snow , Stefan Hajnoczi 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" Set the inconsistent bit on load instead of rejecting such bitmaps. There is no way to un-set it; the only option is to delete it. Obvervations: - bitmap loading does not need to update the header for in_use bitmaps. - inconsistent bitmaps don't need to have their data loaded; they're glorified corruption sentinels. - bitmap saving does not need to save inconsistent bitmaps back to disk. - bitmap reopening DOES need to drop the readonly flag from inconsistent bitmaps to allow reopening of qcow2 files with non-qemu-owned bitmaps being eventually flushed back to disk. Signed-off-by: John Snow --- block/qcow2-bitmap.c | 77 +++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 37 deletions(-) diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index 3ee524da4b..d1cc11da88 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -343,9 +343,15 @@ static BdrvDirtyBitmap *load_bitmap(BlockDriverState *= bs, uint32_t granularity; BdrvDirtyBitmap *bitmap =3D NULL; =20 + granularity =3D 1U << bm->granularity_bits; + bitmap =3D bdrv_create_dirty_bitmap(bs, granularity, bm->name, errp); + if (bitmap =3D=3D NULL) { + goto fail; + } + if (bm->flags & BME_FLAG_IN_USE) { - error_setg(errp, "Bitmap '%s' is in use", bm->name); - goto fail; + /* Data is unusable, skip loading it */ + return bitmap; } =20 ret =3D bitmap_table_load(bs, &bm->table, &bitmap_table); @@ -356,12 +362,6 @@ static BdrvDirtyBitmap *load_bitmap(BlockDriverState *= bs, goto fail; } =20 - granularity =3D 1U << bm->granularity_bits; - bitmap =3D bdrv_create_dirty_bitmap(bs, granularity, bm->name, errp); - if (bitmap =3D=3D NULL) { - goto fail; - } - ret =3D load_bitmap_data(bs, bitmap_table, bm->table.size, bitmap); if (ret < 0) { error_setg_errno(errp, -ret, "Could not read bitmap '%s' from imag= e", @@ -949,6 +949,7 @@ bool qcow2_load_dirty_bitmaps(BlockDriverState *bs, Err= or **errp) Qcow2Bitmap *bm; GSList *created_dirty_bitmaps =3D NULL; bool header_updated =3D false; + bool needs_update =3D false; =20 if (s->nb_bitmaps =3D=3D 0) { /* No bitmaps - nothing to do */ @@ -962,23 +963,27 @@ bool qcow2_load_dirty_bitmaps(BlockDriverState *bs, E= rror **errp) } =20 QSIMPLEQ_FOREACH(bm, bm_list, entry) { - if (!(bm->flags & BME_FLAG_IN_USE)) { - BdrvDirtyBitmap *bitmap =3D load_bitmap(bs, bm, errp); - if (bitmap =3D=3D NULL) { - goto fail; - } + BdrvDirtyBitmap *bitmap =3D load_bitmap(bs, bm, errp); + if (bitmap =3D=3D NULL) { + goto fail; + } =20 - if (!(bm->flags & BME_FLAG_AUTO)) { - bdrv_disable_dirty_bitmap(bitmap); - } - bdrv_dirty_bitmap_set_persistance(bitmap, true); + if (bm->flags & BME_FLAG_IN_USE) { + bdrv_dirty_bitmap_set_inconsistent(bitmap); + } else { + /* NB: updated flags only get written if can_write(bs) is true= . */ bm->flags |=3D BME_FLAG_IN_USE; - created_dirty_bitmaps =3D - g_slist_append(created_dirty_bitmaps, bitmap); + needs_update =3D true; } + if (!(bm->flags & BME_FLAG_AUTO)) { + bdrv_disable_dirty_bitmap(bitmap); + } + bdrv_dirty_bitmap_set_persistance(bitmap, true); + created_dirty_bitmaps =3D + g_slist_append(created_dirty_bitmaps, bitmap); } =20 - if (created_dirty_bitmaps !=3D NULL) { + if (needs_update) { if (can_write(bs)) { /* in_use flags must be updated */ int ret =3D update_ext_header_and_dir_in_place(bs, bm_list); @@ -1112,23 +1117,21 @@ int qcow2_reopen_bitmaps_rw_hint(BlockDriverState *= bs, bool *header_updated, } =20 QSIMPLEQ_FOREACH(bm, bm_list, entry) { - if (!(bm->flags & BME_FLAG_IN_USE)) { - BdrvDirtyBitmap *bitmap =3D bdrv_find_dirty_bitmap(bs, bm->nam= e); - if (bitmap =3D=3D NULL) { - continue; - } - - if (!bdrv_dirty_bitmap_readonly(bitmap)) { - error_setg(errp, "Bitmap %s is not readonly but not marked" - "'IN_USE' in the image. Something went wr= ong," - "all the bitmaps may be corrupted", bm->n= ame); - ret =3D -EINVAL; - goto out; - } + BdrvDirtyBitmap *bitmap =3D bdrv_find_dirty_bitmap(bs, bm->name); + if (bitmap =3D=3D NULL) { + continue; + } =20 - bm->flags |=3D BME_FLAG_IN_USE; - ro_dirty_bitmaps =3D g_slist_append(ro_dirty_bitmaps, bitmap); + if (!bdrv_dirty_bitmap_readonly(bitmap)) { + error_setg(errp, "Bitmap %s was loaded prior to rw-reopen, but= was " + "not marked as readonly. This is a bug, something w= ent " + "wrong. All of the bitmaps may be corrupted", bm->n= ame); + ret =3D -EINVAL; + goto out; } + + bm->flags |=3D BME_FLAG_IN_USE; + ro_dirty_bitmaps =3D g_slist_append(ro_dirty_bitmaps, bitmap); } =20 if (ro_dirty_bitmaps !=3D NULL) { @@ -1424,8 +1427,8 @@ void qcow2_store_persistent_dirty_bitmaps(BlockDriver= State *bs, Error **errp) Qcow2Bitmap *bm; =20 if (!bdrv_dirty_bitmap_get_persistance(bitmap) || - bdrv_dirty_bitmap_readonly(bitmap)) - { + bdrv_dirty_bitmap_readonly(bitmap) || + bdrv_dirty_bitmap_inconsistent(bitmap)) { continue; } =20 --=20 2.17.2