]> git.ozlabs.org Git - ccan/commitdiff
Import from SAMBA tdb:
authorRusty Russell <rusty@rustcorp.com.au>
Wed, 29 Jul 2009 12:52:31 +0000 (22:22 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Wed, 29 Jul 2009 12:52:31 +0000 (22:22 +0930)
commit 4b4fec65db4e202afa13b2d15867f4d8a54d154e
Author: Andrew Tridgell <tridge@samba.org>
Date:   Thu May 28 16:08:28 2009 +1000

    make TDB_NOSYNC affect all the fsync/msync calls in transactions

    During a transaction commit tdb normally uses fsync/msync calls to
    make it crash safe. This can be disabled using the TDB_NOSYNC flag,
    but it wasn't disabling all the code paths that caused a fsync/msync.

ccan/tdb/transaction.c

index 4c261598972dad139442abc12e03ed3a37cc5379..1086c5f037793d9df00269ff78b14ae2ad126e72 100644 (file)
@@ -423,6 +423,10 @@ static const struct tdb_methods transaction_methods = {
 */
 static int transaction_sync(struct tdb_context *tdb, tdb_off_t offset, tdb_len_t length)
 {      
+       if (tdb->flags & TDB_NOSYNC) {
+               return 0;
+       }
+
        if (fsync(tdb->fd) != 0) {
                tdb->ecode = TDB_ERR_IO;
                TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction: fsync failed\n"));
@@ -1066,11 +1070,9 @@ int tdb_transaction_commit(struct tdb_context *tdb)
        SAFE_FREE(tdb->transaction->blocks);
        tdb->transaction->num_blocks = 0;
 
-       if (!(tdb->flags & TDB_NOSYNC)) {
-               /* ensure the new data is on disk */
-               if (transaction_sync(tdb, 0, tdb->map_size) == -1) {
-                       return -1;
-               }
+       /* ensure the new data is on disk */
+       if (transaction_sync(tdb, 0, tdb->map_size) == -1) {
+               return -1;
        }
 
        tdb_brlock(tdb, GLOBAL_LOCK, F_UNLCK, F_SETLKW, 0, 1);