+
+bool tdb_have_extra_locks(struct tdb_context *tdb)
+{
+ unsigned int extra = tdb->num_lockrecs;
+
+ if (tdb->allrecord_lock.count) {
+ return true;
+ }
+
+ /* In a transaction, we expect to hold the transaction lock */
+ if (tdb->transaction && find_nestlock(tdb, TRANSACTION_LOCK)) {
+ extra--;
+ }
+
+ return extra;
+}
+
+/* The transaction code uses this to remove all locks. */
+void tdb_release_extra_locks(struct tdb_context *tdb)
+{
+ unsigned int i, extra = 0;
+
+ if (tdb->allrecord_lock.count != 0) {
+ tdb_brunlock(tdb, tdb->allrecord_lock.ltype,
+ FREELIST_TOP, 4*tdb->header.hash_size);
+ tdb->allrecord_lock.count = 0;
+ }
+
+ for (i=0;i<tdb->num_lockrecs;i++) {
+ struct tdb_lock_type *lck = &tdb->lockrecs[i];
+
+ if (tdb->transaction && lck->off == TRANSACTION_LOCK) {
+ tdb->lockrecs[extra++] = *lck;
+ } else {
+ tdb_brunlock(tdb, lck->ltype, lck->off, 1);
+ }
+ }
+ tdb->num_locks = extra;
+ tdb->num_lockrecs = extra;
+ if (tdb->num_lockrecs == 0) {
+ SAFE_FREE(tdb->lockrecs);
+ }
+}