From 0fd8c17c54bcbdae8480ed91a1ba8dbb2bb5f203 Mon Sep 17 00:00:00 2001
From: Alberto Bertogli <albertito@blitiri.com.ar>
Date: Sat, 28 Mar 2009 23:06:40 -0300
Subject: [PATCH 28/32] Call fdatasync() after writing to the real file

If O_SYNC was not passed to jopen(), then we could loose data because
jtrans_commit() assumes writes to the file are synchronous. That behaviour
was undocumented, so the user could have assumed O_SYNC was not necessary.

This patch implements a much more sane semantic by calling fdatasync() on
the file fd after writing the transaction when lingering transactions are
not enabled, avoiding the need to open the file with O_SYNC.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
---
 UPGRADING      |    4 ++++
 libjio/trans.c |    3 +++
 2 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/UPGRADING b/UPGRADING
index 72b9c9e..2d3f8fd 100644
--- a/UPGRADING
+++ b/UPGRADING
@@ -11,6 +11,10 @@ take much. If it's mandatory, it will be noted.
 
 If you want to see what motivated the changes, see the changelog or just ask.
 
+0.24 -> 0.25
+* It is no longer necessary to pass O_SYNC to jopen() if lingering
+	transactions are not in use.
+
 0.22 -> 0.24
 * The return values of jfsck() have changed, so applications using it need to
 	be recompiled.
diff --git a/libjio/trans.c b/libjio/trans.c
index bd0eab5..8f003d4 100644
--- a/libjio/trans.c
+++ b/libjio/trans.c
@@ -416,6 +416,9 @@ ssize_t jtrans_commit(struct jtrans *ts)
 		ts->fs->ltrans = linger;
 		pthread_mutex_unlock(&(ts->fs->ltlock));
 	} else {
+		if (fdatasync(ts->fs->fd) != 0)
+			goto rollback_exit;
+
 		/* the transaction has been applied, so we cleanup and remove
 		 * it from the disk */
 		unlink(name);
-- 
1.6.2.rc0.226.gf08f


