Commit a446f1d4 authored by Rusty Russell's avatar Rusty Russell

tdb2: make tdb1_open use attributes for logging, hash function.

This brings it closer to tdb_open(), so we can unify more easily.
parent c8f6f8c2
...@@ -37,23 +37,10 @@ ...@@ -37,23 +37,10 @@
typedef int (*tdb1_traverse_func)(struct tdb_context *, TDB_DATA, TDB_DATA, void *); typedef int (*tdb1_traverse_func)(struct tdb_context *, TDB_DATA, TDB_DATA, void *);
typedef void (*tdb1_log_func)(struct tdb_context *, enum tdb_log_level, enum TDB_ERROR,
const char *, void *);
typedef uint64_t (*tdb1_hash_func)(const void *key, size_t len, uint64_t seed,
void *data);
struct tdb1_logging_context {
tdb1_log_func log_fn;
void *log_private;
};
struct tdb_context *tdb1_open(const char *name, int hash_size, int tdb1_flags, struct tdb_context *tdb1_open(const char *name, int hash_size, int tdb1_flags,
int open_flags, mode_t mode); int open_flags, mode_t mode,
union tdb_attribute *attributes);
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);
void tdb1_set_max_dead(struct tdb_context *tdb, int max_dead); void tdb1_set_max_dead(struct tdb_context *tdb, int max_dead);
......
...@@ -95,23 +95,15 @@ static int tdb1_new_database(struct tdb_context *tdb, int hash_size) ...@@ -95,23 +95,15 @@ static int tdb1_new_database(struct tdb_context *tdb, int hash_size)
return ret; return ret;
} }
typedef void (*tdb1_log_func)(struct tdb_context *, enum tdb_log_level, enum TDB_ERROR,
const char *, void *);
typedef uint64_t (*tdb1_hash_func)(const void *key, size_t len, uint64_t seed,
void *data);
struct tdb1_logging_context {
/* open the database, creating it if necessary tdb1_log_func log_fn;
void *log_private;
The open_flags and mode are passed straight to the open call on the };
database file. A flags value of O_WRONLY is invalid. The hash size
is advisory, use zero for a default value.
Return is NULL on error, in which case errno is also set. Don't
try to call tdb1_error or tdb1_errname, just do strerror(errno).
@param name may be NULL for internal databases. */
struct tdb_context *tdb1_open(const char *name, int hash_size, int tdb1_flags,
int open_flags, mode_t mode)
{
return tdb1_open_ex(name, hash_size, tdb1_flags, open_flags, mode, NULL, NULL);
}
static bool hash_correct(struct tdb_context *tdb, static bool hash_correct(struct tdb_context *tdb,
uint32_t *m1, uint32_t *m2) uint32_t *m1, uint32_t *m2)
...@@ -137,7 +129,7 @@ static bool check_header_hash(struct tdb_context *tdb, ...@@ -137,7 +129,7 @@ static bool check_header_hash(struct tdb_context *tdb,
return hash_correct(tdb, m1, m2); return hash_correct(tdb, m1, m2);
} }
struct tdb_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flags, static struct tdb_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flags,
int open_flags, mode_t mode, int open_flags, mode_t mode,
const struct tdb1_logging_context *log_ctx, const struct tdb1_logging_context *log_ctx,
tdb1_hash_func hash_fn) tdb1_hash_func hash_fn)
...@@ -366,6 +358,34 @@ struct tdb_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flags ...@@ -366,6 +358,34 @@ struct tdb_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flags
} }
} }
/* Temporart wrapper for transition. */
struct tdb_context *tdb1_open(const char *name, int hash_size, 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;
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;
default:
abort();
}
attr = attr->base.next;
}
return tdb1_open_ex(name, hash_size, tdb1_flags, open_flags, mode,
log_ctx, hash_fn);
}
/* /*
* Set the maximum number of dead records per hash chain * Set the maximum number of dead records per hash chain
*/ */
......
...@@ -843,7 +843,7 @@ int tdb1_repack(struct tdb_context *tdb) ...@@ -843,7 +843,7 @@ int tdb1_repack(struct tdb_context *tdb)
return -1; return -1;
} }
tmp_db = tdb1_open("tmpdb", tdb1_hash_size(tdb), TDB_INTERNAL, O_RDWR|O_CREAT, 0); tmp_db = tdb1_open("tmpdb", tdb1_hash_size(tdb), TDB_INTERNAL, O_RDWR|O_CREAT, 0, NULL);
if (tmp_db == NULL) { if (tmp_db == NULL) {
tdb->last_error = tdb_logerr(tdb, TDB_ERR_OOM, TDB_LOG_ERROR, tdb->last_error = tdb_logerr(tdb, TDB_ERR_OOM, TDB_LOG_ERROR,
__location__ " Failed to create tmp_db"); __location__ " Failed to create tmp_db");
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include <ccan/tap/tap.h> #include <ccan/tap/tap.h>
#include <stdlib.h> #include <stdlib.h>
#include <err.h> #include <err.h>
#include "tdb1-logging.h" #include "logging.h"
static int tdb1_expand_file_sparse(struct tdb_context *tdb, static int tdb1_expand_file_sparse(struct tdb_context *tdb,
tdb1_off_t size, tdb1_off_t size,
...@@ -66,8 +66,8 @@ int main(int argc, char *argv[]) ...@@ -66,8 +66,8 @@ int main(int argc, char *argv[])
struct tdb1_record rec; struct tdb1_record rec;
plan_tests(24); plan_tests(24);
tdb = tdb1_open_ex("run-36-file.tdb", 1024, TDB_DEFAULT, tdb = tdb1_open("run-36-file.tdb", 1024, TDB_DEFAULT,
O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL); O_CREAT|O_TRUNC|O_RDWR, 0600, &tap_log_attr);
ok1(tdb); ok1(tdb);
tdb->tdb1.io = &large_io_methods; tdb->tdb1.io = &large_io_methods;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include <ccan/tap/tap.h> #include <ccan/tap/tap.h>
#include <stdlib.h> #include <stdlib.h>
#include <err.h> #include <err.h>
#include "tdb1-logging.h" #include "logging.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
...@@ -16,11 +16,11 @@ int main(int argc, char *argv[]) ...@@ -16,11 +16,11 @@ int main(int argc, char *argv[])
ok1(fd >= 0); ok1(fd >= 0);
ok1(write(fd, "hello world", 11) == 11); ok1(write(fd, "hello world", 11) == 11);
close(fd); close(fd);
tdb = tdb1_open_ex("run-bad-tdb-header.tdb", 1024, 0, O_RDWR, 0, tdb = tdb1_open("run-bad-tdb-header.tdb", 1024, 0, O_RDWR, 0,
&taplogctx, NULL); &tap_log_attr);
ok1(!tdb); ok1(!tdb);
tdb = tdb1_open_ex("run-bad-tdb-header.tdb", 1024, 0, O_CREAT|O_RDWR, tdb = tdb1_open("run-bad-tdb-header.tdb", 1024, 0, O_CREAT|O_RDWR,
0600, &taplogctx, NULL); 0600, &tap_log_attr);
ok1(tdb); ok1(tdb);
tdb1_close(tdb); tdb1_close(tdb);
...@@ -34,14 +34,14 @@ int main(int argc, char *argv[]) ...@@ -34,14 +34,14 @@ int main(int argc, char *argv[])
ok1(write(fd, &hdr, sizeof(hdr)) == sizeof(hdr)); ok1(write(fd, &hdr, sizeof(hdr)) == sizeof(hdr));
close(fd); close(fd);
tdb = tdb1_open_ex("run-bad-tdb-header.tdb", 1024, 0, O_RDWR|O_CREAT, tdb = tdb1_open("run-bad-tdb-header.tdb", 1024, 0, O_RDWR|O_CREAT,
0600, &taplogctx, NULL); 0600, &tap_log_attr);
ok1(errno == EIO); ok1(errno == EIO);
ok1(!tdb); ok1(!tdb);
/* With truncate, will be fine. */ /* With truncate, will be fine. */
tdb = tdb1_open_ex("run-bad-tdb-header.tdb", 1024, 0, tdb = tdb1_open("run-bad-tdb-header.tdb", 1024, 0,
O_RDWR|O_CREAT|O_TRUNC, 0600, &taplogctx, NULL); O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
ok1(tdb); ok1(tdb);
tdb1_close(tdb); tdb1_close(tdb);
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include <ccan/tap/tap.h> #include <ccan/tap/tap.h>
#include <stdlib.h> #include <stdlib.h>
#include <err.h> #include <err.h>
#include "tdb1-logging.h" #include "logging.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
...@@ -10,8 +10,8 @@ int main(int argc, char *argv[]) ...@@ -10,8 +10,8 @@ int main(int argc, char *argv[])
TDB_DATA key, data; TDB_DATA key, data;
plan_tests(13); plan_tests(13);
tdb = tdb1_open_ex("run-check.tdb", 1, TDB_DEFAULT, tdb = tdb1_open("run-check.tdb", 1, TDB_DEFAULT,
O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL); O_CREAT|O_TRUNC|O_RDWR, 0600, &tap_log_attr);
ok1(tdb); ok1(tdb);
ok1(tdb1_check(tdb, NULL, NULL) == 0); ok1(tdb1_check(tdb, NULL, NULL) == 0);
...@@ -25,28 +25,28 @@ int main(int argc, char *argv[]) ...@@ -25,28 +25,28 @@ int main(int argc, char *argv[])
ok1(tdb1_check(tdb, NULL, NULL) == 0); ok1(tdb1_check(tdb, NULL, NULL) == 0);
tdb1_close(tdb); tdb1_close(tdb);
tdb = tdb1_open_ex("run-check.tdb", 1024, 0, O_RDWR, 0, tdb = tdb1_open("run-check.tdb", 1024, 0, O_RDWR, 0,
&taplogctx, NULL); &tap_log_attr);
ok1(tdb); ok1(tdb);
ok1(tdb1_check(tdb, NULL, NULL) == 0); ok1(tdb1_check(tdb, NULL, NULL) == 0);
tdb1_close(tdb); tdb1_close(tdb);
tdb = tdb1_open_ex("test/tdb1.corrupt", 1024, 0, O_RDWR, 0, tdb = tdb1_open("test/tdb1.corrupt", 1024, 0, O_RDWR, 0,
&taplogctx, NULL); &tap_log_attr);
ok1(tdb); ok1(tdb);
ok1(tdb1_check(tdb, NULL, NULL) == -1); ok1(tdb1_check(tdb, NULL, NULL) == -1);
ok1(tdb_error(tdb) == TDB_ERR_CORRUPT); ok1(tdb_error(tdb) == TDB_ERR_CORRUPT);
tdb1_close(tdb); tdb1_close(tdb);
/* Big and little endian should work! */ /* Big and little endian should work! */
tdb = tdb1_open_ex("test/old-nohash-le.tdb1", 1024, 0, O_RDWR, 0, tdb = tdb1_open("test/old-nohash-le.tdb1", 1024, 0, O_RDWR, 0,
&taplogctx, NULL); &tap_log_attr);
ok1(tdb); ok1(tdb);
ok1(tdb1_check(tdb, NULL, NULL) == 0); ok1(tdb1_check(tdb, NULL, NULL) == 0);
tdb1_close(tdb); tdb1_close(tdb);
tdb = tdb1_open_ex("test/old-nohash-be.tdb1", 1024, 0, O_RDWR, 0, tdb = tdb1_open("test/old-nohash-be.tdb1", 1024, 0, O_RDWR, 0,
&taplogctx, NULL); &tap_log_attr);
ok1(tdb); ok1(tdb);
ok1(tdb1_check(tdb, NULL, NULL) == 0); ok1(tdb1_check(tdb, NULL, NULL) == 0);
tdb1_close(tdb); tdb1_close(tdb);
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include <ccan/tap/tap.h> #include <ccan/tap/tap.h>
#include <stdlib.h> #include <stdlib.h>
#include <err.h> #include <err.h>
#include "tdb1-logging.h" #include "logging.h"
static int check(TDB_DATA key, TDB_DATA data, void *private) static int check(TDB_DATA key, TDB_DATA data, void *private)
{ {
...@@ -97,8 +97,8 @@ int main(int argc, char *argv[]) ...@@ -97,8 +97,8 @@ int main(int argc, char *argv[])
plan_tests(4); plan_tests(4);
/* This should use mmap. */ /* This should use mmap. */
tdb = tdb1_open_ex("run-corrupt.tdb", 2, TDB_DEFAULT, tdb = tdb1_open("run-corrupt.tdb", 2, TDB_DEFAULT,
O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL); O_CREAT|O_TRUNC|O_RDWR, 0600, &tap_log_attr);
if (!tdb) if (!tdb)
abort(); abort();
...@@ -106,8 +106,8 @@ int main(int argc, char *argv[]) ...@@ -106,8 +106,8 @@ int main(int argc, char *argv[])
tdb1_close(tdb); tdb1_close(tdb);
/* This should not. */ /* This should not. */
tdb = tdb1_open_ex("run-corrupt.tdb", 2, TDB_NOMMAP, tdb = tdb1_open("run-corrupt.tdb", 2, TDB_NOMMAP,
O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL); O_CREAT|O_TRUNC|O_RDWR, 0600, &tap_log_attr);
if (!tdb) if (!tdb)
abort(); abort();
......
...@@ -18,7 +18,7 @@ static int ftruncate_check(int fd, off_t length); ...@@ -18,7 +18,7 @@ static int ftruncate_check(int fd, off_t length);
#include <err.h> #include <err.h>
#include <setjmp.h> #include <setjmp.h>
#include "tdb1-external-agent.h" #include "tdb1-external-agent.h"
#include "tdb1-logging.h" #include "logging.h"
#undef write #undef write
#undef pwrite #undef pwrite
...@@ -89,8 +89,8 @@ static bool test_death(enum operation op, struct agent *agent) ...@@ -89,8 +89,8 @@ static bool test_death(enum operation op, struct agent *agent)
current = target = 0; current = target = 0;
reset: reset:
unlink(TEST_DBNAME); unlink(TEST_DBNAME);
tdb = tdb1_open_ex(TEST_DBNAME, 1024, TDB_NOMMAP, tdb = tdb1_open(TEST_DBNAME, 1024, TDB_NOMMAP,
O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL); O_CREAT|O_TRUNC|O_RDWR, 0600, &tap_log_attr);
if (setjmp(jmpbuf) != 0) { if (setjmp(jmpbuf) != 0) {
/* We're partway through. Simulate our death. */ /* We're partway through. Simulate our death. */
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include <ccan/tap/tap.h> #include <ccan/tap/tap.h>
#include <stdlib.h> #include <stdlib.h>
#include <err.h> #include <err.h>
#include "tdb1-logging.h" #include "logging.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
...@@ -10,9 +10,9 @@ int main(int argc, char *argv[]) ...@@ -10,9 +10,9 @@ int main(int argc, char *argv[])
TDB_DATA key, data; TDB_DATA key, data;
plan_tests(13); plan_tests(13);
tdb = tdb1_open_ex("run-endian.tdb", 1024, tdb = tdb1_open("run-endian.tdb", 1024,
TDB_CONVERT, TDB_CONVERT,
O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL); O_CREAT|O_TRUNC|O_RDWR, 0600, &tap_log_attr);
ok1(tdb); ok1(tdb);
key.dsize = strlen("hi"); key.dsize = strlen("hi");
...@@ -38,8 +38,8 @@ int main(int argc, char *argv[]) ...@@ -38,8 +38,8 @@ int main(int argc, char *argv[])
tdb1_close(tdb); tdb1_close(tdb);
/* Reopen: should read it */ /* Reopen: should read it */
tdb = tdb1_open_ex("run-endian.tdb", 1024, 0, O_RDWR, 0, tdb = tdb1_open("run-endian.tdb", 1024, 0, O_RDWR, 0,
&taplogctx, NULL); &tap_log_attr);
ok1(tdb); ok1(tdb);
key.dsize = strlen("hi"); key.dsize = strlen("hi");
......
...@@ -49,7 +49,29 @@ int main(int argc, char *argv[]) ...@@ -49,7 +49,29 @@ int main(int argc, char *argv[])
struct tdb_context *tdb; struct tdb_context *tdb;
unsigned int log_count, flags; unsigned int log_count, flags;
TDB_DATA d; TDB_DATA d;
struct tdb1_logging_context log_ctx = { log_fn, &log_count }; union tdb_attribute log_attr, jhash_attr, ohash_attr,
incompat_hash_attr, dumbhash_attr;
log_attr.base.attr = TDB_ATTRIBUTE_LOG;
log_attr.base.next = NULL;
log_attr.log.fn = log_fn;
log_attr.log.data = &log_count;
jhash_attr.base.attr = TDB_ATTRIBUTE_HASH;
jhash_attr.base.next = &log_attr;
jhash_attr.hash.fn = jenkins_hashfn;
ohash_attr.base.attr = TDB_ATTRIBUTE_HASH;
ohash_attr.base.next = &log_attr;
ohash_attr.hash.fn = old_hash;
incompat_hash_attr.base.attr = TDB_ATTRIBUTE_HASH;
incompat_hash_attr.base.next = &log_attr;
incompat_hash_attr.hash.fn = tdb1_incompatible_hash;
dumbhash_attr.base.attr = TDB_ATTRIBUTE_HASH;
dumbhash_attr.base.next = &log_attr;
dumbhash_attr.hash.fn = tdb1_dumb_hash;
plan_tests(38 * 2); plan_tests(38 * 2);
...@@ -61,9 +83,8 @@ int main(int argc, char *argv[]) ...@@ -61,9 +83,8 @@ int main(int argc, char *argv[])
/* Create an old-style hash. */ /* Create an old-style hash. */
log_count = 0; log_count = 0;
tdb = tdb1_open_ex("run-incompatible.tdb", 0, flags, tdb = tdb1_open("run-incompatible.tdb", 0, flags,
O_CREAT|O_RDWR|O_TRUNC, 0600, &log_ctx, O_CREAT|O_RDWR|O_TRUNC, 0600, &log_attr);
NULL);
ok1(tdb); ok1(tdb);
ok1(log_count == 0); ok1(log_count == 0);
d.dptr = (void *)"Hello"; d.dptr = (void *)"Hello";
...@@ -76,10 +97,9 @@ int main(int argc, char *argv[]) ...@@ -76,10 +97,9 @@ int main(int argc, char *argv[])
/* We can still open any old-style with incompat hash. */ /* We can still open any old-style with incompat hash. */
log_count = 0; log_count = 0;
tdb = tdb1_open_ex("run-incompatible.tdb", 0, tdb = tdb1_open("run-incompatible.tdb", 0,
TDB_DEFAULT, TDB_DEFAULT,
O_RDWR, 0600, &log_ctx, O_RDWR, 0600, &incompat_hash_attr);
tdb1_incompatible_hash);
ok1(tdb); ok1(tdb);
ok1(log_count == 0); ok1(log_count == 0);
d = tdb1_fetch(tdb, d); d = tdb1_fetch(tdb, d);
...@@ -89,16 +109,16 @@ int main(int argc, char *argv[]) ...@@ -89,16 +109,16 @@ int main(int argc, char *argv[])
tdb1_close(tdb); tdb1_close(tdb);
log_count = 0; log_count = 0;
tdb = tdb1_open_ex("test/jenkins-le-hash.tdb1", 0, 0, O_RDONLY, tdb = tdb1_open("test/jenkins-le-hash.tdb1", 0, 0, O_RDONLY,
0, &log_ctx, jenkins_hashfn); 0, &jhash_attr);
ok1(tdb); ok1(tdb);
ok1(log_count == 0); ok1(log_count == 0);
ok1(tdb1_check(tdb, NULL, NULL) == 0); ok1(tdb1_check(tdb, NULL, NULL) == 0);
tdb1_close(tdb); tdb1_close(tdb);
log_count = 0; log_count = 0;
tdb = tdb1_open_ex("test/jenkins-be-hash.tdb1", 0, 0, O_RDONLY, tdb = tdb1_open("test/jenkins-be-hash.tdb1", 0, 0, O_RDONLY,
0, &log_ctx, jenkins_hashfn); 0, &jhash_attr);
ok1(tdb); ok1(tdb);
ok1(log_count == 0); ok1(log_count == 0);
ok1(tdb1_check(tdb, NULL, NULL) == 0); ok1(tdb1_check(tdb, NULL, NULL) == 0);
...@@ -106,10 +126,10 @@ int main(int argc, char *argv[]) ...@@ -106,10 +126,10 @@ int main(int argc, char *argv[])
/* OK, now create with incompatible hash. */ /* OK, now create with incompatible hash. */
log_count = 0; log_count = 0;
tdb = tdb1_open_ex("run-incompatible.tdb", 0, tdb = tdb1_open("run-incompatible.tdb", 0,
flags, flags,
O_CREAT|O_RDWR|O_TRUNC, 0600, &log_ctx, O_CREAT|O_RDWR|O_TRUNC, 0600,
tdb1_incompatible_hash); &incompat_hash_attr);
ok1(tdb); ok1(tdb);
ok1(log_count == 0); ok1(log_count == 0);
d.dptr = (void *)"Hello"; d.dptr = (void *)"Hello";
...@@ -122,15 +142,15 @@ int main(int argc, char *argv[]) ...@@ -122,15 +142,15 @@ int main(int argc, char *argv[])
/* Cannot open with old hash. */ /* Cannot open with old hash. */
log_count = 0; log_count = 0;
tdb = tdb1_open_ex("run-incompatible.tdb", 0, 0, tdb = tdb1_open("run-incompatible.tdb", 0, 0,
O_RDWR, 0600, &log_ctx, old_hash); O_RDWR, 0600, &ohash_attr);
ok1(!tdb); ok1(!tdb);
ok1(log_count == 1); ok1(log_count == 1);
/* Can open with jenkins hash. */ /* Can open with jenkins hash. */
log_count = 0; log_count = 0;
tdb = tdb1_open_ex("run-incompatible.tdb", 0, 0, tdb = tdb1_open("run-incompatible.tdb", 0, 0,
O_RDWR, 0600, &log_ctx, jenkins_hashfn); O_RDWR, 0600, &jhash_attr);
ok1(tdb); ok1(tdb);
ok1(log_count == 0); ok1(log_count == 0);
d = tdb1_fetch(tdb, d); d = tdb1_fetch(tdb, d);
...@@ -141,8 +161,8 @@ int main(int argc, char *argv[]) ...@@ -141,8 +161,8 @@ int main(int argc, char *argv[])
/* Can open by letting it figure it out itself. */ /* Can open by letting it figure it out itself. */
log_count = 0; log_count = 0;
tdb = tdb1_open_ex("run-incompatible.tdb", 0, 0, tdb = tdb1_open("run-incompatible.tdb", 0, 0,
O_RDWR, 0600, &log_ctx, NULL); O_RDWR, 0600, &log_attr);
ok1(tdb); ok1(tdb);
ok1(log_count == 0); ok1(log_count == 0);
d.dptr = (void *)"Hello"; d.dptr = (void *)"Hello";
...@@ -156,10 +176,9 @@ int main(int argc, char *argv[]) ...@@ -156,10 +176,9 @@ int main(int argc, char *argv[])
/* FIXME: Not possible with TDB2 :( */ /* FIXME: Not possible with TDB2 :( */
/* We can also use incompatible hash with other hashes. */ /* We can also use incompatible hash with other hashes. */
log_count = 0; log_count = 0;
tdb = tdb1_open_ex("run-incompatible.tdb", 0, tdb = tdb1_open("run-incompatible.tdb", 0,
flags, flags,
O_CREAT|O_RDWR|O_TRUNC, 0600, &log_ctx, O_CREAT|O_RDWR|O_TRUNC, 0600, &dumbhash_attr);
tdb1_dumb_hash);
ok1(tdb); ok1(tdb);
ok1(log_count == 0); ok1(log_count == 0);
d.dptr = (void *)"Hello"; d.dptr = (void *)"Hello";
...@@ -172,15 +191,15 @@ int main(int argc, char *argv[]) ...@@ -172,15 +191,15 @@ int main(int argc, char *argv[])
/* It should not open if we don't specify. */ /* It should not open if we don't specify. */
log_count = 0; log_count = 0;
tdb = tdb1_open_ex("run-incompatible.tdb", 0, 0, O_RDWR, 0, tdb = tdb1_open("run-incompatible.tdb", 0, 0, O_RDWR, 0,
&log_ctx, NULL); &log_attr);
ok1(!tdb); ok1(!tdb);
ok1(log_count == 1); ok1(log_count == 1);
/* Should reopen with correct hash. */ /* Should reopen with correct hash. */
log_count = 0; log_count = 0;
tdb = tdb1_open_ex("run-incompatible.tdb", 0, 0, O_RDWR, 0, tdb = tdb1_open("run-incompatible.tdb", 0, 0, O_RDWR, 0,
&log_ctx, tdb1_dumb_hash); &dumbhash_attr);
ok1(tdb); ok1(tdb);
ok1(log_count == 0); ok1(log_count == 0);
d = tdb1_fetch(tdb, d); d = tdb1_fetch(tdb, d);
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h> #include <stdbool.h>
#include <err.h> #include <err.h>
#include "tdb1-logging.h" #include "logging.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
...@@ -14,9 +14,9 @@ int main(int argc, char *argv[]) ...@@ -14,9 +14,9 @@ int main(int argc, char *argv[])
key.dsize = strlen("hi"); key.dsize = strlen("hi");
key.dptr = (void *)"hi"; key.dptr = (void *)"hi";
tdb = tdb1_open_ex("run-nested-transactions.tdb", tdb = tdb1_open("run-nested-transactions.tdb",
1024, TDB_DEFAULT, 1024, TDB_DEFAULT,
O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL); O_CREAT|O_TRUNC|O_RDWR, 0600, &tap_log_attr);
ok1(tdb); ok1(tdb);
/* No nesting by default. */ /* No nesting by default. */
...@@ -42,8 +42,8 @@ int main(int argc, char *argv[]) ...@@ -42,8 +42,8 @@ int main(int argc, char *argv[])
free(data.dptr); free(data.dptr);
tdb1_close(tdb); tdb1_close(tdb);
tdb = tdb1_open_ex("run-nested-transactions.tdb", tdb = tdb1_open("run-nested-transactions.tdb",
1024, TDB_ALLOW_NESTING, O_RDWR, 0, &taplogctx, NULL); 1024, TDB_ALLOW_NESTING, O_RDWR, 0, &tap_log_attr);
ok1(tdb); ok1(tdb);
ok1(tdb1_transaction_start(tdb) == 0); ok1(tdb1_transaction_start(tdb) == 0);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <err.h> #include <err.h>
#include "tdb1-external-agent.h" #include "tdb1-external-agent.h"
#include "tdb1-logging.h" #include "logging.h"
static struct agent *agent; static struct agent *agent;
...@@ -56,8 +56,8 @@ int main(int argc, char *argv[]) ...@@ -56,8 +56,8 @@ int main(int argc, char *argv[])
if (!agent) if (!agent)
err(1, "preparing agent"); err(1, "preparing agent");
tdb = tdb1_open_ex("run-nested-traverse.tdb", 1024, TDB_DEFAULT, tdb = tdb1_open("run-nested-traverse.tdb", 1024, TDB_DEFAULT,
O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL); O_CREAT|O_TRUNC|O_RDWR, 0600, &tap_log_attr);
ok1(tdb); ok1(tdb);
ok1(external_agent_operation1(agent, OPEN, tdb->name) == SUCCESS); ok1(external_agent_operation1(agent, OPEN, tdb->name) == SUCCESS);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include <ccan/tap/tap.h> #include <ccan/tap/tap.h>
#include <stdlib.h> #include <stdlib.h>
#include <err.h> #include <err.h>
#include "tdb1-logging.h" #include "logging.h"
#undef fcntl #undef fcntl
...@@ -70,9 +70,9 @@ int main(int argc, char *argv[]) ...@@ -70,9 +70,9 @@ int main(int argc, char *argv[])
int errors = 0; int errors = 0;
plan_tests(41); plan_tests(41);
tdb = tdb1_open_ex("run-no-lock-during-traverse.tdb", tdb = tdb1_open("run-no-lock-during-traverse.tdb",
1024, TDB_DEFAULT, O_CREAT|O_TRUNC|O_RDWR, 1024, TDB_DEFAULT, O_CREAT|O_TRUNC|O_RDWR,
0600, &taplogctx, NULL); 0600, &tap_log_attr);
ok1(tdb); ok1(tdb);
ok1(prepare_entries(tdb)); ok1(prepare_entries(tdb));
......
...@@ -2,36 +2,41 @@ ...@@ -2,36 +2,41 @@
#include <ccan/tap/tap.h> #include <ccan/tap/tap.h>
#include <stdlib.h> #include <stdlib.h>
#include <err.h> #include <err.h>
#include "tdb1-logging.h" #include "logging.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
struct tdb_context *tdb; struct tdb_context *tdb;
union tdb_attribute incompat_hash_attr;
incompat_hash_attr.base.attr = TDB_ATTRIBUTE_HASH;
incompat_hash_attr.base.next = &tap_log_attr;
incompat_hash_attr.hash.fn = tdb1_incompatible_hash;
plan_tests(8); plan_tests(8);
/* Old format (with zeroes in the hash magic fields) should /* Old format (with zeroes in the hash magic fields) should
* open with any hash (since we don't know what hash they used). */ * open with any hash (since we don't know what hash they used). */
tdb = tdb1_open_ex("test/old-nohash-le.tdb1", 0, 0, O_RDWR, 0, tdb = tdb1_open("test/old-nohash-le.tdb1", 0, 0, O_RDWR, 0,
&taplogctx, NULL); &tap_log_attr);
ok1(tdb); ok1(tdb);
ok1(tdb1_check(tdb, NULL, NULL) == 0); ok1(tdb1_check(tdb, NULL, NULL) == 0);
tdb1_close(tdb); tdb1_close(tdb);
tdb = tdb1_open_ex("test/old-nohash-be.tdb1", 0, 0, O_RDWR, 0, tdb = tdb1_open("test/old-nohash-be.tdb1", 0, 0, O_RDWR, 0,
&taplogctx, NULL); &tap_log_attr);
ok1(tdb); ok1(tdb);
ok1(tdb1_check(tdb, NULL, NULL) == 0); ok1(tdb1_check(tdb, NULL, NULL) == 0);
tdb1_close(tdb); tdb1_close(tdb);
tdb = tdb1_open_ex("test/old-nohash-le.tdb1", 0, 0, O_RDWR, 0, tdb = tdb1_open("test/old-nohash-le.tdb1", 0, 0, O_RDWR, 0,
&taplogctx, tdb1_incompatible_hash); &incompat_hash_attr);
ok1(tdb); ok1(tdb);
ok1(tdb1_check(tdb, NULL, NULL) == 0); ok1(tdb1_check(tdb, NULL, NULL) == 0);
tdb1_close(tdb); tdb1_close(tdb);
tdb = tdb1_open_ex("test/old-nohash-be.tdb1", 0, 0, O_RDWR, 0, tdb = tdb1_open("test/old-nohash-be.tdb1", 0, 0, O_RDWR, 0,
&taplogctx, tdb1_incompatible_hash); &incompat_hash_attr);
ok1(tdb); ok1(tdb);
ok1(tdb1_check(tdb, NULL, NULL) == 0); ok1(tdb1_check(tdb, NULL, NULL) == 0);
tdb1_close(tdb); tdb1_close(tdb);
......
...@@ -18,7 +18,7 @@ static int ftruncate_check(int fd, off_t length); ...@@ -18,7 +18,7 @@ static int ftruncate_check(int fd, off_t length);
#include <stdarg.h> #include <stdarg.h>
#include <err.h> #include <err.h>
#include "tdb1-external-agent.h" #include "tdb1-external-agent.h"
#include "tdb1-logging.h" #include "logging.h"
static struct agent *agent; static struct agent *agent;
static bool opened; static bool opened;
...@@ -145,9 +145,9 @@ int main(int argc, char *argv[]) ...@@ -145,9 +145,9 @@ int main(int argc, char *argv[])
"DEFAULT", "DEFAULT",
(flags[i] & TDB_NOMMAP) ? "no mmap" : "mmap"); (flags[i] & TDB_NOMMAP) ? "no mmap" : "mmap");
unlink(TEST_DBNAME); unlink(TEST_DBNAME);
tdb = tdb1_open_ex(TEST_DBNAME, 1024, flags[i], tdb = tdb1_open(TEST_DBNAME, 1024, flags[i],
O_CREAT|O_TRUNC|O_RDWR, 0600, O_CREAT|O_TRUNC|O_RDWR, 0600,
&taplogctx, NULL); &tap_log_attr);
ok1(tdb); ok1(tdb);
opened = true; opened = true;
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include <ccan/tap/tap.h> #include <ccan/tap/tap.h>
#include <stdlib.h> #include <stdlib.h>
#include <err.h> #include <err.h>
#include "tdb1-logging.h" #include "logging.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
...@@ -12,9 +12,9 @@ int main(int argc, char *argv[]) ...@@ -12,9 +12,9 @@ int main(int argc, char *argv[])
TDB_DATA key, data; TDB_DATA key, data;
plan_tests(11); plan_tests(11);
tdb = tdb1_open_ex("run-readonly-check.tdb", 1024, tdb = tdb1_open("run-readonly-check.tdb", 1024,
TDB_DEFAULT, TDB_DEFAULT,
O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL); O_CREAT|O_TRUNC|O_RDWR, 0600, &tap_log_attr);
ok1(tdb); ok1(tdb);
key.dsize = strlen("hi"); key.dsize = strlen("hi");
...@@ -30,8 +30,8 @@ int main(int argc, char *argv[]) ...@@ -30,8 +30,8 @@ int main(int argc, char *argv[])
ok1(tdb1_check(tdb, NULL, NULL) == 0); ok1(tdb1_check(tdb, NULL, NULL) == 0);
ok1(tdb1_close(tdb) == 0); ok1(tdb1_close(tdb) == 0);
tdb = tdb1_open_ex("run-readonly-check.tdb", 1024, tdb = tdb1_open("run-readonly-check.tdb", 1024,
TDB_DEFAULT, O_RDONLY, 0, &taplogctx, NULL); TDB_DEFAULT, O_RDONLY, 0, &tap_log_attr);
ok1(tdb); ok1(tdb);
ok1(tdb1_store(tdb, key, data, TDB_MODIFY) == -1); ok1(tdb1_store(tdb, key, data, TDB_MODIFY) == -1);
......
...@@ -16,20 +16,25 @@ int main(int argc, char *argv[]) ...@@ -16,20 +16,25 @@ int main(int argc, char *argv[])
{ {
struct tdb_context *tdb; struct tdb_context *tdb;
unsigned int log_count; unsigned int log_count;
struct tdb1_logging_context log_ctx = { log_fn, &log_count }; union tdb_attribute log_attr;
log_attr.base.attr = TDB_ATTRIBUTE_LOG;
log_attr.base.next = NULL;
log_attr.log.fn = log_fn;
log_attr.log.data = &log_count;
plan_tests(4); plan_tests(4);
/* We should fail to open rwlock-using tdbs of either endian. */ /* We should fail to open rwlock-using tdbs of either endian. */
log_count = 0; log_count = 0;
tdb = tdb1_open_ex("test/rwlock-le.tdb1", 0, 0, O_RDWR, 0, tdb = tdb1_open("test/rwlock-le.tdb1", 0, 0, O_RDWR, 0,
&log_ctx, NULL); &log_attr);
ok1(!tdb); ok1(!tdb);
ok1(log_count == 1); ok1(log_count == 1);
log_count = 0; log_count = 0;
tdb = tdb1_open_ex("test/rwlock-be.tdb1", 0, 0, O_RDWR, 0, tdb = tdb1_open("test/rwlock-be.tdb1", 0, 0, O_RDWR, 0,
&log_ctx, NULL); &log_attr);
ok1(!tdb); ok1(!tdb);
ok1(log_count == 1); ok1(log_count == 1);
......
...@@ -17,7 +17,7 @@ int main(int argc, char *argv[]) ...@@ -17,7 +17,7 @@ int main(int argc, char *argv[])
plan_tests(sizeof(flags) / sizeof(flags[0]) * 14); plan_tests(sizeof(flags) / sizeof(flags[0]) * 14);
for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) { for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
tdb = tdb1_open("run-summary.tdb", 131, flags[i], tdb = tdb1_open("run-summary.tdb", 131, flags[i],
O_RDWR|O_CREAT|O_TRUNC, 0600); O_RDWR|O_CREAT|O_TRUNC, 0600, NULL);
ok1(tdb); ok1(tdb);
if (!tdb) if (!tdb)
continue; continue;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <err.h> #include <err.h>
#include "tdb1-external-agent.h" #include "tdb1-external-agent.h"
#include "tdb1-logging.h" #include "logging.h"
static struct agent *agent; static struct agent *agent;
...@@ -42,9 +42,9 @@ int main(int argc, char *argv[]) ...@@ -42,9 +42,9 @@ int main(int argc, char *argv[])
if (!agent) if (!agent)
err(1, "preparing agent"); err(1, "preparing agent");
tdb = tdb1_open_ex("run-traverse-in-transaction.tdb", tdb = tdb1_open("run-traverse-in-transaction.tdb",
1024, TDB_DEFAULT, O_CREAT|O_TRUNC|O_RDWR, 1024, TDB_DEFAULT, O_CREAT|O_TRUNC|O_RDWR,
0600, &taplogctx, NULL); 0600, &tap_log_attr);
ok1(tdb); ok1(tdb);
key.dsize = strlen("hi"); key.dsize = strlen("hi");
......
...@@ -30,14 +30,32 @@ int main(int argc, char *argv[]) ...@@ -30,14 +30,32 @@ int main(int argc, char *argv[])
struct tdb_context *tdb; struct tdb_context *tdb;
unsigned int log_count; unsigned int log_count;
TDB_DATA d; TDB_DATA d;
struct tdb1_logging_context log_ctx = { log_fn, &log_count }; union tdb_attribute log_attr, jhash_attr, ohash_attr,
incompat_hash_attr;
log_attr.base.attr = TDB_ATTRIBUTE_LOG;
log_attr.base.next = NULL;
log_attr.log.fn = log_fn;
log_attr.log.data = &log_count;
jhash_attr.base.attr = TDB_ATTRIBUTE_HASH;
jhash_attr.base.next = &log_attr;
jhash_attr.hash.fn = jenkins_hashfn;
ohash_attr.base.attr = TDB_ATTRIBUTE_HASH;
ohash_attr.base.next = &log_attr;
ohash_attr.hash.fn = old_hash;
incompat_hash_attr.base.attr = TDB_ATTRIBUTE_HASH;
incompat_hash_attr.base.next = &log_attr;
incompat_hash_attr.hash.fn = tdb1_incompatible_hash;
plan_tests(28); plan_tests(28);
/* Create with default hash. */ /* Create with default hash. */
log_count = 0; log_count = 0;
tdb = tdb1_open_ex("run-wronghash-fail.tdb", 0, 0, tdb = tdb1_open("run-wronghash-fail.tdb", 0, 0,
O_CREAT|O_RDWR|O_TRUNC, 0600, &log_ctx, NULL); O_CREAT|O_RDWR|O_TRUNC, 0600, &log_attr);
ok1(tdb); ok1(tdb);
ok1(log_count == 0); ok1(log_count == 0);
d.dptr = (void *)"Hello"; d.dptr = (void *)"Hello";
...@@ -46,51 +64,51 @@ int main(int argc, char *argv[]) ...@@ -46,51 +64,51 @@ int main(int argc, char *argv[])
tdb1_close(tdb); tdb1_close(tdb);
/* Fail to open with different hash. */ /* Fail to open with different hash. */
tdb = tdb1_open_ex("run-wronghash-fail.tdb", 0, 0, O_RDWR, 0, tdb = tdb1_open("run-wronghash-fail.tdb", 0, 0, O_RDWR, 0,
&log_ctx, jenkins_hashfn); &jhash_attr);
ok1(!tdb); ok1(!tdb);
ok1(log_count == 1); ok1(log_count == 1);
/* Create with different hash. */ /* Create with different hash. */
log_count = 0; log_count = 0;
tdb = tdb1_open_ex("run-wronghash-fail.tdb", 0, 0, tdb = tdb1_open("run-wronghash-fail.tdb", 0, 0,
O_CREAT|O_RDWR|O_TRUNC, O_CREAT|O_RDWR|O_TRUNC,
0600, &log_ctx, jenkins_hashfn); 0600, &jhash_attr);
ok1(tdb); ok1(tdb);
ok1(log_count == 0); ok1(log_count == 0);
tdb1_close(tdb); tdb1_close(tdb);
/* Endian should be no problem. */ /* Endian should be no problem. */
log_count = 0; log_count = 0;
tdb = tdb1_open_ex("test/jenkins-le-hash.tdb1", 0, 0, O_RDWR, 0, tdb = tdb1_open("test/jenkins-le-hash.tdb1", 0, 0, O_RDWR, 0,
&log_ctx, old_hash); &ohash_attr);
ok1(!tdb); ok1(!tdb);
ok1(log_count == 1); ok1(log_count == 1);
log_count = 0; log_count = 0;
tdb = tdb1_open_ex("test/jenkins-be-hash.tdb1", 0, 0, O_RDWR, 0, tdb = tdb1_open("test/jenkins-be-hash.tdb1", 0, 0, O_RDWR, 0,
&log_ctx, old_hash); &ohash_attr);
ok1(!tdb); ok1(!tdb);
ok1(log_count == 1); ok1(log_count == 1);
log_count = 0; log_count = 0;
/* Fail to open with old default hash. */ /* Fail to open with old default hash. */
tdb = tdb1_open_ex("run-wronghash-fail.tdb", 0, 0, O_RDWR, 0, tdb = tdb1_open("run-wronghash-fail.tdb", 0, 0, O_RDWR, 0,
&log_ctx, old_hash); &ohash_attr);
ok1(!tdb); ok1(!tdb);
ok1(log_count == 1); ok1(log_count == 1);
log_count = 0; log_count = 0;
tdb = tdb1_open_ex("test/jenkins-le-hash.tdb1", 0, 0, O_RDONLY, tdb = tdb1_open("test/jenkins-le-hash.tdb1", 0, 0, O_RDONLY,
0, &log_ctx, tdb1_incompatible_hash); 0, &incompat_hash_attr);
ok1(tdb); ok1(tdb);
ok1(log_count == 0); ok1(log_count == 0);
ok1(tdb1_check(tdb, NULL, NULL) == 0); ok1(tdb1_check(tdb, NULL, NULL) == 0);
tdb1_close(tdb); tdb1_close(tdb);
log_count = 0; log_count = 0;
tdb = tdb1_open_ex("test/jenkins-be-hash.tdb1", 0, 0, O_RDONLY, tdb = tdb1_open("test/jenkins-be-hash.tdb1", 0, 0, O_RDONLY,
0, &log_ctx, tdb1_incompatible_hash); 0, &incompat_hash_attr);
ok1(tdb); ok1(tdb);
ok1(log_count == 0); ok1(log_count == 0);
ok1(tdb1_check(tdb, NULL, NULL) == 0); ok1(tdb1_check(tdb, NULL, NULL) == 0);
...@@ -98,24 +116,24 @@ int main(int argc, char *argv[]) ...@@ -98,24 +116,24 @@ int main(int argc, char *argv[])
/* It should open with jenkins hash if we don't specify. */ /* It should open with jenkins hash if we don't specify. */
log_count = 0; log_count = 0;
tdb = tdb1_open_ex("test/jenkins-le-hash.tdb1", 0, 0, O_RDWR, 0, tdb = tdb1_open("test/jenkins-le-hash.tdb1", 0, 0, O_RDWR, 0,
&log_ctx, NULL); &log_attr);
ok1(tdb); ok1(tdb);
ok1(log_count == 0); ok1(log_count == 0);
ok1(tdb1_check(tdb, NULL, NULL) == 0); ok1(tdb1_check(tdb, NULL, NULL) == 0);
tdb1_close(tdb); tdb1_close(tdb);
log_count = 0; log_count = 0;
tdb = tdb1_open_ex("test/jenkins-be-hash.tdb1", 0, 0, O_RDWR, 0, tdb = tdb1_open("test/jenkins-be-hash.tdb1", 0, 0, O_RDWR, 0,
&log_ctx, NULL); &log_attr);
ok1(tdb); ok1(tdb);
ok1(log_count == 0); ok1(log_count == 0);
ok1(tdb1_check(tdb, NULL, NULL) == 0); ok1(tdb1_check(tdb, NULL, NULL) == 0);
tdb1_close(tdb); tdb1_close(tdb);
log_count = 0; log_count = 0;
tdb = tdb1_open_ex("run-wronghash-fail.tdb", 0, 0, O_RDONLY, tdb = tdb1_open("run-wronghash-fail.tdb", 0, 0, O_RDONLY,
0, &log_ctx, NULL); 0, &log_attr);
ok1(tdb); ok1(tdb);
ok1(log_count == 0); ok1(log_count == 0);
ok1(tdb1_check(tdb, NULL, NULL) == 0); ok1(tdb1_check(tdb, NULL, NULL) == 0);
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include <ccan/tap/tap.h> #include <ccan/tap/tap.h>
#include <stdlib.h> #include <stdlib.h>
#include <err.h> #include <err.h>
#include "tdb1-logging.h" #include "logging.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
...@@ -10,8 +10,8 @@ int main(int argc, char *argv[]) ...@@ -10,8 +10,8 @@ int main(int argc, char *argv[])
TDB_DATA key, data; TDB_DATA key, data;
plan_tests(4); plan_tests(4);
tdb = tdb1_open_ex(NULL, 1024, TDB_INTERNAL, O_CREAT|O_TRUNC|O_RDWR, tdb = tdb1_open(NULL, 1024, TDB_INTERNAL, O_CREAT|O_TRUNC|O_RDWR,
0600, &taplogctx, NULL); 0600, &tap_log_attr);
ok1(tdb); ok1(tdb);
/* Tickle bug on appending zero length buffer to zero length buffer. */ /* Tickle bug on appending zero length buffer to zero length buffer. */
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include <ccan/tap/tap.h> #include <ccan/tap/tap.h>
#include <stdlib.h> #include <stdlib.h>
#include <err.h> #include <err.h>
#include "tdb1-logging.h" #include "logging.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
...@@ -10,8 +10,8 @@ int main(int argc, char *argv[]) ...@@ -10,8 +10,8 @@ int main(int argc, char *argv[])
TDB_DATA key, data; TDB_DATA key, data;
plan_tests(10); plan_tests(10);
tdb = tdb1_open_ex("run.tdb", 1024, TDB_DEFAULT, tdb = tdb1_open("run.tdb", 1024, TDB_DEFAULT,
O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL); O_CREAT|O_TRUNC|O_RDWR, 0600, &tap_log_attr);
ok1(tdb); ok1(tdb);
key.dsize = strlen("hi"); key.dsize = strlen("hi");
......
#include "tdb1-external-agent.h" #include "tdb1-external-agent.h"
#include "tdb1-lock-tracking.h" #include "tdb1-lock-tracking.h"
#include "tdb1-logging.h" #include "logging.h"
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <unistd.h> #include <unistd.h>
...@@ -39,8 +39,8 @@ static enum agent_return do_operation(enum operation op, const char *name) ...@@ -39,8 +39,8 @@ static enum agent_return do_operation(enum operation op, const char *name)
diag("Already have tdb %s open", tdb->name); diag("Already have tdb %s open", tdb->name);
return OTHER_FAILURE; return OTHER_FAILURE;
} }
tdb = tdb1_open_ex(name, 0, TDB_DEFAULT, O_RDWR, 0, tdb = tdb1_open(name, 0, TDB_DEFAULT, O_RDWR, 0,
&taplogctx, NULL); &tap_log_attr);
if (!tdb) { if (!tdb) {
if (!locking_would_block1) if (!locking_would_block1)
diag("Opening tdb gave %s", strerror(errno)); diag("Opening tdb gave %s", strerror(errno));
......
#include "tdb1-logging.h"
#include <ccan/tap/tap.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
/* Turn log messages into tap diag messages. */
static void taplog(struct tdb_context *tdb,
enum tdb_log_level level,
enum TDB_ERROR ecode,
const char *message,
void *data)
{
if (suppress_logging)
return;
/* Strip trailing \n: diag adds it. */
if (message[0] && message[strlen(message)-1] == '\n')
diag("%s%.*s", log_prefix, (unsigned)strlen(message)-1, message);
else
diag("%s%s", log_prefix, message);
}
struct tdb1_logging_context taplogctx = { taplog, NULL };
#ifndef TDB_TEST_LOGGING_H
#define TDB_TEST_LOGGING_H
#include <ccan/tdb2/tdb1.h>
#include <stdbool.h>
extern bool suppress_logging;
extern const char *log_prefix;
extern struct tdb1_logging_context taplogctx;
#endif /* TDB_TEST_LOGGING_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment