- tdb_off_t hash_size;
-
- /* FIXME: There are no locks on read-only dbs */
- if (tdb->read_only) {
- tdb->ecode = TDB_ERR_LOCK;
- tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv,
- "tdb_allrecord_unlock: read-only\n");
- return -1;
- }
-
- if (tdb->allrecord_lock.count == 0) {
- tdb->ecode = TDB_ERR_LOCK;
- tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv,
- "tdb_allrecord_unlock: not locked!\n");
- return -1;
- }
-
- /* Upgradable locks are marked as write locks. */
- if (tdb->allrecord_lock.ltype != ltype
- && (!tdb->allrecord_lock.off || ltype != F_RDLCK)) {
- tdb->ecode = TDB_ERR_LOCK;
- tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv,
- "tdb_allrecord_unlock: have %s lock\n",
- tdb->allrecord_lock.ltype == F_RDLCK
- ? "read" : "write");
- return -1;
- }
-
- if (tdb->allrecord_lock.count > 1) {
- tdb->allrecord_lock.count--;
- return 0;
- }
-
- tdb->allrecord_lock.count = 0;
- tdb->allrecord_lock.ltype = 0;
- tdb->header_uptodate = false;
-
- hash_size = (1ULL << tdb->header.v.hash_bits);
-
- return tdb_brunlock(tdb, ltype, TDB_HASH_LOCK_START, hash_size);