tdb: Simplify logic in tdb_lock_list slightly
authorVolker Lendecke <vl@samba.org>
Thu, 13 Dec 2012 21:14:34 +0000 (22:14 +0100)
committerStefan Metzmacher <metze@samba.org>
Fri, 21 Dec 2012 10:55:55 +0000 (11:55 +0100)
Reviewed-by: Rusty Russell <rusty@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
lib/tdb/common/lock.c

index 333af1bebb349d3bdd4205b1d68cd3384fb6c912..f2d0ae78362077a9d87a20aa8ab4e9037237d5e8 100644 (file)
@@ -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. */