From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, famz@redhat.com,
qemu-block@nongnu.org, mreitz@redhat.com, stefanha@redhat.com,
pbonzini@redhat.com, den@openvz.org, jsnow@redhat.com
Subject: [Qemu-devel] [PATCH 17/22] qcow2-dirty-bitmap: add IN_USE flag
Date: Tue, 15 Mar 2016 23:04:23 +0300 [thread overview]
Message-ID: <1458072268-53705-18-git-send-email-vsementsov@virtuozzo.com> (raw)
In-Reply-To: <1458072268-53705-1-git-send-email-vsementsov@virtuozzo.com>
This flag is set on bitmap load and unset on store. If it is already
set when loading the bitmap, the bitmap should not be load (it is in
use by other drive or it is inconsistent (was not successfully saved))
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
block/qcow2-dirty-bitmap.c | 45 ++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 44 insertions(+), 1 deletion(-)
diff --git a/block/qcow2-dirty-bitmap.c b/block/qcow2-dirty-bitmap.c
index 384ccea..f210fee 100644
--- a/block/qcow2-dirty-bitmap.c
+++ b/block/qcow2-dirty-bitmap.c
@@ -42,7 +42,8 @@
#define BME_MAX_NAME_SIZE 1023
/* Bitmap directory entry flags */
-#define BME_RESERVED_FLAGS 0xffffffff
+#define BME_RESERVED_FLAGS 0xfffffffe
+#define BME_FLAG_IN_USE 1
/* bits [1, 8] U [56, 63] are reserved */
#define BME_TABLE_ENTRY_RESERVED_MASK 0xff000000000001fe
@@ -134,6 +135,29 @@ static QCow2BitmapHeader *bitmap_header(BDRVQcow2State *s,
(s->bitmap_directory + bitmap->offset);
}
+static int update_bitmap_header_sync(BlockDriverState *bs, QCow2Bitmap *bitmap)
+{
+ int ret;
+ BDRVQcow2State *s = bs->opaque;
+ QCow2BitmapHeader *h = bitmap_header(s, bitmap);
+
+ bitmap_header_to_be(h);
+ ret = bdrv_pwrite(bs->file->bs,
+ s->bitmap_directory_offset + bitmap->offset,
+ h, dir_entry_size(h));
+ bitmap_header_to_cpu(h);
+ if (ret < 0) {
+ return ret;
+ }
+
+ ret = bdrv_flush(bs);
+ if (ret < 0) {
+ return ret;
+ }
+
+ return 0;
+}
+
static int directory_read(BlockDriverState *bs, Error **errp)
{
int ret;
@@ -293,6 +317,11 @@ static BdrvDirtyBitmap *load_bitmap(BlockDriverState *bs, QCow2Bitmap *bm,
bmh = bitmap_header(s, bm);
+ if (bmh->flags & BME_FLAG_IN_USE) {
+ error_setg(errp, "Bitmap '%s' is in use", bm->name);
+ return NULL;
+ }
+
bitmap_table = g_try_malloc(bmh->bitmap_table_size * sizeof(uint64_t));
if (bitmap_table == NULL) {
error_setg_errno(errp, -ENOMEM,
@@ -321,6 +350,13 @@ static BdrvDirtyBitmap *load_bitmap(BlockDriverState *bs, QCow2Bitmap *bm,
goto fail;
}
+ bmh->flags |= BME_FLAG_IN_USE;
+ ret = update_bitmap_header_sync(bs, bm);
+ if (ret < 0) {
+ error_setg_errno(errp, -ret, "Could not set in_use in bitmap header");
+ goto fail;
+ }
+
g_free(bitmap_table);
return bitmap;
@@ -769,6 +805,13 @@ void qcow2_bitmap_store(BlockDriverState *bs,
goto finish;
}
+ bmh->flags &= ~BME_FLAG_IN_USE;
+ ret = update_bitmap_header_sync(bs, bm);
+ if (ret < 0) {
+ error_setg_errno(errp, ret, "Can't update bitmap header.");
+ goto finish;
+ }
+
finish:
g_free(bitmap_table);
}
--
1.8.3.1
next prev parent reply other threads:[~2016-03-15 20:05 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-15 20:04 [Qemu-devel] [PATCH v5 00/22] qcow2: persistent dirty bitmaps Vladimir Sementsov-Ogievskiy
2016-03-15 20:04 ` [Qemu-devel] [PATCH 01/22] block: Add two dirty bitmap getters Vladimir Sementsov-Ogievskiy
2016-03-15 20:08 ` Vladimir Sementsov-Ogievskiy
2016-03-22 16:37 ` Eric Blake
2016-03-22 18:06 ` John Snow
2016-03-15 20:04 ` [Qemu-devel] [PATCH 02/22] block: fix bdrv_dirty_bitmap_granularity signature Vladimir Sementsov-Ogievskiy
2016-03-15 20:04 ` [Qemu-devel] [PATCH 03/22] iotests: maintain several vms in test Vladimir Sementsov-Ogievskiy
2016-03-15 20:04 ` [Qemu-devel] [PATCH 04/22] iotests: add default node-name Vladimir Sementsov-Ogievskiy
2016-03-22 18:08 ` John Snow
2016-03-15 20:04 ` [Qemu-devel] [PATCH 05/22] qapi: add md5 checksum of last dirty bitmap level to query-block Vladimir Sementsov-Ogievskiy
2016-03-15 20:04 ` [Qemu-devel] [PATCH 06/22] hbitmap: load/store Vladimir Sementsov-Ogievskiy
2016-03-21 22:42 ` John Snow
2016-03-22 10:47 ` Vladimir Sementsov-Ogievskiy
2016-03-22 21:49 ` John Snow
2016-03-23 8:22 ` Vladimir Sementsov-Ogievskiy
2016-03-28 20:20 ` John Snow
2016-03-15 20:04 ` [Qemu-devel] [PATCH 07/22] qcow2: Bitmaps extension: structs and consts Vladimir Sementsov-Ogievskiy
2016-03-15 20:04 ` [Qemu-devel] [PATCH 08/22] qcow2-dirty-bitmap: read dirty bitmap directory Vladimir Sementsov-Ogievskiy
2016-03-15 20:04 ` [Qemu-devel] [PATCH 09/22] qcow2-dirty-bitmap: add qcow2_bitmap_load() Vladimir Sementsov-Ogievskiy
2016-03-15 20:04 ` [Qemu-devel] [PATCH 10/22] qcow2-dirty-bitmap: add qcow2_bitmap_store() Vladimir Sementsov-Ogievskiy
2016-03-22 18:49 ` Eric Blake
2016-03-23 8:25 ` Vladimir Sementsov-Ogievskiy
2016-03-15 20:04 ` [Qemu-devel] [PATCH 11/22] qcow2: add dirty bitmaps extension Vladimir Sementsov-Ogievskiy
2016-03-15 20:04 ` [Qemu-devel] [PATCH 12/22] qcow2-dirty-bitmap: add qcow2_bitmap_load_check() Vladimir Sementsov-Ogievskiy
2016-03-22 18:49 ` Eric Blake
2016-03-15 20:04 ` [Qemu-devel] [PATCH 13/22] block: store persistent dirty bitmaps Vladimir Sementsov-Ogievskiy
2016-03-15 20:04 ` [Qemu-devel] [PATCH 14/22] block: add bdrv_load_dirty_bitmap() Vladimir Sementsov-Ogievskiy
2016-03-15 20:04 ` [Qemu-devel] [PATCH 15/22] qcow2-dirty-bitmap: add autoclear bit Vladimir Sementsov-Ogievskiy
2016-03-15 20:04 ` [Qemu-devel] [PATCH 16/22] qemu: command line option for dirty bitmaps Vladimir Sementsov-Ogievskiy
2016-03-15 20:04 ` Vladimir Sementsov-Ogievskiy [this message]
2016-03-15 20:04 ` [Qemu-devel] [PATCH 18/22] qcow2-dirty-bitmaps: disallow stroing bitmap to other bs Vladimir Sementsov-Ogievskiy
2016-03-22 18:51 ` Eric Blake
2016-03-15 20:04 ` [Qemu-devel] [PATCH 19/22] iotests: add VM.test_launcn() Vladimir Sementsov-Ogievskiy
2016-03-22 18:25 ` Eric Blake
2016-03-15 20:04 ` [Qemu-devel] [PATCH 20/22] iotests: test internal persistent dirty bitmap Vladimir Sementsov-Ogievskiy
2016-03-22 18:27 ` Eric Blake
2016-03-23 8:28 ` Vladimir Sementsov-Ogievskiy
2016-03-15 20:04 ` [Qemu-devel] [PATCH 21/22] qcow2-dirty-bitmap: add AUTO flag Vladimir Sementsov-Ogievskiy
2016-03-15 20:04 ` [Qemu-devel] [PATCH 22/22] qcow2-dirty-bitmap: add EXTRA_DATA_COMPATIBLE flag Vladimir Sementsov-Ogievskiy
2016-03-22 18:51 ` Eric Blake
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=1458072268-53705-18-git-send-email-vsementsov@virtuozzo.com \
--to=vsementsov@virtuozzo.com \
--cc=den@openvz.org \
--cc=famz@redhat.com \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.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).