summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2012-12-13 22:14:34 +0100
committerStefan Metzmacher <metze@samba.org>2012-12-21 11:55:55 +0100
commit26b8545df44df7e60ba0ba7336ffbdda8a14e423 (patch)
tree31d08d6479de47dc43a3e45ae2d5fc73b3bbf94c
parent0f4e7a1401998746a6818b9469ab369d70418ac1 (diff)
downloadsamba-26b8545df44df7e60ba0ba7336ffbdda8a14e423.tar.gz
tdb: Simplify logic in tdb_lock_list slightly
Reviewed-by: Rusty Russell <rusty@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
-rw-r--r--lib/tdb/common/lock.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/lib/tdb/common/lock.c b/lib/tdb/common/lock.c
index 333af1bebb3..f2d0ae78362 100644
--- a/lib/tdb/common/lock.c
+++ b/lib/tdb/common/lock.c
@@ -341,14 +341,29 @@ static int tdb_lock_list(struct tdb_context *tdb, int list, int ltype,
bool check = false;
/* 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;
+
+ if (ltype == F_RDLCK) {
+ /*
+ * The allrecord_lock is equal (F_RDLCK) or stronger
+ * (F_WRLCK). Pass.
+ */
+ return 0;
+ }
+
+ if (tdb->allrecord_lock.ltype == F_RDLCK) {
+ /*
+ * We ask for ltype==F_WRLCK, but the allrecord_lock
+ * is too weak. We can't upgrade here, so fail.
+ */
+ tdb->ecode = TDB_ERR_LOCK;
+ return -1;
+ }
+
+ /*
+ * Asking for F_WRLCK, allrecord is F_WRLCK as well. Pass.
+ */
+ return 0;
}
/* Only check when we grab first data lock. */