tdb: Factor out tdb_lock_covered_by_allrecord_lock from tdb_lock_list
authorVolker Lendecke <vl@samba.org>
Fri, 14 Dec 2012 08:21:42 +0000 (09:21 +0100)
committerStefan Metzmacher <metze@samba.org>
Fri, 21 Dec 2012 10:56:09 +0000 (11:56 +0100)
Reviewed-by: Rusty Russell <rusty@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
lib/tdb/common/lock.c

index f2d0ae78362077a9d87a20aa8ab4e9037237d5e8..4d06a41b7d40afeed23dc749820dcc9e34c87170 100644 (file)
@@ -334,36 +334,44 @@ static bool have_data_locks(const struct tdb_context *tdb)
        return false;
 }
 
+/*
+ * A allrecord lock allows us to avoid per chain locks. Check if the allrecord
+ * lock is strong enough.
+ */
+static int tdb_lock_covered_by_allrecord_lock(struct tdb_context *tdb,
+                                             int ltype)
+{
+       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;
+}
+
 static int tdb_lock_list(struct tdb_context *tdb, int list, int ltype,
                         enum tdb_lock_flags waitflag)
 {
        int ret;
        bool check = false;
 
-       /* a allrecord lock allows us to avoid per chain locks */
        if (tdb->allrecord_lock.count) {
-
-               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;
+               return tdb_lock_covered_by_allrecord_lock(tdb, ltype);
        }
 
        /* Only check when we grab first data lock. */