Skip to contentSkip to conversation

block: Flush image after open

PATCH In review Kevin Wolf 4 participants 6 messages Mar 9, 2011 – Mar 21, 2011

lore
Share & tools
lore

Kevin Wolf

author
#0 lore raw

PATCH 1/1 block: Flush image after open

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.

---
 block.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
block.c +8 -0
index 8dea0b5..bf6892f 100644
@@ -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:
Signature · 1 line
1.7.2.3
#1 lore raw
Quoted 10 lines · Kevin Wolf

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.

Except for SCSI with ordered tags (which we don't support) there are not ordering guarantees in the storage protocols, and as such the above explanation doesn't make any sense at all.

#2 lore raw
Quoted 9 lines · Christoph Hellwig
Quoted 8 lines · Kevin Wolf

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.

Quoted 5 lines
Quoted 2 lines

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.

Except for SCSI with ordered tags (which we don't support) there are not ordering guarantees in the storage protocols, and as such the above explanation doesn't make any sense at all.

Even if there was, a guest shouldn't be relying on the ordering of a write that comes from a non-guest.

I don't understand the failure scenario here.

Regards,

Anthony Liguori

Quoted 1 line
#3 lore raw
Quoted 15 lines · Anthony Liguori
Quoted 14 lines · Christoph Hellwig
Quoted 13 lines · Kevin Wolf

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.

Quoted 7 lines
Quoted 3 lines

Except for SCSI with ordered tags (which we don't support) there are not ordering guarantees in the storage protocols, and as such the above explanation doesn't make any sense at all.

Even if there was, a guest shouldn't be relying on the ordering of a write that comes from a non-guest.

I don't understand the failure scenario here.

  $ cp x.img y.img
  $ qemu -drive file=y.img,cache=writeback
<read something from disk, send it over the network>
<no guest flushes>
<host crash>

The guest may expect that any or none of its writes hit the disk, but that anything that it read from the disk, stays there.

Signature · 1 line
error compiling committee.c: too many arguments to function
author
#4 lore raw

Am 21.03.2011 13:23, schrieb Avi Kivity:

Quoted 26 lines · Anthony Liguori
Quoted 20 lines · Christoph Hellwig
Quoted 12 lines · Kevin Wolf
Quoted 11 lines

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.

Quoted 6 lines
Quoted 2 lines

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.

Except for SCSI with ordered tags (which we don't support) there are not ordering guarantees in the storage protocols, and as such the above explanation
doesn't make any sense at all.

Quoted 4 lines

Even if there was, a guest shouldn't be relying on the ordering of a write that comes from a non-guest.

I don't understand the failure scenario here.

Quoted 8 lines
   $ cp x.img y.img
   $ qemu -drive file=y.img,cache=writeback
<read something from disk, send it over the network>
<no guest flushes>
<host crash>

The guest may expect that any or none of its writes hit the disk, but that anything that it read from the disk, stays there.

Is it true for real hardware? Consider a reboot, you could still have some data in a volatile disk write cache if the OS that ran before the reboot hasn't flushed it.

Kevin

#5 lore raw
Quoted 33 lines · Kevin Wolf

Am 21.03.2011 13:23, schrieb Avi Kivity:

Quoted 32 lines · Anthony Liguori
Quoted 20 lines · Christoph Hellwig
Quoted 12 lines · Kevin Wolf
Quoted 11 lines

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.

Quoted 6 lines
Quoted 2 lines

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.

Except for SCSI with ordered tags (which we don't support) there are not ordering guarantees in the storage protocols, and as such the above explanation
doesn't make any sense at all.

Quoted 4 lines

Even if there was, a guest shouldn't be relying on the ordering of a write that comes from a non-guest.

I don't understand the failure scenario here.

    $ cp x.img y.img
    $ qemu -drive file=y.img,cache=writeback
 <read something from disk, send it over the network>
 <no guest flushes>
 <host crash>
Quoted 6 lines
Quoted 2 lines

The guest may expect that any or none of its writes hit the disk, but that anything that it read from the disk, stays there.

Is it true for real hardware? Consider a reboot, you could still have some data in a volatile disk write cache if the OS that ran before the reboot hasn't flushed it.

That's if RESET doesn't flush the cache. It's probably false for fc or iscsi, but possibly true for IDE.

But it can't happen for a single-boot host, or a dual boot host with no shared partitions.

Signature · 1 line
error compiling committee.c: too many arguments to function