From: Supriya Kannery <supriyak@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
Shrinidhi Joshi <spjoshi31@gmail.com>,
Stefan Hajnoczi <stefanha@gmail.com>,
Jeff Cody <jcody@redhat.com>,
Luiz Capitulino <lcapitulino@redhat.com>,
Christoph Hellwig <hch@lst.de>
Subject: [Qemu-devel] [v2 Patch 4/9]block: vmdk image file reopen
Date: Tue, 31 Jul 2012 03:05:10 +0530 [thread overview]
Message-ID: <20120730213510.21536.12928.sendpatchset@skannery.in.ibm.com> (raw)
In-Reply-To: <20120730213409.21536.7589.sendpatchset@skannery.in.ibm.com>
vmdk driver changes for bdrv_reopen_xx functions to
safely reopen image files. Reopening of image files while
changing hostcache dynamically is handled here.
Signed-off-by: Supriya Kannery <supriyak@linux.vnet.ibm.com>
---
Index: qemu/block/vmdk.c
===================================================================
--- qemu.orig/block/vmdk.c
+++ qemu/block/vmdk.c
@@ -115,6 +115,14 @@ typedef struct VmdkGrainMarker {
uint8_t data[0];
} VmdkGrainMarker;
+typedef struct BDRVVmdkReopenState {
+ BDRVReopenState reopen_state;
+ BDRVVmdkState *stash_s;
+} BDRVVmdkReopenState;
+
+static void vmdk_stash_state(BDRVVmdkState *stashed_state, BDRVVmdkState *s);
+static void vmdk_revert_state(BDRVVmdkState *s, BDRVVmdkState *stashed_state);
+
static int vmdk_probe(const uint8_t *buf, int buf_size, const char *filename)
{
uint32_t magic;
@@ -588,7 +596,6 @@ static int vmdk_parse_extents(const char
if (!strcmp(type, "FLAT")) {
/* FLAT extent */
VmdkExtent *extent;
-
extent = vmdk_add_extent(bs, extent_file, true, sectors,
0, 0, 0, 0, sectors);
extent->flat_start_offset = flat_offset << 9;
@@ -675,6 +682,94 @@ fail:
return ret;
}
+static int vmdk_reopen_prepare(BlockDriverState *bs, BDRVReopenState **prs,
+ int flags)
+{
+ BDRVVmdkReopenState *vmdk_rs = g_malloc0(sizeof(BDRVVmdkReopenState));
+ int ret = 0;
+ BDRVVmdkState *s = bs->opaque;
+
+ vmdk_rs->reopen_state.bs = bs;
+
+ /* save state before reopen */
+ vmdk_rs->stash_s = g_malloc0(sizeof(BDRVVmdkState));
+ vmdk_stash_state(vmdk_rs->stash_s, s);
+ s->num_extents = 0;
+ s->extents = NULL;
+ s->migration_blocker = NULL;
+ *prs = &(vmdk_rs->reopen_state);
+
+ /* create extents afresh with new flags */
+ ret = vmdk_open(bs, flags);
+ return ret;
+}
+
+static void vmdk_reopen_commit(BlockDriverState *bs, BDRVReopenState *rs)
+{
+ BDRVVmdkReopenState *vmdk_rs;
+ BDRVVmdkState *stashed_s;
+ VmdkExtent *e;
+ int i;
+
+ vmdk_rs = container_of(rs, BDRVVmdkReopenState, reopen_state);
+ stashed_s = vmdk_rs->stash_s;
+
+ /* clean up stashed state */
+ for (i = 0; i < stashed_s->num_extents; i++) {
+ e = &stashed_s->extents[i];
+ g_free(e->l1_table);
+ g_free(e->l2_cache);
+ g_free(e->l1_backup_table);
+ }
+ g_free(stashed_s->extents);
+ g_free(vmdk_rs->stash_s);
+ g_free(vmdk_rs);
+}
+
+static void vmdk_reopen_abort(BlockDriverState *bs, BDRVReopenState *rs)
+{
+ BDRVVmdkReopenState *vmdk_rs;
+ BDRVVmdkState *s = bs->opaque;
+ VmdkExtent *e;
+ int i;
+
+ vmdk_rs = container_of(rs, BDRVVmdkReopenState, reopen_state);
+
+ /* revert to stashed state */
+ for (i = 0; i < s->num_extents; i++) {
+ e = &s->extents[i];
+ g_free(e->l1_table);
+ g_free(e->l2_cache);
+ g_free(e->l1_backup_table);
+ }
+ g_free(s->extents);
+ vmdk_revert_state(s, vmdk_rs->stash_s);
+ g_free(vmdk_rs->stash_s);
+ g_free(vmdk_rs);
+}
+
+static void vmdk_stash_state(BDRVVmdkState *stashed_state, BDRVVmdkState *s)
+{
+ stashed_state->lock = s->lock;
+ stashed_state->desc_offset = s->desc_offset;
+ stashed_state->cid_updated = s->cid_updated;
+ stashed_state->parent_cid = s->parent_cid;
+ stashed_state->num_extents = s->num_extents;
+ stashed_state->extents = s->extents;
+ stashed_state->migration_blocker = s->migration_blocker;
+}
+
+static void vmdk_revert_state(BDRVVmdkState *s, BDRVVmdkState *stashed_state)
+{
+ s->lock = stashed_state->lock;
+ s->desc_offset = stashed_state->desc_offset;
+ s->cid_updated = stashed_state->cid_updated;
+ s->parent_cid = stashed_state->parent_cid;
+ s->num_extents = stashed_state->num_extents;
+ s->extents = stashed_state->extents;
+ s->migration_blocker = stashed_state->migration_blocker;
+}
+
static int get_whole_cluster(BlockDriverState *bs,
VmdkExtent *extent,
uint64_t cluster_offset,
@@ -1593,6 +1688,12 @@ static BlockDriver bdrv_vmdk = {
.instance_size = sizeof(BDRVVmdkState),
.bdrv_probe = vmdk_probe,
.bdrv_open = vmdk_open,
+ .bdrv_reopen_prepare
+ = vmdk_reopen_prepare,
+ .bdrv_reopen_commit
+ = vmdk_reopen_commit,
+ .bdrv_reopen_abort
+ = vmdk_reopen_abort,
.bdrv_read = vmdk_co_read,
.bdrv_write = vmdk_co_write,
.bdrv_close = vmdk_close,
next prev parent reply other threads:[~2012-07-30 21:35 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-30 21:34 [Qemu-devel] [v2 Patch 0/9]block: Image file reopen and dynamic host pagecache change Supriya Kannery
2012-07-30 21:34 ` [Qemu-devel] [v2 Patch 1/9]block: Framework for reopening image files safely Supriya Kannery
2012-08-01 15:51 ` Stefan Hajnoczi
2012-08-02 20:19 ` Luiz Capitulino
2012-08-14 8:54 ` Supriya Kannery
2012-08-08 21:13 ` Jeff Cody
2012-08-14 9:21 ` Supriya Kannery
2012-08-09 4:26 ` Jeff Cody
2012-08-09 9:20 ` Kevin Wolf
2012-08-09 13:02 ` Jeff Cody
2012-08-14 10:24 ` Supriya Kannery
2012-07-30 21:34 ` [Qemu-devel] [v2 Patch 2/9]block: raw-posix image file reopen Supriya Kannery
2012-07-31 17:17 ` Eric Blake
2012-08-01 6:18 ` Kevin Wolf
2012-08-03 22:32 ` Jeff Cody
2012-08-14 10:53 ` Supriya Kannery
2012-08-09 4:26 ` Jeff Cody
2012-08-10 13:45 ` Corey Bryant
2012-08-14 11:13 ` Supriya Kannery
2012-08-14 11:35 ` Kevin Wolf
2012-07-30 21:34 ` [Qemu-devel] [v2 Patch 3/9]block: raw-win32 " Supriya Kannery
2012-07-30 21:35 ` Supriya Kannery [this message]
2012-07-31 17:43 ` [Qemu-devel] [v2 Patch 4/9]block: vmdk " Eric Blake
2012-07-30 21:35 ` [Qemu-devel] [v2 Patch 5/9]block: qcow2 " Supriya Kannery
2012-08-09 4:26 ` Jeff Cody
2012-08-09 9:37 ` Kevin Wolf
2012-07-30 21:35 ` [Qemu-devel] [v2 Patch 7/9]block: qed " Supriya Kannery
2012-07-30 21:36 ` [Qemu-devel] [v2 Patch 9/9]block: Enhance "info block" to display host cache setting Supriya Kannery
2012-07-31 17:47 ` Eric Blake
2012-07-31 20:33 ` [Qemu-devel] [v2 Patch 0/9]block: Image file reopen and dynamic host pagecache change Jeff Cody
2012-08-01 17:11 ` Supriya Kannery
2012-08-01 18:36 ` [Qemu-devel] [v2 Patch 6/9]block: qcow image file reopen Supriya Kannery
2012-08-01 18:44 ` [Qemu-devel] [v2 Patch 8/9]block: Cmd "block_set_hostcache" for dynamic cache change Supriya Kannery
2012-08-01 19:21 ` Eric Blake
2012-08-02 20:36 ` Luiz Capitulino
2012-08-31 19:32 ` Jeff Cody
2012-08-09 4:26 ` [Qemu-devel] [v2 Patch 0/9]block: Image file reopen and dynamic host pagecache change Jeff Cody
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=20120730213510.21536.12928.sendpatchset@skannery.in.ibm.com \
--to=supriyak@linux.vnet.ibm.com \
--cc=hch@lst.de \
--cc=jcody@redhat.com \
--cc=kwolf@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=spjoshi31@gmail.com \
--cc=stefanha@gmail.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).