Commit 8a47d50d authored by Rusty Russell's avatar Rusty Russell

tdb2: Make tdb1 share tdb_store flags, struct tdb_data and TDB_MAGIC_FOOD.

parent 91993735
...@@ -35,10 +35,6 @@ ...@@ -35,10 +35,6 @@
#include <sys/stat.h> #include <sys/stat.h>
#endif #endif
/** Flags to tdb1_store() */
#define TDB1_REPLACE 1 /** Unused */
#define TDB1_INSERT 2 /** Don't overwrite an existing entry */
#define TDB1_MODIFY 3 /** Don't create an existing entry */
/** Flags for tdb1_open() */ /** Flags for tdb1_open() */
#define TDB1_DEFAULT 0 /** just a readability place holder */ #define TDB1_DEFAULT 0 /** just a readability place holder */
...@@ -55,19 +51,13 @@ ...@@ -55,19 +51,13 @@
#define TDB1_DISALLOW_NESTING 1024 /** Disallow transactions to nest */ #define TDB1_DISALLOW_NESTING 1024 /** Disallow transactions to nest */
#define TDB1_INCOMPATIBLE_HASH 2048 /** Better hashing: can't be opened by tdb < 1.2.6. */ #define TDB1_INCOMPATIBLE_HASH 2048 /** Better hashing: can't be opened by tdb < 1.2.6. */
/** The tdb data structure */
typedef struct TDB1_DATA {
unsigned char *dptr;
size_t dsize;
} TDB1_DATA;
/** This is the context structure that is returned from a db open. */ /** This is the context structure that is returned from a db open. */
typedef struct tdb1_context TDB1_CONTEXT; typedef struct tdb1_context TDB1_CONTEXT;
typedef int (*tdb1_traverse_func)(struct tdb1_context *, TDB1_DATA, TDB1_DATA, void *); typedef int (*tdb1_traverse_func)(struct tdb1_context *, TDB_DATA, TDB_DATA, void *);
typedef void (*tdb1_log_func)(struct tdb1_context *, enum tdb_log_level, enum TDB_ERROR, typedef void (*tdb1_log_func)(struct tdb1_context *, enum tdb_log_level, enum TDB_ERROR,
const char *, void *); const char *, void *);
typedef unsigned int (*tdb1_hash_func)(TDB1_DATA *key); typedef unsigned int (*tdb1_hash_func)(TDB_DATA *key);
struct tdb1_logging_context { struct tdb1_logging_context {
tdb1_log_func log_fn; tdb1_log_func log_fn;
...@@ -84,30 +74,30 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag ...@@ -84,30 +74,30 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag
void tdb1_set_max_dead(struct tdb1_context *tdb, int max_dead); void tdb1_set_max_dead(struct tdb1_context *tdb, int max_dead);
TDB1_DATA tdb1_fetch(struct tdb1_context *tdb, TDB1_DATA key); TDB_DATA tdb1_fetch(struct tdb1_context *tdb, TDB_DATA key);
int tdb1_parse_record(struct tdb1_context *tdb, TDB1_DATA key, int tdb1_parse_record(struct tdb1_context *tdb, TDB_DATA key,
int (*parser)(TDB1_DATA key, TDB1_DATA data, int (*parser)(TDB_DATA key, TDB_DATA data,
void *private_data), void *private_data),
void *private_data); void *private_data);
int tdb1_delete(struct tdb1_context *tdb, TDB1_DATA key); int tdb1_delete(struct tdb1_context *tdb, TDB_DATA key);
int tdb1_store(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA dbuf, int flag); int tdb1_store(struct tdb1_context *tdb, TDB_DATA key, TDB_DATA dbuf, int flag);
int tdb1_append(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA new_dbuf); int tdb1_append(struct tdb1_context *tdb, TDB_DATA key, TDB_DATA new_dbuf);
int tdb1_close(struct tdb1_context *tdb); int tdb1_close(struct tdb1_context *tdb);
TDB1_DATA tdb1_firstkey(struct tdb1_context *tdb); TDB_DATA tdb1_firstkey(struct tdb1_context *tdb);
TDB1_DATA tdb1_nextkey(struct tdb1_context *tdb, TDB1_DATA key); TDB_DATA tdb1_nextkey(struct tdb1_context *tdb, TDB_DATA key);
int tdb1_traverse(struct tdb1_context *tdb, tdb1_traverse_func fn, void *private_data); int tdb1_traverse(struct tdb1_context *tdb, tdb1_traverse_func fn, void *private_data);
int tdb1_traverse_read(struct tdb1_context *tdb, tdb1_traverse_func fn, void *private_data); int tdb1_traverse_read(struct tdb1_context *tdb, tdb1_traverse_func fn, void *private_data);
int tdb1_exists(struct tdb1_context *tdb, TDB1_DATA key); int tdb1_exists(struct tdb1_context *tdb, TDB_DATA key);
int tdb1_lockall(struct tdb1_context *tdb); int tdb1_lockall(struct tdb1_context *tdb);
...@@ -131,19 +121,19 @@ int tdb1_hash_size(struct tdb1_context *tdb); ...@@ -131,19 +121,19 @@ int tdb1_hash_size(struct tdb1_context *tdb);
void tdb1_increment_seqnum_nonblock(struct tdb1_context *tdb); void tdb1_increment_seqnum_nonblock(struct tdb1_context *tdb);
unsigned int tdb1_jenkins_hash(TDB1_DATA *key); unsigned int tdb1_jenkins_hash(TDB_DATA *key);
int tdb1_check(struct tdb1_context *tdb, int tdb1_check(struct tdb1_context *tdb,
int (*check) (TDB1_DATA key, TDB1_DATA data, void *private_data), int (*check) (TDB_DATA key, TDB_DATA data, void *private_data),
void *private_data); void *private_data);
/* @} ******************************************************************/ /* @} ******************************************************************/
/* Low level locking functions: use with care */ /* Low level locking functions: use with care */
int tdb1_chainlock(struct tdb1_context *tdb, TDB1_DATA key); int tdb1_chainlock(struct tdb1_context *tdb, TDB_DATA key);
int tdb1_chainunlock(struct tdb1_context *tdb, TDB1_DATA key); int tdb1_chainunlock(struct tdb1_context *tdb, TDB_DATA key);
int tdb1_chainlock_read(struct tdb1_context *tdb, TDB1_DATA key); int tdb1_chainlock_read(struct tdb1_context *tdb, TDB_DATA key);
int tdb1_chainunlock_read(struct tdb1_context *tdb, TDB1_DATA key); int tdb1_chainunlock_read(struct tdb1_context *tdb, TDB_DATA key);
/* wipe and repack */ /* wipe and repack */
...@@ -153,6 +143,6 @@ int tdb1_repack(struct tdb1_context *tdb); ...@@ -153,6 +143,6 @@ int tdb1_repack(struct tdb1_context *tdb);
/* Debug functions. Not used in production. */ /* Debug functions. Not used in production. */
char *tdb1_summary(struct tdb1_context *tdb); char *tdb1_summary(struct tdb1_context *tdb);
extern TDB1_DATA tdb1_null; extern TDB_DATA tdb1_null;
#endif /* tdb1.h */ #endif /* tdb1.h */
...@@ -32,7 +32,7 @@ static bool tdb1_check_header(struct tdb1_context *tdb, tdb1_off_t *recovery) ...@@ -32,7 +32,7 @@ static bool tdb1_check_header(struct tdb1_context *tdb, tdb1_off_t *recovery)
if (tdb->methods->tdb1_read(tdb, 0, &hdr, sizeof(hdr), 0) == -1) if (tdb->methods->tdb1_read(tdb, 0, &hdr, sizeof(hdr), 0) == -1)
return false; return false;
if (strcmp(hdr.magic_food, TDB1_MAGIC_FOOD) != 0) if (strcmp(hdr.magic_food, TDB_MAGIC_FOOD) != 0)
goto corrupt; goto corrupt;
TDB1_CONV(hdr); TDB1_CONV(hdr);
...@@ -132,10 +132,10 @@ corrupt: ...@@ -132,10 +132,10 @@ corrupt:
/* Grab some bytes: may copy if can't use mmap. /* Grab some bytes: may copy if can't use mmap.
Caller has already done bounds check. */ Caller has already done bounds check. */
static TDB1_DATA get_bytes(struct tdb1_context *tdb, static TDB_DATA get_bytes(struct tdb1_context *tdb,
tdb1_off_t off, tdb1_len_t len) tdb1_off_t off, tdb1_len_t len)
{ {
TDB1_DATA d; TDB_DATA d;
d.dsize = len; d.dsize = len;
...@@ -147,7 +147,7 @@ static TDB1_DATA get_bytes(struct tdb1_context *tdb, ...@@ -147,7 +147,7 @@ static TDB1_DATA get_bytes(struct tdb1_context *tdb,
} }
/* Frees data if we're not able to simply use mmap. */ /* Frees data if we're not able to simply use mmap. */
static void put_bytes(struct tdb1_context *tdb, TDB1_DATA d) static void put_bytes(struct tdb1_context *tdb, TDB_DATA d)
{ {
if (tdb->transaction == NULL && tdb->map_ptr != NULL) if (tdb->transaction == NULL && tdb->map_ptr != NULL)
return; return;
...@@ -236,10 +236,10 @@ static bool tdb1_check_used_record(struct tdb1_context *tdb, ...@@ -236,10 +236,10 @@ static bool tdb1_check_used_record(struct tdb1_context *tdb,
tdb1_off_t off, tdb1_off_t off,
const struct tdb1_record *rec, const struct tdb1_record *rec,
unsigned char **hashes, unsigned char **hashes,
int (*check)(TDB1_DATA, TDB1_DATA, void *), int (*check)(TDB_DATA, TDB_DATA, void *),
void *private_data) void *private_data)
{ {
TDB1_DATA key, data; TDB_DATA key, data;
if (!tdb1_check_record(tdb, off, rec)) if (!tdb1_check_record(tdb, off, rec))
return false; return false;
...@@ -323,7 +323,7 @@ size_t tdb1_dead_space(struct tdb1_context *tdb, tdb1_off_t off) ...@@ -323,7 +323,7 @@ size_t tdb1_dead_space(struct tdb1_context *tdb, tdb1_off_t off)
} }
int tdb1_check(struct tdb1_context *tdb, int tdb1_check(struct tdb1_context *tdb,
int (*check)(TDB1_DATA key, TDB1_DATA data, void *private_data), int (*check)(TDB_DATA key, TDB_DATA data, void *private_data),
void *private_data) void *private_data)
{ {
unsigned int h; unsigned int h;
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include "tdb1_private.h" #include "tdb1_private.h"
/* This is based on the hash algorithm from gdbm */ /* This is based on the hash algorithm from gdbm */
unsigned int tdb1_old_hash(TDB1_DATA *key) unsigned int tdb1_old_hash(TDB_DATA *key)
{ {
uint32_t value; /* Used to compute the hash value. */ uint32_t value; /* Used to compute the hash value. */
uint32_t i; /* Used to cycle through random values. */ uint32_t i; /* Used to cycle through random values. */
...@@ -339,7 +339,7 @@ static uint32_t hashlittle( const void *key, size_t length ) ...@@ -339,7 +339,7 @@ static uint32_t hashlittle( const void *key, size_t length )
return c; return c;
} }
unsigned int tdb1_jenkins_hash(TDB1_DATA *key) unsigned int tdb1_jenkins_hash(TDB_DATA *key)
{ {
return hashlittle(key->dptr, key->dsize); return hashlittle(key->dptr, key->dsize);
} }
...@@ -427,13 +427,13 @@ unsigned char *tdb1_alloc_read(struct tdb1_context *tdb, tdb1_off_t offset, tdb1 ...@@ -427,13 +427,13 @@ unsigned char *tdb1_alloc_read(struct tdb1_context *tdb, tdb1_off_t offset, tdb1
/* Give a piece of tdb data to a parser */ /* Give a piece of tdb data to a parser */
int tdb1_parse_data(struct tdb1_context *tdb, TDB1_DATA key, int tdb1_parse_data(struct tdb1_context *tdb, TDB_DATA key,
tdb1_off_t offset, tdb1_len_t len, tdb1_off_t offset, tdb1_len_t len,
int (*parser)(TDB1_DATA key, TDB1_DATA data, int (*parser)(TDB_DATA key, TDB_DATA data,
void *private_data), void *private_data),
void *private_data) void *private_data)
{ {
TDB1_DATA data; TDB_DATA data;
int result; int result;
data.dsize = len; data.dsize = len;
......
...@@ -130,7 +130,7 @@ static tdb1_off_t lock_offset(int list) ...@@ -130,7 +130,7 @@ static tdb1_off_t lock_offset(int list)
*/ */
int tdb1_brlock(struct tdb1_context *tdb, int tdb1_brlock(struct tdb1_context *tdb,
int rw_type, tdb1_off_t offset, size_t len, int rw_type, tdb1_off_t offset, size_t len,
enum tdb1_lock_flags flags) enum tdb_lock_flags flags)
{ {
int ret; int ret;
...@@ -145,7 +145,7 @@ int tdb1_brlock(struct tdb1_context *tdb, ...@@ -145,7 +145,7 @@ int tdb1_brlock(struct tdb1_context *tdb,
do { do {
ret = fcntl_lock(tdb, rw_type, offset, len, ret = fcntl_lock(tdb, rw_type, offset, len,
flags & TDB1_LOCK_WAIT); flags & TDB_LOCK_WAIT);
} while (ret == -1 && errno == EINTR); } while (ret == -1 && errno == EINTR);
if (ret == -1) { if (ret == -1) {
...@@ -153,7 +153,7 @@ int tdb1_brlock(struct tdb1_context *tdb, ...@@ -153,7 +153,7 @@ int tdb1_brlock(struct tdb1_context *tdb,
/* Generic lock error. errno set by fcntl. /* Generic lock error. errno set by fcntl.
* EAGAIN is an expected return from non-blocking * EAGAIN is an expected return from non-blocking
* locks. */ * locks. */
if (!(flags & TDB1_LOCK_PROBE) && errno != EAGAIN) { if (!(flags & TDB_LOCK_PROBE) && errno != EAGAIN) {
tdb_logerr(tdb, TDB_ERR_LOCK, TDB_LOG_ERROR, tdb_logerr(tdb, TDB_ERR_LOCK, TDB_LOG_ERROR,
"tdb1_brlock failed (fd=%d) at offset %d rw_type=%d flags=%d len=%d", "tdb1_brlock failed (fd=%d) at offset %d rw_type=%d flags=%d len=%d",
tdb->fd, offset, rw_type, flags, (int)len); tdb->fd, offset, rw_type, flags, (int)len);
...@@ -213,7 +213,7 @@ int tdb1_allrecord_upgrade(struct tdb1_context *tdb) ...@@ -213,7 +213,7 @@ int tdb1_allrecord_upgrade(struct tdb1_context *tdb)
while (count--) { while (count--) {
struct timeval tv; struct timeval tv;
if (tdb1_brlock(tdb, F_WRLCK, TDB1_FREELIST_TOP, 0, if (tdb1_brlock(tdb, F_WRLCK, TDB1_FREELIST_TOP, 0,
TDB1_LOCK_WAIT|TDB1_LOCK_PROBE) == 0) { TDB_LOCK_WAIT|TDB_LOCK_PROBE) == 0) {
tdb->allrecord_lock.ltype = F_WRLCK; tdb->allrecord_lock.ltype = F_WRLCK;
tdb->allrecord_lock.off = 0; tdb->allrecord_lock.off = 0;
return 0; return 0;
...@@ -246,7 +246,7 @@ static struct tdb1_lock_type *tdb1_find_nestlock(struct tdb1_context *tdb, ...@@ -246,7 +246,7 @@ static struct tdb1_lock_type *tdb1_find_nestlock(struct tdb1_context *tdb,
/* lock an offset in the database. */ /* lock an offset in the database. */
int tdb1_nest_lock(struct tdb1_context *tdb, uint32_t offset, int ltype, int tdb1_nest_lock(struct tdb1_context *tdb, uint32_t offset, int ltype,
enum tdb1_lock_flags flags) enum tdb_lock_flags flags)
{ {
struct tdb1_lock_type *new_lck; struct tdb1_lock_type *new_lck;
...@@ -298,11 +298,11 @@ static int tdb1_lock_and_recover(struct tdb1_context *tdb) ...@@ -298,11 +298,11 @@ static int tdb1_lock_and_recover(struct tdb1_context *tdb)
int ret; int ret;
/* We need to match locking order in transaction commit. */ /* We need to match locking order in transaction commit. */
if (tdb1_brlock(tdb, F_WRLCK, TDB1_FREELIST_TOP, 0, TDB1_LOCK_WAIT)) { if (tdb1_brlock(tdb, F_WRLCK, TDB1_FREELIST_TOP, 0, TDB_LOCK_WAIT)) {
return -1; return -1;
} }
if (tdb1_brlock(tdb, F_WRLCK, TDB1_OPEN_LOCK, 1, TDB1_LOCK_WAIT)) { if (tdb1_brlock(tdb, F_WRLCK, TDB1_OPEN_LOCK, 1, TDB_LOCK_WAIT)) {
tdb1_brunlock(tdb, F_WRLCK, TDB1_FREELIST_TOP, 0); tdb1_brunlock(tdb, F_WRLCK, TDB1_FREELIST_TOP, 0);
return -1; return -1;
} }
...@@ -327,7 +327,7 @@ static bool have_data_locks(const struct tdb1_context *tdb) ...@@ -327,7 +327,7 @@ static bool have_data_locks(const struct tdb1_context *tdb)
} }
static int tdb1_lock_list(struct tdb1_context *tdb, int list, int ltype, static int tdb1_lock_list(struct tdb1_context *tdb, int list, int ltype,
enum tdb1_lock_flags waitflag) enum tdb_lock_flags waitflag)
{ {
int ret; int ret;
bool check = false; bool check = false;
...@@ -363,7 +363,7 @@ int tdb1_lock(struct tdb1_context *tdb, int list, int ltype) ...@@ -363,7 +363,7 @@ int tdb1_lock(struct tdb1_context *tdb, int list, int ltype)
{ {
int ret; int ret;
ret = tdb1_lock_list(tdb, list, ltype, TDB1_LOCK_WAIT); ret = tdb1_lock_list(tdb, list, ltype, TDB_LOCK_WAIT);
if (ret) { if (ret) {
tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR, tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
"tdb1_lock failed on list %d " "tdb1_lock failed on list %d "
...@@ -447,7 +447,7 @@ int tdb1_unlock(struct tdb1_context *tdb, int list, int ltype) ...@@ -447,7 +447,7 @@ int tdb1_unlock(struct tdb1_context *tdb, int list, int ltype)
get the transaction lock get the transaction lock
*/ */
int tdb1_transaction_lock(struct tdb1_context *tdb, int ltype, int tdb1_transaction_lock(struct tdb1_context *tdb, int ltype,
enum tdb1_lock_flags lockflags) enum tdb_lock_flags lockflags)
{ {
return tdb1_nest_lock(tdb, TDB1_TRANSACTION_LOCK, ltype, lockflags); return tdb1_nest_lock(tdb, TDB1_TRANSACTION_LOCK, ltype, lockflags);
} }
...@@ -462,7 +462,7 @@ int tdb1_transaction_unlock(struct tdb1_context *tdb, int ltype) ...@@ -462,7 +462,7 @@ int tdb1_transaction_unlock(struct tdb1_context *tdb, int ltype)
/* Returns 0 if all done, -1 if error, 1 if ok. */ /* Returns 0 if all done, -1 if error, 1 if ok. */
static int tdb1_allrecord_check(struct tdb1_context *tdb, int ltype, static int tdb1_allrecord_check(struct tdb1_context *tdb, int ltype,
enum tdb1_lock_flags flags, bool upgradable) enum tdb_lock_flags flags, bool upgradable)
{ {
/* There are no locks on read-only dbs */ /* There are no locks on read-only dbs */
if (tdb->read_only || tdb->traverse_read) { if (tdb->read_only || tdb->traverse_read) {
...@@ -498,11 +498,11 @@ static int tdb1_allrecord_check(struct tdb1_context *tdb, int ltype, ...@@ -498,11 +498,11 @@ static int tdb1_allrecord_check(struct tdb1_context *tdb, int ltype,
/* We only need to lock individual bytes, but Linux merges consecutive locks /* We only need to lock individual bytes, but Linux merges consecutive locks
* so we lock in contiguous ranges. */ * so we lock in contiguous ranges. */
static int tdb1_chainlock_gradual(struct tdb1_context *tdb, static int tdb1_chainlock_gradual(struct tdb1_context *tdb,
int ltype, enum tdb1_lock_flags flags, int ltype, enum tdb_lock_flags flags,
size_t off, size_t len) size_t off, size_t len)
{ {
int ret; int ret;
enum tdb1_lock_flags nb_flags = (flags & ~TDB1_LOCK_WAIT); enum tdb_lock_flags nb_flags = (flags & ~TDB_LOCK_WAIT);
if (len <= 4) { if (len <= 4) {
/* Single record. Just do blocking lock. */ /* Single record. Just do blocking lock. */
...@@ -533,7 +533,7 @@ static int tdb1_chainlock_gradual(struct tdb1_context *tdb, ...@@ -533,7 +533,7 @@ static int tdb1_chainlock_gradual(struct tdb1_context *tdb,
* other way of guaranteeing exclusivity (ie. transaction write lock). * other way of guaranteeing exclusivity (ie. transaction write lock).
* We do the locking gradually to avoid being starved by smaller locks. */ * We do the locking gradually to avoid being starved by smaller locks. */
int tdb1_allrecord_lock(struct tdb1_context *tdb, int ltype, int tdb1_allrecord_lock(struct tdb1_context *tdb, int ltype,
enum tdb1_lock_flags flags, bool upgradable) enum tdb_lock_flags flags, bool upgradable)
{ {
switch (tdb1_allrecord_check(tdb, ltype, flags, upgradable)) { switch (tdb1_allrecord_check(tdb, ltype, flags, upgradable)) {
case -1: case -1:
...@@ -622,7 +622,7 @@ int tdb1_allrecord_unlock(struct tdb1_context *tdb, int ltype) ...@@ -622,7 +622,7 @@ int tdb1_allrecord_unlock(struct tdb1_context *tdb, int ltype)
/* lock entire database with write lock */ /* lock entire database with write lock */
int tdb1_lockall(struct tdb1_context *tdb) int tdb1_lockall(struct tdb1_context *tdb)
{ {
return tdb1_allrecord_lock(tdb, F_WRLCK, TDB1_LOCK_WAIT, false); return tdb1_allrecord_lock(tdb, F_WRLCK, TDB_LOCK_WAIT, false);
} }
/* unlock entire database with write lock */ /* unlock entire database with write lock */
...@@ -634,7 +634,7 @@ int tdb1_unlockall(struct tdb1_context *tdb) ...@@ -634,7 +634,7 @@ int tdb1_unlockall(struct tdb1_context *tdb)
/* lock entire database with read lock */ /* lock entire database with read lock */
int tdb1_lockall_read(struct tdb1_context *tdb) int tdb1_lockall_read(struct tdb1_context *tdb)
{ {
return tdb1_allrecord_lock(tdb, F_RDLCK, TDB1_LOCK_WAIT, false); return tdb1_allrecord_lock(tdb, F_RDLCK, TDB_LOCK_WAIT, false);
} }
/* unlock entire database with read lock */ /* unlock entire database with read lock */
...@@ -645,25 +645,25 @@ int tdb1_unlockall_read(struct tdb1_context *tdb) ...@@ -645,25 +645,25 @@ int tdb1_unlockall_read(struct tdb1_context *tdb)
/* lock/unlock one hash chain. This is meant to be used to reduce /* lock/unlock one hash chain. This is meant to be used to reduce
contention - it cannot guarantee how many records will be locked */ contention - it cannot guarantee how many records will be locked */
int tdb1_chainlock(struct tdb1_context *tdb, TDB1_DATA key) int tdb1_chainlock(struct tdb1_context *tdb, TDB_DATA key)
{ {
int ret = tdb1_lock(tdb, TDB1_BUCKET(tdb->hash_fn(&key)), F_WRLCK); int ret = tdb1_lock(tdb, TDB1_BUCKET(tdb->hash_fn(&key)), F_WRLCK);
return ret; return ret;
} }
int tdb1_chainunlock(struct tdb1_context *tdb, TDB1_DATA key) int tdb1_chainunlock(struct tdb1_context *tdb, TDB_DATA key)
{ {
return tdb1_unlock(tdb, TDB1_BUCKET(tdb->hash_fn(&key)), F_WRLCK); return tdb1_unlock(tdb, TDB1_BUCKET(tdb->hash_fn(&key)), F_WRLCK);
} }
int tdb1_chainlock_read(struct tdb1_context *tdb, TDB1_DATA key) int tdb1_chainlock_read(struct tdb1_context *tdb, TDB_DATA key)
{ {
int ret; int ret;
ret = tdb1_lock(tdb, TDB1_BUCKET(tdb->hash_fn(&key)), F_RDLCK); ret = tdb1_lock(tdb, TDB1_BUCKET(tdb->hash_fn(&key)), F_RDLCK);
return ret; return ret;
} }
int tdb1_chainunlock_read(struct tdb1_context *tdb, TDB1_DATA key) int tdb1_chainunlock_read(struct tdb1_context *tdb, TDB_DATA key)
{ {
return tdb1_unlock(tdb, TDB1_BUCKET(tdb->hash_fn(&key)), F_RDLCK); return tdb1_unlock(tdb, TDB1_BUCKET(tdb->hash_fn(&key)), F_RDLCK);
} }
...@@ -674,7 +674,7 @@ int tdb1_lock_record(struct tdb1_context *tdb, tdb1_off_t off) ...@@ -674,7 +674,7 @@ int tdb1_lock_record(struct tdb1_context *tdb, tdb1_off_t off)
if (tdb->allrecord_lock.count) { if (tdb->allrecord_lock.count) {
return 0; return 0;
} }
return off ? tdb1_brlock(tdb, F_RDLCK, off, 1, TDB1_LOCK_WAIT) : 0; return off ? tdb1_brlock(tdb, F_RDLCK, off, 1, TDB_LOCK_WAIT) : 0;
} }
/* /*
...@@ -694,7 +694,7 @@ int tdb1_write_lock_record(struct tdb1_context *tdb, tdb1_off_t off) ...@@ -694,7 +694,7 @@ int tdb1_write_lock_record(struct tdb1_context *tdb, tdb1_off_t off)
} }
return -1; return -1;
} }
return tdb1_brlock(tdb, F_WRLCK, off, 1, TDB1_LOCK_NOWAIT|TDB1_LOCK_PROBE); return tdb1_brlock(tdb, F_WRLCK, off, 1, TDB_LOCK_NOWAIT|TDB_LOCK_PROBE);
} }
int tdb1_write_unlock_record(struct tdb1_context *tdb, tdb1_off_t off) int tdb1_write_unlock_record(struct tdb1_context *tdb, tdb1_off_t off)
......
...@@ -34,11 +34,11 @@ static struct tdb1_context *tdb1s = NULL; ...@@ -34,11 +34,11 @@ static struct tdb1_context *tdb1s = NULL;
void tdb1_header_hash(struct tdb1_context *tdb, void tdb1_header_hash(struct tdb1_context *tdb,
uint32_t *magic1_hash, uint32_t *magic2_hash) uint32_t *magic1_hash, uint32_t *magic2_hash)
{ {
TDB1_DATA hash_key; TDB_DATA hash_key;
uint32_t tdb1_magic = TDB1_MAGIC; uint32_t tdb1_magic = TDB1_MAGIC;
hash_key.dptr = (unsigned char *)TDB1_MAGIC_FOOD; hash_key.dptr = (unsigned char *)TDB_MAGIC_FOOD;
hash_key.dsize = sizeof(TDB1_MAGIC_FOOD); hash_key.dsize = sizeof(TDB_MAGIC_FOOD);
*magic1_hash = tdb->hash_fn(&hash_key); *magic1_hash = tdb->hash_fn(&hash_key);
hash_key.dptr = (unsigned char *)TDB1_CONV(tdb1_magic); hash_key.dptr = (unsigned char *)TDB1_CONV(tdb1_magic);
...@@ -93,7 +93,7 @@ static int tdb1_new_database(struct tdb1_context *tdb, int hash_size) ...@@ -93,7 +93,7 @@ static int tdb1_new_database(struct tdb1_context *tdb, int hash_size)
TDB1_CONV(*newdb); TDB1_CONV(*newdb);
memcpy(&tdb->header, newdb, sizeof(tdb->header)); memcpy(&tdb->header, newdb, sizeof(tdb->header));
/* Don't endian-convert the magic food! */ /* Don't endian-convert the magic food! */
memcpy(newdb->magic_food, TDB1_MAGIC_FOOD, strlen(TDB1_MAGIC_FOOD)+1); memcpy(newdb->magic_food, TDB_MAGIC_FOOD, strlen(TDB_MAGIC_FOOD)+1);
/* we still have "ret == -1" here */ /* we still have "ret == -1" here */
if (tdb1_write_all(tdb->fd, newdb, size)) if (tdb1_write_all(tdb->fd, newdb, size))
ret = 0; ret = 0;
...@@ -293,7 +293,7 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag ...@@ -293,7 +293,7 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag
fcntl(tdb->fd, F_SETFD, v | FD_CLOEXEC); fcntl(tdb->fd, F_SETFD, v | FD_CLOEXEC);
/* ensure there is only one process initialising at once */ /* ensure there is only one process initialising at once */
if (tdb1_nest_lock(tdb, TDB1_OPEN_LOCK, F_WRLCK, TDB1_LOCK_WAIT) == -1) { if (tdb1_nest_lock(tdb, TDB1_OPEN_LOCK, F_WRLCK, TDB_LOCK_WAIT) == -1) {
tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR, tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
"tdb1_open_ex: failed to get open lock on %s: %s", "tdb1_open_ex: failed to get open lock on %s: %s",
name, strerror(errno)); name, strerror(errno));
...@@ -303,7 +303,7 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag ...@@ -303,7 +303,7 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag
/* we need to zero database if we are the only one with it open */ /* we need to zero database if we are the only one with it open */
if ((tdb1_flags & TDB1_CLEAR_IF_FIRST) && if ((tdb1_flags & TDB1_CLEAR_IF_FIRST) &&
(!tdb->read_only) && (!tdb->read_only) &&
(locked = (tdb1_nest_lock(tdb, TDB1_ACTIVE_LOCK, F_WRLCK, TDB1_LOCK_NOWAIT|TDB1_LOCK_PROBE) == 0))) { (locked = (tdb1_nest_lock(tdb, TDB1_ACTIVE_LOCK, F_WRLCK, TDB_LOCK_NOWAIT|TDB_LOCK_PROBE) == 0))) {
open_flags |= O_CREAT; open_flags |= O_CREAT;
if (ftruncate(tdb->fd, 0) == -1) { if (ftruncate(tdb->fd, 0) == -1) {
tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR, tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
...@@ -316,7 +316,7 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag ...@@ -316,7 +316,7 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag
errno = 0; errno = 0;
if (read(tdb->fd, &tdb->header, sizeof(tdb->header)) != sizeof(tdb->header) if (read(tdb->fd, &tdb->header, sizeof(tdb->header)) != sizeof(tdb->header)
|| strcmp(tdb->header.magic_food, TDB1_MAGIC_FOOD) != 0) { || strcmp(tdb->header.magic_food, TDB_MAGIC_FOOD) != 0) {
if (!(open_flags & O_CREAT) || tdb1_new_database(tdb, hash_size) == -1) { if (!(open_flags & O_CREAT) || tdb1_new_database(tdb, hash_size) == -1) {
if (errno == 0) { if (errno == 0) {
errno = EIO; /* ie bad format or something */ errno = EIO; /* ie bad format or something */
...@@ -401,7 +401,7 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag ...@@ -401,7 +401,7 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag
if (tdb1_flags & TDB1_CLEAR_IF_FIRST) { if (tdb1_flags & TDB1_CLEAR_IF_FIRST) {
/* leave this lock in place to indicate it's in use */ /* leave this lock in place to indicate it's in use */
if (tdb1_nest_lock(tdb, TDB1_ACTIVE_LOCK, F_RDLCK, TDB1_LOCK_WAIT) == -1) { if (tdb1_nest_lock(tdb, TDB1_ACTIVE_LOCK, F_RDLCK, TDB_LOCK_WAIT) == -1) {
goto fail; goto fail;
} }
} }
......
...@@ -63,7 +63,6 @@ typedef uint32_t tdb1_off_t; ...@@ -63,7 +63,6 @@ typedef uint32_t tdb1_off_t;
#define offsetof(t,f) ((unsigned int)&((t *)0)->f) #define offsetof(t,f) ((unsigned int)&((t *)0)->f)
#endif #endif
#define TDB1_MAGIC_FOOD "TDB file\n"
#define TDB1_VERSION (0x26011967 + 6) #define TDB1_VERSION (0x26011967 + 6)
#define TDB1_MAGIC (0x26011999U) #define TDB1_MAGIC (0x26011999U)
#define TDB1_FREE_MAGIC (~TDB1_MAGIC) #define TDB1_FREE_MAGIC (~TDB1_MAGIC)
...@@ -131,7 +130,7 @@ struct tdb1_header { ...@@ -131,7 +130,7 @@ struct tdb1_header {
tdb1_off_t rwlocks; /* obsolete - kept to detect old formats */ tdb1_off_t rwlocks; /* obsolete - kept to detect old formats */
tdb1_off_t recovery_start; /* offset of transaction recovery region */ tdb1_off_t recovery_start; /* offset of transaction recovery region */
tdb1_off_t sequence_number; /* used when TDB1_SEQNUM is set */ tdb1_off_t sequence_number; /* used when TDB1_SEQNUM is set */
uint32_t magic1_hash; /* hash of TDB1_MAGIC_FOOD. */ uint32_t magic1_hash; /* hash of TDB_MAGIC_FOOD. */
uint32_t magic2_hash; /* hash of TDB1_MAGIC. */ uint32_t magic2_hash; /* hash of TDB1_MAGIC. */
tdb1_off_t reserved[27]; tdb1_off_t reserved[27];
}; };
...@@ -149,14 +148,6 @@ struct tdb1_traverse_lock { ...@@ -149,14 +148,6 @@ struct tdb1_traverse_lock {
int lock_rw; int lock_rw;
}; };
enum tdb1_lock_flags {
/* WAIT == F_SETLKW, NOWAIT == F_SETLK */
TDB1_LOCK_NOWAIT = 0,
TDB1_LOCK_WAIT = 1,
/* If set, don't log an error on failure. */
TDB1_LOCK_PROBE = 2,
};
struct tdb1_context; struct tdb1_context;
struct tdb1_methods { struct tdb1_methods {
...@@ -197,7 +188,7 @@ struct tdb1_context { ...@@ -197,7 +188,7 @@ struct tdb1_context {
struct tdb1_traverse_lock travlocks; /* current traversal locks */ struct tdb1_traverse_lock travlocks; /* current traversal locks */
dev_t device; /* uniquely identifies this tdb */ dev_t device; /* uniquely identifies this tdb */
ino_t inode; /* uniquely identifies this tdb */ ino_t inode; /* uniquely identifies this tdb */
unsigned int (*hash_fn)(TDB1_DATA *key); unsigned int (*hash_fn)(TDB_DATA *key);
int open_flags; /* flags used in the open - needed by reopen */ int open_flags; /* flags used in the open - needed by reopen */
const struct tdb1_methods *methods; const struct tdb1_methods *methods;
struct tdb1_transaction *transaction; struct tdb1_transaction *transaction;
...@@ -212,25 +203,25 @@ int tdb1_munmap(struct tdb1_context *tdb); ...@@ -212,25 +203,25 @@ int tdb1_munmap(struct tdb1_context *tdb);
void tdb1_mmap(struct tdb1_context *tdb); void tdb1_mmap(struct tdb1_context *tdb);
int tdb1_lock(struct tdb1_context *tdb, int list, int ltype); int tdb1_lock(struct tdb1_context *tdb, int list, int ltype);
int tdb1_nest_lock(struct tdb1_context *tdb, uint32_t offset, int ltype, int tdb1_nest_lock(struct tdb1_context *tdb, uint32_t offset, int ltype,
enum tdb1_lock_flags flags); enum tdb_lock_flags flags);
int tdb1_nest_unlock(struct tdb1_context *tdb, uint32_t offset, int ltype); int tdb1_nest_unlock(struct tdb1_context *tdb, uint32_t offset, int ltype);
int tdb1_unlock(struct tdb1_context *tdb, int list, int ltype); int tdb1_unlock(struct tdb1_context *tdb, int list, int ltype);
int tdb1_brlock(struct tdb1_context *tdb, int tdb1_brlock(struct tdb1_context *tdb,
int rw_type, tdb1_off_t offset, size_t len, int rw_type, tdb1_off_t offset, size_t len,
enum tdb1_lock_flags flags); enum tdb_lock_flags flags);
int tdb1_brunlock(struct tdb1_context *tdb, int tdb1_brunlock(struct tdb1_context *tdb,
int rw_type, tdb1_off_t offset, size_t len); int rw_type, tdb1_off_t offset, size_t len);
bool tdb1_have_extra_locks(struct tdb1_context *tdb); bool tdb1_have_extra_locks(struct tdb1_context *tdb);
void tdb1_release_transaction_locks(struct tdb1_context *tdb); void tdb1_release_transaction_locks(struct tdb1_context *tdb);
int tdb1_transaction_lock(struct tdb1_context *tdb, int ltype, int tdb1_transaction_lock(struct tdb1_context *tdb, int ltype,
enum tdb1_lock_flags lockflags); enum tdb_lock_flags lockflags);
int tdb1_transaction_unlock(struct tdb1_context *tdb, int ltype); int tdb1_transaction_unlock(struct tdb1_context *tdb, int ltype);
int tdb1_recovery_area(struct tdb1_context *tdb, int tdb1_recovery_area(struct tdb1_context *tdb,
const struct tdb1_methods *methods, const struct tdb1_methods *methods,
tdb1_off_t *recovery_offset, tdb1_off_t *recovery_offset,
struct tdb1_record *rec); struct tdb1_record *rec);
int tdb1_allrecord_lock(struct tdb1_context *tdb, int ltype, int tdb1_allrecord_lock(struct tdb1_context *tdb, int ltype,
enum tdb1_lock_flags flags, bool upgradable); enum tdb_lock_flags flags, bool upgradable);
int tdb1_allrecord_unlock(struct tdb1_context *tdb, int ltype); int tdb1_allrecord_unlock(struct tdb1_context *tdb, int ltype);
int tdb1_allrecord_upgrade(struct tdb1_context *tdb); int tdb1_allrecord_upgrade(struct tdb1_context *tdb);
int tdb1_write_lock_record(struct tdb1_context *tdb, tdb1_off_t off); int tdb1_write_lock_record(struct tdb1_context *tdb, tdb1_off_t off);
...@@ -249,12 +240,12 @@ int tdb1_rec_read(struct tdb1_context *tdb, tdb1_off_t offset, struct tdb1_recor ...@@ -249,12 +240,12 @@ int tdb1_rec_read(struct tdb1_context *tdb, tdb1_off_t offset, struct tdb1_recor
int tdb1_rec_write(struct tdb1_context *tdb, tdb1_off_t offset, struct tdb1_record *rec); int tdb1_rec_write(struct tdb1_context *tdb, tdb1_off_t offset, struct tdb1_record *rec);
int tdb1_do_delete(struct tdb1_context *tdb, tdb1_off_t rec_ptr, struct tdb1_record *rec); int tdb1_do_delete(struct tdb1_context *tdb, tdb1_off_t rec_ptr, struct tdb1_record *rec);
unsigned char *tdb1_alloc_read(struct tdb1_context *tdb, tdb1_off_t offset, tdb1_len_t len); unsigned char *tdb1_alloc_read(struct tdb1_context *tdb, tdb1_off_t offset, tdb1_len_t len);
int tdb1_parse_data(struct tdb1_context *tdb, TDB1_DATA key, int tdb1_parse_data(struct tdb1_context *tdb, TDB_DATA key,
tdb1_off_t offset, tdb1_len_t len, tdb1_off_t offset, tdb1_len_t len,
int (*parser)(TDB1_DATA key, TDB1_DATA data, int (*parser)(TDB_DATA key, TDB_DATA data,
void *private_data), void *private_data),
void *private_data); void *private_data);
tdb1_off_t tdb1_find_lock_hash(struct tdb1_context *tdb, TDB1_DATA key, uint32_t hash, int locktype, tdb1_off_t tdb1_find_lock_hash(struct tdb1_context *tdb, TDB_DATA key, uint32_t hash, int locktype,
struct tdb1_record *rec); struct tdb1_record *rec);
void tdb1_io_init(struct tdb1_context *tdb); void tdb1_io_init(struct tdb1_context *tdb);
int tdb1_expand(struct tdb1_context *tdb, tdb1_off_t size); int tdb1_expand(struct tdb1_context *tdb, tdb1_off_t size);
...@@ -264,6 +255,6 @@ bool tdb1_write_all(int fd, const void *buf, size_t count); ...@@ -264,6 +255,6 @@ bool tdb1_write_all(int fd, const void *buf, size_t count);
int tdb1_transaction_recover(struct tdb1_context *tdb); int tdb1_transaction_recover(struct tdb1_context *tdb);
void tdb1_header_hash(struct tdb1_context *tdb, void tdb1_header_hash(struct tdb1_context *tdb,
uint32_t *magic1_hash, uint32_t *magic2_hash); uint32_t *magic1_hash, uint32_t *magic2_hash);
unsigned int tdb1_old_hash(TDB1_DATA *key); unsigned int tdb1_old_hash(TDB_DATA *key);
size_t tdb1_dead_space(struct tdb1_context *tdb, tdb1_off_t off); size_t tdb1_dead_space(struct tdb1_context *tdb, tdb1_off_t off);
#endif /* CCAN_TDB2_TDB1_PRIVATE_H */ #endif /* CCAN_TDB2_TDB1_PRIVATE_H */
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include "tdb1_private.h" #include "tdb1_private.h"
TDB1_DATA tdb1_null; TDB_DATA tdb1_null;
/* /*
non-blocking increment of the tdb sequence number if the tdb has been opened using non-blocking increment of the tdb sequence number if the tdb has been opened using
...@@ -60,7 +60,7 @@ static void tdb1_increment_seqnum(struct tdb1_context *tdb) ...@@ -60,7 +60,7 @@ static void tdb1_increment_seqnum(struct tdb1_context *tdb)
} }
if (tdb1_nest_lock(tdb, TDB1_SEQNUM_OFS, F_WRLCK, if (tdb1_nest_lock(tdb, TDB1_SEQNUM_OFS, F_WRLCK,
TDB1_LOCK_WAIT|TDB1_LOCK_PROBE) != 0) { TDB_LOCK_WAIT|TDB_LOCK_PROBE) != 0) {
return; return;
} }
...@@ -69,14 +69,14 @@ static void tdb1_increment_seqnum(struct tdb1_context *tdb) ...@@ -69,14 +69,14 @@ static void tdb1_increment_seqnum(struct tdb1_context *tdb)
tdb1_nest_unlock(tdb, TDB1_SEQNUM_OFS, F_WRLCK); tdb1_nest_unlock(tdb, TDB1_SEQNUM_OFS, F_WRLCK);
} }
static int tdb1_key_compare(TDB1_DATA key, TDB1_DATA data, void *private_data) static int tdb1_key_compare(TDB_DATA key, TDB_DATA data, void *private_data)
{ {
return memcmp(data.dptr, key.dptr, data.dsize); return memcmp(data.dptr, key.dptr, data.dsize);
} }
/* Returns 0 on fail. On success, return offset of record, and fills /* Returns 0 on fail. On success, return offset of record, and fills
in rec */ in rec */
static tdb1_off_t tdb1_find(struct tdb1_context *tdb, TDB1_DATA key, uint32_t hash, static tdb1_off_t tdb1_find(struct tdb1_context *tdb, TDB_DATA key, uint32_t hash,
struct tdb1_record *r) struct tdb1_record *r)
{ {
tdb1_off_t rec_ptr; tdb1_off_t rec_ptr;
...@@ -111,7 +111,7 @@ static tdb1_off_t tdb1_find(struct tdb1_context *tdb, TDB1_DATA key, uint32_t ha ...@@ -111,7 +111,7 @@ static tdb1_off_t tdb1_find(struct tdb1_context *tdb, TDB1_DATA key, uint32_t ha
} }
/* As tdb1_find, but if you succeed, keep the lock */ /* As tdb1_find, but if you succeed, keep the lock */
tdb1_off_t tdb1_find_lock_hash(struct tdb1_context *tdb, TDB1_DATA key, uint32_t hash, int locktype, tdb1_off_t tdb1_find_lock_hash(struct tdb1_context *tdb, TDB_DATA key, uint32_t hash, int locktype,
struct tdb1_record *rec) struct tdb1_record *rec)
{ {
uint32_t rec_ptr; uint32_t rec_ptr;
...@@ -123,13 +123,13 @@ tdb1_off_t tdb1_find_lock_hash(struct tdb1_context *tdb, TDB1_DATA key, uint32_t ...@@ -123,13 +123,13 @@ tdb1_off_t tdb1_find_lock_hash(struct tdb1_context *tdb, TDB1_DATA key, uint32_t
return rec_ptr; return rec_ptr;
} }
static TDB1_DATA _tdb1_fetch(struct tdb1_context *tdb, TDB1_DATA key); static TDB_DATA _tdb1_fetch(struct tdb1_context *tdb, TDB_DATA key);
/* update an entry in place - this only works if the new data size /* update an entry in place - this only works if the new data size
is <= the old data size and the key exists. is <= the old data size and the key exists.
on failure return -1. on failure return -1.
*/ */
static int tdb1_update_hash(struct tdb1_context *tdb, TDB1_DATA key, uint32_t hash, TDB1_DATA dbuf) static int tdb1_update_hash(struct tdb1_context *tdb, TDB_DATA key, uint32_t hash, TDB_DATA dbuf)
{ {
struct tdb1_record rec; struct tdb1_record rec;
tdb1_off_t rec_ptr; tdb1_off_t rec_ptr;
...@@ -143,7 +143,7 @@ static int tdb1_update_hash(struct tdb1_context *tdb, TDB1_DATA key, uint32_t ha ...@@ -143,7 +143,7 @@ static int tdb1_update_hash(struct tdb1_context *tdb, TDB1_DATA key, uint32_t ha
if (rec.key_len == key.dsize && if (rec.key_len == key.dsize &&
rec.data_len == dbuf.dsize && rec.data_len == dbuf.dsize &&
rec.full_hash == hash) { rec.full_hash == hash) {
TDB1_DATA data = _tdb1_fetch(tdb, key); TDB_DATA data = _tdb1_fetch(tdb, key);
if (data.dsize == dbuf.dsize && if (data.dsize == dbuf.dsize &&
memcmp(data.dptr, dbuf.dptr, data.dsize) == 0) { memcmp(data.dptr, dbuf.dptr, data.dsize) == 0) {
if (data.dptr) { if (data.dptr) {
...@@ -178,14 +178,14 @@ static int tdb1_update_hash(struct tdb1_context *tdb, TDB1_DATA key, uint32_t ha ...@@ -178,14 +178,14 @@ static int tdb1_update_hash(struct tdb1_context *tdb, TDB1_DATA key, uint32_t ha
/* find an entry in the database given a key */ /* find an entry in the database given a key */
/* If an entry doesn't exist tdb1_err will be set to /* If an entry doesn't exist tdb1_err will be set to
* TDB_ERR_NOEXIST. If a key has no data attached * TDB_ERR_NOEXIST. If a key has no data attached
* then the TDB1_DATA will have zero length but * then the TDB_DATA will have zero length but
* a non-zero pointer * a non-zero pointer
*/ */
static TDB1_DATA _tdb1_fetch(struct tdb1_context *tdb, TDB1_DATA key) static TDB_DATA _tdb1_fetch(struct tdb1_context *tdb, TDB_DATA key)
{ {
tdb1_off_t rec_ptr; tdb1_off_t rec_ptr;
struct tdb1_record rec; struct tdb1_record rec;
TDB1_DATA ret; TDB_DATA ret;
uint32_t hash; uint32_t hash;
/* find which hash bucket it is in */ /* find which hash bucket it is in */
...@@ -200,9 +200,9 @@ static TDB1_DATA _tdb1_fetch(struct tdb1_context *tdb, TDB1_DATA key) ...@@ -200,9 +200,9 @@ static TDB1_DATA _tdb1_fetch(struct tdb1_context *tdb, TDB1_DATA key)
return ret; return ret;
} }
TDB1_DATA tdb1_fetch(struct tdb1_context *tdb, TDB1_DATA key) TDB_DATA tdb1_fetch(struct tdb1_context *tdb, TDB_DATA key)
{ {
TDB1_DATA ret = _tdb1_fetch(tdb, key); TDB_DATA ret = _tdb1_fetch(tdb, key);
return ret; return ret;
} }
...@@ -225,8 +225,8 @@ TDB1_DATA tdb1_fetch(struct tdb1_context *tdb, TDB1_DATA key) ...@@ -225,8 +225,8 @@ TDB1_DATA tdb1_fetch(struct tdb1_context *tdb, TDB1_DATA key)
* Return -1 if the record was not found. * Return -1 if the record was not found.
*/ */
int tdb1_parse_record(struct tdb1_context *tdb, TDB1_DATA key, int tdb1_parse_record(struct tdb1_context *tdb, TDB_DATA key,
int (*parser)(TDB1_DATA key, TDB1_DATA data, int (*parser)(TDB_DATA key, TDB_DATA data,
void *private_data), void *private_data),
void *private_data) void *private_data)
{ {
...@@ -258,7 +258,7 @@ int tdb1_parse_record(struct tdb1_context *tdb, TDB1_DATA key, ...@@ -258,7 +258,7 @@ int tdb1_parse_record(struct tdb1_context *tdb, TDB1_DATA key,
this doesn't match the conventions in the rest of this module, but is this doesn't match the conventions in the rest of this module, but is
compatible with gdbm compatible with gdbm
*/ */
static int tdb1_exists_hash(struct tdb1_context *tdb, TDB1_DATA key, uint32_t hash) static int tdb1_exists_hash(struct tdb1_context *tdb, TDB_DATA key, uint32_t hash)
{ {
struct tdb1_record rec; struct tdb1_record rec;
...@@ -268,7 +268,7 @@ static int tdb1_exists_hash(struct tdb1_context *tdb, TDB1_DATA key, uint32_t ha ...@@ -268,7 +268,7 @@ static int tdb1_exists_hash(struct tdb1_context *tdb, TDB1_DATA key, uint32_t ha
return 1; return 1;
} }
int tdb1_exists(struct tdb1_context *tdb, TDB1_DATA key) int tdb1_exists(struct tdb1_context *tdb, TDB_DATA key)
{ {
uint32_t hash = tdb->hash_fn(&key); uint32_t hash = tdb->hash_fn(&key);
int ret; int ret;
...@@ -374,7 +374,7 @@ static int tdb1_purge_dead(struct tdb1_context *tdb, uint32_t hash) ...@@ -374,7 +374,7 @@ static int tdb1_purge_dead(struct tdb1_context *tdb, uint32_t hash)
} }
/* delete an entry in the database given a key */ /* delete an entry in the database given a key */
static int tdb1_delete_hash(struct tdb1_context *tdb, TDB1_DATA key, uint32_t hash) static int tdb1_delete_hash(struct tdb1_context *tdb, TDB_DATA key, uint32_t hash)
{ {
tdb1_off_t rec_ptr; tdb1_off_t rec_ptr;
struct tdb1_record rec; struct tdb1_record rec;
...@@ -427,7 +427,7 @@ static int tdb1_delete_hash(struct tdb1_context *tdb, TDB1_DATA key, uint32_t ha ...@@ -427,7 +427,7 @@ static int tdb1_delete_hash(struct tdb1_context *tdb, TDB1_DATA key, uint32_t ha
return ret; return ret;
} }
int tdb1_delete(struct tdb1_context *tdb, TDB1_DATA key) int tdb1_delete(struct tdb1_context *tdb, TDB_DATA key)
{ {
uint32_t hash = tdb->hash_fn(&key); uint32_t hash = tdb->hash_fn(&key);
int ret; int ret;
...@@ -465,8 +465,8 @@ static tdb1_off_t tdb1_find_dead(struct tdb1_context *tdb, uint32_t hash, ...@@ -465,8 +465,8 @@ static tdb1_off_t tdb1_find_dead(struct tdb1_context *tdb, uint32_t hash,
return 0; return 0;
} }
static int _tdb1_store(struct tdb1_context *tdb, TDB1_DATA key, static int _tdb1_store(struct tdb1_context *tdb, TDB_DATA key,
TDB1_DATA dbuf, int flag, uint32_t hash) TDB_DATA dbuf, int flag, uint32_t hash)
{ {
struct tdb1_record rec; struct tdb1_record rec;
tdb1_off_t rec_ptr; tdb1_off_t rec_ptr;
...@@ -474,7 +474,7 @@ static int _tdb1_store(struct tdb1_context *tdb, TDB1_DATA key, ...@@ -474,7 +474,7 @@ static int _tdb1_store(struct tdb1_context *tdb, TDB1_DATA key,
int ret = -1; int ret = -1;
/* check for it existing, on insert. */ /* check for it existing, on insert. */
if (flag == TDB1_INSERT) { if (flag == TDB_INSERT) {
if (tdb1_exists_hash(tdb, key, hash)) { if (tdb1_exists_hash(tdb, key, hash)) {
tdb->last_error = TDB_ERR_EXISTS; tdb->last_error = TDB_ERR_EXISTS;
goto fail; goto fail;
...@@ -485,7 +485,7 @@ static int _tdb1_store(struct tdb1_context *tdb, TDB1_DATA key, ...@@ -485,7 +485,7 @@ static int _tdb1_store(struct tdb1_context *tdb, TDB1_DATA key,
goto done; goto done;
} }
if (tdb->last_error == TDB_ERR_NOEXIST && if (tdb->last_error == TDB_ERR_NOEXIST &&
flag == TDB1_MODIFY) { flag == TDB_MODIFY) {
/* if the record doesn't exist and we are in TDB1_MODIFY mode then /* if the record doesn't exist and we are in TDB1_MODIFY mode then
we should fail the store */ we should fail the store */
goto fail; goto fail;
...@@ -497,7 +497,7 @@ static int _tdb1_store(struct tdb1_context *tdb, TDB1_DATA key, ...@@ -497,7 +497,7 @@ static int _tdb1_store(struct tdb1_context *tdb, TDB1_DATA key,
/* delete any existing record - if it doesn't exist we don't /* delete any existing record - if it doesn't exist we don't
care. Doing this first reduces fragmentation, and avoids care. Doing this first reduces fragmentation, and avoids
coalescing with `allocated' block before it's updated. */ coalescing with `allocated' block before it's updated. */
if (flag != TDB1_INSERT) if (flag != TDB_INSERT)
tdb1_delete_hash(tdb, key, hash); tdb1_delete_hash(tdb, key, hash);
/* Copy key+value *before* allocating free space in case malloc /* Copy key+value *before* allocating free space in case malloc
...@@ -596,7 +596,7 @@ static int _tdb1_store(struct tdb1_context *tdb, TDB1_DATA key, ...@@ -596,7 +596,7 @@ static int _tdb1_store(struct tdb1_context *tdb, TDB1_DATA key,
return 0 on success, -1 on failure return 0 on success, -1 on failure
*/ */
int tdb1_store(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA dbuf, int flag) int tdb1_store(struct tdb1_context *tdb, TDB_DATA key, TDB_DATA dbuf, int flag)
{ {
uint32_t hash; uint32_t hash;
int ret; int ret;
...@@ -617,10 +617,10 @@ int tdb1_store(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA dbuf, int flag ...@@ -617,10 +617,10 @@ int tdb1_store(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA dbuf, int flag
} }
/* Append to an entry. Create if not exist. */ /* Append to an entry. Create if not exist. */
int tdb1_append(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA new_dbuf) int tdb1_append(struct tdb1_context *tdb, TDB_DATA key, TDB_DATA new_dbuf)
{ {
uint32_t hash; uint32_t hash;
TDB1_DATA dbuf; TDB_DATA dbuf;
int ret = -1; int ret = -1;
/* find which hash bucket it is in */ /* find which hash bucket it is in */
...@@ -819,10 +819,10 @@ struct traverse_state { ...@@ -819,10 +819,10 @@ struct traverse_state {
/* /*
traverse function for repacking traverse function for repacking
*/ */
static int repack_traverse(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA data, void *private_data) static int repack_traverse(struct tdb1_context *tdb, TDB_DATA key, TDB_DATA data, void *private_data)
{ {
struct traverse_state *state = (struct traverse_state *)private_data; struct traverse_state *state = (struct traverse_state *)private_data;
if (tdb1_store(state->dest_db, key, data, TDB1_INSERT) != 0) { if (tdb1_store(state->dest_db, key, data, TDB_INSERT) != 0) {
state->error = state->dest_db->last_error; state->error = state->dest_db->last_error;
return -1; return -1;
} }
......
...@@ -478,7 +478,7 @@ static int _tdb1_transaction_start(struct tdb1_context *tdb) ...@@ -478,7 +478,7 @@ static int _tdb1_transaction_start(struct tdb1_context *tdb)
/* get the transaction write lock. This is a blocking lock. As /* get the transaction write lock. This is a blocking lock. As
discussed with Volker, there are a number of ways we could discussed with Volker, there are a number of ways we could
make this async, which we will probably do in the future */ make this async, which we will probably do in the future */
if (tdb1_transaction_lock(tdb, F_WRLCK, TDB1_LOCK_WAIT) == -1) { if (tdb1_transaction_lock(tdb, F_WRLCK, TDB_LOCK_WAIT) == -1) {
SAFE_FREE(tdb->transaction->blocks); SAFE_FREE(tdb->transaction->blocks);
SAFE_FREE(tdb->transaction); SAFE_FREE(tdb->transaction);
return -1; return -1;
...@@ -486,7 +486,7 @@ static int _tdb1_transaction_start(struct tdb1_context *tdb) ...@@ -486,7 +486,7 @@ static int _tdb1_transaction_start(struct tdb1_context *tdb)
/* get a read lock from the freelist to the end of file. This /* get a read lock from the freelist to the end of file. This
is upgraded to a write lock during the commit */ is upgraded to a write lock during the commit */
if (tdb1_allrecord_lock(tdb, F_RDLCK, TDB1_LOCK_WAIT, true) == -1) { if (tdb1_allrecord_lock(tdb, F_RDLCK, TDB_LOCK_WAIT, true) == -1) {
tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR, tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
"tdb1_transaction_start: failed to get hash locks"); "tdb1_transaction_start: failed to get hash locks");
goto fail_allrecord_lock; goto fail_allrecord_lock;
...@@ -973,7 +973,7 @@ static int _tdb1_transaction_prepare_commit(struct tdb1_context *tdb) ...@@ -973,7 +973,7 @@ static int _tdb1_transaction_prepare_commit(struct tdb1_context *tdb)
/* get the open lock - this prevents new users attaching to the database /* get the open lock - this prevents new users attaching to the database
during the commit */ during the commit */
if (tdb1_nest_lock(tdb, TDB1_OPEN_LOCK, F_WRLCK, TDB1_LOCK_WAIT) == -1) { if (tdb1_nest_lock(tdb, TDB1_OPEN_LOCK, F_WRLCK, TDB_LOCK_WAIT) == -1) {
tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR, tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
"tdb1_transaction_prepare_commit:" "tdb1_transaction_prepare_commit:"
" failed to get open lock"); " failed to get open lock");
......
...@@ -147,7 +147,7 @@ static int tdb1_traverse_internal(struct tdb1_context *tdb, ...@@ -147,7 +147,7 @@ static int tdb1_traverse_internal(struct tdb1_context *tdb,
tdb1_traverse_func fn, void *private_data, tdb1_traverse_func fn, void *private_data,
struct tdb1_traverse_lock *tl) struct tdb1_traverse_lock *tl)
{ {
TDB1_DATA key, dbuf; TDB_DATA key, dbuf;
struct tdb1_record rec; struct tdb1_record rec;
int ret = 0, count = 0; int ret = 0, count = 0;
tdb1_off_t off; tdb1_off_t off;
...@@ -223,7 +223,7 @@ int tdb1_traverse_read(struct tdb1_context *tdb, ...@@ -223,7 +223,7 @@ int tdb1_traverse_read(struct tdb1_context *tdb,
/* we need to get a read lock on the transaction lock here to /* we need to get a read lock on the transaction lock here to
cope with the lock ordering semantics of solaris10 */ cope with the lock ordering semantics of solaris10 */
if (tdb1_transaction_lock(tdb, F_RDLCK, TDB1_LOCK_WAIT)) { if (tdb1_transaction_lock(tdb, F_RDLCK, TDB_LOCK_WAIT)) {
return -1; return -1;
} }
...@@ -253,7 +253,7 @@ int tdb1_traverse(struct tdb1_context *tdb, ...@@ -253,7 +253,7 @@ int tdb1_traverse(struct tdb1_context *tdb,
return tdb1_traverse_read(tdb, fn, private_data); return tdb1_traverse_read(tdb, fn, private_data);
} }
if (tdb1_transaction_lock(tdb, F_WRLCK, TDB1_LOCK_WAIT)) { if (tdb1_transaction_lock(tdb, F_WRLCK, TDB_LOCK_WAIT)) {
return -1; return -1;
} }
...@@ -268,9 +268,9 @@ int tdb1_traverse(struct tdb1_context *tdb, ...@@ -268,9 +268,9 @@ int tdb1_traverse(struct tdb1_context *tdb,
/* find the first entry in the database and return its key */ /* find the first entry in the database and return its key */
TDB1_DATA tdb1_firstkey(struct tdb1_context *tdb) TDB_DATA tdb1_firstkey(struct tdb1_context *tdb)
{ {
TDB1_DATA key; TDB_DATA key;
struct tdb1_record rec; struct tdb1_record rec;
tdb1_off_t off; tdb1_off_t off;
...@@ -298,10 +298,10 @@ TDB1_DATA tdb1_firstkey(struct tdb1_context *tdb) ...@@ -298,10 +298,10 @@ TDB1_DATA tdb1_firstkey(struct tdb1_context *tdb)
} }
/* find the next entry in the database, returning its key */ /* find the next entry in the database, returning its key */
TDB1_DATA tdb1_nextkey(struct tdb1_context *tdb, TDB1_DATA oldkey) TDB_DATA tdb1_nextkey(struct tdb1_context *tdb, TDB_DATA oldkey)
{ {
uint32_t oldhash; uint32_t oldhash;
TDB1_DATA key = tdb1_null; TDB_DATA key = tdb1_null;
struct tdb1_record rec; struct tdb1_record rec;
unsigned char *k = NULL; unsigned char *k = NULL;
tdb1_off_t off; tdb1_off_t off;
......
...@@ -46,10 +46,10 @@ static const struct tdb1_methods large_io_methods = { ...@@ -46,10 +46,10 @@ static const struct tdb1_methods large_io_methods = {
tdb1_expand_file_sparse tdb1_expand_file_sparse
}; };
static int test_traverse(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA data, static int test_traverse(struct tdb1_context *tdb, TDB_DATA key, TDB_DATA data,
void *_data) void *_data)
{ {
TDB1_DATA *expect = _data; TDB_DATA *expect = _data;
ok1(key.dsize == strlen("hi")); ok1(key.dsize == strlen("hi"));
ok1(memcmp(key.dptr, "hi", strlen("hi")) == 0); ok1(memcmp(key.dptr, "hi", strlen("hi")) == 0);
ok1(data.dsize == expect->dsize); ok1(data.dsize == expect->dsize);
...@@ -60,7 +60,7 @@ static int test_traverse(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA data ...@@ -60,7 +60,7 @@ static int test_traverse(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA data
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
struct tdb1_context *tdb; struct tdb1_context *tdb;
TDB1_DATA key, orig_data, data; TDB_DATA key, orig_data, data;
uint32_t hash; uint32_t hash;
tdb1_off_t rec_ptr; tdb1_off_t rec_ptr;
struct tdb1_record rec; struct tdb1_record rec;
...@@ -81,7 +81,7 @@ int main(int argc, char *argv[]) ...@@ -81,7 +81,7 @@ int main(int argc, char *argv[])
orig_data.dsize = strlen("world"); orig_data.dsize = strlen("world");
orig_data.dptr = (void *)"world"; orig_data.dptr = (void *)"world";
ok1(tdb1_store(tdb, key, orig_data, TDB1_INSERT) == 0); ok1(tdb1_store(tdb, key, orig_data, TDB_INSERT) == 0);
data = tdb1_fetch(tdb, key); data = tdb1_fetch(tdb, key);
ok1(data.dsize == strlen("world")); ok1(data.dsize == strlen("world"));
...@@ -105,7 +105,7 @@ int main(int argc, char *argv[]) ...@@ -105,7 +105,7 @@ int main(int argc, char *argv[])
/* Transactions should work. */ /* Transactions should work. */
ok1(tdb1_transaction_start(tdb) == 0); ok1(tdb1_transaction_start(tdb) == 0);
ok1(tdb1_store(tdb, key, orig_data, TDB1_INSERT) == 0); ok1(tdb1_store(tdb, key, orig_data, TDB_INSERT) == 0);
data = tdb1_fetch(tdb, key); data = tdb1_fetch(tdb, key);
ok1(data.dsize == strlen("world")); ok1(data.dsize == strlen("world"));
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
struct tdb1_context *tdb; struct tdb1_context *tdb;
TDB1_DATA key, data; TDB_DATA key, data;
plan_tests(13); plan_tests(13);
tdb = tdb1_open_ex("run-check.tdb", 1, TDB1_CLEAR_IF_FIRST, tdb = tdb1_open_ex("run-check.tdb", 1, TDB1_CLEAR_IF_FIRST,
...@@ -21,7 +21,7 @@ int main(int argc, char *argv[]) ...@@ -21,7 +21,7 @@ int main(int argc, char *argv[])
data.dsize = strlen("world"); data.dsize = strlen("world");
data.dptr = (void *)"world"; data.dptr = (void *)"world";
ok1(tdb1_store(tdb, key, data, TDB1_INSERT) == 0); ok1(tdb1_store(tdb, key, data, TDB_INSERT) == 0);
ok1(tdb1_check(tdb, NULL, NULL) == 0); ok1(tdb1_check(tdb, NULL, NULL) == 0);
tdb1_close(tdb); tdb1_close(tdb);
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include <err.h> #include <err.h>
#include "tdb1-logging.h" #include "tdb1-logging.h"
static int check(TDB1_DATA key, TDB1_DATA data, void *private) static int check(TDB_DATA key, TDB_DATA data, void *private)
{ {
unsigned int *sizes = private; unsigned int *sizes = private;
...@@ -42,7 +42,7 @@ static void tdb1_flip_bit(struct tdb1_context *tdb, unsigned int bit) ...@@ -42,7 +42,7 @@ static void tdb1_flip_bit(struct tdb1_context *tdb, unsigned int bit)
static void check_test(struct tdb1_context *tdb) static void check_test(struct tdb1_context *tdb)
{ {
TDB1_DATA key, data; TDB_DATA key, data;
unsigned int i, verifiable, corrupt, sizes[2], dsize, ksize; unsigned int i, verifiable, corrupt, sizes[2], dsize, ksize;
ok1(tdb1_check(tdb, NULL, NULL) == 0); ok1(tdb1_check(tdb, NULL, NULL) == 0);
...@@ -58,13 +58,13 @@ static void check_test(struct tdb1_context *tdb) ...@@ -58,13 +58,13 @@ static void check_test(struct tdb1_context *tdb)
for (key.dsize = 1; key.dsize <= 5; key.dsize++) { for (key.dsize = 1; key.dsize <= 5; key.dsize++) {
ksize += key.dsize; ksize += key.dsize;
dsize += data.dsize; dsize += data.dsize;
if (tdb1_store(tdb, key, data, TDB1_INSERT) != 0) if (tdb1_store(tdb, key, data, TDB_INSERT) != 0)
abort(); abort();
} }
/* This is how many bytes we expect to be verifiable. */ /* This is how many bytes we expect to be verifiable. */
/* From the file header. */ /* From the file header. */
verifiable = strlen(TDB1_MAGIC_FOOD) + 1 verifiable = strlen(TDB_MAGIC_FOOD) + 1
+ 2 * sizeof(uint32_t) + 2 * sizeof(tdb1_off_t) + 2 * sizeof(uint32_t) + 2 * sizeof(tdb1_off_t)
+ 2 * sizeof(uint32_t); + 2 * sizeof(uint32_t);
/* From the free list chain and hash chains. */ /* From the free list chain and hash chains. */
......
...@@ -82,7 +82,7 @@ static int ftruncate_check(int fd, off_t length) ...@@ -82,7 +82,7 @@ static int ftruncate_check(int fd, off_t length)
static bool test_death(enum operation op, struct agent *agent) static bool test_death(enum operation op, struct agent *agent)
{ {
struct tdb1_context *tdb = NULL; struct tdb1_context *tdb = NULL;
TDB1_DATA key; TDB_DATA key;
enum agent_return ret; enum agent_return ret;
int needed_recovery = 0; int needed_recovery = 0;
...@@ -150,7 +150,7 @@ reset: ...@@ -150,7 +150,7 @@ reset:
/* Put key for agent to fetch. */ /* Put key for agent to fetch. */
key.dsize = strlen(KEY_STRING); key.dsize = strlen(KEY_STRING);
key.dptr = (void *)KEY_STRING; key.dptr = (void *)KEY_STRING;
if (tdb1_store(tdb, key, key, TDB1_INSERT) != 0) if (tdb1_store(tdb, key, key, TDB_INSERT) != 0)
return false; return false;
/* This is the key we insert in transaction. */ /* This is the key we insert in transaction. */
...@@ -168,7 +168,7 @@ reset: ...@@ -168,7 +168,7 @@ reset:
if (tdb1_transaction_start(tdb) != 0) if (tdb1_transaction_start(tdb) != 0)
return false; return false;
if (tdb1_store(tdb, key, key, TDB1_INSERT) != 0) if (tdb1_store(tdb, key, key, TDB_INSERT) != 0)
return false; return false;
if (tdb1_transaction_commit(tdb) != 0) if (tdb1_transaction_commit(tdb) != 0)
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
struct tdb1_context *tdb; struct tdb1_context *tdb;
TDB1_DATA key, data; TDB_DATA key, data;
plan_tests(13); plan_tests(13);
tdb = tdb1_open_ex("run-endian.tdb", 1024, tdb = tdb1_open_ex("run-endian.tdb", 1024,
...@@ -20,12 +20,12 @@ int main(int argc, char *argv[]) ...@@ -20,12 +20,12 @@ int main(int argc, char *argv[])
data.dsize = strlen("world"); data.dsize = strlen("world");
data.dptr = (void *)"world"; data.dptr = (void *)"world";
ok1(tdb1_store(tdb, key, data, TDB1_MODIFY) < 0); ok1(tdb1_store(tdb, key, data, TDB_MODIFY) < 0);
ok1(tdb_error(tdb) == TDB_ERR_NOEXIST); ok1(tdb_error(tdb) == TDB_ERR_NOEXIST);
ok1(tdb1_store(tdb, key, data, TDB1_INSERT) == 0); ok1(tdb1_store(tdb, key, data, TDB_INSERT) == 0);
ok1(tdb1_store(tdb, key, data, TDB1_INSERT) < 0); ok1(tdb1_store(tdb, key, data, TDB_INSERT) < 0);
ok1(tdb_error(tdb) == TDB_ERR_EXISTS); ok1(tdb_error(tdb) == TDB_ERR_EXISTS);
ok1(tdb1_store(tdb, key, data, TDB1_MODIFY) == 0); ok1(tdb1_store(tdb, key, data, TDB_MODIFY) == 0);
data = tdb1_fetch(tdb, key); data = tdb1_fetch(tdb, key);
ok1(data.dsize == strlen("world")); ok1(data.dsize == strlen("world"));
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <err.h> #include <err.h>
static unsigned int tdb1_dumb_hash(TDB1_DATA *key) static unsigned int tdb1_dumb_hash(TDB_DATA *key)
{ {
return key->dsize; return key->dsize;
} }
...@@ -35,7 +35,7 @@ int main(int argc, char *argv[]) ...@@ -35,7 +35,7 @@ int main(int argc, char *argv[])
{ {
struct tdb1_context *tdb; struct tdb1_context *tdb;
unsigned int log_count, flags; unsigned int log_count, flags;
TDB1_DATA d; TDB_DATA d;
struct tdb1_logging_context log_ctx = { log_fn, &log_count }; struct tdb1_logging_context log_ctx = { log_fn, &log_count };
plan_tests(38 * 2); plan_tests(38 * 2);
...@@ -55,7 +55,7 @@ int main(int argc, char *argv[]) ...@@ -55,7 +55,7 @@ int main(int argc, char *argv[])
ok1(log_count == 0); ok1(log_count == 0);
d.dptr = (void *)"Hello"; d.dptr = (void *)"Hello";
d.dsize = 5; d.dsize = 5;
ok1(tdb1_store(tdb, d, d, TDB1_INSERT) == 0); ok1(tdb1_store(tdb, d, d, TDB_INSERT) == 0);
tdb1_close(tdb); tdb1_close(tdb);
/* Should not have marked rwlocks field. */ /* Should not have marked rwlocks field. */
...@@ -100,7 +100,7 @@ int main(int argc, char *argv[]) ...@@ -100,7 +100,7 @@ int main(int argc, char *argv[])
ok1(log_count == 0); ok1(log_count == 0);
d.dptr = (void *)"Hello"; d.dptr = (void *)"Hello";
d.dsize = 5; d.dsize = 5;
ok1(tdb1_store(tdb, d, d, TDB1_INSERT) == 0); ok1(tdb1_store(tdb, d, d, TDB_INSERT) == 0);
tdb1_close(tdb); tdb1_close(tdb);
/* Should have marked rwlocks field. */ /* Should have marked rwlocks field. */
...@@ -149,7 +149,7 @@ int main(int argc, char *argv[]) ...@@ -149,7 +149,7 @@ int main(int argc, char *argv[])
ok1(log_count == 0); ok1(log_count == 0);
d.dptr = (void *)"Hello"; d.dptr = (void *)"Hello";
d.dsize = 5; d.dsize = 5;
ok1(tdb1_store(tdb, d, d, TDB1_INSERT) == 0); ok1(tdb1_store(tdb, d, d, TDB_INSERT) == 0);
tdb1_close(tdb); tdb1_close(tdb);
/* Should have marked rwlocks field. */ /* Should have marked rwlocks field. */
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
struct tdb1_context *tdb; struct tdb1_context *tdb;
TDB1_DATA key, data; TDB_DATA key, data;
plan_tests(27); plan_tests(27);
key.dsize = strlen("hi"); key.dsize = strlen("hi");
...@@ -22,7 +22,7 @@ int main(int argc, char *argv[]) ...@@ -22,7 +22,7 @@ int main(int argc, char *argv[])
ok1(tdb1_transaction_start(tdb) == 0); ok1(tdb1_transaction_start(tdb) == 0);
data.dptr = (void *)"world"; data.dptr = (void *)"world";
data.dsize = strlen("world"); data.dsize = strlen("world");
ok1(tdb1_store(tdb, key, data, TDB1_INSERT) == 0); ok1(tdb1_store(tdb, key, data, TDB_INSERT) == 0);
data = tdb1_fetch(tdb, key); data = tdb1_fetch(tdb, key);
ok1(data.dsize == strlen("world")); ok1(data.dsize == strlen("world"));
ok1(memcmp(data.dptr, "world", strlen("world")) == 0); ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
......
...@@ -11,19 +11,19 @@ ...@@ -11,19 +11,19 @@
static struct agent *agent; static struct agent *agent;
static bool correct_key(TDB1_DATA key) static bool correct_key(TDB_DATA key)
{ {
return key.dsize == strlen("hi") return key.dsize == strlen("hi")
&& memcmp(key.dptr, "hi", key.dsize) == 0; && memcmp(key.dptr, "hi", key.dsize) == 0;
} }
static bool correct_data(TDB1_DATA data) static bool correct_data(TDB_DATA data)
{ {
return data.dsize == strlen("world") return data.dsize == strlen("world")
&& memcmp(data.dptr, "world", data.dsize) == 0; && memcmp(data.dptr, "world", data.dsize) == 0;
} }
static int traverse2(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA data, static int traverse2(struct tdb1_context *tdb, TDB_DATA key, TDB_DATA data,
void *p) void *p)
{ {
ok1(correct_key(key)); ok1(correct_key(key));
...@@ -31,7 +31,7 @@ static int traverse2(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA data, ...@@ -31,7 +31,7 @@ static int traverse2(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA data,
return 0; return 0;
} }
static int traverse1(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA data, static int traverse1(struct tdb1_context *tdb, TDB_DATA key, TDB_DATA data,
void *p) void *p)
{ {
ok1(correct_key(key)); ok1(correct_key(key));
...@@ -49,7 +49,7 @@ static int traverse1(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA data, ...@@ -49,7 +49,7 @@ static int traverse1(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA data,
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
struct tdb1_context *tdb; struct tdb1_context *tdb;
TDB1_DATA key, data; TDB_DATA key, data;
plan_tests(17); plan_tests(17);
agent = prepare_external_agent1(); agent = prepare_external_agent1();
...@@ -71,7 +71,7 @@ int main(int argc, char *argv[]) ...@@ -71,7 +71,7 @@ int main(int argc, char *argv[])
data.dptr = (void *)"world"; data.dptr = (void *)"world";
data.dsize = strlen("world"); data.dsize = strlen("world");
ok1(tdb1_store(tdb, key, data, TDB1_INSERT) == 0); ok1(tdb1_store(tdb, key, data, TDB_INSERT) == 0);
tdb1_traverse(tdb, traverse1, NULL); tdb1_traverse(tdb, traverse1, NULL);
tdb1_traverse_read(tdb, traverse1, NULL); tdb1_traverse_read(tdb, traverse1, NULL);
tdb1_close(tdb); tdb1_close(tdb);
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
static bool prepare_entries(struct tdb1_context *tdb) static bool prepare_entries(struct tdb1_context *tdb)
{ {
unsigned int i; unsigned int i;
TDB1_DATA key, data; TDB_DATA key, data;
for (i = 0; i < NUM_ENTRIES; i++) { for (i = 0; i < NUM_ENTRIES; i++) {
key.dsize = sizeof(i); key.dsize = sizeof(i);
...@@ -34,7 +34,7 @@ static bool prepare_entries(struct tdb1_context *tdb) ...@@ -34,7 +34,7 @@ static bool prepare_entries(struct tdb1_context *tdb)
static void delete_entries(struct tdb1_context *tdb) static void delete_entries(struct tdb1_context *tdb)
{ {
unsigned int i; unsigned int i;
TDB1_DATA key; TDB_DATA key;
for (i = 0; i < NUM_ENTRIES; i++) { for (i = 0; i < NUM_ENTRIES; i++) {
key.dsize = sizeof(i); key.dsize = sizeof(i);
...@@ -45,7 +45,7 @@ static void delete_entries(struct tdb1_context *tdb) ...@@ -45,7 +45,7 @@ static void delete_entries(struct tdb1_context *tdb)
} }
/* We don't know how many times this will run. */ /* We don't know how many times this will run. */
static int delete_other(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA data, static int delete_other(struct tdb1_context *tdb, TDB_DATA key, TDB_DATA data,
void *private_data) void *private_data)
{ {
unsigned int i; unsigned int i;
...@@ -57,7 +57,7 @@ static int delete_other(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA data, ...@@ -57,7 +57,7 @@ static int delete_other(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA data,
return 0; return 0;
} }
static int delete_self(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA data, static int delete_self(struct tdb1_context *tdb, TDB_DATA key, TDB_DATA data,
void *private_data) void *private_data)
{ {
ok1(tdb1_delete(tdb, key) == 0); ok1(tdb1_delete(tdb, key) == 0);
......
...@@ -138,7 +138,7 @@ int main(int argc, char *argv[]) ...@@ -138,7 +138,7 @@ int main(int argc, char *argv[])
TDB1_CLEAR_IF_FIRST | TDB1_NOMMAP }; TDB1_CLEAR_IF_FIRST | TDB1_NOMMAP };
int i; int i;
struct tdb1_context *tdb; struct tdb1_context *tdb;
TDB1_DATA key, data; TDB_DATA key, data;
plan_tests(20); plan_tests(20);
agent = prepare_external_agent1(); agent = prepare_external_agent1();
...@@ -164,7 +164,7 @@ int main(int argc, char *argv[]) ...@@ -164,7 +164,7 @@ int main(int argc, char *argv[])
data.dptr = (void *)"world"; data.dptr = (void *)"world";
data.dsize = strlen("world"); data.dsize = strlen("world");
ok1(tdb1_store(tdb, key, data, TDB1_INSERT) == 0); ok1(tdb1_store(tdb, key, data, TDB_INSERT) == 0);
ok1(tdb1_transaction_commit(tdb) == 0); ok1(tdb1_transaction_commit(tdb) == 0);
ok(!errors, "We had %u open errors", errors); ok(!errors, "We had %u open errors", errors);
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
struct tdb1_context *tdb; struct tdb1_context *tdb;
TDB1_DATA key, data; TDB_DATA key, data;
plan_tests(11); plan_tests(11);
tdb = tdb1_open_ex("run-readonly-check.tdb", 1024, tdb = tdb1_open_ex("run-readonly-check.tdb", 1024,
...@@ -22,7 +22,7 @@ int main(int argc, char *argv[]) ...@@ -22,7 +22,7 @@ int main(int argc, char *argv[])
data.dsize = strlen("world"); data.dsize = strlen("world");
data.dptr = (void *)"world"; data.dptr = (void *)"world";
ok1(tdb1_store(tdb, key, data, TDB1_INSERT) == 0); ok1(tdb1_store(tdb, key, data, TDB_INSERT) == 0);
ok1(tdb1_check(tdb, NULL, NULL) == 0); ok1(tdb1_check(tdb, NULL, NULL) == 0);
/* We are also allowed to do a check inside a transaction. */ /* We are also allowed to do a check inside a transaction. */
...@@ -34,7 +34,7 @@ int main(int argc, char *argv[]) ...@@ -34,7 +34,7 @@ int main(int argc, char *argv[])
TDB1_DEFAULT, O_RDONLY, 0, &taplogctx, NULL); TDB1_DEFAULT, O_RDONLY, 0, &taplogctx, NULL);
ok1(tdb); ok1(tdb);
ok1(tdb1_store(tdb, key, data, TDB1_MODIFY) == -1); ok1(tdb1_store(tdb, key, data, TDB_MODIFY) == -1);
ok1(tdb_error(tdb) == TDB_ERR_RDONLY); ok1(tdb_error(tdb) == TDB_ERR_RDONLY);
ok1(tdb1_check(tdb, NULL, NULL) == 0); ok1(tdb1_check(tdb, NULL, NULL) == 0);
ok1(tdb1_close(tdb) == 0); ok1(tdb1_close(tdb) == 0);
......
...@@ -10,8 +10,8 @@ int main(int argc, char *argv[]) ...@@ -10,8 +10,8 @@ int main(int argc, char *argv[])
int flags[] = { TDB1_INTERNAL, TDB1_DEFAULT, TDB1_NOMMAP, int flags[] = { TDB1_INTERNAL, TDB1_DEFAULT, TDB1_NOMMAP,
TDB1_INTERNAL|TDB1_CONVERT, TDB1_CONVERT, TDB1_INTERNAL|TDB1_CONVERT, TDB1_CONVERT,
TDB1_NOMMAP|TDB1_CONVERT }; TDB1_NOMMAP|TDB1_CONVERT };
TDB1_DATA key = { (unsigned char *)&j, sizeof(j) }; TDB_DATA key = { (unsigned char *)&j, sizeof(j) };
TDB1_DATA data = { (unsigned char *)&j, sizeof(j) }; TDB_DATA data = { (unsigned char *)&j, sizeof(j) };
char *summary; char *summary;
plan_tests(sizeof(flags) / sizeof(flags[0]) * 14); plan_tests(sizeof(flags) / sizeof(flags[0]) * 14);
...@@ -26,7 +26,7 @@ int main(int argc, char *argv[]) ...@@ -26,7 +26,7 @@ int main(int argc, char *argv[])
for (j = 0; j < 500; j++) { for (j = 0; j < 500; j++) {
/* Make sure padding varies to we get some graphs! */ /* Make sure padding varies to we get some graphs! */
data.dsize = j % (sizeof(j) + 1); data.dsize = j % (sizeof(j) + 1);
if (tdb1_store(tdb, key, data, TDB1_REPLACE) != 0) if (tdb1_store(tdb, key, data, TDB_REPLACE) != 0)
fail("Storing in tdb"); fail("Storing in tdb");
} }
......
...@@ -12,19 +12,19 @@ ...@@ -12,19 +12,19 @@
static struct agent *agent; static struct agent *agent;
static bool correct_key(TDB1_DATA key) static bool correct_key(TDB_DATA key)
{ {
return key.dsize == strlen("hi") return key.dsize == strlen("hi")
&& memcmp(key.dptr, "hi", key.dsize) == 0; && memcmp(key.dptr, "hi", key.dsize) == 0;
} }
static bool correct_data(TDB1_DATA data) static bool correct_data(TDB_DATA data)
{ {
return data.dsize == strlen("world") return data.dsize == strlen("world")
&& memcmp(data.dptr, "world", data.dsize) == 0; && memcmp(data.dptr, "world", data.dsize) == 0;
} }
static int traverse(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA data, static int traverse(struct tdb1_context *tdb, TDB_DATA key, TDB_DATA data,
void *p) void *p)
{ {
ok1(correct_key(key)); ok1(correct_key(key));
...@@ -35,7 +35,7 @@ static int traverse(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA data, ...@@ -35,7 +35,7 @@ static int traverse(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA data,
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
struct tdb1_context *tdb; struct tdb1_context *tdb;
TDB1_DATA key, data; TDB_DATA key, data;
plan_tests(13); plan_tests(13);
agent = prepare_external_agent1(); agent = prepare_external_agent1();
...@@ -52,7 +52,7 @@ int main(int argc, char *argv[]) ...@@ -52,7 +52,7 @@ int main(int argc, char *argv[])
data.dptr = (void *)"world"; data.dptr = (void *)"world";
data.dsize = strlen("world"); data.dsize = strlen("world");
ok1(tdb1_store(tdb, key, data, TDB1_INSERT) == 0); ok1(tdb1_store(tdb, key, data, TDB_INSERT) == 0);
ok1(external_agent_operation1(agent, OPEN, tdb->name) == SUCCESS); ok1(external_agent_operation1(agent, OPEN, tdb->name) == SUCCESS);
......
...@@ -15,7 +15,7 @@ int main(int argc, char *argv[]) ...@@ -15,7 +15,7 @@ int main(int argc, char *argv[])
{ {
struct tdb1_context *tdb; struct tdb1_context *tdb;
unsigned int log_count; unsigned int log_count;
TDB1_DATA d; TDB_DATA d;
struct tdb1_logging_context log_ctx = { log_fn, &log_count }; struct tdb1_logging_context log_ctx = { log_fn, &log_count };
plan_tests(28); plan_tests(28);
...@@ -28,7 +28,7 @@ int main(int argc, char *argv[]) ...@@ -28,7 +28,7 @@ int main(int argc, char *argv[])
ok1(log_count == 0); ok1(log_count == 0);
d.dptr = (void *)"Hello"; d.dptr = (void *)"Hello";
d.dsize = 5; d.dsize = 5;
ok1(tdb1_store(tdb, d, d, TDB1_INSERT) == 0); ok1(tdb1_store(tdb, d, d, TDB_INSERT) == 0);
tdb1_close(tdb); tdb1_close(tdb);
/* Fail to open with different hash. */ /* Fail to open with different hash. */
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
struct tdb1_context *tdb; struct tdb1_context *tdb;
TDB1_DATA key, data; TDB_DATA key, data;
plan_tests(4); plan_tests(4);
tdb = tdb1_open_ex(NULL, 1024, TDB1_INTERNAL, O_CREAT|O_TRUNC|O_RDWR, tdb = tdb1_open_ex(NULL, 1024, TDB1_INTERNAL, O_CREAT|O_TRUNC|O_RDWR,
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
struct tdb1_context *tdb; struct tdb1_context *tdb;
TDB1_DATA key, data; TDB_DATA key, data;
plan_tests(10); plan_tests(10);
tdb = tdb1_open_ex("run.tdb", 1024, TDB1_CLEAR_IF_FIRST, tdb = tdb1_open_ex("run.tdb", 1024, TDB1_CLEAR_IF_FIRST,
...@@ -19,12 +19,12 @@ int main(int argc, char *argv[]) ...@@ -19,12 +19,12 @@ int main(int argc, char *argv[])
data.dsize = strlen("world"); data.dsize = strlen("world");
data.dptr = (void *)"world"; data.dptr = (void *)"world";
ok1(tdb1_store(tdb, key, data, TDB1_MODIFY) < 0); ok1(tdb1_store(tdb, key, data, TDB_MODIFY) < 0);
ok1(tdb_error(tdb) == TDB_ERR_NOEXIST); ok1(tdb_error(tdb) == TDB_ERR_NOEXIST);
ok1(tdb1_store(tdb, key, data, TDB1_INSERT) == 0); ok1(tdb1_store(tdb, key, data, TDB_INSERT) == 0);
ok1(tdb1_store(tdb, key, data, TDB1_INSERT) < 0); ok1(tdb1_store(tdb, key, data, TDB_INSERT) < 0);
ok1(tdb_error(tdb) == TDB_ERR_EXISTS); ok1(tdb_error(tdb) == TDB_ERR_EXISTS);
ok1(tdb1_store(tdb, key, data, TDB1_MODIFY) == 0); ok1(tdb1_store(tdb, key, data, TDB_MODIFY) == 0);
data = tdb1_fetch(tdb, key); data = tdb1_fetch(tdb, key);
ok1(data.dsize == strlen("world")); ok1(data.dsize == strlen("world"));
......
...@@ -20,9 +20,9 @@ static struct tdb1_context *tdb; ...@@ -20,9 +20,9 @@ static struct tdb1_context *tdb;
static enum agent_return do_operation(enum operation op, const char *name) static enum agent_return do_operation(enum operation op, const char *name)
{ {
TDB1_DATA k; TDB_DATA k;
enum agent_return ret; enum agent_return ret;
TDB1_DATA data; TDB_DATA data;
if (op != OPEN && op != OPEN_WITH_CLEAR_IF_FIRST && !tdb) { if (op != OPEN && op != OPEN_WITH_CLEAR_IF_FIRST && !tdb) {
diag("external: No tdb open!"); diag("external: No tdb open!");
......
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