lib/tdb: Add/expose lock functions to support CTDB
authorAmitay Isaacs <amitay@gmail.com>
Mon, 26 Mar 2012 22:44:33 +0000 (09:44 +1100)
committerRusty Russell <rusty@rustcorp.com.au>
Thu, 29 Mar 2012 09:37:03 +0000 (20:07 +1030)
This patch adds two lock functions used by CTDB to perform asynchronous
locking. These functions do not actually perform any fcntl operations,
but only increment internal counters.

 - tdb_transaction_write_lock_mark()
 - tdb_transaction_write_lock_unmark()

It also exposes two internal functions
 - tdb_lock_nonblock()
 - tdb_unlock()

These functions are NOT exposed in include/tdb.h to prevent any further
uses of these functions. If you ever need to use these functions, consider
using tdb2.

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
lib/tdb/common/lock.c

index c6a2485171c2d3230d492bcdf10c27815e1266c8..88a52e9dfa4c007c85fb4ef0af6f0c89dec8ae55 100644 (file)
@@ -380,7 +380,7 @@ int tdb_lock(struct tdb_context *tdb, int list, int ltype)
 }
 
 /* lock a list in the database. list -1 is the alloc list. non-blocking lock */
-int tdb_lock_nonblock(struct tdb_context *tdb, int list, int ltype)
+_PUBLIC_ int tdb_lock_nonblock(struct tdb_context *tdb, int list, int ltype)
 {
        return tdb_lock_list(tdb, list, ltype, TDB_LOCK_NOWAIT);
 }
@@ -445,7 +445,7 @@ int tdb_nest_unlock(struct tdb_context *tdb, uint32_t offset, int ltype,
        return ret;
 }
 
-int tdb_unlock(struct tdb_context *tdb, int list, int ltype)
+_PUBLIC_ int tdb_unlock(struct tdb_context *tdb, int list, int ltype)
 {
        /* a global lock allows us to avoid per chain locks */
        if (tdb->allrecord_lock.count &&
@@ -859,3 +859,17 @@ void tdb_release_transaction_locks(struct tdb_context *tdb)
                SAFE_FREE(tdb->lockrecs);
        }
 }
+
+/* Following functions are added specifically to support CTDB. */
+
+/* Don't do actual fcntl locking, just mark tdb locked */
+_PUBLIC_ int tdb_transaction_write_lock_mark(struct tdb_context *tdb)
+{
+       return tdb_transaction_lock(tdb, F_WRLCK, TDB_LOCK_MARK_ONLY);
+}
+
+/* Don't do actual fcntl unlocking, just mark tdb unlocked */
+_PUBLIC_ int tdb_transaction_write_lock_unmark(struct tdb_context *tdb)
+{
+       return tdb_nest_unlock(tdb, TRANSACTION_LOCK, F_WRLCK, true);
+}