git » libjio » commit 0fd8c17

Call fdatasync() after writing to the real file

author Alberto Bertogli
2009-03-29 02:06:40 UTC
committer Alberto Bertogli
2009-03-29 02:33:22 UTC
parent 6e8652bb2d1e40dd8ce59ac4a8ca4891f0f06ab9

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 -0
libjio/trans.c +3 -0

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);