qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] QEMU: fsync AIO writes on flush request
@ 2008-03-28 15:05 Marcelo Tosatti
  2008-03-28 15:07 ` Jamie Lokier
  2008-03-28 17:25 ` Ian Jackson
  0 siblings, 2 replies; 17+ messages in thread
From: Marcelo Tosatti @ 2008-03-28 15:05 UTC (permalink / raw)
  To: Avi Kivity; +Cc: kvm-devel, qemu-devel


Its necessary to guarantee that pending AIO writes have reached stable
storage when the flush request returns.

Also change fsync() to fdatasync(), since the modification time is not
critical data.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>


Index: kvm-userspace.io/qemu/block-raw-posix.c
===================================================================
--- kvm-userspace.io.orig/qemu/block-raw-posix.c
+++ kvm-userspace.io/qemu/block-raw-posix.c
@@ -557,10 +557,40 @@ static int raw_create(const char *filena
     return 0;
 }
 
+static void raw_aio_flush_complete(void *opaque, int ret)
+{
+    if (ret)
+        printf("WARNING: aio_fsync failed (completion)\n");
+}
+
+static void raw_aio_flush(BlockDriverState *bs)
+{
+    RawAIOCB *acb;
+
+    acb = raw_aio_setup(bs, 0, NULL, 0, raw_aio_flush_complete, NULL);
+    if (!acb)
+        return;
+
+    if (aio_fsync(O_DSYNC, &acb->aiocb) < 0) {
+        qemu_aio_release(acb);
+        perror("aio_fsync");
+        printf("WARNING: aio_fsync failed\n");
+        return;
+    }
+}
+
 static void raw_flush(BlockDriverState *bs)
 {
     BDRVRawState *s = bs->opaque;
-    fsync(s->fd);
+    raw_aio_flush(bs);
+    fdatasync(s->fd);
+
+    /* We rely on the fact that no other AIO will be submitted
+     * in parallel, but this should be fixed by per-device
+     * AIO queues when allowing multiple CPU's to process IO
+     * in QEMU.
+     */
+    qemu_aio_flush();
 }
 
 BlockDriver bdrv_raw = {

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

end of thread, other threads:[~2008-03-29  6:46 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-28 15:05 [Qemu-devel] [PATCH] QEMU: fsync AIO writes on flush request Marcelo Tosatti
2008-03-28 15:07 ` Jamie Lokier
2008-03-28 16:31   ` [kvm-devel] " Marcelo Tosatti
2008-03-28 16:40     ` Paul Brook
2008-03-28 16:59       ` Marcelo Tosatti
2008-03-28 17:00         ` Paul Brook
2008-03-28 18:13           ` Marcelo Tosatti
2008-03-29  1:17             ` Jamie Lokier
2008-03-29  2:02               ` Paul Brook
2008-03-29  2:11                 ` Jamie Lokier
2008-03-29  2:43                   ` Paul Brook
2008-03-28 18:03     ` Jamie Lokier
2008-03-28 18:36       ` Marcelo Tosatti
2008-03-29  1:09         ` Jamie Lokier
2008-03-29  6:49           ` Marcelo Tosatti
2008-03-28 17:25 ` Ian Jackson
2008-03-28 19:11   ` [kvm-devel] " Marcelo Tosatti

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