Browse Source

tdb2: unify tdb1_open into tdb_open

Finally, we gut tdb1_open() to the tdb1-specific parts, and call it
from tdb_open if they specify the TDB_VERSION1 flag or the version is
a TDB1.

We also unify tdb_close(), based on the TDB_VERSION1 flag.

Note that tdb_open(TDB_VERSION1) will fail on an existing tdb if it's
a TDB2.
Rusty Russell 14 years ago
parent
commit
c8c3b35686

+ 6 - 1
ccan/tdb2/lock.c

@@ -862,7 +862,12 @@ void tdb_lock_cleanup(struct tdb_context *tdb)
 
 	while (tdb->file->allrecord_lock.count
 	       && tdb->file->allrecord_lock.owner == tdb) {
-		tdb_allrecord_unlock(tdb, tdb->file->allrecord_lock.ltype);
+		if (tdb->flags & TDB_VERSION1)
+			tdb1_allrecord_unlock(tdb,
+					      tdb->file->allrecord_lock.ltype);
+		else
+			tdb_allrecord_unlock(tdb,
+					     tdb->file->allrecord_lock.ltype);
 	}
 
 	for (i=0; i<tdb->file->num_lockrecs; i++) {

+ 107 - 26
ccan/tdb2/open.c

@@ -16,6 +16,7 @@
    License along with this library; if not, see <http://www.gnu.org/licenses/>.
 */
 #include "private.h"
+#include <ccan/build_assert/build_assert.h>
 #include <assert.h>
 
 /* all tdbs, to detect double-opens (fcntl file don't nest!) */
@@ -95,6 +96,15 @@ static uint64_t random_number(struct tdb_context *tdb)
 	return ret;
 }
 
+static void tdb2_context_init(struct tdb_context *tdb)
+{
+	/* Initialize the TDB2 fields here */
+	tdb_io_init(tdb);
+	tdb->tdb2.direct_access = 0;
+	tdb->tdb2.transaction = NULL;
+	tdb->tdb2.access = NULL;
+}
+
 struct new_database {
 	struct tdb_header hdr;
 	struct tdb_freetable ftable;
@@ -195,6 +205,7 @@ static enum TDB_ERROR tdb_new_file(struct tdb_context *tdb)
 	tdb->file->lockrecs = NULL;
 	tdb->file->allrecord_lock.count = 0;
 	tdb->file->refcnt = 1;
+	tdb->file->map_ptr = NULL;
 	return TDB_SUCCESS;
 }
 
@@ -347,6 +358,23 @@ void tdb_unset_attribute(struct tdb_context *tdb,
 	}
 }
 
+static bool is_tdb1(struct tdb1_header *hdr, const void *buf, ssize_t rlen)
+{
+	/* This code assumes we've tried to read entire tdb1 header. */
+	BUILD_ASSERT(sizeof(*hdr) <= sizeof(struct tdb_header));
+
+	if (rlen < (ssize_t)sizeof(*hdr)) {
+		return false;
+	}
+
+	memcpy(hdr, buf, sizeof(*hdr));
+	if (strcmp(hdr->magic_food, TDB_MAGIC_FOOD) != 0)
+		return false;
+
+	return hdr->version == TDB1_VERSION
+		|| hdr->version == TDB1_BYTEREV(TDB1_VERSION);
+}
+
 struct tdb_context *tdb_open(const char *name, int tdb_flags,
 			     int open_flags, mode_t mode,
 			     union tdb_attribute *attr)
@@ -388,10 +416,6 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags,
 	memset(&tdb->stats, 0, sizeof(tdb->stats));
 	tdb->stats.base.attr = TDB_ATTRIBUTE_STATS;
 	tdb->stats.size = sizeof(tdb->stats);
-	tdb_io_init(tdb);
-	tdb->tdb2.direct_access = 0;
-	tdb->tdb2.transaction = NULL;
-	tdb->tdb2.access = NULL;
 
 	while (attr) {
 		switch (attr->base.attr) {
@@ -420,7 +444,7 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags,
 
 	if (tdb_flags & ~(TDB_INTERNAL | TDB_NOLOCK | TDB_NOMMAP | TDB_CONVERT
 			  | TDB_NOSYNC | TDB_SEQNUM | TDB_ALLOW_NESTING
-			  | TDB_RDONLY)) {
+			  | TDB_RDONLY | TDB_VERSION1)) {
 		ecode = tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_LOG_USE_ERROR,
 				   "tdb_open: unknown flags %u", tdb_flags);
 		goto fail;
@@ -486,13 +510,21 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags,
 			goto fail;
 		}
 		tdb->file->fd = -1;
-		ecode = tdb_new_database(tdb, seed, &hdr);
+		if (tdb->flags & TDB_VERSION1)
+			ecode = tdb1_new_database(tdb, hsize_attr);
+		else {
+			ecode = tdb_new_database(tdb, seed, &hdr);
+			if (ecode == TDB_SUCCESS) {
+				tdb_convert(tdb, &hdr.hash_seed,
+					    sizeof(hdr.hash_seed));
+				tdb->hash_seed = hdr.hash_seed;
+				tdb2_context_init(tdb);
+				tdb_ftable_init(tdb);
+			}
+		}
 		if (ecode != TDB_SUCCESS) {
 			goto fail;
 		}
-		tdb_convert(tdb, &hdr.hash_seed, sizeof(hdr.hash_seed));
-		tdb->hash_seed = hdr.hash_seed;
-		tdb_ftable_init(tdb);
 		return tdb;
 	}
 
@@ -534,7 +566,7 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags,
 		tdb->file->device = st.st_dev;
 		tdb->file->inode = st.st_ino;
 		tdb->file->map_ptr = NULL;
-		tdb->file->map_size = sizeof(struct tdb_header);
+		tdb->file->map_size = 0;
  	}
 
 	/* ensure there is only one process initialising at once */
@@ -558,6 +590,12 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags,
 	/* If they used O_TRUNC, read will return 0. */
 	rlen = pread(tdb->file->fd, &hdr, sizeof(hdr), 0);
 	if (rlen == 0 && (open_flags & O_CREAT)) {
+		if (tdb->flags & TDB_VERSION1) {
+			ecode = tdb1_new_database(tdb, hsize_attr);
+			if (ecode != TDB_SUCCESS)
+				goto fail;
+			goto finished;
+		}
 		ecode = tdb_new_database(tdb, seed, &hdr);
 		if (ecode != TDB_SUCCESS) {
 			goto fail;
@@ -569,6 +607,12 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags,
 		goto fail;
 	} else if (rlen < sizeof(hdr)
 		   || strcmp(hdr.magic_food, TDB_MAGIC_FOOD) != 0) {
+		if (is_tdb1(&tdb->tdb1.header, &hdr, rlen)) {
+			ecode = tdb1_open(tdb);
+			if (!ecode)
+				goto finished;
+			goto fail;
+		}
 		ecode = tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
 				   "tdb_open: %s is not a tdb file", name);
 		goto fail;
@@ -578,6 +622,12 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags,
 		if (hdr.version == bswap_64(TDB_VERSION))
 			tdb->flags |= TDB_CONVERT;
 		else {
+			if (is_tdb1(&tdb->tdb1.header, &hdr, rlen)) {
+				ecode = tdb1_open(tdb);
+				if (!ecode)
+					goto finished;
+				goto fail;
+			}
 			/* wrong version */
 			ecode = tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
 					   "tdb_open:"
@@ -593,6 +643,16 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags,
 		goto fail;
 	}
 
+	if (tdb->flags & TDB_VERSION1) {
+		ecode = tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
+				   "tdb_open:"
+				   " %s does not need TDB_VERSION1",
+				   name);
+		goto fail;
+	}
+
+	tdb2_context_init(tdb);
+
 	tdb_convert(tdb, &hdr, sizeof(hdr));
 	tdb->hash_seed = hdr.hash_seed;
 	hash_test = TDB_HASH_MAGIC;
@@ -617,31 +677,46 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags,
 			goto fail;
 	}
 
+finished:
+	if (tdb->flags & TDB_VERSION1) {
+		/* if needed, run recovery */
+		if (tdb1_transaction_recover(tdb) == -1) {
+			ecode = tdb->last_error;
+			goto fail;
+		}
+	}
+
 	tdb_unlock_open(tdb, openlock);
 
-	/* This make sure we have current map_size and mmap. */
-	ecode = tdb->tdb2.io->oob(tdb, tdb->file->map_size + 1, true);
+	/* This makes sure we have current map_size and mmap. */
+	if (tdb->flags & TDB_VERSION1) {
+		ecode = tdb1_probe_length(tdb);
+	} else {
+		ecode = tdb->tdb2.io->oob(tdb, tdb->file->map_size + 1, true);
+	}
 	if (unlikely(ecode != TDB_SUCCESS))
 		goto fail;
 
