From: Rusty Russell Date: Tue, 23 Nov 2010 01:40:32 +0000 (+1030) Subject: tdb2: remove all the dead code X-Git-Url: http://git.ozlabs.org/?p=ccan;a=commitdiff_plain;h=6520c8318b9b8f2d92ae4b9f062788b7e4035aac;hp=5e8b9af5e7fe5f1ccac407873a3b782b8a629782;ds=sidebyside 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. --- diff --git a/ccan/tdb2/io.c b/ccan/tdb2/io.c index 676f4942..6c8f847b 100644 --- a/ccan/tdb2/io.c +++ b/ccan/tdb2/io.c @@ -536,114 +536,6 @@ int tdb_access_commit(struct tdb_context *tdb, void *p) 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) { if (unlikely(!tdb->map_ptr)) diff --git a/ccan/tdb2/lock.c b/ccan/tdb2/lock.c index a4cfd26c..fe607243 100644 --- a/ccan/tdb2/lock.c +++ b/ccan/tdb2/lock.c @@ -614,52 +614,6 @@ bool tdb_has_hash_locks(struct tdb_context *tdb) 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) { unsigned int i; @@ -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); } -#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; inum_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) { tdb->num_lockrecs = 0; diff --git a/ccan/tdb2/private.h b/ccan/tdb2/private.h index 46a0e051..22014759 100644 --- a/ccan/tdb2/private.h +++ b/ccan/tdb2/private.h @@ -507,59 +507,6 @@ int next_in_hash(struct tdb_context *tdb, int ltype, int tdb_transaction_recover(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 void tdb_trace(struct tdb_context *tdb, const char *op); void tdb_trace_seqnum(struct tdb_context *tdb, uint32_t seqnum, const char *op);