summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2014-02-13 16:48:35 +0100
committerJeremy Allison <jra@samba.org>2014-02-14 15:55:46 -0800
commitcde8e290c9195cbc7a2388455df9e76a1f36135f (patch)
tree5ba28ee33ff3139a33bbcafc9d9561281e92194d
parentadb2cd1eee69550fa58d8cb11441b7174dccae5b (diff)
downloadsamba-cde8e290c9195cbc7a2388455df9e76a1f36135f.tar.gz
samba-cde8e290c9195cbc7a2388455df9e76a1f36135f.tar.xz
samba-cde8e290c9195cbc7a2388455df9e76a1f36135f.zip
tdb: simplify tdb_delete_hash() a bit
Make the lock/unlock bracket more obvious by extracting locking (and finding) from the special cases to the top of the function. This also lets us take lock and find the record outside the special case branches (use dead records or not). There is a small semantic change implied: In the dead records case, the record to delete is looked up before the current dead records are potentially purged. Hence, if the record to delete is not found, the dead records are also not purge. This does not make a big difference though, because purging is only delayed until directly befor the next record to delete is in fact found. Signed-off-by: Michael Adam <obnox@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
-rw-r--r--lib/tdb/common/tdb.c17
1 files changed, 5 insertions, 12 deletions
diff --git a/lib/tdb/common/tdb.c b/lib/tdb/common/tdb.c
index 6256a05d04..f24493ccd8 100644
--- a/lib/tdb/common/tdb.c
+++ b/lib/tdb/common/tdb.c
@@ -387,6 +387,11 @@ static int tdb_delete_hash(struct tdb_context *tdb, TDB_DATA key, uint32_t hash)
struct tdb_record rec;
int ret;
+ rec_ptr = tdb_find_lock_hash(tdb, key, hash, F_WRLCK, &rec);
+ if (rec_ptr == 0) {
+ return -1;
+ }
+
if (tdb->max_dead_records != 0) {
/*
@@ -394,9 +399,6 @@ static int tdb_delete_hash(struct tdb_context *tdb, TDB_DATA key, uint32_t hash)
* tdb's with a very high create/delete rate like locking.tdb.
*/
- if (tdb_lock(tdb, BUCKET(hash), F_WRLCK) == -1)
- return -1;
-
if (tdb_count_dead(tdb, hash) >= tdb->max_dead_records) {
/*
* Don't let the per-chain freelist grow too large,
@@ -405,11 +407,6 @@ static int tdb_delete_hash(struct tdb_context *tdb, TDB_DATA key, uint32_t hash)
tdb_purge_dead(tdb, hash);
}
- if (!(rec_ptr = tdb_find(tdb, key, hash, &rec))) {
- tdb_unlock(tdb, BUCKET(hash), F_WRLCK);
- return -1;
- }
-
/*
* Just mark the record as dead.
*/
@@ -417,10 +414,6 @@ static int tdb_delete_hash(struct tdb_context *tdb, TDB_DATA key, uint32_t hash)
ret = tdb_rec_write(tdb, rec_ptr, &rec);
}
else {
- if (!(rec_ptr = tdb_find_lock_hash(tdb, key, hash, F_WRLCK,
- &rec)))
- return -1;
-
ret = tdb_do_delete(tdb, rec_ptr, &rec);
}