-	/* Now it's fully formed, recover if necessary. */
-	berr = tdb_needs_recovery(tdb);
-	if (unlikely(berr != false)) {
-		if (berr < 0) {
-			ecode = berr;
-			goto fail;
+	if (!(tdb->flags & TDB_VERSION1)) {
+		/* Now it's fully formed, recover if necessary. */
+		berr = tdb_needs_recovery(tdb);
+		if (unlikely(berr != false)) {
+			if (berr < 0) {
+				ecode = berr;
+				goto fail;
+			}
+			ecode = tdb_lock_and_recover(tdb);
+			if (ecode != TDB_SUCCESS) {
+				goto fail;
+			}
 		}
-		ecode = tdb_lock_and_recover(tdb);
+
+		ecode = tdb_ftable_init(tdb);
 		if (ecode != TDB_SUCCESS) {
 			goto fail;
 		}
 	}
 
-	ecode = tdb_ftable_init(tdb);
-	if (ecode != TDB_SUCCESS) {
-		goto fail;
-	}
-
 	tdb->next = tdbs;
 	tdbs = tdb;
 	return tdb;
@@ -702,8 +777,14 @@ int tdb_close(struct tdb_context *tdb)
 
 	tdb_trace(tdb, "tdb_close");
 
-	if (tdb->tdb2.transaction) {
-		tdb_transaction_cancel(tdb);
+	if (tdb->flags & TDB_VERSION1) {
+		if (tdb->tdb1.transaction) {
+			tdb1_transaction_cancel(tdb);
+		}
+	} else {
+		if (tdb->tdb2.transaction) {
+			tdb_transaction_cancel(tdb);
+		}
 	}
 
 	if (tdb->file->map_ptr) {

+ 18 - 0
ccan/tdb2/private.h

@@ -55,6 +55,7 @@ typedef uint64_t tdb_off_t;
 
 #define TDB_MAGIC_FOOD "TDB file\n"
 #define TDB_VERSION ((uint64_t)(0x26011967 + 7))
+#define TDB1_VERSION (0x26011967 + 6)
 #define TDB_USED_MAGIC ((uint64_t)0x1999)
 #define TDB_HTABLE_MAGIC ((uint64_t)0x1888)
 #define TDB_CHAIN_MAGIC ((uint64_t)0x1777)
@@ -628,6 +629,23 @@ struct tdb_context {
 	} tdb1;
 };
 
+#define TDB1_BYTEREV(x) (((((x)&0xff)<<24)|((x)&0xFF00)<<8)|(((x)>>8)&0xFF00)|((x)>>24))
+
+/* tdb1_open.c: */
+int tdb1_new_database(struct tdb_context *tdb,
+		      struct tdb_attribute_tdb1_hashsize *hashsize);
+enum TDB_ERROR tdb1_open(struct tdb_context *tdb);
+
+/* tdb1_io.c: */
+enum TDB_ERROR tdb1_probe_length(struct tdb_context *tdb);
+
+/* tdb1_lock.c: */
+int tdb1_allrecord_unlock(struct tdb_context *tdb, int ltype);
+
+/* tdb1_transaction.c: */
+int tdb1_transaction_recover(struct tdb_context *tdb);
+int tdb1_transaction_cancel(struct tdb_context *tdb);
+
 /* tdb.c: */
 enum TDB_ERROR COLD tdb_logerr(struct tdb_context *tdb,
 			       enum TDB_ERROR ecode,

+ 0 - 8
ccan/tdb2/tdb1.h

@@ -38,10 +38,6 @@
 
 typedef int (*tdb1_traverse_func)(struct tdb_context *, TDB_DATA, TDB_DATA, void *);
 
-struct tdb_context *tdb1_open(const char *name, int tdb1_flags,
-			      int open_flags, mode_t mode,
-			      union tdb_attribute *attributes);
-
 void tdb1_set_max_dead(struct tdb_context *tdb, int max_dead);
 
 TDB_DATA tdb1_fetch(struct tdb_context *tdb, TDB_DATA key);
@@ -57,8 +53,6 @@ int tdb1_store(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf, int flag);
 
 int tdb1_append(struct tdb_context *tdb, TDB_DATA key, TDB_DATA new_dbuf);
 
-int tdb1_close(struct tdb_context *tdb);
-
 TDB_DATA tdb1_firstkey(struct tdb_context *tdb);
 
 TDB_DATA tdb1_nextkey(struct tdb_context *tdb, TDB_DATA key);
@@ -83,8 +77,6 @@ int tdb1_transaction_prepare_commit(struct tdb_context *tdb);
 
 int tdb1_transaction_commit(struct tdb_context *tdb);
 
-int tdb1_transaction_cancel(struct tdb_context *tdb);
-
 int tdb1_get_seqnum(struct tdb_context *tdb);
 
 void tdb1_increment_seqnum_nonblock(struct tdb_context *tdb);

+ 7 - 0
ccan/tdb2/tdb1_io.c

@@ -503,3 +503,10 @@ void tdb1_io_init(struct tdb_context *tdb)
 {
 	tdb->tdb1.io = &io1_methods;
 }
+
+enum TDB_ERROR tdb1_probe_length(struct tdb_context *tdb)
+{
+	tdb->last_error = TDB_SUCCESS;
+	tdb->tdb1.io->tdb1_oob(tdb, tdb->file->map_size + 1, true);
+	return tdb->last_error;
+}

+ 76 - 295
ccan/tdb2/tdb1_open.c

@@ -26,6 +26,7 @@
 */
 #include <assert.h>
 #include "tdb1_private.h"
+#include <assert.h>
 
 /* We use two hashes to double-check they're using the right hash function. */
 void tdb1_header_hash(struct tdb_context *tdb,
@@ -41,18 +42,48 @@ void tdb1_header_hash(struct tdb_context *tdb,
 		*magic1_hash = 1;
 }
 
-/* initialise a new database with a specified hash size */
-static int tdb1_new_database(struct tdb_context *tdb, int hash_size)
+static void tdb1_context_init(struct tdb_context *tdb)
+{
+	assert(tdb->flags & TDB_VERSION1);
+
+	tdb1_io_init(tdb);
+
+	tdb->tdb1.traverse_read = tdb->tdb1.traverse_write = 0;
+	memset(&tdb->tdb1.travlocks, 0, sizeof(tdb->tdb1.travlocks));
+	tdb->tdb1.transaction = NULL;
+
+	/* cache the page size */
+	tdb->tdb1.page_size = getpagesize();
+	if (tdb->tdb1.page_size <= 0) {
+		tdb->tdb1.page_size = 0x2000;
+	}
+
+	/* FIXME: Used to be 5 for TDB_VOLATILE. */
+	tdb->tdb1.max_dead_records = 0;
+}
+
+/* initialise a new database */
+enum TDB_ERROR tdb1_new_database(struct tdb_context *tdb,
+				 struct tdb_attribute_tdb1_hashsize *hashsize)
 {
 	struct tdb1_header *newdb;
 	size_t size;
-	int ret = -1;
+	int hash_size = TDB1_DEFAULT_HASH_SIZE;
+	enum TDB_ERROR ret = TDB_ERR_IO;
+
+	tdb1_context_init(tdb);
+
+	/* Default TDB2 hash becomes default TDB1 hash. */
+	if (tdb->hash_fn == tdb_jenkins_hash)
+		tdb->hash_fn = tdb1_old_hash;
+
+	if (hashsize)
+		hash_size = hashsize->hsize;
 
 	/* We make it up in memory, then write it out if not internal */
 	size = sizeof(struct tdb1_header) + (hash_size+1)*sizeof(tdb1_off_t);
 	if (!(newdb = (struct tdb1_header *)calloc(size, 1))) {
-		tdb->last_error = TDB_ERR_OOM;
-		return -1;
+		return TDB_ERR_OOM;
 	}
 
 	/* Fill in the header */
@@ -66,14 +97,16 @@ static int tdb1_new_database(struct tdb_context *tdb, int hash_size)
 	if (tdb->hash_fn == tdb1_incompatible_hash)
 		newdb->rwlocks = TDB1_HASH_RWLOCK_MAGIC;
 
+	memcpy(&tdb->tdb1.header, newdb, sizeof(tdb->tdb1.header));
+	/* This creates an endian-converted db. */
+	TDB1_CONV(*newdb);
+	/* Don't endian-convert the magic food! */
+	memcpy(newdb->magic_food, TDB_MAGIC_FOOD, strlen(TDB_MAGIC_FOOD)+1);
+
 	if (tdb->flags & TDB_INTERNAL) {
-		tdb->file->fd = -1;
 		tdb->file->map_size = size;
 		tdb->file->map_ptr = (char *)newdb;
-		memcpy(&tdb->tdb1.header, newdb, sizeof(tdb->tdb1.header));
-		/* Convert the `ondisk' version if asked. */
-		TDB1_CONV(*newdb);
-		return 0;
+		return TDB_SUCCESS;
 	}
 	if (lseek(tdb->file->fd, 0, SEEK_SET) == -1)
 		goto fail;
@@ -81,14 +114,9 @@ static int tdb1_new_database(struct tdb_context *tdb, int hash_size)
 	if (ftruncate(tdb->file->fd, 0) == -1)
 		goto fail;
 
-	/* This creates an endian-converted header, as if read from disk */
-	TDB1_CONV(*newdb);
-	memcpy(&tdb->tdb1.header, newdb, sizeof(tdb->tdb1.header));
-	/* Don't endian-convert the magic food! */
-	memcpy(newdb->magic_food, TDB_MAGIC_FOOD, strlen(TDB_MAGIC_FOOD)+1);
-	/* we still have "ret == -1" here */
+	/* we still have "ret == TDB_ERR_IO" here */
 	if (tdb1_write_all(tdb->file->fd, newdb, size))
-		ret = 0;
+		ret = TDB_SUCCESS;
 
   fail:
 	SAFE_FREE(newdb);
@@ -108,6 +136,12 @@ struct tdb1_logging_context {
 static bool hash_correct(struct tdb_context *tdb,
 			 uint32_t *m1, uint32_t *m2)
 {
+	/* older TDB without magic hash references */
+	if (tdb->tdb1.header.magic1_hash == 0
+	    && tdb->tdb1.header.magic2_hash == 0) {
+		return true;
+	}
+
 	tdb1_header_hash(tdb, m1, m2);
 	return (tdb->tdb1.header.magic1_hash == *m1 &&
 		tdb->tdb1.header.magic2_hash == *m2);
@@ -129,278 +163,58 @@ static bool check_header_hash(struct tdb_context *tdb,
 	return hash_correct(tdb, m1, m2);
 }
 
-static struct tdb_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flags,
-				int open_flags, mode_t mode,
-				const struct tdb1_logging_context *log_ctx,
-				tdb1_hash_func hash_fn)
+/* We are hold the TDB open lock on tdb->fd. */
+enum TDB_ERROR tdb1_open(struct tdb_context *tdb)
 {
-	struct tdb_context *tdb;
-	struct stat st;
-	int rev = 0;
-	unsigned v;
 	const char *hash_alg;
 	uint32_t magic1, magic2;
 
-	if (!(tdb = (struct tdb_context *)calloc(1, sizeof *tdb))) {
-		/* Can't log this */
-		errno = ENOMEM;
-		goto fail;
-	}
-	tdb->file = calloc(1, sizeof *tdb->file);
-	if (!tdb->file) {
-		free(tdb);
-		errno = ENOMEM;
-		goto fail;
-	}
-	tdb1_io_init(tdb);
-	tdb->file->fd = -1;
-	tdb->name = NULL;
-	tdb->file->map_ptr = NULL;
-	tdb->flags = tdb1_flags|TDB_VERSION1;
-	tdb->open_flags = open_flags;
-	tdb->lock_fn = tdb_fcntl_lock;
-	tdb->unlock_fn = tdb_fcntl_unlock;
-	if (log_ctx) {
-		tdb->log_fn = log_ctx->log_fn;
-		tdb->log_data = log_ctx->log_private;
-	} else
-		tdb->log_fn = NULL;
-
-	if (name == NULL && (tdb1_flags & TDB_INTERNAL)) {
-		name = "__TDB1_INTERNAL__";
-	}
+	tdb->flags |= TDB_VERSION1;
 
-	if (name == NULL) {
-		tdb->name = (char *)"__NULL__";
-		tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_LOG_USE_ERROR,
-			   "tdb1_open_ex: called with name == NULL");
-		tdb->name = NULL;
-		errno = EINVAL;
-		goto fail;
-	}
+	tdb1_context_init(tdb);
 
-	/* now make a copy of the name, as the caller memory might went away */
-	if (!(tdb->name = (char *)strdup(name))) {
-		/*
-		 * set the name as the given string, so that tdb1_name() will
-		 * work in case of an error.
-		 */
-		tdb->name = (char *)name;
-		tdb_logerr(tdb, TDB_ERR_OOM, TDB_LOG_ERROR,
-			   "tdb1_open_ex: can't strdup(%s)", name);
-		tdb->name = NULL;
-		errno = ENOMEM;
-		goto fail;
-	}
-	tdb->hash_seed = 0;
-
-	if (hash_fn) {
-		tdb->hash_fn = hash_fn;
-		if (hash_fn == tdb1_incompatible_hash)
-			hash_alg = "tdb1_incompatible_hash";
-		else
-			hash_alg = "the user defined";
-	} else {
+	/* Default TDB2 hash becomes default TDB1 hash. */
+	if (tdb->hash_fn == tdb_jenkins_hash) {
 		tdb->hash_fn = tdb1_old_hash;
 		hash_alg = "default";
-	}
-
-	/* cache the page size */
-	tdb->tdb1.page_size = getpagesize();
-	if (tdb->tdb1.page_size <= 0) {
-		tdb->tdb1.page_size = 0x2000;
-	}
-
-	/* FIXME: Used to be 5 for TDB_VOLATILE. */
-	tdb->tdb1.max_dead_records = 0;
-
-	if ((open_flags & O_ACCMODE) == O_WRONLY) {
-		tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_LOG_USE_ERROR,
-			   "tdb1_open_ex: can't open tdb %s write-only",
-			   name);
-		errno = EINVAL;
-		goto fail;
-	}
-
-	if ((open_flags & O_ACCMODE) == O_RDONLY) {
-		tdb->flags |= TDB_RDONLY;
-		/* 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 & 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!");
-			goto fail;
-		}
-		goto internal;
-	}
-
-	if ((tdb->file->fd = open(name, open_flags, mode)) == -1) {
-		tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
-			   "tdb1_open_ex: could not open file %s: %s",
-			   name, strerror(errno));
-		goto fail;	/* errno set by open(2) */
-	}
-
-	/* on exec, don't inherit the fd */
-	v = fcntl(tdb->file->fd, F_GETFD, 0);
-        fcntl(tdb->file->fd, F_SETFD, v | FD_CLOEXEC);
-
-	/* ensure there is only one process initialising at once */
-	if (tdb1_nest_lock(tdb, TDB1_OPEN_LOCK, F_WRLCK, TDB_LOCK_WAIT) == -1) {
-		tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
-			   "tdb1_open_ex: failed to get open lock on %s: %s",
-			   name, strerror(errno));
-		goto fail;	/* errno set by tdb1_brlock */
-	}
-
-	errno = 0;
-	if (read(tdb->file->fd, &tdb->tdb1.header, sizeof(tdb->tdb1.header)) != sizeof(tdb->tdb1.header)
-	    || strcmp(tdb->tdb1.header.magic_food, TDB_MAGIC_FOOD) != 0) {
-		if (!(open_flags & O_CREAT) || tdb1_new_database(tdb, hash_size) == -1) {
-			if (errno == 0) {
-				errno = EIO; /* ie bad format or something */
-			}
-			goto fail;
+	} else if (tdb->hash_fn == tdb1_incompatible_hash)
+		hash_alg = "tdb1_incompatible_hash";
+	else
+		hash_alg = "the user defined";
+
+	if (tdb->tdb1.header.version != TDB1_BYTEREV(TDB1_VERSION)) {
+		if (tdb->flags & TDB_CONVERT) {
+			return tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
+					  "tdb1_open:"
+					  " %s does not need TDB_CONVERT",
+					  tdb->name);
 		}
-		rev = (tdb->flags & TDB_CONVERT);
-	} else if (tdb->tdb1.header.version != TDB1_VERSION
-		   && !(rev = (tdb->tdb1.header.version==TDB1_BYTEREV(TDB1_VERSION)))) {
-		/* wrong version */
-		errno = EIO;
-		goto fail;
-	}
-	if (!rev)
-		tdb->flags &= ~TDB_CONVERT;
-	else {
+	} else {
 		tdb->flags |= TDB_CONVERT;
 		tdb1_convert(&tdb->tdb1.header, sizeof(tdb->tdb1.header));
 	}
-	if (fstat(tdb->file->fd, &st) == -1)
-		goto fail;
 
 	if (tdb->tdb1.header.rwlocks != 0 &&
 	    tdb->tdb1.header.rwlocks != TDB1_HASH_RWLOCK_MAGIC) {
-		tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_ERROR,
-			   "tdb1_open_ex: spinlocks no longer supported");
-		goto fail;
+		return tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_ERROR,
+				  "tdb1_open: spinlocks no longer supported");
 	}
 
-	if ((tdb->tdb1.header.magic1_hash == 0) && (tdb->tdb1.header.magic2_hash == 0)) {
-		/* older TDB without magic hash references */
-		tdb->hash_fn = tdb1_old_hash;
-	} else if (!check_header_hash(tdb, &magic1, &magic2)) {
-		tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_USE_ERROR,
-			   "tdb1_open_ex: "
+	if (!check_header_hash(tdb, &magic1, &magic2)) {
+		return tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_USE_ERROR,
+			   "tdb1_open: "
 			   "%s was not created with %s hash function we are using\n"
 			   "magic1_hash[0x%08X %s 0x%08X] "
 			   "magic2_hash[0x%08X %s 0x%08X]",
-			   name, hash_alg,
+			   tdb->name, hash_alg,
 			   tdb->tdb1.header.magic1_hash,
 			   (tdb->tdb1.header.magic1_hash == magic1) ? "==" : "!=",
 			   magic1,
 			   tdb->tdb1.header.magic2_hash,
 			   (tdb->tdb1.header.magic2_hash == magic2) ? "==" : "!=",
 			   magic2);
-		errno = EINVAL;
-		goto fail;
-	}
-
-	tdb->file->map_size = st.st_size;
-	tdb->file->device = st.st_dev;
-	tdb->file->inode = st.st_ino;
-	tdb1_mmap(tdb);
-
-	/* if needed, run recovery */
-	if (tdb1_transaction_recover(tdb) == -1) {
-		goto fail;
-	}
-
- internal:
-	/* Internal (memory-only) databases skip all the code above to
-	 * do with disk files, and resume here by releasing their
-	 * open lock and hooking into the active list. */
-	if (tdb1_nest_unlock(tdb, TDB1_OPEN_LOCK, F_WRLCK) == -1) {
-		goto fail;
-	}
-	return tdb;
-
- fail:
-	{ int save_errno = errno;
-
-	if (!tdb)
-		return NULL;
-
-	if (tdb->file->map_ptr) {
-		if (tdb->flags & TDB_INTERNAL)
-			SAFE_FREE(tdb->file->map_ptr);
-		else
-			tdb1_munmap(tdb);
-	}
-	if (tdb->file->fd != -1)
-		if (close(tdb->file->fd) != 0)
-			tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
-				   "tdb1_open_ex: failed to close tdb->fd on error!");
-	if (tdb->file) {
-		SAFE_FREE(tdb->file->lockrecs);
-		SAFE_FREE(tdb->file);
-	}
-	SAFE_FREE(tdb->name);
-	SAFE_FREE(tdb);
-	errno = save_errno;
-	return NULL;
 	}
-}
-
-/* Temporart wrapper for transition. */
-struct tdb_context *tdb1_open(const char *name, int tdb1_flags,
-			      int open_flags, mode_t mode,
-			      union tdb_attribute *attr)
-{
-	struct tdb1_logging_context *log_ctx = NULL, log;
-	tdb1_hash_func hash_fn = NULL;
-	struct tdb_attribute_tdb1_hashsize *hsize = NULL;
-
-	while (attr) {
-		switch (attr->base.attr) {
-		case TDB_ATTRIBUTE_HASH:
-			hash_fn = attr->hash.fn;
-			break;
-		case TDB_ATTRIBUTE_LOG:
-			log.log_fn = attr->log.fn;
-			log.log_private = attr->log.data;
-			log_ctx = &log;
-			break;
-		case TDB_ATTRIBUTE_TDB1_HASHSIZE:
-			hsize = &attr->tdb1_hashsize;
-			break;
-			break;
-		default:
-			abort();
-		}
-		attr = attr->base.next;
-	}
-
-	if (hsize && !(open_flags & O_CREAT)) {
-		if (log_ctx) {
-			log_ctx->log_fn(NULL,
-					TDB_ERR_EINVAL,
-					TDB_LOG_USE_ERROR,
-					"tdb_open: can only use"
-					" TDB_ATTRIBUTE_TDB1_HASHSIZE when"
-					" creating a tdb",
-					log_ctx->log_private);
-		}
-		errno = EINVAL;
-		return NULL;
-	}
-	return tdb1_open_ex(name, hsize ? hsize->hsize : TDB1_DEFAULT_HASH_SIZE,
-			    tdb1_flags, open_flags, mode,
-			    log_ctx, hash_fn);
+	return TDB_SUCCESS;
 }
 
 /*
@@ -411,36 +225,3 @@ void tdb1_set_max_dead(struct tdb_context *tdb, int max_dead)
 {
 	tdb->tdb1.max_dead_records = max_dead;
 }
-
-/**
- * Close a database.
- *
- * @returns -1 for error; 0 for success.
- **/
-int tdb1_close(struct tdb_context *tdb)
-{
-	int ret = 0;
-
-	if (tdb->tdb1.transaction) {
-		tdb1_transaction_cancel(tdb);
-	}
-
-	if (tdb->file->map_ptr) {
-		if (tdb->flags & TDB_INTERNAL)
-			SAFE_FREE(tdb->file->map_ptr);
-		else
-			tdb1_munmap(tdb);
-	}
-	SAFE_FREE(tdb->name);
-	if (tdb->file->fd != -1) {
-		ret = close(tdb->file->fd);
-		tdb->file->fd = -1;
-	}
-	SAFE_FREE(tdb->file->lockrecs);
-	SAFE_FREE(tdb->file);
-
-	memset(tdb, 0, sizeof(*tdb));
-	SAFE_FREE(tdb);
-
-	return ret;
-}

+ 0 - 3
ccan/tdb2/tdb1_private.h

@@ -62,7 +62,6 @@
 #define TDB1_DEFAULT_HASH_SIZE 131
 #define TDB1_FREELIST_TOP (sizeof(struct tdb1_header))
 #define TDB1_ALIGN(x,a) (((x) + (a)-1) & ~((a)-1))
-#define TDB1_BYTEREV(x) (((((x)&0xff)<<24)|((x)&0xFF00)<<8)|(((x)>>8)&0xFF00)|((x)>>24))
 #define TDB1_DEAD(r) ((r)->magic == TDB1_DEAD_MAGIC)
 #define TDB1_BAD_MAGIC(r) ((r)->magic != TDB1_MAGIC && !TDB1_DEAD(r))
 #define TDB1_HASH_TOP(hash) (TDB1_FREELIST_TOP + (TDB1_BUCKET(hash)+1)*sizeof(tdb1_off_t))
@@ -145,7 +144,6 @@ int tdb1_recovery_area(struct tdb_context *tdb,
 		      struct tdb1_record *rec);
 int tdb1_allrecord_lock(struct tdb_context *tdb, int ltype,
 		       enum tdb_lock_flags flags, bool upgradable);
-int tdb1_allrecord_unlock(struct tdb_context *tdb, int ltype);
 int tdb1_allrecord_upgrade(struct tdb_context *tdb);
 int tdb1_write_lock_record(struct tdb_context *tdb, tdb1_off_t off);
 int tdb1_write_unlock_record(struct tdb_context *tdb, tdb1_off_t off);
@@ -175,7 +173,6 @@ int tdb1_expand(struct tdb_context *tdb, tdb1_off_t size);
 int tdb1_rec_free_read(struct tdb_context *tdb, tdb1_off_t off,
 		      struct tdb1_record *rec);
 bool tdb1_write_all(int fd, const void *buf, size_t count);
-int tdb1_transaction_recover(struct tdb_context *tdb);
 void tdb1_header_hash(struct tdb_context *tdb,
 		     uint32_t *magic1_hash, uint32_t *magic2_hash);
 uint64_t tdb1_old_hash(const void *key, size_t len, uint64_t seed, void *);

+ 7 - 7
ccan/tdb2/tdb1_tdb.c

@@ -843,7 +843,7 @@ int tdb1_repack(struct tdb_context *tdb)
 		return -1;
 	}
 
-	tmp_db = tdb1_open("tmpdb", TDB_INTERNAL, O_RDWR|O_CREAT, 0, &hsize);
+	tmp_db = tdb_open("tmpdb", TDB_INTERNAL, O_RDWR|O_CREAT, 0, &hsize);
 	if (tmp_db == NULL) {
 		tdb->last_error = tdb_logerr(tdb, TDB_ERR_OOM, TDB_LOG_ERROR,
 					__location__ " Failed to create tmp_db");
@@ -858,7 +858,7 @@ int tdb1_repack(struct tdb_context *tdb)
 		tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
 			   __location__ " Failed to traverse copying out");
 		tdb1_transaction_cancel(tdb);
-		tdb1_close(tmp_db);
+		tdb_close(tmp_db);
 		return -1;
 	}
 
