[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH] block: Flush image after open

From: Kevin Wolf
Subject: [Qemu-devel] [PATCH] block: Flush image after open
Date: Wed, 9 Mar 2011 17:15:53 +0100

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 <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
 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;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]