qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] qcow2: make cache=unsafe usable
@ 2011-09-07  9:24 Avi Kivity
  2011-09-07  9:47 ` Alexander Graf
  2011-09-07  9:56 ` Kevin Wolf
  0 siblings, 2 replies; 4+ messages in thread
From: Avi Kivity @ 2011-09-07  9:24 UTC (permalink / raw)
  To: Kevin Wolf; +Cc: qemu-devel

Currently cache=unsafe is unsafe to the point of unusability - the
caches are never written to disk except on exit so anything except
an orderly exit -- including live migration -- leaves the disk image
corrupted.

Fix by interpreting flush requests and doing everything except flushing
the underlying file.  The contents of the metadata cache are transferred
to the host pagecache, so that qemu aborts keep the disk in a consistent
state, and live migration (on the same host, or if using a coherent
filesystem) works.

Signed-off-by: Avi Kivity <avi@redhat.com>
---

Untested - is this the right approach?

 block/qcow2.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/block/qcow2.c b/block/qcow2.c
index bfff6cd..7ecd096 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -275,6 +275,13 @@ static int qcow2_open(BlockDriverState *bs, int flags)
         ret = -EINVAL;
         goto fail;
     }
+    /*
+     * Request flush callbask so that we can write metadata to the host
+     * pagecache.  Flushes to bs->file will still be ignored.  This keeps
+     * metadata consistent in host pagecache, so we're safe wrt unexpected
+     * exits, but avoids slow disk flushes (and is vulnerable to host crashes)
+     */
+    bs->open_flags &= ~BDRV_O_NO_FLUSH;
 
     /* Initialise locks */
     qemu_co_mutex_init(&s->lock);
-- 
1.7.6.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] qcow2: make cache=unsafe usable
  2011-09-07  9:24 [Qemu-devel] [PATCH] qcow2: make cache=unsafe usable Avi Kivity
@ 2011-09-07  9:47 ` Alexander Graf
  2011-09-07  9:56 ` Kevin Wolf
  1 sibling, 0 replies; 4+ messages in thread
From: Alexander Graf @ 2011-09-07  9:47 UTC (permalink / raw)
  To: Avi Kivity; +Cc: Kevin Wolf, qemu-devel


On 07.09.2011, at 11:24, Avi Kivity wrote:

> Currently cache=unsafe is unsafe to the point of unusability - the
> caches are never written to disk except on exit so anything except
> an orderly exit -- including live migration -- leaves the disk image
> corrupted.
> 
> Fix by interpreting flush requests and doing everything except flushing
> the underlying file.  The contents of the metadata cache are transferred
> to the host pagecache, so that qemu aborts keep the disk in a consistent
> state, and live migration (on the same host, or if using a coherent
> filesystem) works.

Yes, I've seen breakage with cache=unsafe and qcow2 myself. Thus semantically, the patch seems very reasonable to me. However, I'll leave it to Kevin to decide if it's a good idea to just unset random flags in open() or if we want to have something more expressive there :)