@@ -866,7 +866,7 @@ int tdb1_repack(struct tdb_context *tdb)
 		tdb->last_error = tdb_logerr(tdb, state.error, TDB_LOG_ERROR,
 					__location__ " Error during traversal");
 		tdb1_transaction_cancel(tdb);
-		tdb1_close(tmp_db);
+		tdb_close(tmp_db);
 		return -1;
 	}
 
@@ -874,7 +874,7 @@ int tdb1_repack(struct tdb_context *tdb)
 		tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
 			   __location__ " Failed to wipe database\n");
 		tdb1_transaction_cancel(tdb);
-		tdb1_close(tmp_db);
+		tdb_close(tmp_db);
 		return -1;
 	}
 
@@ -885,7 +885,7 @@ int tdb1_repack(struct tdb_context *tdb)
 		tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
 			   __location__ " Failed to traverse copying back");
 		tdb1_transaction_cancel(tdb);
-		tdb1_close(tmp_db);
+		tdb_close(tmp_db);
 		return -1;
 	}
 
@@ -893,11 +893,11 @@ int tdb1_repack(struct tdb_context *tdb)
 		tdb->last_error = tdb_logerr(tdb, state.error, TDB_LOG_ERROR,
 					__location__ " Error during second traversal");
 		tdb1_transaction_cancel(tdb);
