summaryrefslogtreecommitdiff
path: root/lib/tdb_compat
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tdb_compat')
-rw-r--r--lib/tdb_compat/tdb_compat.c222
-rw-r--r--lib/tdb_compat/tdb_compat.h85
-rw-r--r--lib/tdb_compat/wscript11
3 files changed, 2 insertions, 316 deletions
diff --git a/lib/tdb_compat/tdb_compat.c b/lib/tdb_compat/tdb_compat.c
index 7fd3caf6b5..32a142de00 100644
--- a/lib/tdb_compat/tdb_compat.c
+++ b/lib/tdb_compat/tdb_compat.c
@@ -1,224 +1,2 @@
#include <tdb_compat.h>
-/* Note: for the moment, we only need this file for TDB2, so we can
- * assume waf. */
-#if BUILD_TDB2
-TDB_DATA tdb_null = { NULL, 0 };
-
-/* Proxy which sets waitflag to false so we never block. */
-static int lock_nonblock(int fd, int rw, off_t off, off_t len, bool waitflag,
- void *_orig)
-{
- struct tdb_attribute_flock *orig = _orig;
-
- return orig->lock(fd, rw, off, len, false, orig->data);
-}
-
-enum TDB_ERROR tdb_transaction_start_nonblock(struct tdb_context *tdb)
-{
- union tdb_attribute locking, orig;
- enum TDB_ERROR ecode;
-
- orig.base.attr = TDB_ATTRIBUTE_FLOCK;
- ecode = tdb_get_attribute(tdb, &orig);
- if (ecode != TDB_SUCCESS)
- return ecode;
-
- /* Replace locking function with our own. */
- locking = orig;
- locking.flock.data = &orig;
- locking.flock.lock = lock_nonblock;
-
- ecode = tdb_set_attribute(tdb, &locking);
- if (ecode != TDB_SUCCESS)
- return ecode;
-
- ecode = tdb_transaction_start(tdb);
- tdb_unset_attribute(tdb, TDB_ATTRIBUTE_FLOCK);
- return ecode;
-}
-
-enum TDB_ERROR tdb_chainlock_nonblock(struct tdb_context *tdb, TDB_DATA key)
-{
- union tdb_attribute locking, orig;
- enum TDB_ERROR ecode;
-
- orig.base.attr = TDB_ATTRIBUTE_FLOCK;
- ecode = tdb_get_attribute(tdb, &orig);
- if (ecode != TDB_SUCCESS)
- return ecode;
-
- /* Replace locking function with our own. */
- locking = orig;
- locking.flock.data = &orig;
- locking.flock.lock = lock_nonblock;
-
- ecode = tdb_set_attribute(tdb, &locking);
- if (ecode != TDB_SUCCESS)
- return ecode;
-
- ecode = tdb_chainlock(tdb, key);
- tdb_unset_attribute(tdb, TDB_ATTRIBUTE_FLOCK);
- return ecode;
-}
-
-/* For TDB1 tdbs, read traverse vs normal matters: write traverse
- locks the entire thing! */
-int64_t tdb_traverse_read_(struct tdb_context *tdb,
- int (*fn)(struct tdb_context *,
- TDB_DATA, TDB_DATA,
- void *),
- void *p)
-{
- int64_t ret;
-
- if (tdb_get_flags(tdb) & TDB_RDONLY) {
- return tdb_traverse(tdb, fn, p);
- }
-
- tdb_add_flag(tdb, TDB_RDONLY);
- ret = tdb_traverse(tdb, fn, p);
- tdb_remove_flag(tdb, TDB_RDONLY);
- return ret;
-}
-
-/*
- * This handles TDB_CLEAR_IF_FIRST.
- */
-static enum TDB_ERROR clear_if_first(int fd, void *unused)
-{
- /* We hold a lock offset 4 always, so we can tell if anyone else is. */
- struct flock fl;
-
- fl.l_type = F_WRLCK;
- fl.l_whence = SEEK_SET;
- fl.l_start = 4; /* ACTIVE_LOCK */
- fl.l_len = 1;
-
- if (fcntl(fd, F_SETLK, &fl) == 0) {
- /* We must be first ones to open it w/ TDB_CLEAR_IF_FIRST! */
- if (ftruncate(fd, 0) != 0) {
- return TDB_ERR_IO;
- }
- }
- fl.l_type = F_RDLCK;
- if (fcntl(fd, F_SETLKW, &fl) != 0) {
- return TDB_ERR_IO;
- }
- return TDB_SUCCESS;
-}
-
-struct tdb_context *
-tdb_open_compat_(const char *name, int hash_size,
- int tdb_flags, int open_flags, mode_t mode,
- void (*log_fn)(struct tdb_context *,
- enum tdb_log_level,
- enum TDB_ERROR,
- const char *message,
- void *data),
- void *log_data)
-{
- union tdb_attribute cif, log, hash, max_dead, hsize, *attr = NULL;
-
- if (!getenv("TDB_COMPAT_USE_TDB2")) {
- tdb_flags |= TDB_VERSION1;
- }
-
- if (log_fn) {
- log.log.base.attr = TDB_ATTRIBUTE_LOG;
- log.log.base.next = NULL;
- log.log.fn = log_fn;
- log.log.data = log_data;
- attr = &log;
- }
-
- if (tdb_flags & TDB_CLEAR_IF_FIRST) {
- cif.openhook.base.attr = TDB_ATTRIBUTE_OPENHOOK;
- cif.openhook.base.next = attr;
- cif.openhook.fn = clear_if_first;
- attr = &cif;
- tdb_flags &= ~TDB_CLEAR_IF_FIRST;
- }
-
- if (tdb_flags & TDB_INCOMPATIBLE_HASH) {
- if (tdb_flags & TDB_VERSION1) {
- hash.hash.base.attr = TDB_ATTRIBUTE_HASH;
- hash.hash.base.next = attr;
- hash.hash.fn = tdb1_incompatible_hash;
- attr = &hash;
- }
- tdb_flags &= ~TDB_INCOMPATIBLE_HASH;
- }
-
- if (tdb_flags & TDB_VOLATILE) {
- if (tdb_flags & TDB_VERSION1) {
- max_dead.base.attr = TDB_ATTRIBUTE_TDB1_MAX_DEAD;
- max_dead.base.next = attr;
- max_dead.tdb1_max_dead.max_dead = 5;
- attr = &max_dead;
- }
- tdb_flags &= ~TDB_VOLATILE;
- }
-
- if (hash_size && (tdb_flags & TDB_VERSION1) && (open_flags & O_CREAT)) {
- hsize.base.attr = TDB_ATTRIBUTE_TDB1_HASHSIZE;
- hsize.base.next = attr;
- hsize.tdb1_hashsize.hsize = hash_size;
- attr = &hsize;
- }
-
- /* Testsuite uses this to speed things up. */
- if (getenv("TDB_NO_FSYNC")) {
- tdb_flags |= TDB_NOSYNC;
- }
-
- return tdb_open(name, tdb_flags|TDB_ALLOW_NESTING, open_flags, mode,
- attr);
-}
-
-/* We only need these for the CLEAR_IF_FIRST lock. */
-static int reacquire_cif_lock(struct tdb_context *tdb, bool *fail)
-{
- struct flock fl;
- union tdb_attribute cif;
-
- cif.openhook.base.attr = TDB_ATTRIBUTE_OPENHOOK;
- cif.openhook.base.next = NULL;
-
- if (tdb_get_attribute(tdb, &cif) != TDB_SUCCESS
- || cif.openhook.fn != clear_if_first) {
- return 0;
- }
-
- /* We hold a lock offset 4 always, so we can tell if anyone else is. */
- fl.l_type = F_RDLCK;
- fl.l_whence = SEEK_SET;
- fl.l_start = 4; /* ACTIVE_LOCK */
- fl.l_len = 1;
- if (fcntl(tdb_fd(tdb), F_SETLKW, &fl) != 0) {
- *fail = true;
- return -1;
- }
- return 0;
-}
-
-int tdb_reopen(struct tdb_context *tdb)
-{
- bool unused;
- return reacquire_cif_lock(tdb, &unused);
-}
-
-int tdb_reopen_all(int parent_longlived)
-{
- bool fail = false;
-
- if (parent_longlived) {
- return 0;
- }
-
- tdb_foreach(reacquire_cif_lock, &fail);
- if (fail)
- return -1;
- return 0;
-}
-#endif
diff --git a/lib/tdb_compat/tdb_compat.h b/lib/tdb_compat/tdb_compat.h
index e0a2bf8e5e..98bccf4137 100644
--- a/lib/tdb_compat/tdb_compat.h
+++ b/lib/tdb_compat/tdb_compat.h
@@ -27,90 +27,6 @@
#include "replace.h"
#include <ccan/typesafe_cb/typesafe_cb.h>
-#if BUILD_TDB2
-#include <tdb2.h>
-#include <fcntl.h>
-#include <unistd.h>
-
-extern TDB_DATA tdb_null;
-
-/* Old-style tdb_fetch. */
-static inline TDB_DATA tdb_fetch_compat(struct tdb_context *tdb, TDB_DATA k)
-{
- TDB_DATA dbuf;
- if (tdb_fetch(tdb, k, &dbuf) != TDB_SUCCESS) {
- return tdb_null;
- }
- return dbuf;
-}
-
-static inline TDB_DATA tdb_firstkey_compat(struct tdb_context *tdb)
-{
- TDB_DATA k;
- if (tdb_firstkey(tdb, &k) != TDB_SUCCESS) {
- return tdb_null;
- }
- return k;
-}
-
-/* Note: this frees the old key.dptr. */
-static inline TDB_DATA tdb_nextkey_compat(struct tdb_context *tdb, TDB_DATA k)
-{
- if (tdb_nextkey(tdb, &k) != TDB_SUCCESS) {
- return tdb_null;
- }
- return k;
-}
-
-#define tdb_traverse_read(tdb, fn, p) \
- tdb_traverse_read_(tdb, typesafe_cb_preargs(int, void *, (fn), (p), \
- struct tdb_context *, \
- TDB_DATA, TDB_DATA), (p))
-int64_t tdb_traverse_read_(struct tdb_context *tdb,
- int (*fn)(struct tdb_context *,
- TDB_DATA, TDB_DATA, void *), void *p);
-
-/* Old-style tdb_errorstr */
-#define tdb_errorstr_compat(tdb) tdb_errorstr(tdb_error(tdb))
-
-/* This typedef doesn't exist in TDB2. */
-typedef struct tdb_context TDB_CONTEXT;
-
-/* We only need these for the CLEAR_IF_FIRST lock. */
-int tdb_reopen(struct tdb_context *tdb);
-int tdb_reopen_all(int parent_longlived);
-
-/* These no longer exist in tdb2. */
-#define TDB_CLEAR_IF_FIRST 1048576
-#define TDB_INCOMPATIBLE_HASH 2097152
-#define TDB_VOLATILE 4194304
-
-/* tdb2 does nonblocking functions via attibutes. */
-enum TDB_ERROR tdb_transaction_start_nonblock(struct tdb_context *tdb);
-enum TDB_ERROR tdb_chainlock_nonblock(struct tdb_context *tdb, TDB_DATA key);
-
-
-/* Convenient (typesafe) wrapper for tdb open with logging */
-#define tdb_open_compat(name, hsize, tdb_fl, open_fl, mode, log_fn, log_data) \
- tdb_open_compat_((name), (hsize), (tdb_fl), (open_fl), (mode), \
- typesafe_cb_preargs(void, void *, \
- (log_fn), (log_data), \
- struct tdb_context *, \
- enum tdb_log_level, \
- enum TDB_ERROR, \
- const char *), \
- (log_data))
-
-struct tdb_context *
-tdb_open_compat_(const char *name, int hash_size,
- int tdb_flags, int open_flags, mode_t mode,
- void (*log_fn)(struct tdb_context *,
- enum tdb_log_level,
- enum TDB_ERROR ecode,
- const char *message,
- void *data),
- void *log_data);
-#else
#include <tdb.h>
/* FIXME: Inlining this is a bit lazy, but eases S3 build. */
@@ -140,6 +56,5 @@ static inline TDB_DATA tdb_nextkey_compat(struct tdb_context *tdb, TDB_DATA k)
}
#define tdb_errorstr_compat(tdb) tdb_errorstr(tdb)
#define tdb_fetch_compat tdb_fetch
-#endif
#endif /* TDB_COMPAT_H */
diff --git a/lib/tdb_compat/wscript b/lib/tdb_compat/wscript
index 9e36ced2bc..5f33f6d70b 100644
--- a/lib/tdb_compat/wscript
+++ b/lib/tdb_compat/wscript
@@ -3,22 +3,15 @@
import Options
def set_options(opt):
- opt.RECURSE('lib/tdb2')
opt.RECURSE('lib/tdb')
def configure(conf):
- if getattr(Options.options, 'BUILD_TDB2', False):
- conf.RECURSE('lib/tdb2')
- else:
- conf.RECURSE('lib/tdb')
+ conf.RECURSE('lib/tdb')
conf.RECURSE('lib/ccan')
def build(bld):
bld.RECURSE('lib/ccan')
- if bld.env.BUILD_TDB2:
- bld.RECURSE('lib/tdb2')
- else:
- bld.RECURSE('lib/tdb')
+ bld.RECURSE('lib/tdb')
bld.SAMBA_LIBRARY('tdb_compat',
source='tdb_compat.c',
deps='replace tdb ccan',