aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2009-09-04 19:01:32 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2009-09-11 10:19:46 -0500
commit6f1953c4c14566d3303709869fd26201828b3ccf (patch)
tree522dacdca726cc3b8bc321e70791d03a3b543e72 /cutils.c
parentblock: add enable_write_cache flag (diff)
downloadqemu-kvm-6f1953c4c14566d3303709869fd26201828b3ccf.tar.gz
qemu-kvm-6f1953c4c14566d3303709869fd26201828b3ccf.tar.bz2
qemu-kvm-6f1953c4c14566d3303709869fd26201828b3ccf.zip
block: use fdatasync instead of fsync if possible
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> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'cutils.c')
-rw-r--r--cutils.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/cutils.c b/cutils.c
index ffe5c717e..7a2234646 100644
--- a/cutils.c
+++ b/cutils.c
@@ -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)