Commit 6520c831 authored by Rusty Russell's avatar Rusty Russell

tdb2: remove all the dead code

I left much tdb1 code in various files for inspiration, and in case I needed
it later.  Now we have all the major features implemented, remove it.
parent 5e8b9af5
...@@ -536,114 +536,6 @@ int tdb_access_commit(struct tdb_context *tdb, void *p) ...@@ -536,114 +536,6 @@ int tdb_access_commit(struct tdb_context *tdb, void *p)
return ret; return ret;
} }
#if 0
/* write a lump of data at a specified offset */
static int tdb_write(struct tdb_context *tdb, tdb_off_t off,
const void *buf, tdb_len_t len)
{
if (len == 0) {
return 0;
}
if (tdb->read_only || tdb->traverse_read) {
tdb->ecode = TDB_ERR_RDONLY;
return -1;
}
if (tdb->methods->tdb_oob(tdb, off + len, 0) != 0)
return -1;
if (tdb->map_ptr) {
memcpy(off + (char *)tdb->map_ptr, buf, len);
} else {
ssize_t written = pwrite(tdb->fd, buf, len, off);
if ((written != (ssize_t)len) && (written != -1)) {
/* try once more */
tdb->ecode = TDB_ERR_IO;
TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_write: wrote only "
"%d of %d bytes at %d, trying once more\n",
(int)written, len, off));
written = pwrite(tdb->fd, (const char *)buf+written,
len-written,
off+written);
}
if (written == -1) {
/* Ensure ecode is set for log fn. */
tdb->ecode = TDB_ERR_IO;
TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_write failed at %d "
"len=%d (%s)\n", off, len, strerror(errno)));
return -1;
} else if (written != (ssize_t)len) {
tdb->ecode = TDB_ERR_IO;
TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_write: failed to "
"write %d bytes at %d in two attempts\n",
len, off));
return -1;
}
}
return 0;
}
/*
do an unlocked scan of the hash table heads to find the next non-zero head. The value
will then be confirmed with the lock held
*/
static void tdb_next_hash_chain(struct tdb_context *tdb, uint32_t *chain)
{
uint32_t h = *chain;
if (tdb->map_ptr) {
for (;h < tdb->header.hash_size;h++) {
if (0 != *(uint32_t *)(TDB_HASH_TOP(h) + (unsigned char *)tdb->map_ptr)) {
break;
}
}
} else {
uint32_t off=0;
for (;h < tdb->header.hash_size;h++) {
if (tdb_ofs_read(tdb, TDB_HASH_TOP(h), &off) != 0 || off != 0) {
break;
}
}
}
(*chain) = h;
}
/* read/write a tdb_off_t */
int tdb_ofs_read(struct tdb_context *tdb, tdb_off_t offset, tdb_off_t *d)
{
return tdb->methods->tdb_read(tdb, offset, (char*)d, sizeof(*d), DOCONV());
}
int tdb_ofs_write(struct tdb_context *tdb, tdb_off_t offset, tdb_off_t *d)
{
tdb_off_t off = *d;
return tdb->methods->tdb_write(tdb, offset, CONVERT(off), sizeof(*d));
}
/* read/write a record */
int tdb_rec_read(struct tdb_context *tdb, tdb_off_t offset, struct tdb_record *rec)
{
if (tdb->methods->tdb_read(tdb, offset, rec, sizeof(*rec),DOCONV()) == -1)
return -1;
if (TDB_BAD_MAGIC(rec)) {
/* Ensure ecode is set for log fn. */
tdb->ecode = TDB_ERR_CORRUPT;
TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_rec_read bad magic 0x%x at offset=%d\n", rec->magic, offset));
return -1;
}
return tdb->methods->tdb_oob(tdb, rec->next+sizeof(*rec), 0);
}
int tdb_rec_write(struct tdb_context *tdb, tdb_off_t offset, struct tdb_record *rec)
{
struct tdb_record r = *rec;
return tdb->methods->tdb_write(tdb, offset, CONVERT(r), sizeof(r));
}
#endif
static void *tdb_direct(struct tdb_context *tdb, tdb_off_t off, size_t len) static void *tdb_direct(struct tdb_context *tdb, tdb_off_t off, size_t len)
{ {
if (unlikely(!tdb->map_ptr)) if (unlikely(!tdb->map_ptr))
......
...@@ -614,52 +614,6 @@ bool tdb_has_hash_locks(struct tdb_context *tdb) ...@@ -614,52 +614,6 @@ bool tdb_has_hash_locks(struct tdb_context *tdb)
return false; 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) static bool tdb_has_free_lock(struct tdb_context *tdb)
{ {
unsigned int i; unsigned int i;
...@@ -781,117 +735,6 @@ void tdb_unlock_free_bucket(struct tdb_context *tdb, tdb_off_t b_off) ...@@ -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); 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) void tdb_lock_init(struct tdb_context *tdb)
{ {
tdb->num_lockrecs = 0; tdb->num_lockrecs = 0;
......
...@@ -507,59 +507,6 @@ int next_in_hash(struct tdb_context *tdb, int ltype, ...@@ -507,59 +507,6 @@ int next_in_hash(struct tdb_context *tdb, int ltype,
int tdb_transaction_recover(struct tdb_context *tdb); int tdb_transaction_recover(struct tdb_context *tdb);
bool tdb_needs_recovery(struct tdb_context *tdb); bool tdb_needs_recovery(struct tdb_context *tdb);
#if 0
/* Low-level locking primitives. */
int tdb_nest_lock(struct tdb_context *tdb, tdb_off_t offset, int ltype,
enum tdb_lock_flags flags);
int tdb_nest_unlock(struct tdb_context *tdb, tdb_off_t offset, int ltype);
int tdb_munmap(struct tdb_context *tdb);
void tdb_mmap(struct tdb_context *tdb);
int tdb_lock(struct tdb_context *tdb, int list, int ltype);
int tdb_lock_nonblock(struct tdb_context *tdb, int list, int ltype);
bool tdb_have_locks(struct tdb_context *tdb);
int tdb_unlock(struct tdb_context *tdb, int list, int ltype);
int tdb_brlock(struct tdb_context *tdb,
int rw_type, tdb_off_t offset, size_t len,
enum tdb_lock_flags flags);
int tdb_brunlock(struct tdb_context *tdb,
int rw_type, tdb_off_t offset, size_t len);
bool tdb_have_extra_locks(struct tdb_context *tdb);
void tdb_release_extra_locks(struct tdb_context *tdb);
int tdb_transaction_lock(struct tdb_context *tdb, int ltype);
int tdb_transaction_unlock(struct tdb_context *tdb, int ltype);
int tdb_allrecord_lock(struct tdb_context *tdb, int ltype,
enum tdb_lock_flags flags, bool upgradable);
int tdb_allrecord_unlock(struct tdb_context *tdb, int ltype);
int tdb_allrecord_upgrade(struct tdb_context *tdb);
int tdb_write_lock_record(struct tdb_context *tdb, tdb_off_t off);
int tdb_write_unlock_record(struct tdb_context *tdb, tdb_off_t off);
int tdb_ofs_read(struct tdb_context *tdb, tdb_off_t offset, tdb_off_t *d);
int tdb_ofs_write(struct tdb_context *tdb, tdb_off_t offset, tdb_off_t *d);
int tdb_free(struct tdb_context *tdb, tdb_off_t offset, struct tdb_record *rec);
tdb_off_t tdb_allocate(struct tdb_context *tdb, tdb_len_t length, struct tdb_record *rec);
int tdb_ofs_read(struct tdb_context *tdb, tdb_off_t offset, tdb_off_t *d);
int tdb_ofs_write(struct tdb_context *tdb, tdb_off_t offset, tdb_off_t *d);
int tdb_lock_record(struct tdb_context *tdb, tdb_off_t off);
int tdb_unlock_record(struct tdb_context *tdb, tdb_off_t off);
bool tdb_needs_recovery(struct tdb_context *tdb);
int tdb_rec_read(struct tdb_context *tdb, tdb_off_t offset, struct tdb_record *rec);
int tdb_rec_write(struct tdb_context *tdb, tdb_off_t offset, struct tdb_record *rec);
int tdb_do_delete(struct tdb_context *tdb, tdb_off_t rec_ptr, struct tdb_record *rec);
unsigned char *tdb_alloc_read(struct tdb_context *tdb, tdb_off_t offset, tdb_len_t len);
int tdb_parse_data(struct tdb_context *tdb, TDB_DATA key,
tdb_off_t offset, tdb_len_t len,
int (*parser)(TDB_DATA key, TDB_DATA data,
void *private_data),
void *private_data);
tdb_off_t tdb_find_lock_hash(struct tdb_context *tdb, TDB_DATA key, uint32_t hash, int locktype,
struct tdb_record *rec);
void tdb_io_init(struct tdb_context *tdb);
int tdb_expand(struct tdb_context *tdb, tdb_off_t size);
int tdb_rec_free_read(struct tdb_context *tdb, tdb_off_t off,
struct tdb_record *rec);
#endif
#ifdef TDB_TRACE #ifdef TDB_TRACE
void tdb_trace(struct tdb_context *tdb, const char *op); void tdb_trace(struct tdb_context *tdb, const char *op);
void tdb_trace_seqnum(struct tdb_context *tdb, uint32_t seqnum, const char *op); void tdb_trace_seqnum(struct tdb_context *tdb, uint32_t seqnum, const char *op);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment