diff options
Diffstat (limited to 'lib/tdb2')
24 files changed, 67 insertions, 165 deletions
diff --git a/lib/tdb2/tdb1.h b/lib/tdb2/tdb1.h index 3869373fbe..67e00c7c86 100644 --- a/lib/tdb2/tdb1.h +++ b/lib/tdb2/tdb1.h @@ -36,20 +36,6 @@ #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. */ typedef struct tdb1_context TDB1_CONTEXT; diff --git a/lib/tdb2/tdb1_io.c b/lib/tdb2/tdb1_io.c index 758eac6394..d5684dc7fd 100644 --- a/lib/tdb2/tdb1_io.c +++ b/lib/tdb2/tdb1_io.c @@ -41,7 +41,7 @@ static int tdb1_oob(struct tdb1_context *tdb, tdb1_off_t len, int probe) struct stat st; if (len <= tdb->map_size) return 0; - if (tdb->flags & TDB1_INTERNAL) { + if (tdb->flags & TDB_INTERNAL) { if (!probe) { tdb->last_error = tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR, "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) int tdb1_munmap(struct tdb1_context *tdb) { - if (tdb->flags & TDB1_INTERNAL) + if (tdb->flags & TDB_INTERNAL) return 0; #if HAVE_MMAP @@ -207,11 +207,11 @@ int tdb1_munmap(struct tdb1_context *tdb) void tdb1_mmap(struct tdb1_context *tdb) { - if (tdb->flags & TDB1_INTERNAL) + if (tdb->flags & TDB_INTERNAL) return; #if HAVE_MMAP - if (!(tdb->flags & TDB1_NOMMAP)) { + if (!(tdb->flags & TDB_NOMMAP)) { tdb->map_ptr = mmap(NULL, tdb->map_size, PROT_READ|(tdb->read_only? 0:PROT_WRITE), MAP_SHARED|MAP_FILE, tdb->fd, 0); @@ -339,7 +339,7 @@ int tdb1_expand(struct tdb1_context *tdb, tdb1_off_t size) new_size = MAX(top_size, 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); /* @@ -349,14 +349,14 @@ int tdb1_expand(struct tdb1_context *tdb, tdb1_off_t size) */ /* 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) goto fail; } tdb->map_size += size; - if (tdb->flags & TDB1_INTERNAL) { + if (tdb->flags & TDB_INTERNAL) { char *new_map_ptr = (char *)realloc(tdb->map_ptr, tdb->map_size); if (!new_map_ptr) { diff --git a/lib/tdb2/tdb1_lock.c b/lib/tdb2/tdb1_lock.c index c427804893..0fba7423a2 100644 --- a/lib/tdb2/tdb1_lock.c +++ b/lib/tdb2/tdb1_lock.c @@ -134,7 +134,7 @@ int tdb1_brlock(struct tdb1_context *tdb, { int ret; - if (tdb->flags & TDB1_NOLOCK) { + if (tdb->flags & TDB_NOLOCK) { return 0; } @@ -168,7 +168,7 @@ int tdb1_brunlock(struct tdb1_context *tdb, { int ret; - if (tdb->flags & TDB1_NOLOCK) { + if (tdb->flags & TDB_NOLOCK) { return 0; } @@ -257,7 +257,7 @@ int tdb1_nest_lock(struct tdb1_context *tdb, uint32_t offset, int ltype, offset, ltype); return -1; } - if (tdb->flags & TDB1_NOLOCK) + if (tdb->flags & TDB_NOLOCK) return 0; new_lck = tdb1_find_nestlock(tdb, offset); @@ -377,7 +377,7 @@ int tdb1_nest_unlock(struct tdb1_context *tdb, uint32_t offset, int ltype) int ret = -1; struct tdb1_lock_type *lck; - if (tdb->flags & TDB1_NOLOCK) + if (tdb->flags & TDB_NOLOCK) return 0; /* Sanity checks */ diff --git a/lib/tdb2/tdb1_open.c b/lib/tdb2/tdb1_open.c index f53a32b5be..5176f57f77 100644 --- a/lib/tdb2/tdb1_open.c +++ b/lib/tdb2/tdb1_open.c @@ -75,7 +75,7 @@ static int tdb1_new_database(struct tdb1_context *tdb, int hash_size) if (tdb->hash_fn == tdb1_incompatible_hash) newdb->rwlocks = TDB1_HASH_RWLOCK_MAGIC; - if (tdb->flags & TDB1_INTERNAL) { + if (tdb->flags & TDB_INTERNAL) { tdb->map_size = size; tdb->map_ptr = (char *)newdb; 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 { struct tdb1_context *tdb; struct stat st; - int rev = 0, locked = 0; - unsigned char *vp; - uint32_t vertest; + int rev = 0; unsigned v; const char *hash_alg; uint32_t magic1, magic2; @@ -190,7 +188,7 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag } else tdb->log_fn = NULL; - if (name == NULL && (tdb1_flags & TDB1_INTERNAL)) { + if (name == NULL && (tdb1_flags & TDB_INTERNAL)) { name = "__TDB1_INTERNAL__"; } @@ -234,7 +232,8 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag 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) { 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 hash_size = TDB1_DEFAULT_HASH_SIZE; if ((open_flags & O_ACCMODE) == O_RDONLY) { tdb->read_only = 1; - /* read only databases don't do locking or clear if first */ - tdb->flags |= TDB1_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; + /* read only databases don't do locking */ + tdb->flags |= TDB_NOLOCK; } /* internal databases don't mmap or lock, and start off cleared */ - if (tdb->flags & TDB1_INTERNAL) { - tdb->flags |= (TDB1_NOLOCK | TDB1_NOMMAP); - tdb->flags &= ~TDB1_CLEAR_IF_FIRST; + if (tdb->flags & TDB_INTERNAL) { + tdb->flags |= (TDB_NOLOCK | TDB_NOMMAP); if (tdb1_new_database(tdb, hash_size) != 0) { tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR, "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 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; if (read(tdb->fd, &tdb->header, sizeof(tdb->header)) != sizeof(tdb->header) || 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 } goto fail; } - rev = (tdb->flags & TDB1_CONVERT); + rev = (tdb->flags & TDB_CONVERT); } else if (tdb->header.version != TDB1_VERSION && !(rev = (tdb->header.version==TDB1_BYTEREV(TDB1_VERSION)))) { /* wrong version */ errno = EIO; 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) - tdb->flags &= ~TDB1_CONVERT; + tdb->flags &= ~TDB_CONVERT; else { - tdb->flags |= TDB1_CONVERT; + tdb->flags |= TDB_CONVERT; tdb1_convert(&tdb->header, sizeof(tdb->header)); } 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 tdb->device = st.st_dev; tdb->inode = st.st_ino; 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 (tdb1_transaction_recover(tdb) == -1) { @@ -430,7 +371,7 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag return NULL; if (tdb->map_ptr) { - if (tdb->flags & TDB1_INTERNAL) + if (tdb->flags & TDB_INTERNAL) SAFE_FREE(tdb->map_ptr); else tdb1_munmap(tdb); @@ -471,7 +412,7 @@ int tdb1_close(struct tdb1_context *tdb) } if (tdb->map_ptr) { - if (tdb->flags & TDB1_INTERNAL) + if (tdb->flags & TDB_INTERNAL) SAFE_FREE(tdb->map_ptr); else tdb1_munmap(tdb); diff --git a/lib/tdb2/tdb1_private.h b/lib/tdb2/tdb1_private.h index 20838bfe7b..0d40d7a919 100644 --- a/lib/tdb2/tdb1_private.h +++ b/lib/tdb2/tdb1_private.h @@ -97,7 +97,7 @@ typedef uint32_t tdb1_off_t; #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) /* the body of the database is made of one tdb1_record for the free space diff --git a/lib/tdb2/tdb1_tdb.c b/lib/tdb2/tdb1_tdb.c index c9406c4b16..a1a0643835 100644 --- a/lib/tdb2/tdb1_tdb.c +++ b/lib/tdb2/tdb1_tdb.c @@ -31,13 +31,13 @@ TDB_DATA tdb1_null; /* 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) { tdb1_off_t seqnum=0; - if (!(tdb->flags & TDB1_SEQNUM)) { + if (!(tdb->flags & TDB_SEQNUM)) { return; } @@ -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 - the TDB1_SEQNUM flag + the TDB_SEQNUM flag */ static void tdb1_increment_seqnum(struct tdb1_context *tdb) { - if (!(tdb->flags & TDB1_SEQNUM)) { + if (!(tdb->flags & TDB_SEQNUM)) { return; } @@ -843,7 +843,7 @@ int tdb1_repack(struct tdb1_context *tdb) 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) { tdb->last_error = tdb_logerr(tdb, TDB_ERR_OOM, TDB_LOG_ERROR, __location__ " Failed to create tmp_db"); diff --git a/lib/tdb2/tdb1_transaction.c b/lib/tdb2/tdb1_transaction.c index 51aa2e11b0..d35c4bc466 100644 --- a/lib/tdb2/tdb1_transaction.c +++ b/lib/tdb2/tdb1_transaction.c @@ -81,25 +81,16 @@ usual. This allows for smooth crash recovery with no administrator 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 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. - It resets the TDB1_DISALLOW_NESTING flag, as both cannot be used together. - The default is that transaction nesting is allowed. - Note: this default may change in future versions of tdb. + The default is that transaction nesting is NOT allowed. Beware. when transactions are nested a transaction successfully 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 = { static int _tdb1_transaction_start(struct tdb1_context *tdb) { /* 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, "tdb1_transaction_start: cannot start a" " transaction on a read-only or" @@ -437,7 +428,7 @@ static int _tdb1_transaction_start(struct tdb1_context *tdb) /* cope with nested tdb1_transaction_start() calls */ if (tdb->transaction != NULL) { - if (!(tdb->flags & TDB1_ALLOW_NESTING)) { + if (!(tdb->flags & TDB_ALLOW_NESTING)) { tdb->last_error = TDB_ERR_EINVAL; return -1; } @@ -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) { - if (tdb->flags & TDB1_NOSYNC) { + if (tdb->flags & TDB_NOSYNC) { return 0; } @@ -981,7 +972,7 @@ static int _tdb1_transaction_prepare_commit(struct tdb1_context *tdb) return -1; } - if (!(tdb->flags & TDB1_NOSYNC)) { + if (!(tdb->flags & TDB_NOSYNC)) { /* write the recovery data to the end of the file */ if (transaction1_setup_recovery(tdb, &tdb->transaction->magic_offset) == -1) { tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR, diff --git a/lib/tdb2/test/run-tdb1-3G-file.c b/lib/tdb2/test/run-tdb1-3G-file.c index 6121b4de48..98e3a3006c 100644 --- a/lib/tdb2/test/run-tdb1-3G-file.c +++ b/lib/tdb2/test/run-tdb1-3G-file.c @@ -66,7 +66,7 @@ int main(int argc, char *argv[]) struct tdb1_record rec; 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); ok1(tdb); diff --git a/lib/tdb2/test/run-tdb1-check.c b/lib/tdb2/test/run-tdb1-check.c index fb49b64e48..f05608feaa 100644 --- a/lib/tdb2/test/run-tdb1-check.c +++ b/lib/tdb2/test/run-tdb1-check.c @@ -10,7 +10,7 @@ int main(int argc, char *argv[]) TDB_DATA key, data; 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); ok1(tdb); diff --git a/lib/tdb2/test/run-tdb1-corrupt.c b/lib/tdb2/test/run-tdb1-corrupt.c index bfc25a5711..2a8d31bf66 100644 --- a/lib/tdb2/test/run-tdb1-corrupt.c +++ b/lib/tdb2/test/run-tdb1-corrupt.c @@ -97,7 +97,7 @@ int main(int argc, char *argv[]) plan_tests(4); /* 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); if (!tdb) @@ -106,7 +106,7 @@ int main(int argc, char *argv[]) tdb1_close(tdb); /* 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); if (!tdb) diff --git a/lib/tdb2/test/run-tdb1-die-during-transaction.c b/lib/tdb2/test/run-tdb1-die-during-transaction.c index 3097e13a33..592f75731f 100644 --- a/lib/tdb2/test/run-tdb1-die-during-transaction.c +++ b/lib/tdb2/test/run-tdb1-die-during-transaction.c @@ -89,7 +89,7 @@ static bool test_death(enum operation op, struct agent *agent) current = target = 0; reset: 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); if (setjmp(jmpbuf) != 0) { diff --git a/lib/tdb2/test/run-tdb1-endian.c b/lib/tdb2/test/run-tdb1-endian.c index 35067d7182..9813050d1e 100644 --- a/lib/tdb2/test/run-tdb1-endian.c +++ b/lib/tdb2/test/run-tdb1-endian.c @@ -11,7 +11,7 @@ int main(int argc, char *argv[]) plan_tests(13); 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); ok1(tdb); diff --git a/lib/tdb2/test/run-tdb1-incompatible.c b/lib/tdb2/test/run-tdb1-incompatible.c index 6f3aee0336..a2754461e2 100644 --- a/lib/tdb2/test/run-tdb1-incompatible.c +++ b/lib/tdb2/test/run-tdb1-incompatible.c @@ -50,10 +50,10 @@ int main(int argc, char *argv[]) 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; - if (flags & TDB1_CONVERT) + if (flags & TDB_CONVERT) tdb1_convert(&rwmagic, sizeof(rwmagic)); /* Create an old-style hash. */ diff --git a/lib/tdb2/test/run-tdb1-nested-transactions.c b/lib/tdb2/test/run-tdb1-nested-transactions.c index f9891fe70d..6a13c13ded 100644 --- a/lib/tdb2/test/run-tdb1-nested-transactions.c +++ b/lib/tdb2/test/run-tdb1-nested-transactions.c @@ -15,10 +15,11 @@ int main(int argc, char *argv[]) key.dptr = (void *)"hi"; 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); ok1(tdb); + /* No nesting by default. */ ok1(tdb1_transaction_start(tdb) == 0); data.dptr = (void *)"world"; data.dsize = strlen("world"); @@ -41,9 +42,8 @@ int main(int argc, char *argv[]) free(data.dptr); tdb1_close(tdb); - /* Allow nesting by default. */ 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(tdb1_transaction_start(tdb) == 0); diff --git a/lib/tdb2/test/run-tdb1-nested-traverse.c b/lib/tdb2/test/run-tdb1-nested-traverse.c index a33efec735..5eadc184ff 100644 --- a/lib/tdb2/test/run-tdb1-nested-traverse.c +++ b/lib/tdb2/test/run-tdb1-nested-traverse.c @@ -56,7 +56,7 @@ int main(int argc, char *argv[]) if (!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); ok1(tdb); diff --git a/lib/tdb2/test/run-tdb1-no-lock-during-traverse.c b/lib/tdb2/test/run-tdb1-no-lock-during-traverse.c index 4035c78c73..c1cb40a49e 100644 --- a/lib/tdb2/test/run-tdb1-no-lock-during-traverse.c +++ b/lib/tdb2/test/run-tdb1-no-lock-during-traverse.c @@ -71,7 +71,7 @@ int main(int argc, char *argv[]) plan_tests(41); 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); ok1(tdb); diff --git a/lib/tdb2/test/run-tdb1-open-during-transaction.c b/lib/tdb2/test/run-tdb1-open-during-transaction.c index ad6c6d6074..875fc3ca9e 100644 --- a/lib/tdb2/test/run-tdb1-open-during-transaction.c +++ b/lib/tdb2/test/run-tdb1-open-during-transaction.c @@ -23,7 +23,6 @@ static int ftruncate_check(int fd, off_t length); static struct agent *agent; static bool opened; static int errors = 0; -static bool clear_if_first; #define TEST_DBNAME "run-open-during-transaction.tdb" #undef write @@ -70,10 +69,7 @@ static void check_file_intact(int fd) } /* Ask agent to open file. */ - ret = external_agent_operation1(agent, clear_if_first ? - OPEN_WITH_CLEAR_IF_FIRST : - OPEN, - TEST_DBNAME); + ret = external_agent_operation1(agent, OPEN, TEST_DBNAME); /* It's OK to open it, but it must not have changed! */ if (!compare_file(fd, contents, st.st_size)) { @@ -132,25 +128,22 @@ static int ftruncate_check(int fd, off_t length) int main(int argc, char *argv[]) { - const int flags[] = { TDB1_DEFAULT, - TDB1_CLEAR_IF_FIRST, - TDB1_NOMMAP, - TDB1_CLEAR_IF_FIRST | TDB1_NOMMAP }; + const int flags[] = { TDB_DEFAULT, + TDB_NOMMAP }; int i; struct tdb1_context *tdb; TDB_DATA key, data; - plan_tests(20); + plan_tests(10); agent = prepare_external_agent1(); if (!agent) err(1, "preparing agent"); unlock_callback1 = after_unlock; 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", - clear_if_first ? "CLEAR" : "DEFAULT", - (flags[i] & TDB1_NOMMAP) ? "no mmap" : "mmap"); + "DEFAULT", + (flags[i] & TDB_NOMMAP) ? "no mmap" : "mmap"); unlink(TEST_DBNAME); tdb = tdb1_open_ex(TEST_DBNAME, 1024, flags[i], O_CREAT|O_TRUNC|O_RDWR, 0600, diff --git a/lib/tdb2/test/run-tdb1-readonly-check.c b/lib/tdb2/test/run-tdb1-readonly-check.c index a764f2da42..ae47aa747d 100644 --- a/lib/tdb2/test/run-tdb1-readonly-check.c +++ b/lib/tdb2/test/run-tdb1-readonly-check.c @@ -13,7 +13,7 @@ int main(int argc, char *argv[]) plan_tests(11); tdb = tdb1_open_ex("run-readonly-check.tdb", 1024, - TDB1_DEFAULT, + TDB_DEFAULT, O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL); ok1(tdb); @@ -31,7 +31,7 @@ int main(int argc, char *argv[]) ok1(tdb1_close(tdb) == 0); 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(tdb1_store(tdb, key, data, TDB_MODIFY) == -1); diff --git a/lib/tdb2/test/run-tdb1-summary.c b/lib/tdb2/test/run-tdb1-summary.c index 616c522507..b563b18730 100644 --- a/lib/tdb2/test/run-tdb1-summary.c +++ b/lib/tdb2/test/run-tdb1-summary.c @@ -7,9 +7,9 @@ int main(int argc, char *argv[]) { unsigned int i, j; struct tdb1_context *tdb; - int flags[] = { TDB1_INTERNAL, TDB1_DEFAULT, TDB1_NOMMAP, - TDB1_INTERNAL|TDB1_CONVERT, TDB1_CONVERT, - TDB1_NOMMAP|TDB1_CONVERT }; + int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP, + TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, + TDB_NOMMAP|TDB_CONVERT }; TDB_DATA key = { (unsigned char *)&j, sizeof(j) }; TDB_DATA data = { (unsigned char *)&j, sizeof(j) }; char *summary; diff --git a/lib/tdb2/test/run-tdb1-traverse-in-transaction.c b/lib/tdb2/test/run-tdb1-traverse-in-transaction.c index 4d3a81f19e..922f73caa7 100644 --- a/lib/tdb2/test/run-tdb1-traverse-in-transaction.c +++ b/lib/tdb2/test/run-tdb1-traverse-in-transaction.c @@ -43,7 +43,7 @@ int main(int argc, char *argv[]) err(1, "preparing agent"); 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); ok1(tdb); diff --git a/lib/tdb2/test/run-tdb1-zero-append.c b/lib/tdb2/test/run-tdb1-zero-append.c index 1ecab54ce4..1304bebdbd 100644 --- a/lib/tdb2/test/run-tdb1-zero-append.c +++ b/lib/tdb2/test/run-tdb1-zero-append.c @@ -10,7 +10,7 @@ int main(int argc, char *argv[]) TDB_DATA key, data; 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); ok1(tdb); diff --git a/lib/tdb2/test/run-tdb1.c b/lib/tdb2/test/run-tdb1.c index 1f234b12e3..84eea75ce2 100644 --- a/lib/tdb2/test/run-tdb1.c +++ b/lib/tdb2/test/run-tdb1.c @@ -10,7 +10,7 @@ int main(int argc, char *argv[]) TDB_DATA key, data; 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); ok1(tdb); diff --git a/lib/tdb2/test/tdb1-external-agent.c b/lib/tdb2/test/tdb1-external-agent.c index f60df5b702..18c76f1124 100644 --- a/lib/tdb2/test/tdb1-external-agent.c +++ b/lib/tdb2/test/tdb1-external-agent.c @@ -24,7 +24,7 @@ static enum agent_return do_operation(enum operation op, const char *name) enum agent_return ret; TDB_DATA data; - if (op != OPEN && op != OPEN_WITH_CLEAR_IF_FIRST && !tdb) { + if (op != OPEN && !tdb) { diag("external: No tdb open!"); return OTHER_FAILURE; } @@ -39,7 +39,7 @@ static enum agent_return do_operation(enum operation op, const char *name) diag("Already have tdb %s open", tdb->name); 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); if (!tdb) { if (!locking_would_block1) @@ -48,13 +48,6 @@ static enum agent_return do_operation(enum operation op, const char *name) } else ret = SUCCESS; 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: ret = tdb1_transaction_start(tdb) == 0 ? SUCCESS : OTHER_FAILURE; break; @@ -183,7 +176,6 @@ const char *operation_name1(enum operation op) { switch (op) { case OPEN: return "OPEN"; - case OPEN_WITH_CLEAR_IF_FIRST: return "OPEN_WITH_CLEAR_IF_FIRST"; case TRANSACTION_START: return "TRANSACTION_START"; case FETCH: return "FETCH"; case STORE: return "STORE"; diff --git a/lib/tdb2/test/tdb1-external-agent.h b/lib/tdb2/test/tdb1-external-agent.h index 8b0c1548a7..ee903b65c5 100644 --- a/lib/tdb2/test/tdb1-external-agent.h +++ b/lib/tdb2/test/tdb1-external-agent.h @@ -5,7 +5,6 @@ * various times. */ enum operation { OPEN, - OPEN_WITH_CLEAR_IF_FIRST, TRANSACTION_START, FETCH, STORE, |