From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MjcAP-0000Rl-Eg for qemu-devel@nongnu.org; Fri, 04 Sep 2009 13:01:41 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MjcAK-0000O9-KK for qemu-devel@nongnu.org; Fri, 04 Sep 2009 13:01:40 -0400 Received: from [199.232.76.173] (port=39731 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MjcAK-0000Nm-Bt for qemu-devel@nongnu.org; Fri, 04 Sep 2009 13:01:36 -0400 Received: from verein.lst.de ([213.95.11.210]:36006) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_3DES_EDE_CBC_SHA1:24) (Exim 4.60) (envelope-from ) id 1MjcAJ-00085X-IX for qemu-devel@nongnu.org; Fri, 04 Sep 2009 13:01:35 -0400 Received: from verein.lst.de (localhost [127.0.0.1]) by verein.lst.de (8.12.3/8.12.3/Debian-7.1) with ESMTP id n84H1WVL023002 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Fri, 4 Sep 2009 19:01:32 +0200 Received: (from hch@localhost) by verein.lst.de (8.12.3/8.12.3/Debian-7.2) id n84H1WKH023001 for qemu-devel@nongnu.org; Fri, 4 Sep 2009 19:01:32 +0200 Date: Fri, 4 Sep 2009 19:01:32 +0200 From: Christoph Hellwig Message-ID: <20090904170132.GB22964@lst.de> References: <20090904170052.GA22640@lst.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20090904170052.GA22640@lst.de> Subject: [Qemu-devel] [PATCH 2/5] block: use fdatasync instead of fsync if possible List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org If we are flushing the caches for our image files we only care about the data (including the metadata required for accessing it) but not things like timestamp updates. So try to use fdatasync instead of fsync to implement the flush operations. Unfortunately many operating systems still do not support fdatasync, so we add a qemu_fdatasync wrapper that uses fdatasync if available as per the _POSIX_SYNCHRONIZED_IO feature macro or fsync otherwise. Signed-off-by: Christoph Hellwig Index: qemu/block/cow.c =================================================================== --- qemu.orig/block/cow.c 2009-09-04 13:41:43.114022303 -0300 +++ qemu/block/cow.c 2009-09-04 13:45:19.146522312 -0300 @@ -258,7 +258,7 @@ static int cow_create(const char *filena static void cow_flush(BlockDriverState *bs) { BDRVCowState *s = bs->opaque; - fsync(s->fd); + qemu_fdatasync(s->fd); } static QEMUOptionParameter cow_create_options[] = { Index: qemu/block/raw-posix.c =================================================================== --- qemu.orig/block/raw-posix.c 2009-09-04 13:41:43.122026044 -0300 +++ qemu/block/raw-posix.c 2009-09-04 13:59:28.402521899 -0300 @@ -723,7 +723,7 @@ static int raw_create(const char *filena static void raw_flush(BlockDriverState *bs) { BDRVRawState *s = bs->opaque; - fsync(s->fd); + qemu_fdatasync(s->fd); } Index: qemu/cutils.c =================================================================== --- qemu.orig/cutils.c 2009-09-04 13:41:43.130023149 -0300 +++ qemu/cutils.c 2009-09-04 13:43:58.230523144 -0300 @@ -115,6 +115,22 @@ int qemu_fls(int i) return 32 - clz32(i); } +/* + * Make sure data goes on disk, but if possible do not bother to + * write out the inode just for timestamp updates. + * + * Unfortunately even in 2009 many operating systems do not support + * fdatasync and have to fall back to fsync. + */ +int qemu_fdatasync(int fd) +{ +#ifdef _POSIX_SYNCHRONIZED_IO + return fdatasync(fd); +#else + return fsync(fd); +#endif +} + /* io vectors */ void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint) Index: qemu/qemu-common.h =================================================================== --- qemu.orig/qemu-common.h 2009-09-04 13:41:43.134022470 -0300 +++ qemu/qemu-common.h 2009-09-04 13:43:58.234522745 -0300 @@ -114,6 +114,7 @@ int stristart(const char *str, const cha int qemu_strnlen(const char *s, int max_len); time_t mktimegm(struct tm *tm); int qemu_fls(int i); +int qemu_fdatasync(int fd); /* path.c */ void init_paths(const char *prefix);