tdb: expose transaction lock infrastructure for ctdb
authorRusty Russell <rusty@rustcorp.com.au>
Tue, 18 Jan 2011 00:17:11 +0000 (10:47 +1030)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Tue, 18 Jan 2011 02:26:41 +0000 (13:26 +1100)
tdb_traverse_read() grabs the transaction lock.  This can cause ctdbd
(which uses it) to block when it should not; expose mark and normal
variants of this lock, so ctdbd's child (the recovery daemon) can
acquire it and the ctdbd parent can mark it was held.

lib/tdb/common/lock.c
lib/tdb/include/tdb.h

index 803feeecbb0587d575206a7b72791cd40d413767..f0da8818d190247be700c69204ec4f0c9327d299 100644 (file)
@@ -861,3 +861,23 @@ void tdb_release_transaction_locks(struct tdb_context *tdb)
                SAFE_FREE(tdb->lockrecs);
        }
 }
+
+int tdb_transaction_write_lock_mark(struct tdb_context *tdb)
+{
+       return tdb_transaction_lock(tdb, F_WRLCK, TDB_LOCK_MARK_ONLY);
+}
+
+int tdb_transaction_write_lock(struct tdb_context *tdb)
+{
+       return tdb_transaction_lock(tdb, F_WRLCK, 0);
+}
+
+int tdb_transaction_write_unlock(struct tdb_context *tdb)
+{
+       return tdb_transaction_unlock(tdb, F_WRLCK);
+}
+
+int tdb_transaction_write_lock_unmark(struct tdb_context *tdb)
+{
+       return tdb_nest_unlock(tdb, TRANSACTION_LOCK, F_WRLCK, true);
+}
index aac7c9221de60013e70dd4ebf22eb33b73b95db8..536a0b373722347c6322504ca787cb196e91ca45 100644 (file)
@@ -161,6 +161,10 @@ _PUBLIC_ int tdb_chainlock_read(struct tdb_context *tdb, TDB_DATA key);
 _PUBLIC_ int tdb_chainunlock_read(struct tdb_context *tdb, TDB_DATA key);
 _PUBLIC_ int tdb_chainlock_mark(struct tdb_context *tdb, TDB_DATA key);
 _PUBLIC_ int tdb_chainlock_unmark(struct tdb_context *tdb, TDB_DATA key);
+_PUBLIC_ int tdb_transaction_write_lock(struct tdb_context *tdb);
+_PUBLIC_ int tdb_transaction_write_unlock(struct tdb_context *tdb);
+_PUBLIC_ int tdb_transaction_write_lock_mark(struct tdb_context *tdb);
+_PUBLIC_ int tdb_transaction_write_lock_unmark(struct tdb_context *tdb);
 
 _PUBLIC_ void tdb_setalarm_sigptr(struct tdb_context *tdb, volatile sig_atomic_t *sigptr);