From: Volker Lendecke Date: Thu, 13 Dec 2012 21:14:34 +0000 (+0100) Subject: tdb: Simplify logic in tdb_lock_list slightly X-Git-Url: http://git.samba.org/samba.git/?p=kai%2Fsamba.git;a=commitdiff_plain;h=26b8545df44df7e60ba0ba7336ffbdda8a14e423 tdb: Simplify logic in tdb_lock_list slightly Reviewed-by: Rusty Russell Reviewed-by: Stefan Metzmacher --- 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. */