From: John Snow <jsnow@redhat.com>
To: qemu-devel@nongnu.org, qemu-block@nongnu.org
Cc: Max Reitz <mreitz@redhat.com>, Fam Zheng <fam@euphon.net>,
John Snow <jsnow@redhat.com>, Kevin Wolf <kwolf@redhat.com>,
Markus Armbruster <armbru@redhat.com>,
eblake@redhat.com, vsementsov@virtuozzo.com,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
Juan Quintela <quintela@redhat.com>
Subject: [Qemu-devel] [PATCH v3 7/7] block/dirty-bitmaps: implement inconsistent bit
Date: Fri, 1 Mar 2019 14:15:45 -0500 [thread overview]
Message-ID: <20190301191545.8728-8-jsnow@redhat.com> (raw)
In-Reply-To: <20190301191545.8728-1-jsnow@redhat.com>
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 <jsnow@redhat.com>
---
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..c3b210ede1 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 = NULL;
+ granularity = 1U << bm->granularity_bits;
+ bitmap = bdrv_create_dirty_bitmap(bs, granularity, bm->name, errp);
+ if (bitmap == 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;
}
ret = bitmap_table_load(bs, &bm->table, &bitmap_table);
@@ -356,12 +362,6 @@ static BdrvDirtyBitmap *load_bitmap(BlockDriverState *bs,
goto fail;
}
- granularity = 1U << bm->granularity_bits;
- bitmap = bdrv_create_dirty_bitmap(bs, granularity, bm->name, errp);
- if (bitmap == NULL) {
- goto fail;
- }
-
ret = load_bitmap_data(bs, bitmap_table, bm->table.size, bitmap);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not read bitmap '%s' from image",
@@ -949,6 +949,7 @@ bool qcow2_load_dirty_bitmaps(BlockDriverState *bs, Error **errp)
Qcow2Bitmap *bm;
GSList *created_dirty_bitmaps = NULL;
bool header_updated = false;
+ bool needs_update = false;
if (s->nb_bitmaps == 0) {
/* No bitmaps - nothing to do */
@@ -962,35 +963,39 @@ bool qcow2_load_dirty_bitmaps(BlockDriverState *bs, Error **errp)
}
QSIMPLEQ_FOREACH(bm, bm_list, entry) {
- if (!(bm->flags & BME_FLAG_IN_USE)) {
- BdrvDirtyBitmap *bitmap = load_bitmap(bs, bm, errp);
- if (bitmap == NULL) {
- goto fail;
- }
-
- if (!(bm->flags & BME_FLAG_AUTO)) {
- bdrv_disable_dirty_bitmap(bitmap);
- }
- bdrv_dirty_bitmap_set_persistance(bitmap, true);
- bm->flags |= BME_FLAG_IN_USE;
- created_dirty_bitmaps =
- g_slist_append(created_dirty_bitmaps, bitmap);
+ BdrvDirtyBitmap *bitmap = load_bitmap(bs, bm, errp);
+ if (bitmap == NULL) {
+ goto fail;
}
- }
- if (created_dirty_bitmaps != NULL) {
- if (can_write(bs)) {
- /* in_use flags must be updated */
- int ret = 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 = 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 |= BME_FLAG_IN_USE;
+ needs_update = true;
}
+ if (!(bm->flags & BME_FLAG_AUTO)) {
+ bdrv_disable_dirty_bitmap(bitmap);
+ }
+ bdrv_dirty_bitmap_set_persistance(bitmap, true);
+ created_dirty_bitmaps =
+ g_slist_append(created_dirty_bitmaps, bitmap);
+ }
+
+ if (needs_update && can_write(bs)) {
+ /* in_use flags must be updated */
+ int ret = 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 = true;
+ }
+
+ if (!can_write(bs)) {
+ g_slist_foreach(created_dirty_bitmaps, set_readonly_helper,
+ (gpointer)true);
}
g_slist_free(created_dirty_bitmaps);
@@ -1112,23 +1117,21 @@ int qcow2_reopen_bitmaps_rw_hint(BlockDriverState *bs, bool *header_updated,
}
QSIMPLEQ_FOREACH(bm, bm_list, entry) {
- if (!(bm->flags & BME_FLAG_IN_USE)) {
- BdrvDirtyBitmap *bitmap = bdrv_find_dirty_bitmap(bs, bm->name);
- if (bitmap == 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 wrong,"
- "all the bitmaps may be corrupted", bm->name);
- ret = -EINVAL;
- goto out;
- }
+ BdrvDirtyBitmap *bitmap = bdrv_find_dirty_bitmap(bs, bm->name);
+ if (bitmap == NULL) {
+ continue;
+ }
- bm->flags |= BME_FLAG_IN_USE;
- ro_dirty_bitmaps = 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 went "
+ "wrong. All of the bitmaps may be corrupted", bm->name);
+ ret = -EINVAL;
+ goto out;
}
+
+ bm->flags |= BME_FLAG_IN_USE;
+ ro_dirty_bitmaps = g_slist_append(ro_dirty_bitmaps, bitmap);
}
if (ro_dirty_bitmaps != NULL) {
@@ -1424,8 +1427,8 @@ void qcow2_store_persistent_dirty_bitmaps(BlockDriverState *bs, Error **errp)
Qcow2Bitmap *bm;
if (!bdrv_dirty_bitmap_get_persistance(bitmap) ||
- bdrv_dirty_bitmap_readonly(bitmap))
- {
+ bdrv_dirty_bitmap_readonly(bitmap) ||
+ bdrv_dirty_bitmap_inconsistent(bitmap)) {
continue;
}
--
2.17.2
next prev parent reply other threads:[~2019-03-01 19:16 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-01 19:15 [Qemu-devel] [PATCH v3 0/7] bitmaps: add inconsistent bit John Snow
2019-03-01 19:15 ` [Qemu-devel] [PATCH v3 1/7] block/dirty-bitmaps: " John Snow
2019-03-01 19:32 ` Eric Blake
2019-03-01 19:44 ` John Snow
2019-03-06 12:25 ` Vladimir Sementsov-Ogievskiy
2019-03-06 13:06 ` Vladimir Sementsov-Ogievskiy
2019-03-06 13:08 ` Vladimir Sementsov-Ogievskiy
2019-03-06 15:15 ` John Snow
2019-03-01 19:15 ` [Qemu-devel] [PATCH v3 2/7] block/dirty-bitmap: add inconsistent status John Snow
2019-03-06 13:05 ` Vladimir Sementsov-Ogievskiy
2019-03-06 15:14 ` John Snow
2019-03-01 19:15 ` [Qemu-devel] [PATCH v3 3/7] block/dirty-bitmaps: add block_dirty_bitmap_check function John Snow
2019-03-01 19:36 ` Eric Blake
2019-03-01 19:57 ` John Snow
2019-03-01 20:03 ` Eric Blake
2019-03-01 20:06 ` Eric Blake
2019-03-06 13:44 ` Vladimir Sementsov-Ogievskiy
2019-03-06 15:17 ` John Snow
2019-03-01 19:15 ` [Qemu-devel] [PATCH v3 4/7] block/dirty-bitmaps: prohibit readonly bitmaps for backups John Snow
2019-03-01 19:38 ` Eric Blake
2019-03-06 13:47 ` Vladimir Sementsov-Ogievskiy
2019-03-01 19:15 ` [Qemu-devel] [PATCH v3 5/7] block/dirty-bitmaps: prohibit removing readonly bitmaps John Snow
2019-03-01 19:39 ` Eric Blake
2019-03-06 13:49 ` Vladimir Sementsov-Ogievskiy
2019-03-01 19:15 ` [Qemu-devel] [PATCH v3 6/7] block/dirty-bitmaps: disallow busy bitmaps as merge source John Snow
2019-03-01 19:44 ` Eric Blake
2019-03-01 19:48 ` John Snow
2019-03-01 19:57 ` Eric Blake
2019-03-01 20:04 ` John Snow
2019-03-06 13:57 ` Vladimir Sementsov-Ogievskiy
2019-03-06 15:24 ` John Snow
2019-03-06 15:29 ` Eric Blake
2019-03-06 13:57 ` Vladimir Sementsov-Ogievskiy
2019-03-01 19:15 ` John Snow [this message]
2019-03-01 19:53 ` [Qemu-devel] [PATCH v3 7/7] block/dirty-bitmaps: implement inconsistent bit Eric Blake
2019-03-06 14:26 ` Vladimir Sementsov-Ogievskiy
2019-03-06 21:46 ` John Snow
2019-03-07 16:37 ` Eric Blake
2019-03-08 18:46 ` John Snow
2019-03-05 23:59 ` [Qemu-devel] [PATCH v3 0/7] bitmaps: add " John Snow
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190301191545.8728-8-jsnow@redhat.com \
--to=jsnow@redhat.com \
--cc=armbru@redhat.com \
--cc=dgilbert@redhat.com \
--cc=eblake@redhat.com \
--cc=fam@euphon.net \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=stefanha@redhat.com \
--cc=vsementsov@virtuozzo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).