-		tdb1_close(tmp_db);
+		tdb_close(tmp_db);
 		return -1;
 	}
 
-	tdb1_close(tmp_db);
+	tdb_close(tmp_db);
 
 	if (tdb1_transaction_commit(tdb) != 0) {
 		tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,

+ 3 - 3
ccan/tdb2/test/failtest_helper.h

@@ -4,9 +4,9 @@
 #include <stdbool.h>
 
 /* FIXME: Check these! */
-#define INITIAL_TDB_MALLOC	"open.c", 367, FAILTEST_MALLOC
-#define URANDOM_OPEN		"open.c", 61, FAILTEST_OPEN
-#define URANDOM_READ		"open.c", 41, FAILTEST_READ
+#define INITIAL_TDB_MALLOC	"open.c", 395, FAILTEST_MALLOC
+#define URANDOM_OPEN		"open.c", 62, FAILTEST_OPEN
+#define URANDOM_READ		"open.c", 42, FAILTEST_READ
 
 bool exit_check_log(struct failtest_call *history, unsigned num);
 bool failmatch(const struct failtest_call *call,

+ 3 - 3
ccan/tdb2/test/run-tdb1-3G-file.c

@@ -71,8 +71,8 @@ int main(int argc, char *argv[])
 	hsize.tdb1_hashsize.hsize = 1024;
 
 	plan_tests(24);
-	tdb = tdb1_open("run-36-file.tdb", TDB_DEFAULT,
-			O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize);
+	tdb = tdb_open("run-36-file.tdb1", TDB_VERSION1,
+		       O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize);
 
 	ok1(tdb);
 	tdb->tdb1.io = &large_io_methods;
@@ -119,7 +119,7 @@ int main(int argc, char *argv[])
 	ok1(tdb1_transaction_commit(tdb) == 0);
 
 	ok1(tdb1_traverse(tdb, test_traverse, &orig_data) == 1);
-	tdb1_close(tdb);
+	tdb_close(tdb);
 
 	return exit_status();
 }

+ 13 - 14
ccan/tdb2/test/run-tdb1-bad-tdb-header.c

@@ -16,20 +16,25 @@ int main(int argc, char *argv[])
 	hsize.tdb1_hashsize.hsize = 1024;
 
 	plan_tests(11);
-	/* Can open fine if complete crap, as long as O_CREAT. */
-	fd = open("run-bad-tdb-header.tdb", O_RDWR|O_CREAT|O_TRUNC, 0600);
+	/* Cannot open fine if complete crap, even with O_CREAT. */
+	fd = open("run-bad-tdb-header.tdb1", O_RDWR|O_CREAT|O_TRUNC, 0600);
 	ok1(fd >= 0);
 	ok1(write(fd, "hello world", 11) == 11);
 	close(fd);
-	tdb = tdb1_open("run-bad-tdb-header.tdb", 0, O_RDWR, 0, &tap_log_attr);
+	tdb = tdb_open("run-bad-tdb-header.tdb1", 0, O_RDWR, 0, &tap_log_attr);
 	ok1(!tdb);
-	tdb = tdb1_open("run-bad-tdb-header.tdb", 0, O_CREAT|O_RDWR,
+	tdb = tdb_open("run-bad-tdb-header.tdb1", 0, O_CREAT|O_RDWR,
 			0600, &hsize);
+	ok1(!tdb);
+
+	/* With truncate, will be fine. */
+	tdb = tdb_open("run-bad-tdb-header.tdb1", TDB_VERSION1,
+		       O_RDWR|O_CREAT|O_TRUNC, 0600, &hsize);
 	ok1(tdb);
-	tdb1_close(tdb);
+	tdb_close(tdb);
 
 	/* Now, with wrong version it should *not* overwrite. */
-	fd = open("run-bad-tdb-header.tdb", O_RDWR);
+	fd = open("run-bad-tdb-header.tdb1", O_RDWR);
 	ok1(fd >= 0);
 	ok1(read(fd, &hdr, sizeof(hdr)) == sizeof(hdr));
 	ok1(hdr.version == TDB1_VERSION);
@@ -38,16 +43,10 @@ int main(int argc, char *argv[])
 	ok1(write(fd, &hdr, sizeof(hdr)) == sizeof(hdr));
 	close(fd);
 
-	tdb = tdb1_open("run-bad-tdb-header.tdb", 0, O_RDWR|O_CREAT,
-			0600, &hsize);
+	tdb = tdb_open("run-bad-tdb-header.tdb1", TDB_VERSION1, O_RDWR|O_CREAT,
+		       0600, &hsize);
 	ok1(errno == EIO);
 	ok1(!tdb);
 
-	/* With truncate, will be fine. */
-	tdb = tdb1_open("run-bad-tdb-header.tdb", 0,
-			O_RDWR|O_CREAT|O_TRUNC, 0600, &hsize);
-	ok1(tdb);
-	tdb1_close(tdb);
-
 	return exit_status();
 }

+ 12 - 13
ccan/tdb2/test/run-tdb1-check.c

@@ -15,8 +15,8 @@ int main(int argc, char *argv[])
 	hsize.tdb1_hashsize.hsize = 1;
 
 	plan_tests(13);
-	tdb = tdb1_open("run-check.tdb", TDB_DEFAULT,
-			O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize);
+	tdb = tdb_open("run-check.tdb1", TDB_VERSION1,
+		       O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize);
 
 	ok1(tdb);
 	ok1(tdb1_check(tdb, NULL, NULL) == 0);
@@ -28,33 +28,32 @@ int main(int argc, char *argv[])
 
 	ok1(tdb1_store(tdb, key, data, TDB_INSERT) == 0);
 	ok1(tdb1_check(tdb, NULL, NULL) == 0);
-	tdb1_close(tdb);
+	tdb_close(tdb);
 
-	tdb = tdb1_open("run-check.tdb", 0, O_RDWR, 0,
-			&tap_log_attr);
+	tdb = tdb_open("run-check.tdb1", TDB_VERSION1, O_RDWR, 0, &tap_log_attr);
 	ok1(tdb);
 	ok1(tdb1_check(tdb, NULL, NULL) == 0);
-	tdb1_close(tdb);
+	tdb_close(tdb);
 
-	tdb = tdb1_open("test/tdb1.corrupt", 0, O_RDWR, 0,
+	tdb = tdb_open("test/tdb1.corrupt", TDB_VERSION1, O_RDWR, 0,
 			&tap_log_attr);
 	ok1(tdb);
 	ok1(tdb1_check(tdb, NULL, NULL) == -1);
 	ok1(tdb_error(tdb) == TDB_ERR_CORRUPT);
-	tdb1_close(tdb);
+	tdb_close(tdb);
 
 	/* Big and little endian should work! */
-	tdb = tdb1_open("test/old-nohash-le.tdb1", 0, O_RDWR, 0,
-			&tap_log_attr);
+	tdb = tdb_open("test/old-nohash-le.tdb1", TDB_VERSION1, O_RDWR, 0,
+		       &tap_log_attr);
 	ok1(tdb);
 	ok1(tdb1_check(tdb, NULL, NULL) == 0);
-	tdb1_close(tdb);
+	tdb_close(tdb);
 
-	tdb = tdb1_open("test/old-nohash-be.tdb1", 0, O_RDWR, 0,
+	tdb = tdb_open("test/old-nohash-be.tdb1", TDB_VERSION1, O_RDWR, 0,
 			&tap_log_attr);
 	ok1(tdb);
 	ok1(tdb1_check(tdb, NULL, NULL) == 0);
-	tdb1_close(tdb);
+	tdb_close(tdb);
 
 	return exit_status();
 }

+ 6 - 6
ccan/tdb2/test/run-tdb1-corrupt.c

@@ -102,22 +102,22 @@ int main(int argc, char *argv[])
 
 	plan_tests(4);
 	/* This should use mmap. */
-	tdb = tdb1_open("run-corrupt.tdb", TDB_DEFAULT,
-			O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize);
+	tdb = tdb_open("run-corrupt.tdb1", TDB_VERSION1,
+		       O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize);
 
 	if (!tdb)
 		abort();
 	check_test(tdb);
-	tdb1_close(tdb);
+	tdb_close(tdb);
 
 	/* This should not. */
-	tdb = tdb1_open("run-corrupt.tdb", TDB_NOMMAP,
-			O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize);
+	tdb = tdb_open("run-corrupt.tdb1", TDB_VERSION1|TDB_NOMMAP,
+		       O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize);
 
 	if (!tdb)
 		abort();
 	check_test(tdb);
-	tdb1_close(tdb);
+	tdb_close(tdb);
 
 	return exit_status();
 }

+ 5 - 5
ccan/tdb2/test/run-tdb1-die-during-transaction.c

@@ -28,7 +28,7 @@ static int ftruncate_check(int fd, off_t length);
 static bool in_transaction;
 static int target, current;
 static jmp_buf jmpbuf;
-#define TEST_DBNAME "run-die-during-transaction.tdb"
+#define TEST_DBNAME "run-die-during-transaction.tdb1"
 #define KEY_STRING "helloworld"
 
 static void maybe_die(int fd)
@@ -94,8 +94,8 @@ static bool test_death(enum operation op, struct agent *agent)
 	current = target = 0;
 reset:
 	unlink(TEST_DBNAME);
-	tdb = tdb1_open(TEST_DBNAME, TDB_NOMMAP,
-			O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize);
+	tdb = tdb_open(TEST_DBNAME, TDB_VERSION1|TDB_NOMMAP,
+		       O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize);
 
 	if (setjmp(jmpbuf) != 0) {
 		/* We're partway through.  Simulate our death. */
@@ -144,7 +144,7 @@ reset:
 		/* Suppress logging as this tries to use closed fd. */
 		suppress_logging = true;
 		suppress_lockcheck1 = true;
-		tdb1_close(tdb);
+		tdb_close(tdb);
 		suppress_logging = false;
 		suppress_lockcheck1 = false;
 		target++;
@@ -183,7 +183,7 @@ reset:
 
 	/* We made it! */
 	diag("Completed %u runs", current);
-	tdb1_close(tdb);
+	tdb_close(tdb);
 	ret = external_agent_operation1(agent, CLOSE, "");
 	if (ret != SUCCESS) {
 		diag("Step %u close failed = %s", current,

+ 6 - 6
ccan/tdb2/test/run-tdb1-endian.c

@@ -15,9 +15,9 @@ int main(int argc, char *argv[])
 	hsize.tdb1_hashsize.hsize = 1024;
 
 	plan_tests(13);
-	tdb = tdb1_open("run-endian.tdb",
-			TDB_CONVERT,
-			O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize);
+	tdb = tdb_open("run-endian.tdb1",
+		       TDB_VERSION1|TDB_CONVERT,
+		       O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize);
 
 	ok1(tdb);
 	key.dsize = strlen("hi");
@@ -40,10 +40,10 @@ int main(int argc, char *argv[])
 	key.dsize++;
 	data = tdb1_fetch(tdb, key);
 	ok1(data.dptr == NULL);
-	tdb1_close(tdb);
+	tdb_close(tdb);
 
 	/* Reopen: should read it */
-	tdb = tdb1_open("run-endian.tdb", 0, O_RDWR, 0, NULL);
+	tdb = tdb_open("run-endian.tdb1", 0, O_RDWR, 0, NULL);
 	ok1(tdb);
 
 	key.dsize = strlen("hi");
@@ -52,7 +52,7 @@ int main(int argc, char *argv[])
 	ok1(data.dsize == strlen("world"));
 	ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
 	free(data.dptr);
-	tdb1_close(tdb);
+	tdb_close(tdb);
 
 	return exit_status();
 }

+ 8 - 8
ccan/tdb2/test/run-tdb1-hashsize.c

@@ -14,8 +14,8 @@ int main(int argc, char *argv[])
 	hsize.tdb1_hashsize.hsize = 1024;
 
 	plan_tests(14);
-	tdb = tdb1_open("run-tdb1-hashsize.tdb1", TDB_DEFAULT,
-			O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize);
+	tdb = tdb_open("run-tdb1-hashsize.tdb1", TDB_VERSION1,
+		       O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize);
 	ok1(tdb);
 	h2.base.attr = TDB_ATTRIBUTE_TDB1_HASHSIZE;
 	ok1(tdb_get_attribute(tdb, &h2) == TDB_SUCCESS);
@@ -23,8 +23,8 @@ int main(int argc, char *argv[])
 	tdb_close(tdb);
 
 	/* Can't specify TDB_ATTRIBUTE_TDB1_HASHSIZE without O_CREAT */
-	tdb = tdb1_open("run-tdb1-hashsize.tdb1", TDB_DEFAULT,
-			O_RDWR, 0600, &hsize);
+	tdb = tdb_open("run-tdb1-hashsize.tdb1", TDB_VERSION1,
+		       O_RDWR, 0600, &hsize);
 	ok1(!tdb);
 	ok1(tap_log_messages == 1);
 
@@ -35,8 +35,8 @@ int main(int argc, char *argv[])
 	ok1(tap_log_messages == 2);
 
 	/* We can get attribute even if we didn't set it though. */
-	tdb = tdb1_open("run-tdb1-hashsize.tdb1", TDB_DEFAULT,
-			O_RDWR, 0600, &tap_log_attr);
+	tdb = tdb_open("run-tdb1-hashsize.tdb1", TDB_DEFAULT,
+		       O_RDWR, 0600, &tap_log_attr);
 
 	ok1(tdb);
 	memset(&h2, 0, sizeof(h2));
@@ -46,8 +46,8 @@ int main(int argc, char *argv[])
 	tdb_close(tdb);
 
 	/* Check for default hash size. */
-	tdb = tdb1_open("run-tdb1-hashsize.tdb1", TDB_DEFAULT,
-			O_CREAT|O_TRUNC|O_RDWR, 0600, &tap_log_attr);
+	tdb = tdb_open("run-tdb1-hashsize.tdb1", TDB_VERSION1,
+		       O_CREAT|O_TRUNC|O_RDWR, 0600, &tap_log_attr);
 
 	ok1(tdb);
 	memset(&h2, 0, sizeof(h2));

+ 38 - 38
ccan/tdb2/test/run-tdb1-incompatible.c

@@ -83,86 +83,86 @@ int main(int argc, char *argv[])
 
 		/* Create an old-style hash. */
 		log_count = 0;
-		tdb = tdb1_open("run-incompatible.tdb", flags,
-				O_CREAT|O_RDWR|O_TRUNC, 0600, &log_attr);
+		tdb = tdb_open("run-incompatible.tdb1", flags|TDB_VERSION1,
+			       O_CREAT|O_RDWR|O_TRUNC, 0600, &log_attr);
 		ok1(tdb);
 		ok1(log_count == 0);
 		d.dptr = (void *)"Hello";
 		d.dsize = 5;
 		ok1(tdb1_store(tdb, d, d, TDB_INSERT) == 0);
-		tdb1_close(tdb);
+		tdb_close(tdb);
 
 		/* Should not have marked rwlocks field. */
-		ok1(hdr_rwlocks("run-incompatible.tdb") == 0);
+		ok1(hdr_rwlocks("run-incompatible.tdb1") == 0);
 
 		/* We can still open any old-style with incompat hash. */
 		log_count = 0;
-		tdb = tdb1_open("run-incompatible.tdb",
-				TDB_DEFAULT,
-				O_RDWR, 0600, &incompat_hash_attr);
+		tdb = tdb_open("run-incompatible.tdb1",
+			       TDB_VERSION1,
+			       O_RDWR, 0600, &incompat_hash_attr);
 		ok1(tdb);
 		ok1(log_count == 0);
 		d = tdb1_fetch(tdb, d);
 		ok1(d.dsize == 5);
 		free(d.dptr);
 		ok1(tdb1_check(tdb, NULL, NULL) == 0);
-		tdb1_close(tdb);
+		tdb_close(tdb);
 
 		log_count = 0;
-		tdb = tdb1_open("test/jenkins-le-hash.tdb1", 0, O_RDONLY,
-				0, &jhash_attr);
+		tdb = tdb_open("test/jenkins-le-hash.tdb1",
+			       TDB_VERSION1, O_RDONLY, 0, &jhash_attr);
 		ok1(tdb);
 		ok1(log_count == 0);
 		ok1(tdb1_check(tdb, NULL, NULL) == 0);
-		tdb1_close(tdb);
+		tdb_close(tdb);
 
 		log_count = 0;
-		tdb = tdb1_open("test/jenkins-be-hash.tdb1", 0, O_RDONLY,
-				0, &jhash_attr);
+		tdb = tdb_open("test/jenkins-be-hash.tdb1",
+			       TDB_VERSION1, O_RDONLY, 0, &jhash_attr);
 		ok1(tdb);
 		ok1(log_count == 0);
 		ok1(tdb1_check(tdb, NULL, NULL) == 0);
-		tdb1_close(tdb);
+		tdb_close(tdb);
 
 		/* OK, now create with incompatible hash. */
 		log_count = 0;
-		tdb = tdb1_open("run-incompatible.tdb",
-				flags,
-				O_CREAT|O_RDWR|O_TRUNC, 0600,
-				&incompat_hash_attr);
+		tdb = tdb_open("run-incompatible.tdb1",
+			       flags|TDB_VERSION1,
+			       O_CREAT|O_RDWR|O_TRUNC, 0600,
+			       &incompat_hash_attr);
 		ok1(tdb);
 		ok1(log_count == 0);
 		d.dptr = (void *)"Hello";
 		d.dsize = 5;
 		ok1(tdb1_store(tdb, d, d, TDB_INSERT) == 0);
-		tdb1_close(tdb);
+		tdb_close(tdb);
 
 		/* Should have marked rwlocks field. */
-		ok1(hdr_rwlocks("run-incompatible.tdb") == rwmagic);
+		ok1(hdr_rwlocks("run-incompatible.tdb1") == rwmagic);
 
 		/* Cannot open with old hash. */
 		log_count = 0;
-		tdb = tdb1_open("run-incompatible.tdb", 0,
-				O_RDWR, 0600, &ohash_attr);
+		tdb = tdb_open("run-incompatible.tdb1", TDB_VERSION1,
+			       O_RDWR, 0600, &ohash_attr);
 		ok1(!tdb);
 		ok1(log_count == 1);
 
 		/* Can open with jenkins hash. */
 		log_count = 0;
-		tdb = tdb1_open("run-incompatible.tdb", 0,
-				O_RDWR, 0600, &jhash_attr);
+		tdb = tdb_open("run-incompatible.tdb1", TDB_VERSION1,
+			       O_RDWR, 0600, &jhash_attr);
 		ok1(tdb);
 		ok1(log_count == 0);
 		d = tdb1_fetch(tdb, d);
 		ok1(d.dsize == 5);
 		free(d.dptr);
 		ok1(tdb1_check(tdb, NULL, NULL) == 0);
-		tdb1_close(tdb);
+		tdb_close(tdb);
 
 		/* Can open by letting it figure it out itself. */
 		log_count = 0;
-		tdb = tdb1_open("run-incompatible.tdb", 0,
-				O_RDWR, 0600, &log_attr);
+		tdb = tdb_open("run-incompatible.tdb1", TDB_VERSION1,
+			       O_RDWR, 0600, &log_attr);
 		ok1(tdb);
 		ok1(log_count == 0);
 		d.dptr = (void *)"Hello";
@@ -171,42 +171,42 @@ int main(int argc, char *argv[])
 		ok1(d.dsize == 5);
 		free(d.dptr);
 		ok1(tdb1_check(tdb, NULL, NULL) == 0);
-		tdb1_close(tdb);
+		tdb_close(tdb);
 
 		/* FIXME: Not possible with TDB2 :( */
 		/* We can also use incompatible hash with other hashes. */
 		log_count = 0;
-		tdb = tdb1_open("run-incompatible.tdb",
-				flags,
-				O_CREAT|O_RDWR|O_TRUNC, 0600, &dumbhash_attr);
+		tdb = tdb_open("run-incompatible.tdb1",
+			       flags|TDB_VERSION1,
+			       O_CREAT|O_RDWR|O_TRUNC, 0600, &dumbhash_attr);
 		ok1(tdb);
 		ok1(log_count == 0);
 		d.dptr = (void *)"Hello";
 		d.dsize = 5;
 		ok1(tdb1_store(tdb, d, d, TDB_INSERT) == 0);
-		tdb1_close(tdb);
+		tdb_close(tdb);
 
 		/* FIXME: Should have marked rwlocks field. */
-		ok1(hdr_rwlocks("run-incompatible.tdb") != rwmagic);
+		ok1(hdr_rwlocks("run-incompatible.tdb1") != rwmagic);
 
 		/* It should not open if we don't specify. */
 		log_count = 0;
-		tdb = tdb1_open("run-incompatible.tdb", 0, O_RDWR, 0,
-				&log_attr);
+		tdb = tdb_open("run-incompatible.tdb1", TDB_VERSION1, O_RDWR, 0,
+			       &log_attr);
 		ok1(!tdb);
 		ok1(log_count == 1);
 
 		/* Should reopen with correct hash. */
 		log_count = 0;
-		tdb = tdb1_open("run-incompatible.tdb", 0, O_RDWR, 0,
-				&dumbhash_attr);
+		tdb = tdb_open("run-incompatible.tdb1", TDB_VERSION1, O_RDWR, 0,
+			       &dumbhash_attr);
 		ok1(tdb);
 		ok1(log_count == 0);
 		d = tdb1_fetch(tdb, d);
 		ok1(d.dsize == 5);
 		free(d.dptr);
 		ok1(tdb1_check(tdb, NULL, NULL) == 0);
-		tdb1_close(tdb);
+		tdb_close(tdb);
 	}
 
 	return exit_status();

+ 6 - 7
ccan/tdb2/test/run-tdb1-nested-transactions.c

@@ -19,9 +19,8 @@ int main(int argc, char *argv[])
 	key.dsize = strlen("hi");
 	key.dptr = (void *)"hi";
 
-	tdb = tdb1_open("run-nested-transactions.tdb",
-			TDB_DEFAULT,
-			O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize);
+	tdb = tdb_open("run-nested-transactions.tdb1",
+		       TDB_VERSION1, O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize);
 	ok1(tdb);
 
 	/* No nesting by default. */
@@ -45,10 +44,10 @@ int main(int argc, char *argv[])
 	ok1(data.dsize == strlen("world"));
 	ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
 	free(data.dptr);
-	tdb1_close(tdb);
+	tdb_close(tdb);
 
-	tdb = tdb1_open("run-nested-transactions.tdb",
-			TDB_ALLOW_NESTING, O_RDWR, 0, &tap_log_attr);
+	tdb = tdb_open("run-nested-transactions.tdb1",
+		       TDB_ALLOW_NESTING, O_RDWR, 0, &tap_log_attr);
 	ok1(tdb);
 
 	ok1(tdb1_transaction_start(tdb) == 0);
@@ -67,7 +66,7 @@ int main(int argc, char *argv[])
 	ok1(!tdb1_exists(tdb, key));
 	ok1(tdb1_transaction_commit(tdb) == 0);
 	ok1(!tdb1_exists(tdb, key));
-	tdb1_close(tdb);
+	tdb_close(tdb);
 
 	return exit_status();
 }

+ 3 - 3
ccan/tdb2/test/run-tdb1-nested-traverse.c

@@ -61,8 +61,8 @@ int main(int argc, char *argv[])
 	if (!agent)
 		err(1, "preparing agent");
 
-	tdb = tdb1_open("run-nested-traverse.tdb", TDB_DEFAULT,
-			O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize);
+	tdb = tdb_open("run-nested-traverse.tdb1", TDB_VERSION1,
+		       O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize);
 	ok1(tdb);
 
 	ok1(external_agent_operation1(agent, OPEN, tdb->name) == SUCCESS);
@@ -79,7 +79,7 @@ int main(int argc, char *argv[])
 	ok1(tdb1_store(tdb, key, data, TDB_INSERT) == 0);
 	tdb1_traverse(tdb, traverse1, NULL);
 	tdb1_traverse_read(tdb, traverse1, NULL);
-	tdb1_close(tdb);
+	tdb_close(tdb);
 
 	return exit_status();
 }

