diff options
author | Volker Lendecke <vl@samba.org> | 2012-12-14 09:21:42 +0100 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2012-12-21 11:56:09 +0100 |
commit | f8dafe5685008671f4f983a4defc90b4a05cf992 (patch) | |
tree | 4af545791167e213c66d7d8bb8bcaab892a43c32 /lib | |
parent | 26b8545df44df7e60ba0ba7336ffbdda8a14e423 (diff) | |
download | samba-f8dafe5685008671f4f983a4defc90b4a05cf992.tar.gz samba-f8dafe5685008671f4f983a4defc90b4a05cf992.tar.bz2 samba-f8dafe5685008671f4f983a4defc90b4a05cf992.zip |
tdb: Factor out tdb_lock_covered_by_allrecord_lock from tdb_lock_list
Reviewed-by: Rusty Russell <rusty@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/tdb/common/lock.c | 54 |
1 files changed, 31 insertions, 23 deletions
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. */ |