From: Christoph Hellwig <hch@lst.de>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 2/5] block: use fdatasync instead of fsync if possible
Date: Fri, 4 Sep 2009 19:01:32 +0200 [thread overview]
Message-ID: <20090904170132.GB22964@lst.de> (raw)
In-Reply-To: <20090904170052.GA22640@lst.de>
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 <hch@lst.de>
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);
next prev parent reply other threads:[~2009-09-04 17:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-04 17:00 [Qemu-devel] [PATCH 0/5] data integrity fixes V2 Christoph Hellwig
2009-09-04 17:01 ` [Qemu-devel] [PATCH 1/5] block: add enable_write_cache flag Christoph Hellwig
2009-09-04 17:01 ` Christoph Hellwig [this message]
2009-09-04 17:01 ` [Qemu-devel] [PATCH 3/5] block: add aio_flush operation Christoph Hellwig
2009-09-04 17:02 ` [Qemu-devel] [PATCH 4/5] ide: use bdrv_aio_flush Christoph Hellwig
2009-09-04 17:02 ` [Qemu-devel] [PATCH 5/5] virtio-blk: add volatile writecache feature Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090904170132.GB22964@lst.de \
--to=hch@lst.de \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).