2 Unix SMB/CIFS implementation.
4 trivial database library
6 Copyright (C) Andrew Tridgell 1999-2005
7 Copyright (C) Paul `Rusty' Russell 2000
8 Copyright (C) Jeremy Allison 2000-2003
10 ** NOTE! The following LGPL license applies to the tdb
11 ** library. This does NOT imply that all of Samba is released
14 This library is free software; you can redistribute it and/or
15 modify it under the terms of the GNU Lesser General Public
16 License as published by the Free Software Foundation; either
17 version 3 of the License, or (at your option) any later version.
19 This library is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 Lesser General Public License for more details.
24 You should have received a copy of the GNU Lesser General Public
25 License along with this library; if not, see <http://www.gnu.org/licenses/>.
30 static int fcntl_lock(struct tdb_context *tdb,
31 int rw, off_t off, off_t len, bool waitflag)
36 fl.l_whence = SEEK_SET;
42 return fcntl(tdb->fd, F_SETLKW, &fl);
44 return fcntl(tdb->fd, F_SETLK, &fl);
47 static int fcntl_unlock(struct tdb_context *tdb, int rw, off_t off, off_t len)
50 #if 0 /* Check they matched up locks and unlocks correctly. */
55 locks = fopen("/proc/locks", "r");
57 while (fgets(line, 80, locks)) {
61 /* eg. 1: FLOCK ADVISORY WRITE 2440 08:01:2180826 0 EOF */
62 p = strchr(line, ':') + 1;
63 if (strncmp(p, " POSIX ADVISORY ", strlen(" POSIX ADVISORY ")))
65 p += strlen(" FLOCK ADVISORY ");
66 if (strncmp(p, "READ ", strlen("READ ")) == 0)
68 else if (strncmp(p, "WRITE ", strlen("WRITE ")) == 0)
73 if (atoi(p) != getpid())
75 p = strchr(strchr(p, ' ') + 1, ' ') + 1;
77 p = strchr(p, ' ') + 1;
78 if (strncmp(p, "EOF", 3) == 0)
81 l = atoi(p) - start + 1;
85 fprintf(stderr, "Len %u should be %u: %s",
90 fprintf(stderr, "Type %s wrong: %s",
91 rw == F_RDLCK ? "READ" : "WRITE", line);
100 fprintf(stderr, "Unlock on %u@%u not found!\n",
109 fl.l_whence = SEEK_SET;
114 return fcntl(tdb->fd, F_SETLKW, &fl);
117 /* a byte range locking function - return 0 on success
118 this functions locks/unlocks 1 byte at the specified offset.
120 note that a len of zero means lock to end of file
122 static int tdb_brlock(struct tdb_context *tdb,
123 int rw_type, tdb_off_t offset, tdb_off_t len,
124 enum tdb_lock_flags flags)
128 if (tdb->flags & TDB_NOLOCK) {
132 if (rw_type == F_WRLCK && tdb->read_only) {
133 tdb->ecode = TDB_ERR_RDONLY;
137 /* A 32 bit system cannot open a 64-bit file, but it could have
138 * expanded since then: check here. */
139 if ((size_t)(offset + len) != offset + len) {
140 tdb->ecode = TDB_ERR_IO;
141 tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv,
142 "tdb_brlock: lock on giant offset %llu\n",
143 (long long)(offset + len));
148 ret = fcntl_lock(tdb, rw_type, offset, len,
149 flags & TDB_LOCK_WAIT);
150 } while (ret == -1 && errno == EINTR);
153 tdb->ecode = TDB_ERR_LOCK;
154 /* Generic lock error. errno set by fcntl.
155 * EAGAIN is an expected return from non-blocking
157 if (!(flags & TDB_LOCK_PROBE) && errno != EAGAIN) {
158 tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv,
159 "tdb_brlock failed (fd=%d) at"
160 " offset %llu rw_type=%d flags=%d len=%llu\n",
161 tdb->fd, (long long)offset, rw_type,
162 flags, (long long)len);
169 static int tdb_brunlock(struct tdb_context *tdb,
170 int rw_type, tdb_off_t offset, size_t len)
174 if (tdb->flags & TDB_NOLOCK) {
179 ret = fcntl_unlock(tdb, rw_type, offset, len);
180 } while (ret == -1 && errno == EINTR);
183 tdb->log(tdb, TDB_DEBUG_TRACE, tdb->log_priv,
184 "tdb_brunlock failed (fd=%d) at offset %llu"
185 " rw_type=%d len=%llu\n",
186 tdb->fd, (long long)offset, rw_type, (long long)len);
193 upgrade a read lock to a write lock. This needs to be handled in a
194 special way as some OSes (such as solaris) have too conservative
195 deadlock detection and claim a deadlock when progress can be
196 made. For those OSes we may loop for a while.
198 int tdb_allrecord_upgrade(struct tdb_context *tdb)
202 if (tdb->allrecord_lock.count != 1) {
203 tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv,
204 "tdb_allrecord_upgrade failed: count %u too high\n",
205 tdb->allrecord_lock.count);
209 if (tdb->allrecord_lock.off != 1) {
210 tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv,
211 "tdb_allrecord_upgrade failed: already upgraded?\n");
217 if (tdb_brlock(tdb, F_WRLCK,
219 + (1ULL << tdb->header.v.hash_bits), 0,
220 TDB_LOCK_WAIT|TDB_LOCK_PROBE) == 0) {
221 tdb->allrecord_lock.ltype = F_WRLCK;
222 tdb->allrecord_lock.off = 0;
225 if (errno != EDEADLK) {
228 /* sleep for as short a time as we can - more portable than usleep() */
231 select(0, NULL, NULL, NULL, &tv);
233 tdb->log(tdb, TDB_DEBUG_WARNING, tdb->log_priv,
234 "tdb_allrecord_upgrade failed\n");
239 static struct tdb_lock_type *find_nestlock(struct tdb_context *tdb,
244 for (i=0; i<tdb->num_lockrecs; i++) {
245 if (tdb->lockrecs[i].off == offset) {
246 return &tdb->lockrecs[i];
252 /* lock an offset in the database. */
253 static int tdb_nest_lock(struct tdb_context *tdb, tdb_off_t offset, int ltype,
254 enum tdb_lock_flags flags)
256 struct tdb_lock_type *new_lck;
258 if (offset >= TDB_HASH_LOCK_START + (1ULL << tdb->header.v.hash_bits)
259 + (tdb->header.v.num_zones * (tdb->header.v.free_buckets+1))) {
260 tdb->ecode = TDB_ERR_LOCK;
261 tdb->log(tdb, TDB_DEBUG_FATAL, tdb->log_priv,
262 "tdb_lock: invalid offset %llu for ltype=%d\n",
263 (long long)offset, ltype);
266 if (tdb->flags & TDB_NOLOCK)
269 new_lck = find_nestlock(tdb, offset);
272 * Just increment the in-memory struct, posix locks
279 new_lck = (struct tdb_lock_type *)realloc(
281 sizeof(*tdb->lockrecs) * (tdb->num_lockrecs+1));
282 if (new_lck == NULL) {
283 tdb->ecode = TDB_ERR_OOM;
284 tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv,
285 "tdb_lock: unable to allocate %llu lock structure",
286 (long long)(tdb->num_lockrecs + 1));
290 tdb->lockrecs = new_lck;
292 /* Since fcntl locks don't nest, we do a lock for the first one,
293 and simply bump the count for future ones */
294 if (tdb_brlock(tdb, ltype, offset, 1, flags)) {
298 tdb->lockrecs[tdb->num_lockrecs].off = offset;
299 tdb->lockrecs[tdb->num_lockrecs].count = 1;
300 tdb->lockrecs[tdb->num_lockrecs].ltype = ltype;
306 static int tdb_lock_and_recover(struct tdb_context *tdb)
312 /* We need to match locking order in transaction commit. */
313 if (tdb_brlock(tdb, F_WRLCK, FREELIST_TOP, 0, TDB_LOCK_WAIT)) {
317 if (tdb_brlock(tdb, F_WRLCK, OPEN_LOCK, 1, TDB_LOCK_WAIT)) {
318 tdb_brunlock(tdb, F_WRLCK, FREELIST_TOP, 0);
322 ret = tdb_transaction_recover(tdb);
324 tdb_brunlock(tdb, F_WRLCK, OPEN_LOCK, 1);
325 tdb_brunlock(tdb, F_WRLCK, FREELIST_TOP, 0);
334 static bool tdb_needs_recovery(struct tdb_context *tdb)
340 static int tdb_nest_unlock(struct tdb_context *tdb, tdb_off_t off, int ltype)
343 struct tdb_lock_type *lck;
345 if (tdb->flags & TDB_NOLOCK)
348 lck = find_nestlock(tdb, off);
349 if ((lck == NULL) || (lck->count == 0)) {
350 tdb->ecode = TDB_ERR_LOCK;
351 tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv,
352 "tdb_unlock: no lock for %llu\n", (long long)off);
356 if (lck->count > 1) {
362 * This lock has count==1 left, so we need to unlock it in the
363 * kernel. We don't bother with decrementing the in-memory array
364 * element, we're about to overwrite it with the last array element
367 ret = tdb_brunlock(tdb, ltype, off, 1);
370 * Shrink the array by overwriting the element just unlocked with the
371 * last array element.
373 *lck = tdb->lockrecs[--tdb->num_lockrecs];
375 if (tdb->num_lockrecs == 0) {
376 /* If we're not holding any locks, header can change. */
377 tdb->header_uptodate = false;
385 get the transaction lock
387 int tdb_transaction_lock(struct tdb_context *tdb, int ltype,
388 enum tdb_lock_flags lockflags)
390 return tdb_nest_lock(tdb, TRANSACTION_LOCK, ltype, lockflags);
394 release the transaction lock
396 int tdb_transaction_unlock(struct tdb_context *tdb, int ltype)
398 return tdb_nest_unlock(tdb, TRANSACTION_LOCK, ltype, false);
402 /* We only need to lock individual bytes, but Linux merges consecutive locks
403 * so we lock in contiguous ranges. */
404 static int tdb_lock_gradual(struct tdb_context *tdb,
405 int ltype, enum tdb_lock_flags flags,
406 tdb_off_t off, tdb_off_t len)
409 enum tdb_lock_flags nb_flags = (flags & ~TDB_LOCK_WAIT);
412 /* Single record. Just do blocking lock. */
413 return tdb_brlock(tdb, ltype, off, len, flags);
416 /* First we try non-blocking. */
417 ret = tdb_brlock(tdb, ltype, off, len, nb_flags);
422 /* Try locking first half, then second. */
423 ret = tdb_lock_gradual(tdb, ltype, flags, off, len / 2);
427 ret = tdb_lock_gradual(tdb, ltype, flags,
428 off + len / 2, len - len / 2);
430 tdb_brunlock(tdb, ltype, off, len / 2);
436 /* lock/unlock entire database. It can only be upgradable if you have some
437 * other way of guaranteeing exclusivity (ie. transaction write lock).
438 * Note that we don't lock the free chains: noone can get those locks
439 * without a hash chain lock first.
440 * The header *will be* up to date once this returns success. */
441 int tdb_allrecord_lock(struct tdb_context *tdb, int ltype,
442 enum tdb_lock_flags flags, bool upgradable)
446 /* FIXME: There are no locks on read-only dbs */
447 if (tdb->read_only) {
448 tdb->ecode = TDB_ERR_LOCK;
449 tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv,
450 "tdb_allrecord_lock: read-only\n");
454 if (tdb->allrecord_lock.count && tdb->allrecord_lock.ltype == ltype) {
455 tdb->allrecord_lock.count++;
459 if (tdb->allrecord_lock.count) {
460 /* a global lock of a different type exists */
461 tdb->ecode = TDB_ERR_LOCK;
462 tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv,
463 "tdb_allrecord_lock: already have %s lock\n",
464 tdb->allrecord_lock.ltype == F_RDLCK
469 if (tdb_has_locks(tdb)) {
470 /* can't combine global and chain locks */
471 tdb->ecode = TDB_ERR_LOCK;
472 tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv,
473 "tdb_allrecord_lock: already have chain lock\n");
477 if (upgradable && ltype != F_RDLCK) {
478 /* tdb error: you can't upgrade a write lock! */
479 tdb->ecode = TDB_ERR_LOCK;
480 tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv,
481 "tdb_allrecord_lock: can't upgrade a write lock\n");
485 /* Lock all the hash buckets. */
487 hash_size = (1ULL << tdb->header.v.hash_bits);
488 if (tdb_lock_gradual(tdb, ltype, TDB_HASH_LOCK_START,
489 1ULL << tdb->header.v.hash_bits, flags)) {
490 if (!(flags & TDB_LOCK_PROBE)) {
491 tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv,
492 "tdb_lockall hashes failed (%s)\n",
498 tdb->allrecord_lock.count = 1;
499 /* If it's upgradable, it's actually exclusive so we can treat
500 * it as a write lock. */
501 tdb->allrecord_lock.ltype = upgradable ? F_WRLCK : ltype;
502 tdb->allrecord_lock.off = upgradable;
504 /* Now we re-check header, holding lock. */
505 if (unlikely(update_header(tdb))) {
506 tdb_allrecord_unlock(tdb, ltype);
510 /* Now check for needing recovery. */
511 if (unlikely(tdb_needs_recovery(tdb))) {
512 tdb_allrecord_unlock(tdb, ltype);
513 if (tdb_lock_and_recover(tdb) == -1) {
522 int tdb_lock_open(struct tdb_context *tdb)
524 return tdb_nest_lock(tdb, TDB_OPEN_LOCK, F_WRLCK, TDB_LOCK_WAIT);
527 void tdb_unlock_open(struct tdb_context *tdb)
529 tdb_nest_unlock(tdb, TDB_OPEN_LOCK, F_WRLCK);
532 /* unlock entire db */
533 int tdb_allrecord_unlock(struct tdb_context *tdb, int ltype)
537 /* FIXME: There are no locks on read-only dbs */
538 if (tdb->read_only) {
539 tdb->ecode = TDB_ERR_LOCK;
540 tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv,
541 "tdb_allrecord_unlock: read-only\n");
545 if (tdb->allrecord_lock.count == 0) {
546 tdb->ecode = TDB_ERR_LOCK;
547 tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv,
548 "tdb_allrecord_unlock: not locked!\n");
552 /* Upgradable locks are marked as write locks. */
553 if (tdb->allrecord_lock.ltype != ltype
554 && (!tdb->allrecord_lock.off || ltype != F_RDLCK)) {
555 tdb->ecode = TDB_ERR_LOCK;
556 tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv,
557 "tdb_allrecord_unlock: have %s lock\n",
558 tdb->allrecord_lock.ltype == F_RDLCK
563 if (tdb->allrecord_lock.count > 1) {
564 tdb->allrecord_lock.count--;
568 tdb->allrecord_lock.count = 0;
569 tdb->allrecord_lock.ltype = 0;
571 hash_size = (1ULL << tdb->header.v.hash_bits);
573 return tdb_brunlock(tdb, ltype, TDB_HASH_LOCK_START, hash_size);
576 bool tdb_has_locks(struct tdb_context *tdb)
578 return tdb->allrecord_lock.count || tdb->num_lockrecs;
582 /* lock entire database with write lock */
583 int tdb_lockall(struct tdb_context *tdb)
585 tdb_trace(tdb, "tdb_lockall");
586 return tdb_allrecord_lock(tdb, F_WRLCK, TDB_LOCK_WAIT, false);
589 /* lock entire database with write lock - nonblocking varient */
590 int tdb_lockall_nonblock(struct tdb_context *tdb)
592 int ret = tdb_allrecord_lock(tdb, F_WRLCK, TDB_LOCK_NOWAIT, false);
593 tdb_trace_ret(tdb, "tdb_lockall_nonblock", ret);
597 /* unlock entire database with write lock */
598 int tdb_unlockall(struct tdb_context *tdb)
600 tdb_trace(tdb, "tdb_unlockall");
601 return tdb_allrecord_unlock(tdb, F_WRLCK);
604 /* lock entire database with read lock */
605 int tdb_lockall_read(struct tdb_context *tdb)
607 tdb_trace(tdb, "tdb_lockall_read");
608 return tdb_allrecord_lock(tdb, F_RDLCK, TDB_LOCK_WAIT, false);
611 /* lock entire database with read lock - nonblock varient */
612 int tdb_lockall_read_nonblock(struct tdb_context *tdb)
614 int ret = tdb_allrecord_lock(tdb, F_RDLCK, TDB_LOCK_NOWAIT, false);
615 tdb_trace_ret(tdb, "tdb_lockall_read_nonblock", ret);
619 /* unlock entire database with read lock */
620 int tdb_unlockall_read(struct tdb_context *tdb)
622 tdb_trace(tdb, "tdb_unlockall_read");
623 return tdb_allrecord_unlock(tdb, F_RDLCK);
627 int tdb_lock_list(struct tdb_context *tdb, tdb_off_t list,
628 int ltype, enum tdb_lock_flags waitflag)
630 /* a allrecord lock allows us to avoid per chain locks */
631 if (tdb->allrecord_lock.count &&
632 (ltype == tdb->allrecord_lock.ltype || ltype == F_RDLCK)) {
636 if (tdb->allrecord_lock.count) {
637 tdb->ecode = TDB_ERR_LOCK;
638 tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv,
639 "tdb_lock_list: have %s allrecordlock\n",
640 tdb->allrecord_lock.ltype == F_RDLCK
645 /* FIXME: Should we do header_uptodate and return retry here? */
646 return tdb_nest_lock(tdb, TDB_HASH_LOCK_START + list, ltype, waitflag);
649 int tdb_unlock_list(struct tdb_context *tdb, tdb_off_t list, int ltype)
651 /* a allrecord lock allows us to avoid per chain locks */
652 if (tdb->allrecord_lock.count) {
653 if (tdb->allrecord_lock.ltype == F_RDLCK
654 && ltype == F_WRLCK) {
655 tdb->ecode = TDB_ERR_LOCK;
656 tdb->log(tdb, TDB_DEBUG_FATAL, tdb->log_priv,
657 "tdb_unlock_list RO allrecord!\n");
662 return tdb_nest_unlock(tdb, TDB_HASH_LOCK_START + list, ltype);
666 /* Free list locks come after hash locks */
667 int tdb_lock_free_list(struct tdb_context *tdb, tdb_off_t flist,
668 enum tdb_lock_flags waitflag)
670 /* You're supposed to have a hash lock first! */
671 if (!tdb_has_locks(tdb)) {
672 tdb->ecode = TDB_ERR_LOCK;
673 tdb->log(tdb, TDB_DEBUG_FATAL, tdb->log_priv,
674 "tdb_lock_free_list without lock!\n");
678 /* a allrecord lock allows us to avoid per chain locks */
679 if (tdb->allrecord_lock.count) {
680 if (tdb->allrecord_lock.ltype == F_WRLCK)
682 tdb->ecode = TDB_ERR_LOCK;
683 tdb->log(tdb, TDB_DEBUG_FATAL, tdb->log_priv,
684 "tdb_lock_free_list with RO allrecordlock!\n");
688 return tdb_nest_lock(tdb, TDB_HASH_LOCK_START
689 + (1ULL << tdb->header.v.hash_bits)
690 + flist, F_WRLCK, waitflag);
693 void tdb_unlock_free_list(struct tdb_context *tdb, tdb_off_t flist)
695 if (tdb->allrecord_lock.count)
698 tdb_nest_unlock(tdb, TDB_HASH_LOCK_START
699 + (1ULL << tdb->header.v.hash_bits)
704 static int chainlock_loop(struct tdb_context *tdb, const TDB_DATA *key,
705 int ltype, enum tdb_lock_flags waitflag,
709 uint64_t h = tdb_hash(tdb, key->dptr, key->dsize);
712 ret = tdb_lock_list(tdb,
713 h & ((1ULL << tdb->header.v.hash_bits) - 1),
715 if (likely(ret == 0) && unlikely(update_header(tdb))) {
716 tdb_unlock_list(tdb, h & ((1ULL << tdb->header.v.hash_bits)-1),
721 tdb_trace_1rec(tdb, func, *key);
725 /* lock/unlock one hash chain. This is meant to be used to reduce
726 contention - it cannot guarantee how many records will be locked */
727 int tdb_chainlock(struct tdb_context *tdb, TDB_DATA key)
729 return chainlock_loop(tdb, &key, F_WRLCK, TDB_LOCK_WAIT,
733 /* lock/unlock one hash chain, non-blocking. This is meant to be used
734 to reduce contention - it cannot guarantee how many records will be
736 int tdb_chainlock_nonblock(struct tdb_context *tdb, TDB_DATA key)
738 return chainlock_loop(tdb, &key, F_WRLCK, TDB_LOCK_NOWAIT,
739 "tdb_chainlock_nonblock");
742 int tdb_chainunlock(struct tdb_context *tdb, TDB_DATA key)
744 uint64_t h = tdb_hash(tdb, key.dptr, key.dsize);
745 tdb_trace_1rec(tdb, "tdb_chainunlock", key);
746 return tdb_unlock_list(tdb, h & ((1ULL << tdb->header.v.hash_bits)-1),
750 int tdb_chainlock_read(struct tdb_context *tdb, TDB_DATA key)
752 return chainlock_loop(tdb, &key, F_RDLCK, TDB_LOCK_WAIT,
753 "tdb_chainlock_read");
756 int tdb_chainunlock_read(struct tdb_context *tdb, TDB_DATA key)
758 uint64_t h = tdb_hash(tdb, key.dptr, key.dsize);
759 tdb_trace_1rec(tdb, "tdb_chainunlock_read", key);
760 return tdb_unlock_list(tdb, h & ((1ULL << tdb->header.v.hash_bits)-1),
764 /* record lock stops delete underneath */
765 int tdb_lock_record(struct tdb_context *tdb, tdb_off_t off)
767 if (tdb->allrecord_lock.count) {
770 return off ? tdb_brlock(tdb, F_RDLCK, off, 1, TDB_LOCK_WAIT) : 0;
774 Write locks override our own fcntl readlocks, so check it here.
775 Note this is meant to be F_SETLK, *not* F_SETLKW, as it's not
776 an error to fail to get the lock here.
778 int tdb_write_lock_record(struct tdb_context *tdb, tdb_off_t off)
780 struct tdb_traverse_lock *i;
781 for (i = &tdb->travlocks; i; i = i->next)
784 if (tdb->allrecord_lock.count) {
785 if (tdb->allrecord_lock.ltype == F_WRLCK) {
790 return tdb_brlock(tdb, F_WRLCK, off, 1, TDB_LOCK_NOWAIT|TDB_LOCK_PROBE);
793 int tdb_write_unlock_record(struct tdb_context *tdb, tdb_off_t off)
795 if (tdb->allrecord_lock.count) {
798 return tdb_brunlock(tdb, F_WRLCK, off, 1);
801 /* fcntl locks don't stack: avoid unlocking someone else's */
802 int tdb_unlock_record(struct tdb_context *tdb, tdb_off_t off)
804 struct tdb_traverse_lock *i;
807 if (tdb->allrecord_lock.count) {
813 for (i = &tdb->travlocks; i; i = i->next)
816 return (count == 1 ? tdb_brunlock(tdb, F_RDLCK, off, 1) : 0);
819 /* The transaction code uses this to remove all locks. */
820 void tdb_release_transaction_locks(struct tdb_context *tdb)
824 if (tdb->allrecord_lock.count != 0) {
825 tdb_off_t hash_size, free_size;
827 hash_size = (1ULL << tdb->header.v.hash_bits)
829 free_size = tdb->header.v.free_zones
830 * (tdb->header.v.free_buckets + 1) * sizeof(tdb_off_t);
832 tdb_brunlock(tdb, tdb->allrecord_lock.ltype,
833 tdb->header.v.hash_off, hash_size);
834 tdb_brunlock(tdb, tdb->allrecord_lock.ltype,
835 tdb->header.v.free_off, free_size);
836 tdb->allrecord_lock.count = 0;
837 tdb->allrecord_lock.ltype = 0;
840 for (i = 0; i<tdb->num_lockrecs; i++) {
841 struct tdb_lock_type *lck = &tdb->lockrecs[i];
843 tdb_brunlock(tdb, lck->ltype, lck->off, 1);
845 tdb->num_lockrecs = 0;
846 SAFE_FREE(tdb->lockrecs);
847 tdb->header_uptodate = false;