]> git.ozlabs.org Git - ccan/commitdiff
tdb2: Make TDB1 code use TDB2's open flags.
authorRusty Russell <rusty@rustcorp.com.au>
Wed, 31 Aug 2011 05:51:16 +0000 (15:21 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Wed, 31 Aug 2011 05:51:16 +0000 (15:21 +0930)
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.

24 files changed:
ccan/tdb2/tdb1.h
ccan/tdb2/tdb1_io.c
ccan/tdb2/tdb1_lock.c
ccan/tdb2/tdb1_open.c
ccan/tdb2/tdb1_private.h
ccan/tdb2/tdb1_tdb.c
ccan/tdb2/tdb1_transaction.c
ccan/tdb2/test/run-tdb1-3G-file.c
ccan/tdb2/test/run-tdb1-check.c
ccan/tdb2/test/run-tdb1-corrupt.c
ccan/tdb2/test/run-tdb1-die-during-transaction.c
ccan/tdb2/test/run-tdb1-endian.c
ccan/tdb2/test/run-tdb1-incompatible.c
ccan/tdb2/test/run-tdb1-nested-transactions.c
ccan/tdb2/test/run-tdb1-nested-traverse.c
ccan/tdb2/test/run-tdb1-no-lock-during-traverse.c
ccan/tdb2/test/run-tdb1-open-during-transaction.c
ccan/tdb2/test/run-tdb1-readonly-check.c
ccan/tdb2/test/run-tdb1-summary.c
ccan/tdb2/test/run-tdb1-traverse-in-transaction.c
ccan/tdb2/test/run-tdb1-zero-append.c
ccan/tdb2/test/run-tdb1.c
ccan/tdb2/test/tdb1-external-agent.c
ccan/tdb2/test/tdb1-external-agent.h

index 3869373fbe8b47cdbae4c0d2f4c03fc47f0173c2..67e00c7c86a9737bad073769ba0f4d5f3f21c2fc 100644 (file)
 #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;
 
index 758eac6394c71c2c4fde5f157dfda062c6e7dff3..d5684dc7fd3efbb35a094829e5a204151c77f028 100644 (file)
@@ -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) {
index c427804893d465d5e3fbea7cd6a850dd2017f740..0fba7423a29005cd4dba00651e1875143e0aec28 100644 (file)
@@ -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 */
index f53a32b5befa977bc2a927dee37ec6da26f9bb81..5176f57f77666dd264a6c2d2dfb693693978fb9f 100644 (file)
@@ -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);
index 20838bfe7b1f32b20cf0bcf5222aa2db798f67fc..0d40d7a9190cc88dad9cc48334e3787a7527c369 100644 (file)
@@ -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
index c9406c4b16448be789c761ba86355f6c52106a28..a1a06438354fb8d6f0a9edc4cbde60473b985ac4 100644 (file)
@@ -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");
index 51aa2e11b00b38066f38afbc3e8b89b35c9e9f4b..d35c4bc4662463da5c2734e1092abcc59ba6efff 100644 (file)
     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,
index 6121b4de48f7ee35693b220d9e5729d2dad4269f..98e3a3006c32da683305e77fe84c63d33146f687 100644 (file)
@@ -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);
index fb49b64e48e0ff452f4acf6a3015702f727433c8..f05608feaadc1929a4804f219b456ce1ae66fc58 100644 (file)
@@ -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);
index bfc25a571110d80e283dd2fdf6202950c155dff1..2a8d31bf6610e8348a9928f85658f8e7a5f9347b 100644 (file)
@@ -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)
index 3097e13a3395896ebfffeb7c416beb9f1daaf9ec..592f75731f264252c0f95aa267563282b0801d5e 100644 (file)
@@ -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) {
index 35067d7182b10794e9cdc5401db218925b9473f6..9813050d1ed39e34b73a21c44366d6c5032318af 100644 (file)
@@ -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);
index 6f3aee0336ebeac25f5f0026df462d60d55aff0a..a2754461e26c515df9807f95947a7ff1233a13b2 100644 (file)
@@ -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. */
index f9891fe70da3b6d66bfabbf13edbba06b6866aab..6a13c13dedfdfa1f512b3fd8d2892717fb52e9d4 100644 (file)
@@ -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);
index a33efec735012f0991ca53dd6692313916fb1848..5eadc184ff9c029ce30983bde7468d430a11b968 100644 (file)
@@ -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);
 
index 4035c78c734d59c7e5cf376abe61aa82467733c9..c1cb40a49e160cb9b41c691a1fd1c9e34bdc2903 100644 (file)
@@ -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);
index ad6c6d60747ad1fce02cd17bd0e52f5e863135e6..875fc3ca9e6ffee46293c4e3d82ad95e46357bf2 100644 (file)
@@ -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,
index a764f2da428d68a5b1956237733ba364be808323..ae47aa747d5fdab28a3bac881c88ed1ec6e98c80 100644 (file)
@@ -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);
index 616c5225079d5fdcdbcadeb4519944ab583d4037..b563b1873023db65127fb03a2d7b62f75f89c0fc 100644 (file)
@@ -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;
index 4d3a81f19ea3cf424fc52bf8e4de9a8081d19b1b..922f73caa734c9570dcdfacf13afce1d225d1bb8 100644 (file)
@@ -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);
 
index 1ecab54ce41465c748bcf26152753bbe304d36a7..1304bebdbdb208d4cbcade6a25e9d13b31cda255 100644 (file)
@@ -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);
 
index 1f234b12e3433232e34391c4a383ee069fd6a651..84eea75ce29e5e3221686b9de4324c81d52f2a1c 100644 (file)
@@ -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);
index f60df5b7025b0feaca808bb585450ac4861b6265..18c76f1124d4d51f03740fa053fb809c433512c1 100644 (file)
@@ -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";
index 8b0c1548a75815b5b6427d129a09827d1b80b15e..ee903b65c51b0e6a79dc630992afc0222038abf4 100644 (file)
@@ -5,7 +5,6 @@
  * various times. */
 enum operation {
        OPEN,
-       OPEN_WITH_CLEAR_IF_FIRST,
        TRANSACTION_START,
        FETCH,
        STORE,