tdb: cleanup: remove ltype argument from _tdb_transaction_cancel.
authorRusty Russell <rusty@rustcorp.com.au>
Wed, 24 Feb 2010 02:12:24 +0000 (12:42 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Wed, 24 Feb 2010 02:12:24 +0000 (12:42 +1030)
Now the transaction allrecord lock is the standard one, and thus is cleaned
in tdb_release_extra_locks(), _tdb_transaction_cancel() doesn't need to
know what type it is.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
lib/tdb/common/transaction.c

index c9718a59b3b22bbf4badb1988a8f2655439188e0..0f9f80c86e0f59bb6860da3e36cac7e01f3db61a 100644 (file)
@@ -577,8 +577,7 @@ static int transaction_sync(struct tdb_context *tdb, tdb_off_t offset, tdb_len_t
 }
 
 
 }
 
 
-/* ltype is F_WRLCK after prepare. */
-static int _tdb_transaction_cancel(struct tdb_context *tdb, int ltype)
+static int _tdb_transaction_cancel(struct tdb_context *tdb)
 {      
        int i, ret = 0;
 
 {      
        int i, ret = 0;
 
@@ -633,11 +632,8 @@ static int _tdb_transaction_cancel(struct tdb_context *tdb, int ltype)
 */
 int tdb_transaction_cancel(struct tdb_context *tdb)
 {
 */
 int tdb_transaction_cancel(struct tdb_context *tdb)
 {
-       int ltype = F_RDLCK;
        tdb_trace(tdb, "tdb_transaction_cancel");
        tdb_trace(tdb, "tdb_transaction_cancel");
-       if (tdb->transaction && tdb->transaction->prepared)
-               ltype = F_WRLCK;
-       return _tdb_transaction_cancel(tdb, ltype);
+       return _tdb_transaction_cancel(tdb);
 }
 
 /*
 }
 
 /*
@@ -903,14 +899,14 @@ static int _tdb_transaction_prepare_commit(struct tdb_context *tdb)
 
        if (tdb->transaction->prepared) {
                tdb->ecode = TDB_ERR_EINVAL;
 
        if (tdb->transaction->prepared) {
                tdb->ecode = TDB_ERR_EINVAL;
-               _tdb_transaction_cancel(tdb, F_WRLCK);
+               _tdb_transaction_cancel(tdb);
                TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_prepare_commit: transaction already prepared\n"));
                return -1;
        }
 
        if (tdb->transaction->transaction_error) {
                tdb->ecode = TDB_ERR_IO;
                TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_prepare_commit: transaction already prepared\n"));
                return -1;
        }
 
        if (tdb->transaction->transaction_error) {
                tdb->ecode = TDB_ERR_IO;
-               _tdb_transaction_cancel(tdb, F_RDLCK);
+               _tdb_transaction_cancel(tdb);
                TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_prepare_commit: transaction error pending\n"));
                return -1;
        }
                TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_prepare_commit: transaction error pending\n"));
                return -1;
        }
@@ -932,14 +928,14 @@ static int _tdb_transaction_prepare_commit(struct tdb_context *tdb)
        if (tdb_have_extra_locks(tdb)) {
                tdb->ecode = TDB_ERR_LOCK;
                TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_prepare_commit: locks pending on commit\n"));
        if (tdb_have_extra_locks(tdb)) {
                tdb->ecode = TDB_ERR_LOCK;
                TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_prepare_commit: locks pending on commit\n"));
-               _tdb_transaction_cancel(tdb, F_RDLCK);
+               _tdb_transaction_cancel(tdb);
                return -1;
        }
 
        /* upgrade the main transaction lock region to a write lock */
        if (tdb_allrecord_upgrade(tdb) == -1) {
                TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_prepare_commit: failed to upgrade hash locks\n"));
                return -1;
        }
 
        /* upgrade the main transaction lock region to a write lock */
        if (tdb_allrecord_upgrade(tdb) == -1) {
                TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_prepare_commit: failed to upgrade hash locks\n"));
-               _tdb_transaction_cancel(tdb, F_RDLCK);
+               _tdb_transaction_cancel(tdb);
                return -1;
        }
 
                return -1;
        }
 
@@ -947,7 +943,7 @@ static int _tdb_transaction_prepare_commit(struct tdb_context *tdb)
           during the commit */
        if (tdb_nest_lock(tdb, OPEN_LOCK, F_WRLCK, TDB_LOCK_WAIT) == -1) {
                TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_prepare_commit: failed to get open lock\n"));
           during the commit */
        if (tdb_nest_lock(tdb, OPEN_LOCK, F_WRLCK, TDB_LOCK_WAIT) == -1) {
                TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_prepare_commit: failed to get open lock\n"));
-               _tdb_transaction_cancel(tdb, F_WRLCK);
+               _tdb_transaction_cancel(tdb);
                return -1;
        }
 
                return -1;
        }
 
@@ -955,7 +951,7 @@ static int _tdb_transaction_prepare_commit(struct tdb_context *tdb)
                /* write the recovery data to the end of the file */
                if (transaction_setup_recovery(tdb, &tdb->transaction->magic_offset) == -1) {
                        TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_prepare_commit: failed to setup recovery data\n"));
                /* write the recovery data to the end of the file */
                if (transaction_setup_recovery(tdb, &tdb->transaction->magic_offset) == -1) {
                        TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_prepare_commit: failed to setup recovery data\n"));
-                       _tdb_transaction_cancel(tdb, F_WRLCK);
+                       _tdb_transaction_cancel(tdb);
                        return -1;
                }
        }
                        return -1;
                }
        }
