From nobody Fri Oct 3 15:50:00 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 1552077806933836.9516062831665; Fri, 8 Mar 2019 12:43:26 -0800 (PST) Received: from localhost ([127.0.0.1]:49658 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h2MKs-0003eT-RF for importer@patchew.org; Fri, 08 Mar 2019 15:43:18 -0500 Received: from eggs.gnu.org ([209.51.188.92]:44926) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h2M7L-0000uS-Ud for qemu-devel@nongnu.org; Fri, 08 Mar 2019 15:29:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h2M7J-0006yg-Rj for qemu-devel@nongnu.org; Fri, 08 Mar 2019 15:29:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56758) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h2M7J-0006v0-Hk for qemu-devel@nongnu.org; Fri, 08 Mar 2019 15:29: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 B121930D78C4; Fri, 8 Mar 2019 20:29:14 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-160.bos.redhat.com [10.18.17.160]) by smtp.corp.redhat.com (Postfix) with ESMTP id 40C7B19751; Fri, 8 Mar 2019 20:29:14 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Date: Fri, 8 Mar 2019 15:28:58 -0500 Message-Id: <20190308202858.26636-18-jsnow@redhat.com> In-Reply-To: <20190308202858.26636-1-jsnow@redhat.com> References: <20190308202858.26636-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.47]); Fri, 08 Mar 2019 20:29:14 +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 17/17] 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: peter.maydell@linaro.org, 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" 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 the bitmap. 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 Reviewed-by: Eric Blake Message-id: 20190301191545.8728-8-jsnow@redhat.com Signed-off-by: John Snow --- block/qcow2-bitmap.c | 103 ++++++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 50 deletions(-) diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index 3ee524da4b..80926966de 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,35 +963,39 @@ 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; - } - - if (!(bm->flags & BME_FLAG_AUTO)) { - bdrv_disable_dirty_bitmap(bitmap); - } - bdrv_dirty_bitmap_set_persistance(bitmap, true); - bm->flags |=3D BME_FLAG_IN_USE; - created_dirty_bitmaps =3D - g_slist_append(created_dirty_bitmaps, bitmap); + BdrvDirtyBitmap *bitmap =3D load_bitmap(bs, bm, errp); + if (bitmap =3D=3D NULL) { + goto fail; } - } =20 - if (created_dirty_bitmaps !=3D NULL) { - if (can_write(bs)) { - /* in_use flags must be updated */ - int ret =3D update_ext_header_and_dir_in_place(bs, bm_list); - if (ret < 0) { - error_setg_errno(errp, -ret, "Can't update bitmap director= y"); - goto fail; - } - header_updated =3D true; + bdrv_dirty_bitmap_set_persistance(bitmap, true); + if (bm->flags & BME_FLAG_IN_USE) { + bdrv_dirty_bitmap_set_inconsistent(bitmap); } else { - g_slist_foreach(created_dirty_bitmaps, set_readonly_helper, - (gpointer)true); + /* NB: updated flags only get written if can_write(bs) is true= . */ + bm->flags |=3D BME_FLAG_IN_USE; + needs_update =3D true; } + if (!(bm->flags & BME_FLAG_AUTO)) { + bdrv_disable_dirty_bitmap(bitmap); + } + created_dirty_bitmaps =3D + g_slist_append(created_dirty_bitmaps, bitmap); + } + + if (needs_update && can_write(bs)) { + /* in_use flags must be updated */ + int ret =3D update_ext_header_and_dir_in_place(bs, bm_list); + if (ret < 0) { + error_setg_errno(errp, -ret, "Can't update bitmap directory"); + goto fail; + } + header_updated =3D true; + } + + if (!can_write(bs)) { + g_slist_foreach(created_dirty_bitmaps, set_readonly_helper, + (gpointer)true); } =20 g_slist_free(created_dirty_bitmaps); @@ -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