+ 4 - 4
ccan/tdb2/test/run-tdb1-no-lock-during-traverse.c

@@ -75,9 +75,9 @@ int main(int argc, char *argv[])
 	hsize.tdb1_hashsize.hsize = 1024;
 
 	plan_tests(41);
-	tdb = tdb1_open("run-no-lock-during-traverse.tdb",
-			TDB_DEFAULT, O_CREAT|O_TRUNC|O_RDWR,
-			0600, &hsize);
+	tdb = tdb_open("run-no-lock-during-traverse.tdb1",
+		       TDB_VERSION1, O_CREAT|O_TRUNC|O_RDWR,
+		       0600, &hsize);
 
 	ok1(tdb);
 	ok1(prepare_entries(tdb));
@@ -105,7 +105,7 @@ int main(int argc, char *argv[])
 	ok1(locking_errors1 == 0);
 	ok1(tdb1_unlockall(tdb) == 0);
 
-	ok1(tdb1_close(tdb) == 0);
+	ok1(tdb_close(tdb) == 0);
 
 	return exit_status();
 }

+ 12 - 12
ccan/tdb2/test/run-tdb1-oldhash.c

@@ -17,29 +17,29 @@ int main(int argc, char *argv[])
 
 	/* Old format (with zeroes in the hash magic fields) should
 	 * open with any hash (since we don't know what hash they used). */
