1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-13 13:18:06 +03:00

tdb: Add a non-blocking version of tdb_transaction_start

(Imported from commit 261c3b4f1b)

(This used to be ctdb commit 87ced00d6d98be4a34719af58694e7c940b4dd68)
This commit is contained in:
Volker Lendecke 2010-04-22 13:58:35 +09:30 committed by Rusty Russell
parent 67312cefef
commit bae2979659
6 changed files with 24 additions and 8 deletions

View 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);
}
/*

View 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);

View 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

View 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;
}

View 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

View 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);