|
|
@@ -614,52 +614,6 @@ bool tdb_has_hash_locks(struct tdb_context *tdb)
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
-#if 0
|
|
|
-/* lock entire database with write lock */
|
|
|
-int tdb_lockall(struct tdb_context *tdb)
|
|
|
-{
|
|
|
- tdb_trace(tdb, "tdb_lockall");
|
|
|
- return tdb_allrecord_lock(tdb, F_WRLCK, TDB_LOCK_WAIT, false);
|
|
|
-}
|
|
|
-
|
|
|
-/* lock entire database with write lock - nonblocking varient */
|
|
|
-int tdb_lockall_nonblock(struct tdb_context *tdb)
|
|
|
-{
|
|
|
- int ret = tdb_allrecord_lock(tdb, F_WRLCK, TDB_LOCK_NOWAIT, false);
|
|
|
- tdb_trace_ret(tdb, "tdb_lockall_nonblock", ret);
|
|
|
- return ret;
|
|
|
-}
|
|
|
-
|
|
|
-/* unlock entire database with write lock */
|
|
|
-int tdb_unlockall(struct tdb_context *tdb)
|
|
|
-{
|
|
|
- tdb_trace(tdb, "tdb_unlockall");
|
|
|
- return tdb_allrecord_unlock(tdb, F_WRLCK);
|
|
|
-}
|
|
|
-
|
|
|
-/* lock entire database with read lock */
|
|
|
-int tdb_lockall_read(struct tdb_context *tdb)
|
|
|
-{
|
|
|
- tdb_trace(tdb, "tdb_lockall_read");
|
|
|
- return tdb_allrecord_lock(tdb, F_RDLCK, TDB_LOCK_WAIT, false);
|
|
|
-}
|
|
|
-
|
|
|
-/* lock entire database with read lock - nonblock varient */
|
|
|
-int tdb_lockall_read_nonblock(struct tdb_context *tdb)
|
|
|
-{
|
|
|
- int ret = tdb_allrecord_lock(tdb, F_RDLCK, TDB_LOCK_NOWAIT, false);
|
|
|
- tdb_trace_ret(tdb, "tdb_lockall_read_nonblock", ret);
|
|
|
- return ret;
|
|
|
-}
|
|
|
-
|
|
|
-/* unlock entire database with read lock */
|
|
|
-int tdb_unlockall_read(struct tdb_context *tdb)
|
|
|
-{
|
|
|
- tdb_trace(tdb, "tdb_unlockall_read");
|
|
|
- return tdb_allrecord_unlock(tdb, F_RDLCK);
|
|
|
-}
|
|
|
-#endif
|
|
|
-
|
|
|
static bool tdb_has_free_lock(struct tdb_context *tdb)
|
|
|
{
|
|
|
unsigned int i;
|
|
|
@@ -781,117 +735,6 @@ void tdb_unlock_free_bucket(struct tdb_context *tdb, tdb_off_t b_off)
|
|
|
tdb_nest_unlock(tdb, free_lock_off(b_off), F_WRLCK);
|
|
|
}
|
|
|
|
|
|
-#if 0
|
|
|
-/* lock/unlock one hash chain, non-blocking. This is meant to be used
|
|
|
- to reduce contention - it cannot guarantee how many records will be
|
|
|
- locked */
|
|
|
-int tdb_chainlock_nonblock(struct tdb_context *tdb, TDB_DATA key)
|
|
|
-{
|
|
|
- return chainlock(tdb, &key, F_WRLCK, TDB_LOCK_NOWAIT,
|
|
|
- "tdb_chainlock_nonblock");
|
|
|
-}
|
|
|
-
|
|
|
-int tdb_chainlock_read(struct tdb_context *tdb, TDB_DATA key)
|
|
|
-{
|
|
|
- return chainlock(tdb, &key, F_RDLCK, TDB_LOCK_WAIT,
|
|
|
- "tdb_chainlock_read");
|
|
|
-}
|
|
|
-
|
|
|
-int tdb_chainunlock_read(struct tdb_context *tdb, TDB_DATA key)
|
|
|
-{
|
|
|
- uint64_t h = tdb_hash(tdb, key.dptr, key.dsize);
|
|
|
- tdb_trace_1rec(tdb, "tdb_chainunlock_read", key);
|
|
|
- return tdb_unlock_list(tdb, h & ((1ULL << tdb->header.v.hash_bits)-1),
|
|
|
- F_RDLCK);
|
|
|
-}
|
|
|
-
|
|
|
-/* record lock stops delete underneath */
|
|
|
-int tdb_lock_record(struct tdb_context *tdb, tdb_off_t off)
|
|
|
-{
|
|
|
- if (tdb->allrecord_lock.count) {
|
|
|
- return 0;
|
|
|
- }
|
|
|
- return off ? tdb_brlock(tdb, F_RDLCK, off, 1, TDB_LOCK_WAIT) : 0;
|
|
|
-}
|
|
|
-
|
|
|
-/*
|
|
|
- Write locks override our own fcntl readlocks, so check it here.
|
|
|
- Note this is meant to be F_SETLK, *not* F_SETLKW, as it's not
|
|
|
- an error to fail to get the lock here.
|
|
|
-*/
|
|
|
-int tdb_write_lock_record(struct tdb_context *tdb, tdb_off_t off)
|
|
|
-{
|
|
|
- struct tdb_traverse_lock *i;
|
|
|
- for (i = &tdb->travlocks; i; i = i->next)
|
|
|
- if (i->off == off)
|
|
|
- return -1;
|
|
|
- if (tdb->allrecord_lock.count) {
|
|
|
- if (tdb->allrecord_lock.ltype == F_WRLCK) {
|
|
|
- return 0;
|
|
|
- }
|
|
|
- return -1;
|
|
|
- }
|
|
|
- return tdb_brlock(tdb, F_WRLCK, off, 1, TDB_LOCK_NOWAIT|TDB_LOCK_PROBE);
|
|
|
-}
|
|
|
-
|
|
|
-int tdb_write_unlock_record(struct tdb_context *tdb, tdb_off_t off)
|
|
|
-{
|
|
|
- if (tdb->allrecord_lock.count) {
|
|
|
- return 0;
|
|
|
- }
|
|
|
- return tdb_brunlock(tdb, F_WRLCK, off, 1);
|
|
|
-}
|
|
|
-
|
|
|
-/* fcntl locks don't stack: avoid unlocking someone else's */
|
|
|
-int tdb_unlock_record(struct tdb_context *tdb, tdb_off_t off)
|
|
|
-{
|
|
|
- struct tdb_traverse_lock *i;
|
|
|
- uint32_t count = 0;
|
|
|
-
|
|
|
- if (tdb->allrecord_lock.count) {
|
|
|
- return 0;
|
|
|
- }
|
|
|
-
|
|
|
- if (off == 0)
|
|
|
- return 0;
|
|
|
- for (i = &tdb->travlocks; i; i = i->next)
|
|
|
- if (i->off == off)
|
|
|
- count++;
|
|
|
- return (count == 1 ? tdb_brunlock(tdb, F_RDLCK, off, 1) : 0);
|
|
|
-}
|
|
|
-
|
|
|
-/* The transaction code uses this to remove all locks. */
|
|
|
-void tdb_release_transaction_locks(struct tdb_context *tdb)
|
|
|
-{
|
|
|
- unsigned int i;
|
|
|
-
|
|
|
- if (tdb->allrecord_lock.count != 0) {
|
|
|
- tdb_off_t hash_size, free_size;
|
|
|
-
|
|
|
- hash_size = (1ULL << tdb->header.v.hash_bits)
|
|
|
- * sizeof(tdb_off_t);
|
|
|
- free_size = tdb->header.v.free_zones
|
|
|
- * (tdb->header.v.free_buckets + 1) * sizeof(tdb_off_t);
|
|
|
-
|
|
|
- tdb_brunlock(tdb, tdb->allrecord_lock.ltype,
|
|
|
- tdb->header.v.hash_off, hash_size);
|
|
|
- tdb_brunlock(tdb, tdb->allrecord_lock.ltype,
|
|
|
- tdb->header.v.free_off, free_size);
|
|
|
- tdb->allrecord_lock.count = 0;
|
|
|
- tdb->allrecord_lock.ltype = 0;
|
|
|
- }
|
|
|
-
|
|
|
- for (i = 0; i<tdb->num_lockrecs; i++) {
|
|
|
- struct tdb_lock_type *lck = &tdb->lockrecs[i];
|
|
|
-
|
|
|
- tdb_brunlock(tdb, lck->ltype, lck->off, 1);
|
|
|
- }
|
|
|
- tdb->num_lockrecs = 0;
|
|
|
- SAFE_FREE(tdb->lockrecs);
|
|
|
- tdb->header_uptodate = false;
|
|
|
-}
|
|
|
-#endif
|
|
|
-
|
|
|
void tdb_lock_init(struct tdb_context *tdb)
|
|
|
{
|
|
|
tdb->num_lockrecs = 0;
|