From f8dafe5685008671f4f983a4defc90b4a05cf992 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 14 Dec 2012 09:21:42 +0100 Subject: tdb: Factor out tdb_lock_covered_by_allrecord_lock from tdb_lock_list Reviewed-by: Rusty Russell Reviewed-by: Stefan Metzmacher --- lib/tdb/common/lock.c | 54 +++++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 23 deletions(-) (limited to 'lib/tdb') diff --git a/lib/tdb/common/lock.c b/lib/tdb/common/lock.c index f2d0ae7836..4d06a41b7d 100644 --- a/lib/tdb/common/lock.c +++ b/lib/tdb/common/lock.c @@ -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. */ -- cgit