|
|
7711c0 |
From 9f251abbe1e79a790aaf3a3ca48de60deb0c2a10 Mon Sep 17 00:00:00 2001
|
|
|
7711c0 |
From: John Snow <jsnow@redhat.com>
|
|
|
7711c0 |
Date: Wed, 3 Apr 2019 18:18:55 +0200
|
|
|
7711c0 |
Subject: [PATCH 150/163] block/dirty-bitmaps: implement inconsistent bit
|
|
|
7711c0 |
|
|
|
7711c0 |
RH-Author: John Snow <jsnow@redhat.com>
|
|
|
7711c0 |
Message-id: <20190403181857.9693-20-jsnow@redhat.com>
|
|
|
7711c0 |
Patchwork-id: 85428
|
|
|
7711c0 |
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 19/21] block/dirty-bitmaps: implement inconsistent bit
|
|
|
7711c0 |
Bugzilla: 1677073
|
|
|
7711c0 |
RH-Acked-by: Max Reitz <mreitz@redhat.com>
|
|
|
7711c0 |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
7711c0 |
RH-Acked-by: Sergio Lopez Pascual <slp@redhat.com>
|
|
|
7711c0 |
|
|
|
7711c0 |
Set the inconsistent bit on load instead of rejecting such bitmaps.
|
|
|
7711c0 |
There is no way to un-set it; the only option is to delete the bitmap.
|
|
|
7711c0 |
|
|
|
7711c0 |
Obvervations:
|
|
|
7711c0 |
- bitmap loading does not need to update the header for in_use bitmaps.
|
|
|
7711c0 |
- inconsistent bitmaps don't need to have their data loaded; they're
|
|
|
7711c0 |
glorified corruption sentinels.
|
|
|
7711c0 |
- bitmap saving does not need to save inconsistent bitmaps back to disk.
|
|
|
7711c0 |
- bitmap reopening DOES need to drop the readonly flag from inconsistent
|
|
|
7711c0 |
bitmaps to allow reopening of qcow2 files with non-qemu-owned bitmaps
|
|
|
7711c0 |
being eventually flushed back to disk.
|
|
|
7711c0 |
|
|
|
7711c0 |
Signed-off-by: John Snow <jsnow@redhat.com>
|
|
|
7711c0 |
Reviewed-by: Eric Blake <eblake@redhat.com>
|
|
|
7711c0 |
Message-id: 20190301191545.8728-8-jsnow@redhat.com
|
|
|
7711c0 |
Signed-off-by: John Snow <jsnow@redhat.com>
|
|
|
7711c0 |
(cherry picked from commit 74da6b943565c451d275de1b0253546c5e729d20)
|
|
|
7711c0 |
Signed-off-by: John Snow <jsnow@redhat.com>
|
|
|
7711c0 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
7711c0 |
---
|
|
|
7711c0 |
block/qcow2-bitmap.c | 99 +++++++++++++++++++++++++++-------------------------
|
|
|
7711c0 |
1 file changed, 51 insertions(+), 48 deletions(-)
|
|
|
7711c0 |
|
|
|
7711c0 |
diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c
|
|
|
7711c0 |
index 4899719..cbab0e5 100644
|
|
|
7711c0 |
--- a/block/qcow2-bitmap.c
|
|
|
7711c0 |
+++ b/block/qcow2-bitmap.c
|
|
|
7711c0 |
@@ -345,11 +345,17 @@ static BdrvDirtyBitmap *load_bitmap(BlockDriverState *bs,
|
|
|
7711c0 |
uint32_t granularity;
|
|
|
7711c0 |
BdrvDirtyBitmap *bitmap = NULL;
|
|
|
7711c0 |
|
|
|
7711c0 |
- if (bm->flags & BME_FLAG_IN_USE) {
|
|
|
7711c0 |
- error_setg(errp, "Bitmap '%s' is in use", bm->name);
|
|
|
7711c0 |
+ granularity = 1U << bm->granularity_bits;
|
|
|
7711c0 |
+ bitmap = bdrv_create_dirty_bitmap(bs, granularity, bm->name, errp);
|
|
|
7711c0 |
+ if (bitmap == NULL) {
|
|
|
7711c0 |
goto fail;
|
|
|
7711c0 |
}
|
|
|
7711c0 |
|
|
|
7711c0 |
+ if (bm->flags & BME_FLAG_IN_USE) {
|
|
|
7711c0 |
+ /* Data is unusable, skip loading it */
|
|
|
7711c0 |
+ return bitmap;
|
|
|
7711c0 |
+ }
|
|
|
7711c0 |
+
|
|
|
7711c0 |
ret = bitmap_table_load(bs, &bm->table, &bitmap_table);
|
|
|
7711c0 |
if (ret < 0) {
|
|
|
7711c0 |
error_setg_errno(errp, -ret,
|
|
|
7711c0 |
@@ -358,12 +364,6 @@ static BdrvDirtyBitmap *load_bitmap(BlockDriverState *bs,
|
|
|
7711c0 |
goto fail;
|
|
|
7711c0 |
}
|
|
|
7711c0 |
|
|
|
7711c0 |
- granularity = 1U << bm->granularity_bits;
|
|
|
7711c0 |
- bitmap = bdrv_create_dirty_bitmap(bs, granularity, bm->name, errp);
|
|
|
7711c0 |
- if (bitmap == NULL) {
|
|
|
7711c0 |
- goto fail;
|
|
|
7711c0 |
- }
|
|
|
7711c0 |
-
|
|
|
7711c0 |
ret = load_bitmap_data(bs, bitmap_table, bm->table.size, bitmap);
|
|
|
7711c0 |
if (ret < 0) {
|
|
|
7711c0 |
error_setg_errno(errp, -ret, "Could not read bitmap '%s' from image",
|
|
|
7711c0 |
@@ -951,6 +951,7 @@ bool qcow2_load_dirty_bitmaps(BlockDriverState *bs, Error **errp)
|
|
|
7711c0 |
Qcow2Bitmap *bm;
|
|
|
7711c0 |
GSList *created_dirty_bitmaps = NULL;
|
|
|
7711c0 |
bool header_updated = false;
|
|
|
7711c0 |
+ bool needs_update = false;
|
|
|
7711c0 |
|
|
|
7711c0 |
if (s->nb_bitmaps == 0) {
|
|
|
7711c0 |
/* No bitmaps - nothing to do */
|
|
|
7711c0 |
@@ -964,35 +965,39 @@ bool qcow2_load_dirty_bitmaps(BlockDriverState *bs, Error **errp)
|
|
|
7711c0 |
}
|
|
|
7711c0 |
|
|
|
7711c0 |
QSIMPLEQ_FOREACH(bm, bm_list, entry) {
|
|
|
7711c0 |
- if (!(bm->flags & BME_FLAG_IN_USE)) {
|
|
|
7711c0 |
- BdrvDirtyBitmap *bitmap = load_bitmap(bs, bm, errp);
|
|
|
7711c0 |
- if (bitmap == NULL) {
|
|
|
7711c0 |
- goto fail;
|
|
|
7711c0 |
- }
|
|
|
7711c0 |
+ BdrvDirtyBitmap *bitmap = load_bitmap(bs, bm, errp);
|
|
|
7711c0 |
+ if (bitmap == NULL) {
|
|
|
7711c0 |
+ goto fail;
|
|
|
7711c0 |
+ }
|
|
|
7711c0 |
|
|
|
7711c0 |
- if (!(bm->flags & BME_FLAG_AUTO)) {
|
|
|
7711c0 |
- bdrv_disable_dirty_bitmap(bitmap);
|
|
|
7711c0 |
- }
|
|
|
7711c0 |
- bdrv_dirty_bitmap_set_persistance(bitmap, true);
|
|
|
7711c0 |
+ bdrv_dirty_bitmap_set_persistance(bitmap, true);
|
|
|
7711c0 |
+ if (bm->flags & BME_FLAG_IN_USE) {
|
|
|
7711c0 |
+ bdrv_dirty_bitmap_set_inconsistent(bitmap);
|
|
|
7711c0 |
+ } else {
|
|
|
7711c0 |
+ /* NB: updated flags only get written if can_write(bs) is true. */
|
|
|
7711c0 |
bm->flags |= BME_FLAG_IN_USE;
|
|
|
7711c0 |
- created_dirty_bitmaps =
|
|
|
7711c0 |
- g_slist_append(created_dirty_bitmaps, bitmap);
|
|
|
7711c0 |
+ needs_update = true;
|
|
|
7711c0 |
}
|
|
|
7711c0 |
+ if (!(bm->flags & BME_FLAG_AUTO)) {
|
|
|
7711c0 |
+ bdrv_disable_dirty_bitmap(bitmap);
|
|
|
7711c0 |
+ }
|
|
|
7711c0 |
+ created_dirty_bitmaps =
|
|
|
7711c0 |
+ g_slist_append(created_dirty_bitmaps, bitmap);
|
|
|
7711c0 |
}
|
|
|
7711c0 |
|
|
|
7711c0 |
- if (created_dirty_bitmaps != NULL) {
|
|
|
7711c0 |
- if (can_write(bs)) {
|
|
|
7711c0 |
- /* in_use flags must be updated */
|
|
|
7711c0 |
- int ret = update_ext_header_and_dir_in_place(bs, bm_list);
|
|
|
7711c0 |
- if (ret < 0) {
|
|
|
7711c0 |
- error_setg_errno(errp, -ret, "Can't update bitmap directory");
|
|
|
7711c0 |
- goto fail;
|
|
|
7711c0 |
- }
|
|
|
7711c0 |
- header_updated = true;
|
|
|
7711c0 |
- } else {
|
|
|
7711c0 |
- g_slist_foreach(created_dirty_bitmaps, set_readonly_helper,
|
|
|
7711c0 |
- (gpointer)true);
|
|
|
7711c0 |
+ if (needs_update && can_write(bs)) {
|
|
|
7711c0 |
+ /* in_use flags must be updated */
|
|
|
7711c0 |
+ int ret = update_ext_header_and_dir_in_place(bs, bm_list);
|
|
|
7711c0 |
+ if (ret < 0) {
|
|
|
7711c0 |
+ error_setg_errno(errp, -ret, "Can't update bitmap directory");
|
|
|
7711c0 |
+ goto fail;
|
|
|
7711c0 |
}
|
|
|
7711c0 |
+ header_updated = true;
|
|
|
7711c0 |
+ }
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+ if (!can_write(bs)) {
|
|
|
7711c0 |
+ g_slist_foreach(created_dirty_bitmaps, set_readonly_helper,
|
|
|
7711c0 |
+ (gpointer)true);
|
|
|
7711c0 |
}
|
|
|
7711c0 |
|
|
|
7711c0 |
g_slist_free(created_dirty_bitmaps);
|
|
|
7711c0 |
@@ -1114,23 +1119,21 @@ int qcow2_reopen_bitmaps_rw_hint(BlockDriverState *bs, bool *header_updated,
|
|
|
7711c0 |
}
|
|
|
7711c0 |
|
|
|
7711c0 |
QSIMPLEQ_FOREACH(bm, bm_list, entry) {
|
|
|
7711c0 |
- if (!(bm->flags & BME_FLAG_IN_USE)) {
|
|
|
7711c0 |
- BdrvDirtyBitmap *bitmap = bdrv_find_dirty_bitmap(bs, bm->name);
|
|
|
7711c0 |
- if (bitmap == NULL) {
|
|
|
7711c0 |
- continue;
|
|
|
7711c0 |
- }
|
|
|
7711c0 |
-
|
|
|
7711c0 |
- if (!bdrv_dirty_bitmap_readonly(bitmap)) {
|
|
|
7711c0 |
- error_setg(errp, "Bitmap %s is not readonly but not marked"
|
|
|
7711c0 |
- "'IN_USE' in the image. Something went wrong,"
|
|
|
7711c0 |
- "all the bitmaps may be corrupted", bm->name);
|
|
|
7711c0 |
- ret = -EINVAL;
|
|
|
7711c0 |
- goto out;
|
|
|
7711c0 |
- }
|
|
|
7711c0 |
+ BdrvDirtyBitmap *bitmap = bdrv_find_dirty_bitmap(bs, bm->name);
|
|
|
7711c0 |
+ if (bitmap == NULL) {
|
|
|
7711c0 |
+ continue;
|
|
|
7711c0 |
+ }
|
|
|
7711c0 |
|
|
|
7711c0 |
- bm->flags |= BME_FLAG_IN_USE;
|
|
|
7711c0 |
- ro_dirty_bitmaps = g_slist_append(ro_dirty_bitmaps, bitmap);
|
|
|
7711c0 |
+ if (!bdrv_dirty_bitmap_readonly(bitmap)) {
|
|
|
7711c0 |
+ error_setg(errp, "Bitmap %s was loaded prior to rw-reopen, but was "
|
|
|
7711c0 |
+ "not marked as readonly. This is a bug, something went "
|
|
|
7711c0 |
+ "wrong. All of the bitmaps may be corrupted", bm->name);
|
|
|
7711c0 |
+ ret = -EINVAL;
|
|
|
7711c0 |
+ goto out;
|
|
|
7711c0 |
}
|
|
|
7711c0 |
+
|
|
|
7711c0 |
+ bm->flags |= BME_FLAG_IN_USE;
|
|
|
7711c0 |
+ ro_dirty_bitmaps = g_slist_append(ro_dirty_bitmaps, bitmap);
|
|
|
7711c0 |
}
|
|
|
7711c0 |
|
|
|
7711c0 |
if (ro_dirty_bitmaps != NULL) {
|
|
|
7711c0 |
@@ -1426,8 +1429,8 @@ void qcow2_store_persistent_dirty_bitmaps(BlockDriverState *bs, Error **errp)
|
|
|
7711c0 |
Qcow2Bitmap *bm;
|
|
|
7711c0 |
|
|
|
7711c0 |
if (!bdrv_dirty_bitmap_get_persistance(bitmap) ||
|
|
|
7711c0 |
- bdrv_dirty_bitmap_readonly(bitmap))
|
|
|
7711c0 |
- {
|
|
|
7711c0 |
+ bdrv_dirty_bitmap_readonly(bitmap) ||
|
|
|
7711c0 |
+ bdrv_dirty_bitmap_inconsistent(bitmap)) {
|
|
|
7711c0 |
continue;
|
|
|
7711c0 |
}
|
|
|
7711c0 |
|
|
|
7711c0 |
--
|
|
|
7711c0 |
1.8.3.1
|
|
|
7711c0 |
|