Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JfJOR-0003JI-GQ for qemu-devel@nongnu.org; Fri, 28 Mar 2008 14:33:35 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JfJOQ-0003IU-Ev for qemu-devel@nongnu.org; Fri, 28 Mar 2008 14:33:34 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JfJOQ-0003IL-AX for qemu-devel@nongnu.org; Fri, 28 Mar 2008 14:33:34 -0400 Received: from kanga.kvack.org ([66.96.29.28]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JfJOQ-0003wt-1Y for qemu-devel@nongnu.org; Fri, 28 Mar 2008 14:33:34 -0400 Date: Fri, 28 Mar 2008 15:36:28 -0300 From: Marcelo Tosatti Subject: Re: [kvm-devel] [Qemu-devel] [PATCH] QEMU: fsync AIO writes on flush request Message-ID: <20080328183628.GB19547@dmt> References: <20080328150517.GA18077@dmt> <20080328150703.GA19624@shareable.org> <20080328163116.GA18853@dmt> <20080328180324.GA22555@shareable.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: QUOTED-PRINTABLE In-Reply-To: <20080328180324.GA22555@shareable.org> Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jamie Lokier , Paul Brook Cc: kvm-devel , qemu-devel@nongnu.org On Fri, Mar 28, 2008 at 06:03:25PM +0000, Jamie Lokier wrote: > Marcelo Tosatti wrote: > > On Fri, Mar 28, 2008 at 03:07:03PM +0000, Jamie Lokier wrote: > > > Marcelo Tosatti wrote: > > > > Its necessary to guarantee that pending AIO writes have reached= stable > > > > storage when the flush request returns. > > > >=20 > > > > Also change fsync() to fdatasync(), since the modification time= is not > > > > critical data. > > > > + if (aio_fsync(O_DSYNC, &acb->aiocb) < 0) { > > >=20 > > > > BDRVRawState *s =3D 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(); > > >=20 > > > I'm a bit confused by this. Why do you need aio_fsync(O_DSYNC) _= and_ > > > synchronous fdatasync() calls? Aren't they equivalent? > >=20 > > fdatasync() will write and wait for completion of dirty file data > > present in memory. > >=20 > > aio_write() only queues data for submission: > >=20 > > The "asynchronous" means that this call returns as soon as t= he request > > has been enqueued; the write may or may not have complet= ed when the > > call returns. One tests for completion using aio_error(3). > >=20 >=20 > > So fdatasync() is not enough because data written via AIO may not > > have been reflected as "dirty file data" through write() by the tim= e > > raw_flush() is called. >=20 > Sure. But why isn't the aio_fsync(O_DSYNC) enough by itself? It is enough, fdatasync() becomes redundant. > It seems to me you should have something like this: >=20 > /* Flush pending aio_writes until they are dirty data, > and wait before the aio_fsync. */ > qemu_aio_flush(); >=20 > /* Call aio_fsync(O_DSYNC). */ > raw_aio_flush(bs); >=20 > /* Wait for the aio_fsync to complete. */ > qemu_aio_flush(); >=20 > What am I missing? I don't think the first qemu_aio_flush() is necessary because the fsync request will be enqueued after pending ones:=20 aio_fsync() function does a sync on all outstanding asynchrono= us I/O operations associated with aiocbp->aio_fildes. More precisely, if op is O_SYNC, then all currently queued I/O = opera- tions shall be completed as if by a call of fsync(2), and i= f op is O_DSYNC, this call is the asynchronous analog of fdatasync(2).= Note that this is a request only =E2=80=94 this call does not wait = for I/O comple- tion. glibc sets the priority for fsync as 0, which is the same priority AIO reads and writes are submitted by QEMU.