qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com
Subject: [Qemu-devel] [PATCH] block: Flush image after open
Date: Wed,  9 Mar 2011 17:15:53 +0100	[thread overview]
Message-ID: <1299687353-20424-1-git-send-email-kwolf@redhat.com> (raw)

Quoting the bug report:

    qemu ensures that guest writes and qemu metadata writes hit the disk
    when necessary to prevent data corruption. However, if an image was
    in host pagecache prior to starting qemu, for example after running
    qemu-img convert, then nothing prevents writes from reaching the
    disk out of order, potentially causing corruption.

I'm not entirely sure if there is a realistic case where we would get
corruption, but it's probably a case of better safe than sorry.

Reported-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/block.c b/block.c
index 8dea0b5..bf6892f 100644
--- a/block.c
+++ b/block.c
@@ -648,6 +648,14 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags,
             bs->change_cb(bs->change_opaque, CHANGE_MEDIA);
     }
 
+    /* Make sure that the image is consistent on disk */
+    if (!bdrv_is_read_only(bs)) {
+        ret = bdrv_flush(bs);
+        if (ret < 0) {
+            goto unlink_and_fail;
+        }
+    }
+
     return 0;
 
 unlink_and_fail:
-- 
1.7.2.3

             reply	other threads:[~2011-03-09 16:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-09 16:15 Kevin Wolf [this message]
2011-03-09 17:27 ` [Qemu-devel] [PATCH] block: Flush image after open Christoph Hellwig
2011-03-09 17:38   ` Anthony Liguori
2011-03-21 12:23     ` Avi Kivity
2011-03-21 13:02       ` Kevin Wolf
2011-03-21 13:21         ` Avi Kivity

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=1299687353-20424-1-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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).