All of lore.kernel.org
 help / color / mirror / Atom feed
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] [v1 Patch 9/10]Qemu: qcow image file reopen
Date: Sat, 16 Jun 2012 02:18:58 +0530	[thread overview]
Message-ID: <20120615204858.9853.80223.sendpatchset@skannery.in.ibm.com> (raw)
In-Reply-To: <20120615204648.9853.1225.sendpatchset@skannery.in.ibm.com>

qcow 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: Shrinidhi Joshi <spjoshi31@gmail.com>

Index: qemu/block/qcow.c
===================================================================
--- qemu.orig/block/qcow.c
+++ qemu/block/qcow.c
@@ -78,7 +78,14 @@ typedef struct BDRVQcowState {
     Error *migration_blocker;
 } BDRVQcowState;
 
+typedef struct BDRVQcowReopenState {
+    BDRVReopenState reopen_state;
+    BDRVQcowState *stash_s;
+} BDRVQcowReopenState;
+
 static int decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset);
+static void qcow_stash_state(BDRVQcowState *stash_s, BDRVQcowState *s);
+static void qcow_revert_state(BDRVQcowState *s, BDRVQcowState *stash_s);
 
 static int qcow_probe(const uint8_t *buf, int buf_size, const char *filename)
 {
@@ -197,6 +204,103 @@ static int qcow_open(BlockDriverState *b
     return ret;
 }
 
+static int qcow_reopen_prepare(BlockDriverState *bs, BDRVReopenState **prs,
+                                         int flags)
+{
+    BDRVQcowReopenState *qcow_rs = g_malloc0(sizeof(BDRVQcowReopenState));
+    int ret = 0;
+    BDRVQcowState *s = bs->opaque;
+
+    qcow_rs->reopen_state.bs = bs;
+    qcow_rs->stash_s = g_malloc0(sizeof(BDRVQcowState));
+    qcow_stash_state(qcow_rs->stash_s, s);
+    *prs = &(qcow_rs->reopen_state);
+
+    ret = qcow_open(bs, flags);
+    return ret;
+}
+
+static void qcow_reopen_commit(BlockDriverState *bs, BDRVReopenState *rs)
+{
+    BDRVQcowReopenState *qcow_rs;
+
+    qcow_rs = container_of(rs, BDRVQcowReopenState, reopen_state);
+    g_free(qcow_rs->stash_s);
+    g_free(qcow_rs);
+}
+
+static void qcow_reopen_abort(BlockDriverState *bs, BDRVReopenState *rs)
+{
+    BDRVQcowReopenState *qcow_rs;
+    BDRVQcowState *s = bs->opaque;
+
+    qcow_rs = container_of(rs, BDRVQcowReopenState, reopen_state);
+
+    /* revert to stashed state */
+    qcow_revert_state(s, qcow_rs->stash_s);
+
+    g_free(qcow_rs->stash_s);
+    g_free(qcow_rs);
+}
+
+static void qcow_stash_state(BDRVQcowState *stash_s, BDRVQcowState *s)
+{
+    int i;
+
+    stash_s->cluster_bits = s->cluster_bits;
+    stash_s->cluster_size = s->cluster_size;
+    stash_s->cluster_sectors = s->cluster_sectors;
+    stash_s->l2_bits = s->l2_bits;
+    stash_s->l2_size = s->l2_size;
+    stash_s->l1_size = s->l1_size;
+    stash_s->cluster_offset_mask = s->cluster_offset_mask;
+    stash_s->l1_table_offset = s->l1_table_offset;
+    stash_s->l1_table = s->l1_table;
+    stash_s->l2_cache = s->l2_cache;
+    for (i = 0; i < L2_CACHE_SIZE; i++) {
+        stash_s->l2_cache_offsets[i] = s->l2_cache_offsets[i];
+        stash_s->l2_cache_counts[i] = s->l2_cache_counts[i];
+    }
+    stash_s->cluster_cache = s->cluster_cache;
+    stash_s->cluster_data = s->cluster_data;
+    stash_s->cluster_cache_offset = s->cluster_cache_offset;
+    stash_s->crypt_method = s->crypt_method;
+    stash_s->crypt_method_header = s->crypt_method_header;
+    stash_s->aes_encrypt_key = s->aes_encrypt_key;
+    stash_s->aes_decrypt_key = s->aes_decrypt_key;
+    stash_s->lock = s->lock;
+    stash_s->migration_blocker = s->migration_blocker;
+}
+
+static void qcow_revert_state(BDRVQcowState *s, BDRVQcowState *stash_s)
+{
+    int i;
+
+    s->cluster_bits = stash_s->cluster_bits;
+    s->cluster_size = stash_s->cluster_size;
+    s->cluster_sectors = stash_s->cluster_sectors;
+    s->l2_bits = stash_s->l2_bits;
+    s->l2_size = stash_s->l2_size;
+    s->l1_size = stash_s->l1_size;
+    s->cluster_offset_mask = stash_s->cluster_offset_mask;
+    s->l1_table_offset = stash_s->l1_table_offset;
+    s->l1_table = stash_s->l1_table;
+    s->l2_cache = stash_s->l2_cache;
+    for (i = 0; i < L2_CACHE_SIZE; i++) {
+        s->l2_cache_offsets[i] = s->l2_cache_offsets[i];
+        s->l2_cache_counts[i] = stash_s->l2_cache_counts[i];
+    }
+    s->cluster_cache = stash_s->cluster_cache;
+    s->cluster_data = stash_s->cluster_data;
+    s->cluster_cache_offset = stash_s->cluster_cache_offset;
+    s->crypt_method = stash_s->crypt_method;
+    s->crypt_method_header = stash_s->crypt_method_header;
+    s->aes_encrypt_key = stash_s->aes_encrypt_key;
+    s->aes_decrypt_key = stash_s->aes_decrypt_key;
+    s->lock = stash_s->lock;
+    s->migration_blocker = stash_s->migration_blocker;
+}
+
 static int qcow_set_key(BlockDriverState *bs, const char *key)
 {
     BDRVQcowState *s = bs->opaque;
@@ -870,6 +974,10 @@ static BlockDriver bdrv_qcow = {
     .bdrv_close		= qcow_close,
     .bdrv_create	= qcow_create,
 
+    .bdrv_reopen_prepare    = qcow_reopen_prepare,
+    .bdrv_reopen_commit     = qcow_reopen_commit,
+    .bdrv_reopen_abort      = qcow_reopen_abort,
+
     .bdrv_co_readv          = qcow_co_readv,
     .bdrv_co_writev         = qcow_co_writev,
     .bdrv_co_is_allocated   = qcow_co_is_allocated,

  parent reply	other threads:[~2012-06-15 20:49 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-15 20:46 [Qemu-devel] [v1 Patch 0/10]Qemu: Dynamic host pagecache change and image file reopen Supriya Kannery
2012-06-15 20:47 ` [Qemu-devel] [v1 Patch 1/10]Qemu: Enhance "info block" to display host cache setting Supriya Kannery
2012-06-15 21:07   ` Eric Blake
2012-07-09 14:43     ` Kevin Wolf
2012-07-11 14:03       ` Luiz Capitulino
2012-07-29  6:21         ` Supriya Kannery
2012-07-05 16:38   ` Jeff Cody
2012-07-29  6:54     ` Supriya Kannery
2012-06-15 20:47 ` [Qemu-devel] [v1 Patch 2/10]Qemu: Error classes for hostcache setting and data sync failures Supriya Kannery
2012-07-09 14:47   ` Kevin Wolf
2012-07-29  6:58     ` Supriya Kannery
2012-06-15 20:47 ` [Qemu-devel] [v1 Patch 3/10]Qemu: Cmd "block_set_hostcache" for dynamic cache change Supriya Kannery
2012-06-15 21:56   ` Eric Blake
2012-07-29  7:33     ` Supriya Kannery
2012-06-20 18:18   ` Jeff Cody
2012-07-04  5:10     ` Shrinidhi Joshi
2012-07-04  6:30       ` Kevin Wolf
2012-07-09 14:52   ` Kevin Wolf
2012-07-11 14:16   ` Luiz Capitulino
2012-07-29  7:56     ` Supriya Kannery
2012-06-15 20:47 ` [Qemu-devel] [v1 Patch 4/10]Qemu: Framework for reopening image files safely Supriya Kannery
2012-06-15 22:02   ` Eric Blake
2012-07-09 15:06   ` Kevin Wolf
2012-06-15 20:48 ` [Qemu-devel] [v1 Patch 5/10]Qemu: raw-posix image file reopen Supriya Kannery
2012-06-15 22:11   ` Eric Blake
2012-07-04  5:15     ` Shrinidhi Joshi
2012-07-04 11:32       ` Eric Blake
2012-06-15 20:48 ` [Qemu-devel] [v1 Patch 6/10]Qemu: raw-win32 " Supriya Kannery
2012-06-15 20:48 ` [Qemu-devel] [v1 Patch 7/10]Qemu: vmdk " Supriya Kannery
2012-06-15 20:48 ` [Qemu-devel] [v1 Patch 8/10]Qemu: qcow2 " Supriya Kannery
2012-06-15 20:48 ` Supriya Kannery [this message]
2012-06-15 20:49 ` [Qemu-devel] [v1 Patch 10/10]Qemu: qed " Supriya Kannery
2012-07-09 17:51 ` [Qemu-devel] [v1 Patch 0/10]Qemu: Dynamic host pagecache change and " Stefan Weil

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=20120615204858.9853.80223.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.