Commit 22d0e0dc authored by Rusty Russell's avatar Rusty Russell

tdb2: Make TDB1 code use TDB2's open flags.

This means getting rid of TDB_VOLATILE (perhaps we should use an
attribute for that?), TDB_INCOMPATIBLE_HASH (use the
tdb_attribute_hash for that) and TDB_CLEAR_IF_FIRST (use the
tdb_attribute_openhook for that).

We also get rid of TDB_DISALLOW_NESTING: that's the default for TDB2.
parent 3004f7e8
...@@ -36,20 +36,6 @@ ...@@ -36,20 +36,6 @@
#endif #endif
/** Flags for tdb1_open() */
#define TDB1_DEFAULT 0 /** just a readability place holder */
#define TDB1_CLEAR_IF_FIRST 1 /** If this is the first open, wipe the db */
#define TDB1_INTERNAL 2 /** Don't store on disk */
#define TDB1_NOLOCK 4 /** Don't do any locking */
#define TDB1_NOMMAP 8 /** Don't use mmap */
#define TDB1_CONVERT 16 /** Convert endian (internal use) */
#define TDB1_BIGENDIAN 32 /** Header is big-endian (internal use) */
#define TDB1_NOSYNC 64 /** Don't use synchronous transactions */
#define TDB1_SEQNUM 128 /** Maintain a sequence number */
#define TDB1_VOLATILE 256 /** Activate the per-hashchain freelist, default 5 */
#define TDB1_ALLOW_NESTING 512 /** Allow transactions to nest */
#define TDB1_DISALLOW_NESTING 1024 /** Disallow transactions to nest */
/** 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;
......
...@@ -41,7 +41,7 @@ static int tdb1_oob(struct tdb1_context *tdb, tdb1_off_t len, int probe) ...@@ -41,7 +41,7 @@ static int tdb1_oob(struct tdb1_context *tdb, tdb1_off_t len, int probe)
struct stat st; struct stat st;
if (len <= tdb->map_size) if (len <= tdb->map_size)
return 0; return 0;
if (tdb->flags & TDB1_INTERNAL) { if (tdb->flags & TDB_INTERNAL) {
if (!probe) { if (!probe) {
tdb->last_error = tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR, tdb->last_error = tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
"tdb1_oob len %d beyond internal malloc size %d", "tdb1_oob len %d beyond internal malloc size %d",
...@@ -189,7 +189,7 @@ static void tdb1_next_hash_chain(struct tdb1_context *tdb, uint32_t *chain) ...@@ -189,7 +189,7 @@ static void tdb1_next_hash_chain(struct tdb1_context *tdb, uint32_t *chain)
int tdb1_munmap(struct tdb1_context *tdb) int tdb1_munmap(struct tdb1_context *tdb)
{ {
if (tdb->flags & TDB1_INTERNAL) if (tdb->flags & TDB_INTERNAL)
return 0; return 0;
#if HAVE_MMAP #if HAVE_MMAP
...@@ -207,11 +207,11 @@ int tdb1_munmap(struct tdb1_context *tdb) ...@@ -207,11 +207,11 @@ int tdb1_munmap(struct tdb1_context *tdb)
void tdb1_mmap(struct tdb1_context *tdb) void tdb1_mmap(struct tdb1_context *tdb)
{ {
if (tdb->flags & TDB1_INTERNAL) if (tdb->flags & TDB_INTERNAL)
return; return;
#if HAVE_MMAP #if HAVE_MMAP
if (!(tdb->flags & TDB1_NOMMAP)) { if (!(tdb->flags & TDB_NOMMAP)) {
tdb->map_ptr = mmap(NULL, tdb->map_size, tdb->map_ptr = mmap(NULL, tdb->map_size,
PROT_READ|(tdb->read_only? 0:PROT_WRITE), PROT_READ|(tdb->read_only? 0:PROT_WRITE),
MAP_SHARED|MAP_FILE, tdb->fd, 0); MAP_SHARED|MAP_FILE, tdb->fd, 0);
...@@ -339,7 +339,7 @@ int tdb1_expand(struct tdb1_context *tdb, tdb1_off_t size) ...@@ -339,7 +339,7 @@ int tdb1_expand(struct tdb1_context *tdb, tdb1_off_t size)
new_size = MAX(top_size, map_size); new_size = MAX(top_size, map_size);
size = TDB1_ALIGN(new_size, tdb->page_size) - tdb->map_size; size = TDB1_ALIGN(new_size, tdb->page_size) - tdb->map_size;
if (!(tdb->flags & TDB1_INTERNAL)) if (!(tdb->flags & TDB_INTERNAL))
tdb1_munmap(tdb); tdb1_munmap(tdb);
/* /*
...@@ -349,14 +349,14 @@ int tdb1_expand(struct tdb1_context *tdb, tdb1_off_t size) ...@@ -349,14 +349,14 @@ int tdb1_expand(struct tdb1_context *tdb, tdb1_off_t size)
*/ */
/* expand the file itself */ /* expand the file itself */
if (!(tdb->flags & TDB1_INTERNAL)) { if (!(tdb->flags & TDB_INTERNAL)) {
if (tdb->methods->tdb1_expand_file(tdb, tdb->map_size, size) != 0) if (tdb->methods->tdb1_expand_file(tdb, tdb->map_size, size) != 0)
goto fail; goto fail;
} }
tdb->map_size += size; tdb->map_size += size;
if (tdb->flags & TDB1_INTERNAL) { if (tdb->flags & TDB_INTERNAL) {
char *new_map_ptr = (char *)realloc(tdb->map_ptr, char *new_map_ptr = (char *)realloc(tdb->map_ptr,
tdb->map_size); tdb->map_size);
if (!new_map_ptr) { if (!new_map_ptr) {
......
...@@ -134,7 +134,7 @@ int tdb1_brlock(struct tdb1_context *tdb, ...@@ -134,7 +134,7 @@ int tdb1_brlock(struct tdb1_context *tdb,
{ {
int ret; int ret;
if (tdb->flags & TDB1_NOLOCK) { if (tdb->flags & TDB_NOLOCK) {
return 0; return 0;
} }
...@@ -168,7 +168,7 @@ int tdb1_brunlock(struct tdb1_context *tdb, ...@@ -168,7 +168,7 @@ int tdb1_brunlock(struct tdb1_context *tdb,
{ {
int ret; int ret;
if (tdb->flags & TDB1_NOLOCK) { if (tdb->flags & TDB_NOLOCK) {
return 0; return 0;
} }
...@@ -257,7 +257,7 @@ int tdb1_nest_lock(struct tdb1_context *tdb, uint32_t offset, int ltype, ...@@ -257,7 +257,7 @@ int tdb1_nest_lock(struct tdb1_context *tdb, uint32_t offset, int ltype,
offset, ltype); offset, ltype);
return -1; return -1;
} }
if (tdb->flags & TDB1_NOLOCK) if (tdb->flags & TDB_NOLOCK)
return 0; return 0;
new_lck = tdb1_find_nestlock(tdb, offset); new_lck = tdb1_find_nestlock(tdb, offset);
...@@ -377,7 +377,7 @@ int tdb1_nest_unlock(struct tdb1_context *tdb, uint32_t offset, int ltype) ...@@ -377,7 +377,7 @@ int tdb1_nest_unlock(struct tdb1_context *tdb, uint32_t offset, int ltype)
int ret = -1; int ret = -1;
struct tdb1_lock_type *lck; struct tdb1_lock_type *lck;
if (tdb->flags & TDB1_NOLOCK) if (tdb->flags & TDB_NOLOCK)
return 0; return 0;
/* Sanity checks */ /* Sanity checks */
......
...@@ -75,7 +75,7 @@ static int tdb1_new_database(struct tdb1_context *tdb, int hash_size) ...@@ -75,7 +75,7 @@ static int tdb1_new_database(struct tdb1_context *tdb, int hash_size)
if (tdb->hash_fn == tdb1_incompatible_hash) if (tdb->hash_fn == tdb1_incompatible_hash)
newdb->rwlocks = TDB1_HASH_RWLOCK_MAGIC; newdb->rwlocks = TDB1_HASH_RWLOCK_MAGIC;
if (tdb->flags & TDB1_INTERNAL) { if (tdb->flags & TDB_INTERNAL) {
tdb->map_size = size; tdb->map_size = size;
tdb->map_ptr = (char *)newdb; tdb->map_ptr = (char *)newdb;
memcpy(&tdb->header, newdb, sizeof(tdb->header)); memcpy(&tdb->header, newdb, sizeof(tdb->header));
...@@ -166,9 +166,7 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag ...@@ -166,9 +166,7 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag
{ {
struct tdb1_context *tdb; struct tdb1_context *tdb;
struct stat st; struct stat st;
int rev = 0, locked = 0; int rev = 0;
unsigned char *vp;
uint32_t vertest;
unsigned v; unsigned v;
const char *hash_alg; const char *hash_alg;
uint32_t magic1, magic2; uint32_t magic1, magic2;
...@@ -190,7 +188,7 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag ...@@ -190,7 +188,7 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag
} else } else
tdb->log_fn = NULL; tdb->log_fn = NULL;
if (name == NULL && (tdb1_flags & TDB1_INTERNAL)) { if (name == NULL && (tdb1_flags & TDB_INTERNAL)) {
name = "__TDB1_INTERNAL__"; name = "__TDB1_INTERNAL__";
} }
...@@ -234,7 +232,8 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag ...@@ -234,7 +232,8 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag
tdb->page_size = 0x2000; tdb->page_size = 0x2000;
} }
tdb->max_dead_records = (tdb1_flags & TDB1_VOLATILE) ? 5 : 0; /* FIXME: Used to be 5 for TDB_VOLATILE. */
tdb->max_dead_records = 0;
if ((open_flags & O_ACCMODE) == O_WRONLY) { if ((open_flags & O_ACCMODE) == O_WRONLY) {
tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_LOG_USE_ERROR, tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_LOG_USE_ERROR,
...@@ -248,32 +247,13 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag ...@@ -248,32 +247,13 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag
hash_size = TDB1_DEFAULT_HASH_SIZE; hash_size = TDB1_DEFAULT_HASH_SIZE;
if ((open_flags & O_ACCMODE) == O_RDONLY) { if ((open_flags & O_ACCMODE) == O_RDONLY) {
tdb->read_only = 1; tdb->read_only = 1;
/* read only databases don't do locking or clear if first */ /* read only databases don't do locking */
tdb->flags |= TDB1_NOLOCK; tdb->flags |= TDB_NOLOCK;
tdb->flags &= ~TDB1_CLEAR_IF_FIRST;
}
if ((tdb->flags & TDB1_ALLOW_NESTING) &&
(tdb->flags & TDB1_DISALLOW_NESTING)) {
tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_LOG_USE_ERROR,
"tdb1_open_ex: "
"allow_nesting and disallow_nesting are not allowed together!");
errno = EINVAL;
goto fail;
}
/*
* TDB1_ALLOW_NESTING is the default behavior.
* Note: this may change in future versions!
*/
if (!(tdb->flags & TDB1_DISALLOW_NESTING)) {
tdb->flags |= TDB1_ALLOW_NESTING;
} }
/* internal databases don't mmap or lock, and start off cleared */ /* internal databases don't mmap or lock, and start off cleared */
if (tdb->flags & TDB1_INTERNAL) { if (tdb->flags & TDB_INTERNAL) {
tdb->flags |= (TDB1_NOLOCK | TDB1_NOMMAP); tdb->flags |= (TDB_NOLOCK | TDB_NOMMAP);
tdb->flags &= ~TDB1_CLEAR_IF_FIRST;
if (tdb1_new_database(tdb, hash_size) != 0) { if (tdb1_new_database(tdb, hash_size) != 0) {
tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR, tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
"tdb1_open_ex: tdb1_new_database failed!"); "tdb1_open_ex: tdb1_new_database failed!");
...@@ -301,20 +281,6 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag ...@@ -301,20 +281,6 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag
goto fail; /* errno set by tdb1_brlock */ goto fail; /* errno set by tdb1_brlock */
} }
/* we need to zero database if we are the only one with it open */
if ((tdb1_flags & TDB1_CLEAR_IF_FIRST) &&
(!tdb->read_only) &&
(locked = (tdb1_nest_lock(tdb, TDB1_ACTIVE_LOCK, F_WRLCK, TDB_LOCK_NOWAIT|TDB_LOCK_PROBE) == 0))) {
open_flags |= O_CREAT;
if (ftruncate(tdb->fd, 0) == -1) {
tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
"tdb1_open_ex: "
"failed to truncate %s: %s",
name, strerror(errno));
goto fail; /* errno set by ftruncate */
}
}
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, TDB_MAGIC_FOOD) != 0) { || strcmp(tdb->header.magic_food, TDB_MAGIC_FOOD) != 0) {
...@@ -324,21 +290,17 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag ...@@ -324,21 +290,17 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag
} }
goto fail; goto fail;
} }
rev = (tdb->flags & TDB1_CONVERT); rev = (tdb->flags & TDB_CONVERT);
} else if (tdb->header.version != TDB1_VERSION } else if (tdb->header.version != TDB1_VERSION
&& !(rev = (tdb->header.version==TDB1_BYTEREV(TDB1_VERSION)))) { && !(rev = (tdb->header.version==TDB1_BYTEREV(TDB1_VERSION)))) {
/* wrong version */ /* wrong version */
errno = EIO; errno = EIO;
goto fail; goto fail;
} }
vp = (unsigned char *)&tdb->header.version;
vertest = (((uint32_t)vp[0]) << 24) | (((uint32_t)vp[1]) << 16) |
(((uint32_t)vp[2]) << 8) | (uint32_t)vp[3];
tdb->flags |= (vertest==TDB1_VERSION) ? TDB1_BIGENDIAN : 0;
if (!rev) if (!rev)
tdb->flags &= ~TDB1_CONVERT; tdb->flags &= ~TDB_CONVERT;
else { else {
tdb->flags |= TDB1_CONVERT; tdb->flags |= TDB_CONVERT;
tdb1_convert(&tdb->header, sizeof(tdb->header)); tdb1_convert(&tdb->header, sizeof(tdb->header));
} }
if (fstat(tdb->fd, &st) == -1) if (fstat(tdb->fd, &st) == -1)
...@@ -385,27 +347,6 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag ...@@ -385,27 +347,6 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag
tdb->device = st.st_dev; tdb->device = st.st_dev;
tdb->inode = st.st_ino; tdb->inode = st.st_ino;
tdb1_mmap(tdb); tdb1_mmap(tdb);
if (locked) {
if (tdb1_nest_unlock(tdb, TDB1_ACTIVE_LOCK, F_WRLCK) == -1) {
tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
"tdb1_open_ex: "
"failed to release ACTIVE_LOCK on %s: %s",
name, strerror(errno));
goto fail;
}
}
/* We always need to do this if the CLEAR_IF_FIRST flag is set, even if
we didn't get the initial exclusive lock as we need to let all other
users know we're using it. */
if (tdb1_flags & TDB1_CLEAR_IF_FIRST) {
/* leave this lock in place to indicate it's in use */
if (tdb1_nest_lock(tdb, TDB1_ACTIVE_LOCK, F_RDLCK, TDB_LOCK_WAIT) == -1) {
goto fail;
}
}
/* if needed, run recovery */ /* if needed, run recovery */
if (tdb1_transaction_recover(tdb) == -1) { if (tdb1_transaction_recover(tdb) == -1) {
...@@ -430,7 +371,7 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag ...@@ -430,7 +371,7 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag
return NULL; return NULL;
if (tdb->map_ptr) { if (tdb->map_ptr) {
if (tdb->flags & TDB1_INTERNAL) if (tdb->flags & TDB_INTERNAL)
SAFE_FREE(tdb->map_ptr); SAFE_FREE(tdb->map_ptr);
else else
tdb1_munmap(tdb); tdb1_munmap(tdb);
...@@ -471,7 +412,7 @@ int tdb1_close(struct tdb1_context *tdb) ...@@ -471,7 +412,7 @@ int tdb1_close(struct tdb1_context *tdb)
} }
if (tdb->map_ptr) { if (tdb->map_ptr) {
if (tdb->flags & TDB1_INTERNAL) if (tdb->flags & TDB_INTERNAL)
SAFE_FREE(tdb->map_ptr); SAFE_FREE(tdb->map_ptr);
else else
tdb1_munmap(tdb); tdb1_munmap(tdb);
......
...@@ -97,7 +97,7 @@ typedef uint32_t tdb1_off_t; ...@@ -97,7 +97,7 @@ typedef uint32_t tdb1_off_t;
#define TDB1_BUCKET(hash) ((hash) % tdb->header.hash_size) #define TDB1_BUCKET(hash) ((hash) % tdb->header.hash_size)
#define TDB1_DOCONV() (tdb->flags & TDB1_CONVERT) #define TDB1_DOCONV() (tdb->flags & TDB_CONVERT)
#define TDB1_CONV(x) (TDB1_DOCONV() ? tdb1_convert(&x, sizeof(x)) : &x) #define TDB1_CONV(x) (TDB1_DOCONV() ? tdb1_convert(&x, sizeof(x)) : &x)
/* the body of the database is made of one tdb1_record for the free space /* the body of the database is made of one tdb1_record for the free space
......
...@@ -31,13 +31,13 @@ TDB_DATA tdb1_null; ...@@ -31,13 +31,13 @@ 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
the TDB1_SEQNUM flag the TDB_SEQNUM flag
*/ */
void tdb1_increment_seqnum_nonblock(struct tdb1_context *tdb) void tdb1_increment_seqnum_nonblock(struct tdb1_context *tdb)
{ {
tdb1_off_t seqnum=0; tdb1_off_t seqnum=0;
if (!(tdb->flags & TDB1_SEQNUM)) { if (!(tdb->flags & TDB_SEQNUM)) {
return; return;
} }
...@@ -51,11 +51,11 @@ void tdb1_increment_seqnum_nonblock(struct tdb1_context *tdb) ...@@ -51,11 +51,11 @@ void tdb1_increment_seqnum_nonblock(struct tdb1_context *tdb)
/* /*
increment the tdb sequence number if the tdb has been opened using increment the tdb sequence number if the tdb has been opened using
the TDB1_SEQNUM flag the TDB_SEQNUM flag
*/ */
static void tdb1_increment_seqnum(struct tdb1_context *tdb) static void tdb1_increment_seqnum(struct tdb1_context *tdb)
{ {
if (!(tdb->flags & TDB1_SEQNUM)) { if (!(tdb->flags & TDB_SEQNUM)) {
return; return;
} }
...@@ -843,7 +843,7 @@ int tdb1_repack(struct tdb1_context *tdb) ...@@ -843,7 +843,7 @@ int tdb1_repack(struct tdb1_context *tdb)
return -1; return -1;
} }
tmp_db = tdb1_open("tmpdb", tdb1_hash_size(tdb), TDB1_INTERNAL, O_RDWR|O_CREAT, 0); tmp_db = tdb1_open("tmpdb", tdb1_hash_size(tdb), TDB_INTERNAL, O_RDWR|O_CREAT, 0);
if (tmp_db == NULL) { if (tmp_db == NULL) {
tdb->last_error = tdb_logerr(tdb, TDB_ERR_OOM, TDB_LOG_ERROR, tdb->last_error = tdb_logerr(tdb, TDB_ERR_OOM, TDB_LOG_ERROR,
__location__ " Failed to create tmp_db"); __location__ " Failed to create tmp_db");
......
...@@ -81,25 +81,16 @@ ...@@ -81,25 +81,16 @@
usual. This allows for smooth crash recovery with no administrator usual. This allows for smooth crash recovery with no administrator
intervention. intervention.
- if TDB1_NOSYNC is passed to flags in tdb1_open then transactions are - if TDB_NOSYNC is passed to flags in tdb1_open then transactions are
still available, but no transaction recovery area is used and no still available, but no transaction recovery area is used and no
fsync/msync calls are made. fsync/msync calls are made.
- if TDB1_ALLOW_NESTING is passed to flags in tdb open, or added using - if TDB_ALLOW_NESTING is passed to flags in tdb open, or added using
tdb1_add_flags() transaction nesting is enabled. tdb1_add_flags() transaction nesting is enabled.
It resets the TDB1_DISALLOW_NESTING flag, as both cannot be used together. The default is that transaction nesting is NOT allowed.
The default is that transaction nesting is allowed.
Note: this default may change in future versions of tdb.
Beware. when transactions are nested a transaction successfully Beware. when transactions are nested a transaction successfully
completed with tdb1_transaction_commit() can be silently unrolled later. completed with tdb1_transaction_commit() can be silently unrolled later.
- if TDB1_DISALLOW_NESTING is passed to flags in tdb open, or added using
tdb1_add_flags() transaction nesting is disabled.
It resets the TDB1_ALLOW_NESTING flag, as both cannot be used together.
An attempt create a nested transaction will fail with TDB_ERR_EINVAL.
The default is that transaction nesting is allowed.
Note: this default may change in future versions of tdb.
*/ */
...@@ -427,7 +418,7 @@ static const struct tdb1_methods transaction1_methods = { ...@@ -427,7 +418,7 @@ static const struct tdb1_methods transaction1_methods = {
static int _tdb1_transaction_start(struct tdb1_context *tdb) static int _tdb1_transaction_start(struct tdb1_context *tdb)
{ {
/* some sanity checks */ /* some sanity checks */
if (tdb->read_only || (tdb->flags & TDB1_INTERNAL) || tdb->traverse_read) { if (tdb->read_only || (tdb->flags & TDB_INTERNAL) || tdb->traverse_read) {
tdb->last_error = tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_LOG_USE_ERROR, tdb->last_error = tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_LOG_USE_ERROR,
"tdb1_transaction_start: cannot start a" "tdb1_transaction_start: cannot start a"
" transaction on a read-only or" " transaction on a read-only or"
...@@ -437,7 +428,7 @@ static int _tdb1_transaction_start(struct tdb1_context *tdb) ...@@ -437,7 +428,7 @@ static int _tdb1_transaction_start(struct tdb1_context *tdb)
/* cope with nested tdb1_transaction_start() calls */ /* cope with nested tdb1_transaction_start() calls */
if (tdb->transaction != NULL) { if (tdb->transaction != NULL) {
if (!(tdb->flags & TDB1_ALLOW_NESTING)) { if (!(tdb->flags & TDB_ALLOW_NESTING)) {
tdb->last_error = TDB_ERR_EINVAL; tdb->last_error = TDB_ERR_EINVAL;
return -1; return -1;
} }
...@@ -539,7 +530,7 @@ int tdb1_transaction_start(struct tdb1_context *tdb) ...@@ -539,7 +530,7 @@ int tdb1_transaction_start(struct tdb1_context *tdb)
*/ */
static int transaction1_sync(struct tdb1_context *tdb, tdb1_off_t offset, tdb1_len_t length) static int transaction1_sync(struct tdb1_context *tdb, tdb1_off_t offset, tdb1_len_t length)
{ {
if (tdb->flags & TDB1_NOSYNC) { if (tdb->flags & TDB_NOSYNC) {
return 0; return 0;
} }
...@@ -981,7 +972,7 @@ static int _tdb1_transaction_prepare_commit(struct tdb1_context *tdb) ...@@ -981,7 +972,7 @@ static int _tdb1_transaction_prepare_commit(struct tdb1_context *tdb)
return -1; return -1;
} }
if (!(tdb->flags & TDB1_NOSYNC)) { if (!(tdb->flags & TDB_NOSYNC)) {
/* write the recovery data to the end of the file */ /* write the recovery data to the end of the file */
if (transaction1_setup_recovery(tdb, &tdb->transaction->magic_offset) == -1) { if (transaction1_setup_recovery(tdb, &tdb->transaction->magic_offset) == -1) {
tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR, tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
......
...@@ -66,7 +66,7 @@ int main(int argc, char *argv[]) ...@@ -66,7 +66,7 @@ int main(int argc, char *argv[])
struct tdb1_record rec; struct tdb1_record rec;
plan_tests(24); plan_tests(24);
tdb = tdb1_open_ex("run-36-file.tdb", 1024, TDB1_CLEAR_IF_FIRST, tdb = tdb1_open_ex("run-36-file.tdb", 1024, TDB_DEFAULT,
O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL); O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
ok1(tdb); ok1(tdb);
......
...@@ -10,7 +10,7 @@ int main(int argc, char *argv[]) ...@@ -10,7 +10,7 @@ int main(int argc, char *argv[])
TDB_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, TDB_DEFAULT,
O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL); O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
ok1(tdb); ok1(tdb);
......
...@@ -97,7 +97,7 @@ int main(int argc, char *argv[]) ...@@ -97,7 +97,7 @@ int main(int argc, char *argv[])
plan_tests(4); plan_tests(4);
/* This should use mmap. */ /* This should use mmap. */
tdb = tdb1_open_ex("run-corrupt.tdb", 2, TDB1_CLEAR_IF_FIRST, tdb = tdb1_open_ex("run-corrupt.tdb", 2, TDB_DEFAULT,
O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL); O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
if (!tdb) if (!tdb)
...@@ -106,7 +106,7 @@ int main(int argc, char *argv[]) ...@@ -106,7 +106,7 @@ int main(int argc, char *argv[])
tdb1_close(tdb); tdb1_close(tdb);
/* This should not. */ /* This should not. */
tdb = tdb1_open_ex("run-corrupt.tdb", 2, TDB1_CLEAR_IF_FIRST|TDB1_NOMMAP, tdb = tdb1_open_ex("run-corrupt.tdb", 2, TDB_NOMMAP,
O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL); O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
if (!tdb) if (!tdb)
......
...@@ -89,7 +89,7 @@ static bool test_death(enum operation op, struct agent *agent) ...@@ -89,7 +89,7 @@ static bool test_death(enum operation op, struct agent *agent)
current = target = 0; current = target = 0;
reset: reset:
unlink(TEST_DBNAME); unlink(TEST_DBNAME);
tdb = tdb1_open_ex(TEST_DBNAME, 1024, TDB1_NOMMAP, tdb = tdb1_open_ex(TEST_DBNAME, 1024, TDB_NOMMAP,
O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL); O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
if (setjmp(jmpbuf) != 0) { if (setjmp(jmpbuf) != 0) {
......
...@@ -11,7 +11,7 @@ int main(int argc, char *argv[]) ...@@ -11,7 +11,7 @@ int main(int argc, char *argv[])
plan_tests(13); plan_tests(13);
tdb = tdb1_open_ex("run-endian.tdb", 1024, tdb = tdb1_open_ex("run-endian.tdb", 1024,
TDB1_CLEAR_IF_FIRST|TDB1_CONVERT, TDB_CONVERT,
O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL); O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
ok1(tdb); ok1(tdb);
......
...@@ -50,10 +50,10 @@ int main(int argc, char *argv[]) ...@@ -50,10 +50,10 @@ int main(int argc, char *argv[])
plan_tests(38 * 2); plan_tests(38 * 2);
for (flags = 0; flags <= TDB1_CONVERT; flags += TDB1_CONVERT) { for (flags = 0; flags <= TDB_CONVERT; flags += TDB_CONVERT) {
unsigned int rwmagic = TDB1_HASH_RWLOCK_MAGIC; unsigned int rwmagic = TDB1_HASH_RWLOCK_MAGIC;
if (flags & TDB1_CONVERT) if (flags & TDB_CONVERT)
tdb1_convert(&rwmagic, sizeof(rwmagic)); tdb1_convert(&rwmagic, sizeof(rwmagic));
/* Create an old-style hash. */ /* Create an old-style hash. */
......
...@@ -15,10 +15,11 @@ int main(int argc, char *argv[]) ...@@ -15,10 +15,11 @@ int main(int argc, char *argv[])
key.dptr = (void *)"hi"; key.dptr = (void *)"hi";
tdb = tdb1_open_ex("run-nested-transactions.tdb", tdb = tdb1_open_ex("run-nested-transactions.tdb",
1024, TDB1_CLEAR_IF_FIRST|TDB1_DISALLOW_NESTING, 1024, TDB_DEFAULT,
O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL); O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
ok1(tdb); ok1(tdb);
/* No nesting by default. */
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");
...@@ -41,9 +42,8 @@ int main(int argc, char *argv[]) ...@@ -41,9 +42,8 @@ int main(int argc, char *argv[])
free(data.dptr); free(data.dptr);
tdb1_close(tdb); tdb1_close(tdb);
/* Allow nesting by default. */
tdb = tdb1_open_ex("run-nested-transactions.tdb", tdb = tdb1_open_ex("run-nested-transactions.tdb",
1024, TDB1_DEFAULT, O_RDWR, 0, &taplogctx, NULL); 1024, TDB_ALLOW_NESTING, O_RDWR, 0, &taplogctx, NULL);
ok1(tdb); ok1(tdb);
ok1(tdb1_transaction_start(tdb) == 0); ok1(tdb1_transaction_start(tdb) == 0);
......
...@@ -56,7 +56,7 @@ int main(int argc, char *argv[]) ...@@ -56,7 +56,7 @@ int main(int argc, char *argv[])
if (!agent) if (!agent)
err(1, "preparing agent"); err(1, "preparing agent");
tdb = tdb1_open_ex("run-nested-traverse.tdb", 1024, TDB1_CLEAR_IF_FIRST, tdb = tdb1_open_ex("run-nested-traverse.tdb", 1024, TDB_DEFAULT,
O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL); O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
ok1(tdb); ok1(tdb);
......
...@@ -71,7 +71,7 @@ int main(int argc, char *argv[]) ...@@ -71,7 +71,7 @@ int main(int argc, char *argv[])
plan_tests(41); plan_tests(41);
tdb = tdb1_open_ex("run-no-lock-during-traverse.tdb", tdb = tdb1_open_ex("run-no-lock-during-traverse.tdb",
1024, TDB1_CLEAR_IF_FIRST, O_CREAT|O_TRUNC|O_RDWR, 1024, TDB_DEFAULT, O_CREAT|O_TRUNC|O_RDWR,
0600, &taplogctx, NULL); 0600, &taplogctx, NULL);
ok1(tdb); ok1(tdb);
......
...@@ -23,7 +23,6 @@ static int ftruncate_check(int fd, off_t length); ...@@ -23,7 +23,6 @@ static int ftruncate_check(int fd, off_t length);
static struct agent *agent; static struct agent *agent;
static bool opened; static bool opened;
static int errors = 0; static int errors = 0;
static bool clear_if_first;
#define TEST_DBNAME "run-open-during-transaction.tdb" #define TEST_DBNAME "run-open-during-transaction.tdb"
#undef write #undef write
...@@ -70,10 +69,7 @@ static void check_file_intact(int fd) ...@@ -70,10 +69,7 @@ static void check_file_intact(int fd)
} }
/* Ask agent to open file. */ /* Ask agent to open file. */
ret = external_agent_operation1(agent, clear_if_first ? ret = external_agent_operation1(agent, OPEN, TEST_DBNAME);
OPEN_WITH_CLEAR_IF_FIRST :
OPEN,
TEST_DBNAME);
/* It's OK to open it, but it must not have changed! */ /* It's OK to open it, but it must not have changed! */
if (!compare_file(fd, contents, st.st_size)) { if (!compare_file(fd, contents, st.st_size)) {
...@@ -132,25 +128,22 @@ static int ftruncate_check(int fd, off_t length) ...@@ -132,25 +128,22 @@ static int ftruncate_check(int fd, off_t length)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
const int flags[] = { TDB1_DEFAULT, const int flags[] = { TDB_DEFAULT,
TDB1_CLEAR_IF_FIRST, TDB_NOMMAP };
TDB1_NOMMAP,
TDB1_CLEAR_IF_FIRST | TDB1_NOMMAP };
int i; int i;
struct tdb1_context *tdb; struct tdb1_context *tdb;
TDB_DATA key, data; TDB_DATA key, data;
plan_tests(20); plan_tests(10);
agent = prepare_external_agent1(); agent = prepare_external_agent1();
if (!agent) if (!agent)
err(1, "preparing agent"); err(1, "preparing agent");
unlock_callback1 = after_unlock; unlock_callback1 = after_unlock;
for (i = 0; i < sizeof(flags)/sizeof(flags[0]); i++) { for (i = 0; i < sizeof(flags)/sizeof(flags[0]); i++) {
clear_if_first = (flags[i] & TDB1_CLEAR_IF_FIRST);
diag("Test with %s and %s\n", diag("Test with %s and %s\n",
clear_if_first ? "CLEAR" : "DEFAULT", "DEFAULT",
(flags[i] & TDB1_NOMMAP) ? "no mmap" : "mmap"); (flags[i] & TDB_NOMMAP) ? "no mmap" : "mmap");
unlink(TEST_DBNAME); unlink(TEST_DBNAME);
tdb = tdb1_open_ex(TEST_DBNAME, 1024, flags[i], tdb = tdb1_open_ex(TEST_DBNAME, 1024, flags[i],
O_CREAT|O_TRUNC|O_RDWR, 0600, O_CREAT|O_TRUNC|O_RDWR, 0600,
......
...@@ -13,7 +13,7 @@ int main(int argc, char *argv[]) ...@@ -13,7 +13,7 @@ int main(int argc, char *argv[])
plan_tests(11); plan_tests(11);
tdb = tdb1_open_ex("run-readonly-check.tdb", 1024, tdb = tdb1_open_ex("run-readonly-check.tdb", 1024,
TDB1_DEFAULT, TDB_DEFAULT,
O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL); O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
ok1(tdb); ok1(tdb);
...@@ -31,7 +31,7 @@ int main(int argc, char *argv[]) ...@@ -31,7 +31,7 @@ int main(int argc, char *argv[])
ok1(tdb1_close(tdb) == 0); ok1(tdb1_close(tdb) == 0);
tdb = tdb1_open_ex("run-readonly-check.tdb", 1024, tdb = tdb1_open_ex("run-readonly-check.tdb", 1024,
TDB1_DEFAULT, O_RDONLY, 0, &taplogctx, NULL); TDB_DEFAULT, O_RDONLY, 0, &taplogctx, NULL);
ok1(tdb); ok1(tdb);
ok1(tdb1_store(tdb, key, data, TDB_MODIFY) == -1); ok1(tdb1_store(tdb, key, data, TDB_MODIFY) == -1);
......
...@@ -7,9 +7,9 @@ int main(int argc, char *argv[]) ...@@ -7,9 +7,9 @@ int main(int argc, char *argv[])
{ {
unsigned int i, j; unsigned int i, j;
struct tdb1_context *tdb; struct tdb1_context *tdb;
int flags[] = { TDB1_INTERNAL, TDB1_DEFAULT, TDB1_NOMMAP, int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
TDB1_INTERNAL|TDB1_CONVERT, TDB1_CONVERT, TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT,
TDB1_NOMMAP|TDB1_CONVERT }; TDB_NOMMAP|TDB_CONVERT };
TDB_DATA key = { (unsigned char *)&j, sizeof(j) }; TDB_DATA key = { (unsigned char *)&j, sizeof(j) };
TDB_DATA data = { (unsigned char *)&j, sizeof(j) }; TDB_DATA data = { (unsigned char *)&j, sizeof(j) };
char *summary; char *summary;
......
...@@ -43,7 +43,7 @@ int main(int argc, char *argv[]) ...@@ -43,7 +43,7 @@ int main(int argc, char *argv[])
err(1, "preparing agent"); err(1, "preparing agent");
tdb = tdb1_open_ex("run-traverse-in-transaction.tdb", tdb = tdb1_open_ex("run-traverse-in-transaction.tdb",
1024, TDB1_CLEAR_IF_FIRST, O_CREAT|O_TRUNC|O_RDWR, 1024, TDB_DEFAULT, O_CREAT|O_TRUNC|O_RDWR,
0600, &taplogctx, NULL); 0600, &taplogctx, NULL);
ok1(tdb); ok1(tdb);
......
...@@ -10,7 +10,7 @@ int main(int argc, char *argv[]) ...@@ -10,7 +10,7 @@ int main(int argc, char *argv[])
TDB_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, TDB_INTERNAL, O_CREAT|O_TRUNC|O_RDWR,
0600, &taplogctx, NULL); 0600, &taplogctx, NULL);
ok1(tdb); ok1(tdb);
......
...@@ -10,7 +10,7 @@ int main(int argc, char *argv[]) ...@@ -10,7 +10,7 @@ int main(int argc, char *argv[])
TDB_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, TDB_DEFAULT,
O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL); O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
ok1(tdb); ok1(tdb);
......
...@@ -24,7 +24,7 @@ static enum agent_return do_operation(enum operation op, const char *name) ...@@ -24,7 +24,7 @@ static enum agent_return do_operation(enum operation op, const char *name)
enum agent_return ret; enum agent_return ret;
TDB_DATA data; TDB_DATA data;
if (op != OPEN && op != OPEN_WITH_CLEAR_IF_FIRST && !tdb) { if (op != OPEN && !tdb) {
diag("external: No tdb open!"); diag("external: No tdb open!");
return OTHER_FAILURE; return OTHER_FAILURE;
} }
...@@ -39,7 +39,7 @@ static enum agent_return do_operation(enum operation op, const char *name) ...@@ -39,7 +39,7 @@ static enum agent_return do_operation(enum operation op, const char *name)
diag("Already have tdb %s open", tdb->name); diag("Already have tdb %s open", tdb->name);
return OTHER_FAILURE; return OTHER_FAILURE;
} }
tdb = tdb1_open_ex(name, 0, TDB1_DEFAULT, O_RDWR, 0, tdb = tdb1_open_ex(name, 0, TDB_DEFAULT, O_RDWR, 0,
&taplogctx, NULL); &taplogctx, NULL);
if (!tdb) { if (!tdb) {
if (!locking_would_block1) if (!locking_would_block1)
...@@ -48,13 +48,6 @@ static enum agent_return do_operation(enum operation op, const char *name) ...@@ -48,13 +48,6 @@ static enum agent_return do_operation(enum operation op, const char *name)
} else } else
ret = SUCCESS; ret = SUCCESS;
break; break;
case OPEN_WITH_CLEAR_IF_FIRST:
if (tdb)
return OTHER_FAILURE;
tdb = tdb1_open_ex(name, 0, TDB1_CLEAR_IF_FIRST, O_RDWR, 0,
&taplogctx, NULL);
ret = tdb ? SUCCESS : OTHER_FAILURE;
break;
case TRANSACTION_START: case TRANSACTION_START:
ret = tdb1_transaction_start(tdb) == 0 ? SUCCESS : OTHER_FAILURE; ret = tdb1_transaction_start(tdb) == 0 ? SUCCESS : OTHER_FAILURE;
break; break;
...@@ -183,7 +176,6 @@ const char *operation_name1(enum operation op) ...@@ -183,7 +176,6 @@ const char *operation_name1(enum operation op)
{ {
switch (op) { switch (op) {
case OPEN: return "OPEN"; case OPEN: return "OPEN";
case OPEN_WITH_CLEAR_IF_FIRST: return "OPEN_WITH_CLEAR_IF_FIRST";
case TRANSACTION_START: return "TRANSACTION_START"; case TRANSACTION_START: return "TRANSACTION_START";
case FETCH: return "FETCH"; case FETCH: return "FETCH";
case STORE: return "STORE"; case STORE: return "STORE";
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
* various times. */ * various times. */
enum operation { enum operation {
OPEN, OPEN,
OPEN_WITH_CLEAR_IF_FIRST,
TRANSACTION_START, TRANSACTION_START,
FETCH, FETCH,
STORE, STORE,
......
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