From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JfG6C-00063E-CY for qemu-devel@nongnu.org; Fri, 28 Mar 2008 11:02:32 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JfG67-00060l-O9 for qemu-devel@nongnu.org; Fri, 28 Mar 2008 11:02:31 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JfG67-00060h-J0 for qemu-devel@nongnu.org; Fri, 28 Mar 2008 11:02:27 -0400 Received: from kanga.kvack.org ([66.96.29.28]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JfG67-0002qw-3o for qemu-devel@nongnu.org; Fri, 28 Mar 2008 11:02:27 -0400 Date: Fri, 28 Mar 2008 12:05:18 -0300 From: Marcelo Tosatti Message-ID: <20080328150517.GA18077@dmt> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Subject: [Qemu-devel] [PATCH] QEMU: fsync AIO writes on flush request Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Avi Kivity Cc: kvm-devel , qemu-devel@nongnu.org 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 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 = {