qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Anthony Liguori <aliguori@us.ibm.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	Lucas Meneghel Rodrigues <lmr@redhat.com>,
	Anthony Liguori <aliguori@us.ibm.com>,
	Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>,
	Juan Quintela <quintela@redhat.com>, Avi Kivity <avi@redhat.com>
Subject: [Qemu-devel] [PATCH 6/7] qcow2: implement bdrv_invalidate_cache
Date: Sat, 12 Nov 2011 09:56:59 -0600	[thread overview]
Message-ID: <1321113420-3252-6-git-send-email-aliguori@us.ibm.com> (raw)
In-Reply-To: <1321113420-3252-1-git-send-email-aliguori@us.ibm.com>

We don't reopen the actual file, but instead invoke the close and open routines.
We specifically ignore the backing file since it's contents are read-only and
therefore immutable.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
 block/qcow2.c |   19 +++++++++++++++++++
 block/qcow2.h |    2 ++
 2 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/block/qcow2.c b/block/qcow2.c
index e4126b7..b5171e0 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -241,6 +241,7 @@ static int qcow2_open(BlockDriverState *bs, int flags)
     s->cluster_data = qemu_blockalign(bs, QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size
                                   + 512);
     s->cluster_cache_offset = -1;
+    s->flags = flags;
 
     ret = qcow2_refcount_init(bs);
     if (ret != 0) {
@@ -641,6 +642,22 @@ static void qcow2_close(BlockDriverState *bs)
     qcow2_refcount_close(bs);
 }
 
+static void qcow2_invalidate_cache(BlockDriverState *bs)
+{
+    BDRVQcowState *s = bs->opaque;
+    int flags = s->flags;
+
+    /*
+     * Backing files are read-only which makes all of their metadata immutable,
+     * that means we don't have to worry about reopening them here.
+     */
+
+    qcow2_close(bs);
+
+    memset(s, 0, sizeof(BDRVQcowState));
+    qcow2_open(bs, flags);
+}
+
 /*
  * Updates the variable length parts of the qcow2 header, i.e. the backing file
  * name and all extensions. qcow2 was not designed to allow such changes, so if
@@ -1278,6 +1295,8 @@ static BlockDriver bdrv_qcow2 = {
 
     .bdrv_change_backing_file   = qcow2_change_backing_file,
 
+    .bdrv_invalidate_cache      = qcow2_invalidate_cache,
+
     .create_options = qcow2_create_options,
     .bdrv_check = qcow2_check,
 };
diff --git a/block/qcow2.h b/block/qcow2.h
index 0734b23..6312cd9 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -127,6 +127,8 @@ typedef struct BDRVQcowState {
     QCowSnapshot *snapshots;
 
     Error *migration_blocker;
+
+    int flags;
 } BDRVQcowState;
 
 /* XXX: use std qcow open function ? */
-- 
1.7.4.1

  parent reply	other threads:[~2011-11-12 15:57 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-12 15:56 [Qemu-devel] [PATCH 1/7] migrate: add migration blockers Anthony Liguori
2011-11-12 15:56 ` [Qemu-devel] [PATCH 2/7] ivshmem: use migration blockers to prevent live migration in peer mode Anthony Liguori
2011-11-14 13:05   ` Juan Quintela
2011-11-14 13:52     ` Anthony Liguori
2011-11-14 19:52       ` Juan Quintela
2011-11-14 19:55         ` Anthony Liguori
2011-11-12 15:56 ` [Qemu-devel] [PATCH 3/7] qcow2: add a migration blocker Anthony Liguori
2011-11-12 15:56 ` [Qemu-devel] [PATCH 4/7] qed: add " Anthony Liguori
2011-11-12 15:56 ` [Qemu-devel] [PATCH 5/7] block: allow migration to work with image files (v2) Anthony Liguori
2011-11-14 13:11   ` Juan Quintela
2011-11-14 14:10     ` Anthony Liguori
2011-11-14 19:46       ` Juan Quintela
2011-11-14 19:49         ` Anthony Liguori
2011-11-14 20:11           ` Kevin Wolf
2011-11-14 20:12             ` Anthony Liguori
2011-11-14 20:28               ` Juan Quintela
2011-11-14 20:36               ` Kevin Wolf
2011-11-14 20:49                 ` Anthony Liguori
2011-11-14 20:15             ` Juan Quintela
2011-11-12 15:56 ` Anthony Liguori [this message]
2011-11-12 15:57 ` [Qemu-devel] [PATCH 7/7] qcow2: relax migration blocker Anthony Liguori
2011-11-14  9:04   ` Kevin Wolf
2011-11-14  9:08 ` [Qemu-devel] [PATCH 1/7] migrate: add migration blockers Kevin Wolf
2011-11-14 18:25   ` Anthony Liguori
2011-11-14  9:12 ` Kevin Wolf
2011-11-14 13:00 ` Juan Quintela
  -- strict thread matches above, loose matches on Subject: below --
2011-11-12 15:57 Anthony Liguori
2011-11-12 15:57 ` [Qemu-devel] [PATCH 6/7] qcow2: implement bdrv_invalidate_cache Anthony Liguori

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=1321113420-3252-6-git-send-email-aliguori@us.ibm.com \
    --to=aliguori@us.ibm.com \
    --cc=avi@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=lmr@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=stefanha@linux.vnet.ibm.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).