-	tdb = tdb1_open("test/old-nohash-le.tdb1", 0, O_RDWR, 0,
-			&tap_log_attr);
+	tdb = tdb_open("test/old-nohash-le.tdb1", TDB_VERSION1, O_RDWR, 0,
+		       &tap_log_attr);
 	ok1(tdb);
 	ok1(tdb1_check(tdb, NULL, NULL) == 0);
-	tdb1_close(tdb);
+	tdb_close(tdb);
 
-	tdb = tdb1_open("test/old-nohash-be.tdb1", 0, O_RDWR, 0,
-			&tap_log_attr);
+	tdb = tdb_open("test/old-nohash-be.tdb1", TDB_VERSION1, O_RDWR, 0,
+		       &tap_log_attr);
 	ok1(tdb);
 	ok1(tdb1_check(tdb, NULL, NULL) == 0);
-	tdb1_close(tdb);
+	tdb_close(tdb);
 
-	tdb = tdb1_open("test/old-nohash-le.tdb1", 0, O_RDWR, 0,
-			&incompat_hash_attr);
+	tdb = tdb_open("test/old-nohash-le.tdb1", TDB_VERSION1, O_RDWR, 0,
+		       &incompat_hash_attr);
 	ok1(tdb);
 	ok1(tdb1_check(tdb, NULL, NULL) == 0);
