diff options
author | Volker Lendecke <vl@samba.org> | 2010-03-26 13:18:33 +0100 |
---|---|---|
committer | Simo Sorce <idra@samba.org> | 2010-03-26 14:27:47 -0400 |
commit | 261c3b4f1beed820647061bacbee3acccbcbb089 (patch) | |
tree | 224c955ab144d8114f0405c2545d95239e122fbe /lib | |
parent | d570a0af0be442d6d1e253309d9bbae9562669cf (diff) | |
download | samba-261c3b4f1beed820647061bacbee3acccbcbb089.tar.gz samba-261c3b4f1beed820647061bacbee3acccbcbb089.tar.bz2 samba-261c3b4f1beed820647061bacbee3acccbcbb089.zip |
tdb: Add a non-blocking version of tdb_transaction_start
Diffstat (limited to 'lib')
-rw-r--r-- | lib/tdb/common/lock.c | 5 | ||||
-rw-r--r-- | lib/tdb/common/tdb_private.h | 3 | ||||
-rw-r--r-- | lib/tdb/common/transaction.c | 17 | ||||
-rw-r--r-- | lib/tdb/common/traverse.c | 4 | ||||
-rw-r--r-- | lib/tdb/configure.ac | 2 | ||||
-rw-r--r-- | lib/tdb/include/tdb.h | 1 |
6 files changed, 24 insertions, 8 deletions
diff --git a/lib/tdb/common/lock.c b/lib/tdb/common/lock.c index 0b130a8935..285b7a34c3 100644 --- a/lib/tdb/common/lock.c +++ b/lib/tdb/common/lock.c @@ -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); } /* diff --git a/lib/tdb/common/tdb_private.h b/lib/tdb/common/tdb_private.h index 4e979ac748..b23b76a416 100644 --- a/lib/tdb/common/tdb_private.h +++ b/lib/tdb/common/tdb_private.h @@ -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); diff --git a/lib/tdb/common/transaction.c b/lib/tdb/common/transaction.c index 504d0f681a..304a03fa38 100644 --- a/lib/tdb/common/transaction.c +++ b/lib/tdb/common/transaction.c @@ -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 diff --git a/lib/tdb/common/traverse.c b/lib/tdb/common/traverse.c index baaf58ae87..d77086a79a 100644 --- a/lib/tdb/common/traverse.c +++ b/lib/tdb/common/traverse.c @@ -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; } diff --git a/lib/tdb/configure.ac b/lib/tdb/configure.ac index 395121937f..4e36779df2 100644 --- a/lib/tdb/configure.ac +++ b/lib/tdb/configure.ac @@ -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 diff --git a/lib/tdb/include/tdb.h b/lib/tdb/include/tdb.h index c9e946a885..c84a39863b 100644 --- a/lib/tdb/include/tdb.h +++ b/lib/tdb/include/tdb.h @@ -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); |