Alex

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] qcow2: make cache=unsafe usable
  2011-09-07  9:24 [Qemu-devel] [PATCH] qcow2: make cache=unsafe usable Avi Kivity
  2011-09-07  9:47 ` Alexander Graf
@ 2011-09-07  9:56 ` Kevin Wolf
  2011-09-07 10:07   ` Avi Kivity
  1 sibling, 1 reply; 4+ messages in thread
From: Kevin Wolf @ 2011-09-07  9:56 UTC (permalink / raw)
  To: Avi Kivity; +Cc: qemu-devel

Am 07.09.2011 11:24, schrieb Avi Kivity:
> Currently cache=unsafe is unsafe to the point of unusability - the
> caches are never written to disk except on exit so anything except
> an orderly exit -- including live migration -- leaves the disk image
> corrupted.
> 
> Fix by interpreting flush requests and doing everything except flushing
> the underlying file.  The contents of the metadata cache are transferred
> to the host pagecache, so that qemu aborts keep the disk in a consistent
> state, and live migration (on the same host, or if using a coherent
> filesystem) works.
> 
> Signed-off-by: Avi Kivity <avi@redhat.com>
> ---
> 
> Untested - is this the right approach?

Hm, could work, even though I don't like it very much. The alternative
approach would be something like this (not only untested, but won't even
compile):

diff --git a/block.c b/block.c
index a8c789a..1aa5967 100644
--- a/block.c
+++ b/block.c
@@ -1723,10 +1723,6 @@ const char *bdrv_get_device_name(BlockDriverState
*bs)

 int bdrv_flush(BlockDriverState *bs)
 {
-    if (bs->open_flags & BDRV_O_NO_FLUSH) {
-        return 0;
-    }
-
     if (bs->drv && bdrv_has_async_flush(bs->drv) && qemu_in_coroutine()) {
         return bdrv_co_flush_em(bs);
     }
@@ -2624,10 +2620,6 @@ BlockDriverAIOCB *bdrv_aio_flush(BlockDriverState
*bs,

     trace_bdrv_aio_flush(bs, opaque);

-    if (bs->open_flags & BDRV_O_NO_FLUSH) {
-        return bdrv_aio_noop_em(bs, cb, opaque);
-    }
-
     if (!drv)
         return NULL;
     return drv->bdrv_aio_flush(bs, cb, opaque);
diff --git a/block/raw-posix.c b/block/raw-posix.c
index bcf50b2..bb0c0c5 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -629,6 +629,10 @@ static BlockDriverAIOCB
*raw_aio_flush(BlockDriverState *bs,
 {
     BDRVRawState *s = bs->opaque;

+    if (bs->open_flags & BDRV_O_NO_FLUSH) {
+        return bdrv_aio_noop_em(bs, cb, opaque);
+    }
+
     if (fd_open(bs) < 0)
         return NULL;

@@ -839,6 +843,11 @@ static int raw_create(const char *filename,
QEMUOptionParameter *options)
 static int raw_flush(BlockDriverState *bs)
 {
     BDRVRawState *s = bs->opaque;
+
+    if (bs->open_flags & BDRV_O_NO_FLUSH) {
+        return 0;
+    }
+
     return qemu_fdatasync(s->fd);
 }

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] qcow2: make cache=unsafe usable
  2011-09-07  9:56 ` Kevin Wolf
@ 2011-09-07 10:07   ` Avi Kivity
  0 siblings, 0 replies; 4+ messages in thread
From: Avi Kivity @ 2011-09-07 10:07 UTC (permalink / raw)
  To: Kevin Wolf; +Cc: qemu-devel

On 09/07/2011 12:56 PM, Kevin Wolf wrote:
> Am 07.09.2011 11:24, schrieb Avi Kivity:
> >  Currently cache=unsafe is unsafe to the point of unusability - the
> >  caches are never written to disk except on exit so anything except
> >  an orderly exit -- including live migration -- leaves the disk image
> >  corrupted.
> >
> >  Fix by interpreting flush requests and doing everything except flushing
> >  the underlying file.  The contents of the metadata cache are transferred
> >  to the host pagecache, so that qemu aborts keep the disk in a consistent
> >  state, and live migration (on the same host, or if using a coherent
> >  filesystem) works.
> >
> >  Signed-off-by: Avi Kivity<avi@redhat.com>
> >  ---
> >
> >  Untested - is this the right approach?
>
> Hm, could work, even though I don't like it very much. The alternative
> approach would be something like this

I think that your version is better - it fixes all the layered format 
drivers at once (even though qcow2 is the only one that needs fixing).

-- 
error compiling committee.c: too many arguments to function

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-09-07 10:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-07  9:24 [Qemu-devel] [PATCH] qcow2: make cache=unsafe usable Avi Kivity
2011-09-07  9:47 ` Alexander Graf
2011-09-07  9:56 ` Kevin Wolf
2011-09-07 10:07   ` Avi Kivity

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).