-	tdb1_close(tdb);
+	tdb_close(tdb);
 
-	tdb = tdb1_open("test/old-nohash-be.tdb1", 0, O_RDWR, 0,
-			&incompat_hash_attr);
+	tdb = tdb_open("test/old-nohash-be.tdb1", TDB_VERSION1, O_RDWR, 0,
+		       &incompat_hash_attr);
 	ok1(tdb);
 	ok1(tdb1_check(tdb, NULL, NULL) == 0);
-	tdb1_close(tdb);
+	tdb_close(tdb);
 
 	return exit_status();
 }

+ 5 - 5
ccan/tdb2/test/run-tdb1-open-during-transaction.c

@@ -23,7 +23,7 @@ static int ftruncate_check(int fd, off_t length);
 static struct agent *agent;
 static bool opened;
 static int errors = 0;
-#define TEST_DBNAME "run-open-during-transaction.tdb"
+#define TEST_DBNAME "run-open-during-transaction.tdb1"
 
 #undef write
 #undef pwrite
@@ -150,9 +150,9 @@ int main(int argc, char *argv[])
 		     "DEFAULT",
 		     (flags[i] & TDB_NOMMAP) ? "no mmap" : "mmap");
 		unlink(TEST_DBNAME);
-		tdb = tdb1_open(TEST_DBNAME, flags[i],
-				O_CREAT|O_TRUNC|O_RDWR, 0600,
-				&hsize);
+		tdb = tdb_open(TEST_DBNAME, flags[i]|TDB_VERSION1,
+			       O_CREAT|O_TRUNC|O_RDWR, 0600,
+			       &hsize);
 		ok1(tdb);
 
 		opened = true;
@@ -167,7 +167,7 @@ int main(int argc, char *argv[])
 		ok(!errors, "We had %u open errors", errors);
 
 		opened = false;
-		tdb1_close(tdb);
+		tdb_close(tdb);
 	}
 
 	return exit_status();

+ 7 - 7
ccan/tdb2/test/run-tdb1-readonly-check.c

@@ -17,9 +17,9 @@ int main(int argc, char *argv[])
 	hsize.tdb1_hashsize.hsize = 1024;
 
 	plan_tests(11);
-	tdb = tdb1_open("run-readonly-check.tdb",
-			TDB_DEFAULT,
-			O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize);
+	tdb = tdb_open("run-readonly-check.tdb1",
+		       TDB_VERSION1,
+		       O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize);
 
 	ok1(tdb);
 	key.dsize = strlen("hi");
@@ -33,16 +33,16 @@ int main(int argc, char *argv[])
 	/* We are also allowed to do a check inside a transaction. */
 	ok1(tdb1_transaction_start(tdb) == 0);
 	ok1(tdb1_check(tdb, NULL, NULL) == 0);
-	ok1(tdb1_close(tdb) == 0);
+	ok1(tdb_close(tdb) == 0);
 
-	tdb = tdb1_open("run-readonly-check.tdb",
-			TDB_DEFAULT, O_RDONLY, 0, &tap_log_attr);
+	tdb = tdb_open("run-readonly-check.tdb1",
+		       TDB_DEFAULT, O_RDONLY, 0, &tap_log_attr);
 
 	ok1(tdb);
 	ok1(tdb1_store(tdb, key, data, TDB_MODIFY) == -1);
 	ok1(tdb_error(tdb) == TDB_ERR_RDONLY);
 	ok1(tdb1_check(tdb, NULL, NULL) == 0);
-	ok1(tdb1_close(tdb) == 0);
+	ok1(tdb_close(tdb) == 0);
 
 	return exit_status();
 }

+ 4 - 4
ccan/tdb2/test/run-tdb1-rwlock-check.c

@@ -27,14 +27,14 @@ int main(int argc, char *argv[])
 
 	/* We should fail to open rwlock-using tdbs of either endian. */
 	log_count = 0;
-	tdb = tdb1_open("test/rwlock-le.tdb1", 0, O_RDWR, 0,
-			&log_attr);
+	tdb = tdb_open("test/rwlock-le.tdb1", TDB_VERSION1, O_RDWR, 0,
+		       &log_attr);
 	ok1(!tdb);
 	ok1(log_count == 1);
 
 	log_count = 0;
-	tdb = tdb1_open("test/rwlock-be.tdb1", 0, O_RDWR, 0,
-			&log_attr);
+	tdb = tdb_open("test/rwlock-be.tdb1", TDB_VERSION1, O_RDWR, 0,
+		       &log_attr);
 	ok1(!tdb);
 	ok1(log_count == 1);
 

+ 3 - 3
ccan/tdb2/test/run-tdb1-summary.c

@@ -16,8 +16,8 @@ int main(int argc, char *argv[])
 
 	plan_tests(sizeof(flags) / sizeof(flags[0]) * 14);
 	for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
-		tdb = tdb1_open("run-summary.tdb", flags[i],
-				O_RDWR|O_CREAT|O_TRUNC, 0600, NULL);
+		tdb = tdb_open("run-summary.tdb1", flags[i]|TDB_VERSION1,
+			       O_RDWR|O_CREAT|O_TRUNC, 0600, NULL);
 		ok1(tdb);
 		if (!tdb)
 			continue;