@@ -969,7 +965,7 @@ static int _tdb_transaction_prepare_commit(struct tdb_context *tdb)
                                             tdb->transaction->old_map_size) == -1) {
                        tdb->ecode = TDB_ERR_IO;
                        TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_prepare_commit: expansion failed\n"));
                                             tdb->transaction->old_map_size) == -1) {
                        tdb->ecode = TDB_ERR_IO;
                        TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_prepare_commit: expansion failed\n"));
-                       _tdb_transaction_cancel(tdb, F_WRLCK);
+                       _tdb_transaction_cancel(tdb);
                        return -1;
                }
                tdb->map_size = tdb->transaction->old_map_size;
                        return -1;
                }
                tdb->map_size = tdb->transaction->old_map_size;
@@ -1008,7 +1004,7 @@ int tdb_transaction_commit(struct tdb_context *tdb)
 
        if (tdb->transaction->transaction_error) {
                tdb->ecode = TDB_ERR_IO;
 
        if (tdb->transaction->transaction_error) {
                tdb->ecode = TDB_ERR_IO;
-               _tdb_transaction_cancel(tdb, F_RDLCK);
+               _tdb_transaction_cancel(tdb);
                TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_commit: transaction error pending\n"));
                return -1;
        }
                TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_commit: transaction error pending\n"));
                return -1;
        }
@@ -1021,7 +1017,7 @@ int tdb_transaction_commit(struct tdb_context *tdb)
 
        /* check for a null transaction */
        if (tdb->transaction->blocks == NULL) {
 
        /* check for a null transaction */
        if (tdb->transaction->blocks == NULL) {
-               _tdb_transaction_cancel(tdb, F_RDLCK);
+               _tdb_transaction_cancel(tdb);
                return 0;
        }
 
                return 0;
        }
 
@@ -1057,7 +1053,7 @@ int tdb_transaction_commit(struct tdb_context *tdb)
                        tdb->methods = methods;
                        tdb_transaction_recover(tdb); 
 
                        tdb->methods = methods;
                        tdb_transaction_recover(tdb); 
 
-                       _tdb_transaction_cancel(tdb, F_WRLCK);
+                       _tdb_transaction_cancel(tdb);
 
                        TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_commit: write failed\n"));
                        return -1;
 
                        TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_commit: write failed\n"));
                        return -1;
@@ -1092,7 +1088,7 @@ int tdb_transaction_commit(struct tdb_context *tdb)
 
        /* use a transaction cancel to free memory and remove the
           transaction locks */
 
        /* use a transaction cancel to free memory and remove the
           transaction locks */
-       _tdb_transaction_cancel(tdb, F_WRLCK);
+       _tdb_transaction_cancel(tdb);
 
        if (need_repack) {
                return tdb_repack(tdb);
 
        if (need_repack) {
                return tdb_repack(tdb);