tdb: Add a non-blocking version of tdb_transaction_start
authorVolker Lendecke <vl@samba.org>
Thu, 22 Apr 2010 04:28:35 +0000 (13:58 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Thu, 22 Apr 2010 04:28:35 +0000 (13:58 +0930)
(Imported from commit 261c3b4f1beed820647061bacbee3acccbcbb089)

lib/tdb/common/lock.c
lib/tdb/common/tdb_private.h
lib/tdb/common/transaction.c
lib/tdb/common/traverse.c
lib/tdb/configure.ac
lib/tdb/include/tdb.h

index 0b130a89351a9a56aa390d4d1a4bb23aa64775fa..285b7a34c3a12cb985b7799fbd9a2da8277ba1d7 100644 (file)
@@ -472,9 +472,10 @@ int tdb_unlock(struct tdb_context *tdb, int list, int ltype)
 /*
   get the transaction lock
  */
-int tdb_transaction_lock(struct tdb_context *tdb, int ltype)
+int tdb_transaction_lock(struct tdb_context *tdb, int ltype,
+                        enum tdb_lock_flags lockflags)
 {
-       return tdb_nest_lock(tdb, TRANSACTION_LOCK, ltype, TDB_LOCK_WAIT);
+       return tdb_nest_lock(tdb, TRANSACTION_LOCK, ltype, lockflags);
 }
 
 /*
index 4e979ac74837842f72758d6f0a9763901ab3582a..b23b76a416b0801c63111e474b2c2719bc195e46 100644 (file)
@@ -232,7 +232,8 @@ int tdb_brunlock(struct tdb_context *tdb,
                 int rw_type, tdb_off_t offset, size_t len);
 bool tdb_have_extra_locks(struct tdb_context *tdb);
 void tdb_release_transaction_locks(struct tdb_context *tdb);
-int tdb_transaction_lock(struct tdb_context *tdb, int ltype);
+int tdb_transaction_lock(struct tdb_context *tdb, int ltype,
+                        enum tdb_lock_flags lockflags);
 int tdb_transaction_unlock(struct tdb_context *tdb, int ltype);
 int tdb_allrecord_lock(struct tdb_context *tdb, int ltype,
                       enum tdb_lock_flags flags, bool upgradable);
index 504d0f681a8be4c60810cc2a23566b12b98e807e..304a03fa3836940197c1319eeae5ddbcb3fce823 100644 (file)
@@ -421,7 +421,8 @@ static const struct tdb_methods transaction_methods = {
   start a tdb transaction. No token is returned, as only a single
   transaction is allowed to be pending per tdb_context
 */
-int tdb_transaction_start(struct tdb_context *tdb)
+static int _tdb_transaction_start(struct tdb_context *tdb,
+                                 enum tdb_lock_flags lockflags)
 {
        /* some sanity checks */
        if (tdb->read_only || (tdb->flags & TDB_INTERNAL) || tdb->traverse_read) {
@@ -473,9 +474,12 @@ int tdb_transaction_start(struct tdb_context *tdb)
        /* get the transaction write lock. This is a blocking lock. As
           discussed with Volker, there are a number of ways we could
           make this async, which we will probably do in the future */
-       if (tdb_transaction_lock(tdb, F_WRLCK) == -1) {
+       if (tdb_transaction_lock(tdb, F_WRLCK, lockflags) == -1) {
                SAFE_FREE(tdb->transaction->blocks);
                SAFE_FREE(tdb->transaction);
+               if ((lockflags & TDB_LOCK_WAIT) == 0) {
+                       tdb->ecode = TDB_ERR_NOLOCK;
+               }
                return -1;
        }
 
@@ -525,6 +529,15 @@ fail_allrecord_lock:
        return -1;
 }
 
+int tdb_transaction_start(struct tdb_context *tdb)
+{
+       return _tdb_transaction_start(tdb, TDB_LOCK_WAIT);
+}
+
+int tdb_transaction_start_nonblock(struct tdb_context *tdb)
+{
+       return _tdb_transaction_start(tdb, TDB_LOCK_NOWAIT|TDB_LOCK_PROBE);
+}
 
 /*
   sync to disk
index baaf58ae87dabc3d0048ca1c95f04ac0780ac298..d77086a79aa6c270dd3a7f799fa978ad74ca8da2 100644 (file)
@@ -220,7 +220,7 @@ int tdb_traverse_read(struct tdb_context *tdb,
 
        /* we need to get a read lock on the transaction lock here to
           cope with the lock ordering semantics of solaris10 */
-       if (tdb_transaction_lock(tdb, F_RDLCK)) {
+       if (tdb_transaction_lock(tdb, F_RDLCK, TDB_LOCK_WAIT)) {
                return -1;
        }
 
@@ -251,7 +251,7 @@ int tdb_traverse(struct tdb_context *tdb,
                return tdb_traverse_read(tdb, fn, private_data);
        }
 
-       if (tdb_transaction_lock(tdb, F_WRLCK)) {
+       if (tdb_transaction_lock(tdb, F_WRLCK, TDB_LOCK_WAIT)) {
                return -1;
        }
 
index ef9a4723327346d993f4fc4f73bf85228672cebc..686b0a6763379ed35969d81c04dd2e546ae7a8e3 100644 (file)
@@ -2,7 +2,7 @@ AC_PREREQ(2.50)
 AC_DEFUN([SMB_MODULE_DEFAULT], [echo -n ""])
 AC_DEFUN([SMB_LIBRARY_ENABLE], [echo -n ""])
 AC_DEFUN([SMB_ENABLE], [echo -n ""])
-AC_INIT(tdb, 1.2.1)
+AC_INIT(tdb, 1.2.2)
 AC_CONFIG_SRCDIR([common/tdb.c])
 AC_CONFIG_HEADER(include/config.h)
 AC_LIBREPLACE_ALL_CHECKS
index db9ce4ad276f094c1ec421d783970f4efaabd428..9a8bc8a10d7250d09b884ac12615a93ed141ac8a 100644 (file)
@@ -130,6 +130,7 @@ int tdb_fd(struct tdb_context *tdb);
 tdb_log_func tdb_log_fn(struct tdb_context *tdb);
 void *tdb_get_logging_private(struct tdb_context *tdb);
 int tdb_transaction_start(struct tdb_context *tdb);
+int tdb_transaction_start_nonblock(struct tdb_context *tdb);
 int tdb_transaction_prepare_commit(struct tdb_context *tdb);
 int tdb_transaction_commit(struct tdb_context *tdb);
 int tdb_transaction_cancel(struct tdb_context *tdb);