summaryrefslogtreecommitdiffstats
path: root/ctdb/lib/tdb
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2010-04-22 13:54:06 +0930
committerRusty Russell <rusty@rustcorp.com.au>2010-04-22 13:54:06 +0930
commita617fb4ab1336cc81f6bf0bd57d0b1af6076110b (patch)
tree3e325ed180abca96c8928965d255961e580b0fcd /ctdb/lib/tdb
parent5c58560d509acbd52730bb2dae280ce433e53a15 (diff)
downloadsamba-a617fb4ab1336cc81f6bf0bd57d0b1af6076110b.tar.gz
samba-a617fb4ab1336cc81f6bf0bd57d0b1af6076110b.tar.xz
samba-a617fb4ab1336cc81f6bf0bd57d0b1af6076110b.zip
patch tdb-refactor-tdb_lock-and-tdb_lock_nonblock.patch
(Imported from commit 1bf482b9ef9ec73dd7ee4387d7087aa3955503dd) (This used to be ctdb commit 52b0f19636565ef633e63d2726a1cc8c41dccedb)
Diffstat (limited to 'ctdb/lib/tdb')
-rw-r--r--ctdb/lib/tdb/common/lock.c29
1 files changed, 13 insertions, 16 deletions
diff --git a/ctdb/lib/tdb/common/lock.c b/ctdb/lib/tdb/common/lock.c
index 030460c781..adff8a6580 100644
--- a/ctdb/lib/tdb/common/lock.c
+++ b/ctdb/lib/tdb/common/lock.c
@@ -309,8 +309,8 @@ int tdb_nest_lock(struct tdb_context *tdb, uint32_t offset, int ltype,
return 0;
}
-/* lock a list in the database. list -1 is the alloc list */
-int tdb_lock(struct tdb_context *tdb, int list, int ltype)
+static int tdb_lock_list(struct tdb_context *tdb, int list, int ltype,
+ enum tdb_lock_flags waitflag)
{
int ret;
@@ -324,9 +324,17 @@ int tdb_lock(struct tdb_context *tdb, int list, int ltype)
tdb->ecode = TDB_ERR_LOCK;
ret = -1;
} else {
- ret = tdb_nest_lock(tdb, lock_offset(list), ltype,
- TDB_LOCK_WAIT);
+ ret = tdb_nest_lock(tdb, lock_offset(list), ltype, waitflag);
}
+ return ret;
+}
+
+/* lock a list in the database. list -1 is the alloc list */
+int tdb_lock(struct tdb_context *tdb, int list, int ltype)
+{
+ int ret;
+
+ ret = tdb_lock_list(tdb, list, ltype, TDB_LOCK_WAIT);
if (ret) {
TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_lock failed on list %d "
"ltype=%d (%s)\n", list, ltype, strerror(errno)));
@@ -337,18 +345,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)
{
- /* a allrecord lock allows us to avoid per chain locks */
- if (tdb->allrecord_lock.count &&
- (ltype == tdb->allrecord_lock.ltype || ltype == F_RDLCK)) {
- return 0;
- }
-
- if (tdb->allrecord_lock.count) {
- tdb->ecode = TDB_ERR_LOCK;
- return -1;
- }
-
- return tdb_nest_lock(tdb, lock_offset(list), ltype, TDB_LOCK_NOWAIT);
+ return tdb_lock_list(tdb, list, ltype, TDB_LOCK_NOWAIT);
}