Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > media > main-src > by-pkgid > aadbe78a25743146bb784eee19f007c5 > files > 245

kvm-83-164.el5_5.9.src.rpm

From f02168425b06ca049dddd85f6470d527786e8f39 Mon Sep 17 00:00:00 2001
From: Christoph Hellwig <chellwig@redhat.com>
Date: Tue, 24 Nov 2009 19:43:06 -0200
Subject: [PATCH 01/11] block: use fdatasync instead of fsync if possible

RH-Author: Christoph Hellwig <chellwig@redhat.com>
Message-id: <1256889799.9905.3.camel@brick.lst.de>
Patchwork-id: 3652
O-Subject: [PATCH 2/5] block: use fdatasync instead of fsync if possible
Bugzilla: 537646
RH-Acked-by: Rik van Riel <riel@redhat.com>
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
RH-Acked-by: Juan Quintela <quintela@redhat.com>

commit 6f1953c4c14566d3303709869fd26201828b3ccf
Author: Christoph Hellwig <hch@lst.de>
Date:   Fri Sep 4 19:01:32 2009 +0200

    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>

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 qemu/block-cow.c       |    2 +-
 qemu/block-raw-posix.c |    2 +-
 qemu/cutils.c          |   16 ++++++++++++++++
 qemu/qemu-common.h     |    1 +
 4 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/qemu/block-cow.c b/qemu/block-cow.c
index 9e7b646..d3bb654 100644
--- a/qemu/block-cow.c
+++ b/qemu/block-cow.c
@@ -249,7 +249,7 @@ static int cow_create(const char *filename, int64_t image_sectors,
 static void cow_flush(BlockDriverState *bs)
 {
     BDRVCowState *s = bs->opaque;
-    fsync(s->fd);
+    qemu_fdatasync(s->fd);
 }
 
 BlockDriver bdrv_cow = {
diff --git a/qemu/block-raw-posix.c b/qemu/block-raw-posix.c
index a5850f4..52ad357 100644
--- a/qemu/block-raw-posix.c
+++ b/qemu/block-raw-posix.c
@@ -813,7 +813,7 @@ static int raw_create(const char *filename, int64_t total_size,
 static void raw_flush(BlockDriverState *bs)
 {
     BDRVRawState *s = bs->opaque;
-    fsync(s->fd);
+    qemu_fdatasync(s->fd);
 }
 
 BlockDriver bdrv_raw = {
diff --git a/qemu/cutils.c b/qemu/cutils.c
index 280d0b1..8562259 100644
--- a/qemu/cutils.c
+++ b/qemu/cutils.c
@@ -140,3 +140,19 @@ 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
+}
diff --git a/qemu/qemu-common.h b/qemu/qemu-common.h
index 5799fd4..2b348f4 100644
--- a/qemu/qemu-common.h
+++ b/qemu/qemu-common.h
@@ -105,6 +105,7 @@ int strstart(const char *str, const char *val, const char **ptr);
 int stristart(const char *str, const char *val, const char **ptr);
 time_t mktimegm(struct tm *tm);
 int qemu_fls(int i);
+int qemu_fdatasync(int fd);
 int hex2bin(char ch);
 char *urldecode(const char *ptr);
 
-- 
1.6.3.rc4.29.g8146