-int tdb_delete(struct tdb_context *tdb, struct tdb_data key)
-{
- tdb_off_t off, start, end, room, extra_locks = 0;
- uint64_t h;
- int ret;
-
- h = tdb_hash(tdb, key.dptr, key.dsize);
- off = find_bucket_and_lock(tdb, &key, h, &start, &end, &room, F_WRLCK);
- if (off == TDB_OFF_ERR)
- return -1;
-
- if (off == 0) {
- unlock_lists(tdb, start, end, F_WRLCK);
- tdb->ecode = TDB_ERR_NOEXIST;
- return -1;
- }
-
- ret = unlink_used_record(tdb, end, &extra_locks);
- if (unlikely(ret == 1)) {
- unsigned int i;
-
- unlock_lists(tdb, start, end, F_WRLCK);
-
- /* We need extra locks at the start. */
- for (i = 0; i < extra_locks; i++) {
- if (tdb_lock_list(tdb, i, F_WRLCK, TDB_LOCK_WAIT)
- == TDB_OFF_ERR) {
- if (i)
- unlock_lists(tdb, 0, i-1, F_WRLCK);
- return -1;
- }
- }
- /* Try again now we're holding more locks. */
- ret = tdb_delete(tdb, key);
- unlock_lists(tdb, 0, i, F_WRLCK);
- return ret;
- }
- unlock_lists(tdb, start, end, F_WRLCK);
- return ret;
-}
-