@@ -47,7 +47,7 @@ int main(int argc, char *argv[])
 		ok1(strstr(summary, "Percentage keys/data/padding/free/dead/rechdrs&tailers/hashes: "));
 
 		free(summary);
-		tdb1_close(tdb);
+		tdb_close(tdb);
 	}
 
 	return exit_status();

+ 4 - 4
ccan/tdb2/test/run-tdb1-traverse-in-transaction.c

@@ -47,9 +47,9 @@ int main(int argc, char *argv[])
 	if (!agent)
 		err(1, "preparing agent");
 
-	tdb = tdb1_open("run-traverse-in-transaction.tdb",
-			TDB_DEFAULT, O_CREAT|O_TRUNC|O_RDWR,
-			0600, &hsize);
+	tdb = tdb_open("run-traverse-in-transaction.tdb1",
+		       TDB_VERSION1, O_CREAT|O_TRUNC|O_RDWR,
+		       0600, &hsize);
 	ok1(tdb);
 
 	key.dsize = strlen("hi");
@@ -79,7 +79,7 @@ int main(int argc, char *argv[])
 	ok1(external_agent_operation1(agent, TRANSACTION_START, tdb->name)
 	    == SUCCESS);
 
-	tdb1_close(tdb);
+	tdb_close(tdb);
 
 	return exit_status();
 }

+ 29 - 30
ccan/tdb2/test/run-tdb1-wronghash-fail.c

@@ -54,90 +54,89 @@ int main(int argc, char *argv[])
 
 	/* Create with default hash. */
 	log_count = 0;
-	tdb = tdb1_open("run-wronghash-fail.tdb", 0,
-			O_CREAT|O_RDWR|O_TRUNC, 0600, &log_attr);
+	tdb = tdb_open("run-wronghash-fail.tdb1", TDB_VERSION1,
+		       O_CREAT|O_RDWR|O_TRUNC, 0600, &log_attr);
 	ok1(tdb);
 	ok1(log_count == 0);
 	d.dptr = (void *)"Hello";
 	d.dsize = 5;
 	ok1(tdb1_store(tdb, d, d, TDB_INSERT) == 0);
-	tdb1_close(tdb);
+	tdb_close(tdb);
 
 	/* Fail to open with different hash. */
-	tdb = tdb1_open("run-wronghash-fail.tdb", 0, O_RDWR, 0,
-			&jhash_attr);
+	tdb = tdb_open("run-wronghash-fail.tdb1", TDB_VERSION1, O_RDWR, 0,
+		       &jhash_attr);
 	ok1(!tdb);
 	ok1(log_count == 1);
 
 	/* Create with different hash. */
 	log_count = 0;
-	tdb = tdb1_open("run-wronghash-fail.tdb", 0,
-			O_CREAT|O_RDWR|O_TRUNC,
-			0600, &jhash_attr);
+	tdb = tdb_open("run-wronghash-fail.tdb1", TDB_VERSION1,
+		       O_CREAT|O_RDWR|O_TRUNC, 0600, &jhash_attr);
 	ok1(tdb);
 	ok1(log_count == 0);
-	tdb1_close(tdb);
+	tdb_close(tdb);
 
 	/* Endian should be no problem. */
 	log_count = 0;
-	tdb = tdb1_open("test/jenkins-le-hash.tdb1", 0, O_RDWR, 0,
-			&ohash_attr);
+	tdb = tdb_open("test/jenkins-le-hash.tdb1", TDB_VERSION1, O_RDWR, 0,
+		       &ohash_attr);
 	ok1(!tdb);
 	ok1(log_count == 1);
 
 	log_count = 0;
-	tdb = tdb1_open("test/jenkins-be-hash.tdb1", 0, O_RDWR, 0,
-			&ohash_attr);
+	tdb = tdb_open("test/jenkins-be-hash.tdb1", TDB_VERSION1, O_RDWR, 0,
+		       &ohash_attr);
 	ok1(!tdb);
 	ok1(log_count == 1);
 
 	log_count = 0;
 	/* Fail to open with old default hash. */
-	tdb = tdb1_open("run-wronghash-fail.tdb", 0, O_RDWR, 0,
-			&ohash_attr);
+	tdb = tdb_open("run-wronghash-fail.tdb1", TDB_VERSION1, O_RDWR, 0,
+		       &ohash_attr);
 	ok1(!tdb);
 	ok1(log_count == 1);
 
 	log_count = 0;
-	tdb = tdb1_open("test/jenkins-le-hash.tdb1", 0, O_RDONLY,
-			0, &incompat_hash_attr);
+	tdb = tdb_open("test/jenkins-le-hash.tdb1", TDB_VERSION1, O_RDONLY,
+		       0, &incompat_hash_attr);
 	ok1(tdb);
 	ok1(log_count == 0);
 	ok1(tdb1_check(tdb, NULL, NULL) == 0);
-	tdb1_close(tdb);
+	tdb_close(tdb);
 
 	log_count = 0;
-	tdb = tdb1_open("test/jenkins-be-hash.tdb1", 0, O_RDONLY,
-			0, &incompat_hash_attr);
+	tdb = tdb_open("test/jenkins-be-hash.tdb1", TDB_VERSION1, O_RDONLY,
+		       0, &incompat_hash_attr);
 	ok1(tdb);
 	ok1(log_count == 0);
 	ok1(tdb1_check(tdb, NULL, NULL) == 0);
-	tdb1_close(tdb);
+	tdb_close(tdb);
 
 	/* It should open with jenkins hash if we don't specify. */
 	log_count = 0;
-	tdb = tdb1_open("test/jenkins-le-hash.tdb1", 0, O_RDWR, 0,
-			&log_attr);
+	tdb = tdb_open("test/jenkins-le-hash.tdb1", TDB_VERSION1, O_RDWR, 0,
+		       &log_attr);
 	ok1(tdb);
 	ok1(log_count == 0);
 	ok1(tdb1_check(tdb, NULL, NULL) == 0);
-	tdb1_close(tdb);
+	tdb_close(tdb);
 
 	log_count = 0;
-	tdb = tdb1_open("test/jenkins-be-hash.tdb1", 0, O_RDWR, 0,
-			&log_attr);
+	tdb = tdb_open("test/jenkins-be-hash.tdb1", TDB_VERSION1, O_RDWR, 0,
+		       &log_attr);
 	ok1(tdb);
 	ok1(log_count == 0);
 	ok1(tdb1_check(tdb, NULL, NULL) == 0);
-	tdb1_close(tdb);
+	tdb_close(tdb);
 
 	log_count = 0;
-	tdb = tdb1_open("run-wronghash-fail.tdb", 0, O_RDONLY,
-			0, &log_attr);
+	tdb = tdb_open("run-wronghash-fail.tdb1", TDB_VERSION1, O_RDONLY,
+		       0, &log_attr);
 	ok1(tdb);
 	ok1(log_count == 0);
 	ok1(tdb1_check(tdb, NULL, NULL) == 0);
-	tdb1_close(tdb);
+	tdb_close(tdb);
 
 
 	return exit_status();

+ 3 - 3
ccan/tdb2/test/run-tdb1-zero-append.c

@@ -15,8 +15,8 @@ int main(int argc, char *argv[])
 	hsize.tdb1_hashsize.hsize = 1024;
 
 	plan_tests(4);
-	tdb = tdb1_open(NULL, TDB_INTERNAL, O_CREAT|O_TRUNC|O_RDWR,
-			0600, &hsize);
+	tdb = tdb_open(NULL, TDB_INTERNAL|TDB_VERSION1, O_CREAT|O_TRUNC|O_RDWR,
+		       0600, &hsize);
 	ok1(tdb);
 
 	/* Tickle bug on appending zero length buffer to zero length buffer. */
@@ -30,7 +30,7 @@ int main(int argc, char *argv[])
 	data = tdb1_fetch(tdb, key);
 	ok1(data.dsize == 0);
 	free(data.dptr);
-	tdb1_close(tdb);
+	tdb_close(tdb);
 
 	return exit_status();
 }

+ 3 - 3
ccan/tdb2/test/run-tdb1.c

@@ -15,8 +15,8 @@ int main(int argc, char *argv[])
 	hsize.tdb1_hashsize.hsize = 1024;
 
 	plan_tests(10);
-	tdb = tdb1_open("run.tdb", TDB_DEFAULT,
-			O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize);
+	tdb = tdb_open("run.tdb1", TDB_VERSION1,
+		       O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize);
 
 	ok1(tdb);
 	key.dsize = strlen("hi");
@@ -39,7 +39,7 @@ int main(int argc, char *argv[])
 	key.dsize++;
 	data = tdb1_fetch(tdb, key);
 	ok1(data.dptr == NULL);
-	tdb1_close(tdb);
+	tdb_close(tdb);
 
 	return exit_status();
 }

+ 2 - 3
ccan/tdb2/test/tdb1-external-agent.c

@@ -39,8 +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(name, TDB_DEFAULT, O_RDWR, 0,
-				&tap_log_attr);
+		tdb = tdb_open(name, TDB_VERSION1, O_RDWR, 0, &tap_log_attr);
 		if (!tdb) {
 			if (!locking_would_block1)
 				diag("Opening tdb gave %s", strerror(errno));
@@ -79,7 +78,7 @@ static enum agent_return do_operation(enum operation op, const char *name)
 		ret = tdb1_needs_recovery(tdb) ? SUCCESS : FAILED;
 		break;
 	case CLOSE:
-		ret = tdb1_close(tdb) == 0 ? SUCCESS : OTHER_FAILURE;
+		ret = tdb_close(tdb) == 0 ? SUCCESS : OTHER_FAILURE;
 		tdb = NULL;
 		break;
 	default: