9 years agotypesafe_cb: fix example macro ordering in typesafe_cb_preargs documentation.
Rusty Russell [Sat, 24 Sep 2011 04:31:19 +0000 (14:01 +0930)]
typesafe_cb: fix example macro ordering in typesafe_cb_preargs documentation.

9 years agojmap: use ccan/tcon and always be typesafe.
Rusty Russell [Fri, 23 Sep 2011 02:30:49 +0000 (12:00 +0930)]
jmap: use ccan/tcon and always be typesafe.

This handles both pointer and integer types using ccan/tcon.

9 years agojbitset: rename to jset, use ccan/tcon
Rusty Russell [Fri, 23 Sep 2011 02:29:49 +0000 (11:59 +0930)]
jbitset: rename to jset, use ccan/tcon

It's now a completely generic set implementation, and uses ccan/tcon
to always be typesafe.  It handles both integer and pointer types.

9 years agotlist: use ccan/tcon
Rusty Russell [Fri, 23 Sep 2011 02:28:52 +0000 (11:58 +0930)]
tlist: use ccan/tcon

No real change for users.

9 years agotcon: routines for creating typesafe generic containers
Rusty Russell [Thu, 22 Sep 2011 06:30:30 +0000 (16:00 +0930)]
tcon: routines for creating typesafe generic containers

9 years agoccanlint: fix output for async commands.
Rusty Russell [Thu, 22 Sep 2011 04:30:21 +0000 (14:00 +0930)]
ccanlint: fix output for async commands.

Previously, it was always "", since we left the nul terminator at the

9 years agotdb2: allow readonly changes even while holding locks.
Rusty Russell [Tue, 20 Sep 2011 02:32:43 +0000 (12:02 +0930)]
tdb2: allow readonly changes even while holding locks.

This happens in SAMBA with the TDB_VERSION1, presumably due to a
read-only traverse nested inside a normal traverse (since it doesn't
occur without TDB_VERSION1).

Signed-off-by: Rusty Russell <>
9 years agotdb2: add error conversion functions.
Rusty Russell [Mon, 12 Sep 2011 04:51:40 +0000 (14:21 +0930)]
tdb2: add error conversion functions.

This clarifies the code a little, but also provides a more explicit
mechanism which can be used to debug error handling (by introducing
tdb_err_t and making it a pointer type).

9 years agoccanlint: run tests in parallel
Rusty Russell [Mon, 12 Sep 2011 04:50:40 +0000 (14:20 +0930)]
ccanlint: run tests in parallel

Measuring ccanlint -d ccan/tdb2 on my dual core hyperthread laptop gives:
Before: 5:30
After: 3:31

9 years agotdb2: make tests work in parallel.
Rusty Russell [Mon, 12 Sep 2011 04:50:40 +0000 (14:20 +0930)]
tdb2: make tests work in parallel.

Lazy cut & paste of tdb names causes failure when we run in parallel.

9 years agoccanlint: compile tests with coverage in parallel
Rusty Russell [Mon, 12 Sep 2011 04:50:39 +0000 (14:20 +0930)]
ccanlint: compile tests with coverage in parallel

Measuring ccanlint -d ccan/tdb2 on my dual core hyperthread laptop gives:
Before: 5:59
After: 5:30

9 years agoccanlint: compile tests in parallel
Rusty Russell [Mon, 12 Sep 2011 04:50:39 +0000 (14:20 +0930)]
ccanlint: compile tests in parallel

Measuring ccanlint -d ccan/tdb2 on my dual core hyperthread laptop gives:
Before: 6:47
After: 5:59

9 years agoccanlint: infrastructure to run commands async.
Rusty Russell [Mon, 12 Sep 2011 04:50:26 +0000 (14:20 +0930)]
ccanlint: infrastructure to run commands async.

We use the lbalance module to figure out how many to run in parallel.

9 years agotools: fix realloc bug.
Rusty Russell [Mon, 12 Sep 2011 03:54:34 +0000 (13:24 +0930)]
tools: fix realloc bug.

Reallocing smaller can move the pointer; certainly valgrind detects
it.  Found while chasing intermittant errors on "make fastcheck".

9 years agottxml: zero terminate the buffer after checking it was allocated
Daniel Burke [Fri, 9 Sep 2011 12:29:32 +0000 (21:59 +0930)]
ttxml: zero terminate the buffer after checking it was allocated

9 years agottxml: covering my shame
Daniel Burke [Mon, 5 Sep 2011 09:36:46 +0000 (19:06 +0930)]
ttxml: covering my shame

9 years agottxml: modified it to use a smaller buffer during testing
Daniel Burke [Mon, 5 Sep 2011 09:24:03 +0000 (18:54 +0930)]
ttxml: modified it to use a smaller buffer during testing

9 years agottxml: ccanlint fixes finished
Daniel Burke [Mon, 5 Sep 2011 09:18:04 +0000 (18:48 +0930)]
ttxml: ccanlint fixes finished

Meets all of the requirements of ccanlint.
Code coverage of the tests covers everything except for a malloc() failure.
Added some xml files for the tests to work on.

9 years agottxml: added drop static keyword
Daniel Burke [Mon, 5 Sep 2011 07:46:50 +0000 (17:16 +0930)]
ttxml: added drop static keyword

9 years agottxml: Passes Valgrind now
Daniel Burke [Mon, 5 Sep 2011 07:38:46 +0000 (17:08 +0930)]
ttxml: Passes Valgrind now

Removed the last references of the old buffering method. Should be
stable now. Time to write some proper testing.

9 years agottxml: Rplaced ratchet buffer with regular buffer, 20x speed increase
Daniel Burke [Mon, 5 Sep 2011 01:10:52 +0000 (10:40 +0930)]
ttxml: Rplaced ratchet buffer with regular buffer, 20x speed increase

9 years agotdb2: fix error handling for tdb1_transaction_commit.
Rusty Russell [Fri, 2 Sep 2011 06:18:17 +0000 (15:48 +0930)]
tdb2: fix error handling for tdb1_transaction_commit.

tdb_repack() returns an enum TDB_ERROR, whereas
tdb1_transaction_commit is expected to return 0 or -1.

9 years agotdb2: don't return -1 (ie. TDB_ERR_CORRUPT) on transaction write fail.
Rusty Russell [Fri, 2 Sep 2011 06:13:20 +0000 (15:43 +0930)]
tdb2: don't return -1 (ie. TDB_ERR_CORRUPT) on transaction write fail.

A left-over -1 return; should be returning ecode (probably TDB_ERR_IO).

9 years agotdb2: fix prototypes which return enum TDB_ERROR.
Rusty Russell [Fri, 2 Sep 2011 06:06:47 +0000 (15:36 +0930)]
tdb2: fix prototypes which return enum TDB_ERROR.

Since enums and ints are compatible in C, the compiler didn't warn
that our prototypes for these functions disagreed with the

9 years agotdb2: set tdb_error() on tdb_transaction_prepare_commit.
Rusty Russell [Fri, 2 Sep 2011 06:03:59 +0000 (15:33 +0930)]
tdb2: set tdb_error() on tdb_transaction_prepare_commit.

9 years agotdb2: enhance tdb1 porting document.
Rusty Russell [Wed, 31 Aug 2011 06:09:17 +0000 (15:39 +0930)]
tdb2: enhance tdb1 porting document.

9 years agotdb2: delete old tdb1 tests.
Rusty Russell [Wed, 31 Aug 2011 06:09:17 +0000 (15:39 +0930)]
tdb2: delete old tdb1 tests.

These two tdb1-specific tests have been superceded by the TDB_VERSION1
flags used in the main tests.

9 years agotdb2: test: Speed up run-01-new_database.
Rusty Russell [Wed, 31 Aug 2011 06:09:17 +0000 (15:39 +0930)]
tdb2: test: Speed up run-01-new_database.

Don't run tdb_check with failtest on, since it is very slow.  Do the
tdb_check w/ failtest in a new test, but skip MMAP suppression which
doesn't add much and slows down valgrind a lot.

Before this change run-01-new_database took 40 seconds (under
valgrind), after it takes 8 seconds, and run-12-check takes 3

9 years agotdb2: speed up testing.
Rusty Russell [Wed, 31 Aug 2011 06:09:17 +0000 (15:39 +0930)]
tdb2: speed up testing.

The time to run tests under valgrind has become excessive; particularly
the failure tests which fork().   Thus we cut down testing:

1) api-94-repack: reduce from 234 seconds to 2 seconds by cutting
   iterations, despite adding TDB_VERSION1 tests.

2) api-missing-entries: reduce from 17 seconds to under 1 second by
   not checking db inside loop, but at end.

This reduces the total ccanlint time from 729 to 489 seconds.

9 years agotdb2: test: convert (non-invasive) run tests to api tests.
Rusty Russell [Wed, 31 Aug 2011 06:09:16 +0000 (15:39 +0930)]
tdb2: test: convert (non-invasive) run tests to api tests.

This reduces compilation time, since these are merely linked with the
pre-built module, rather than recompiling it into the test (which
allows for fancy things like failtest).

This reduces the test compile time down from about 62 seconds to 45
seconds.  Since ccanlint compiles tests three times (once normally,
once with coverage, and once with reduced config.h) this makes a
difference: we go from 780 seconds to 729 seconds.

9 years agotdb2: test: fix run-57-die-during-transaction.c to be more efficient.
Rusty Russell [Wed, 31 Aug 2011 06:09:16 +0000 (15:39 +0930)]
tdb2: test: fix run-57-die-during-transaction.c to be more efficient.

We track malloc and free, but we didn't catch the free() inside
external_agent, which means that our list of allocations keeps
growing.  Particularly under valgrind, which re-uses memory less than
the glibc allocator.

9 years agotdb2: don't continue if tdb1_find fails.
Rusty Russell [Wed, 31 Aug 2011 06:08:53 +0000 (15:38 +0930)]
tdb2: don't continue if tdb1_find fails.

The TDB1 code's tdb1_find() returns 0 on error; the callers should
not assume that the error means that the entry wasn't found, but use
last_error to determine it.

This was found by looking at how long the failure path testing for
test/run-10-simple-store.c was taking under valgrind, ie:

valgrind -q ./run-10-simple-store --show-slowest

This change dropped the time for that test from 53 seconds to 19

9 years agotdb2: test: try (almost) all tests with TDB_VERSION1 flag.
Rusty Russell [Wed, 31 Aug 2011 06:01:08 +0000 (15:31 +0930)]
tdb2: test: try (almost) all tests with TDB_VERSION1 flag.

There are some minor changes required, in particular:

1) Make sure lockcheck understands tdb1 allrecord lock upgrades.
2) Handle tdb1 sequence number jumps: various operations increment the
   sequence number twice, especually tdb_append.
3) Don't test fail on unlock, since it gets triggered with traversal on the
   tdb1 backend (we didn't actually ever test this case for tdb2).
4) Move clear_if_first to offset 4, to match tdb1.

9 years agotdb2: log allocation failures in tdb1 backend.
Rusty Russell [Wed, 31 Aug 2011 06:01:08 +0000 (15:31 +0930)]
tdb2: log allocation failures in tdb1 backend.

The TDB2 tests are stricter about this; they want every error logged.

9 years agotdb2: fix bogus error from tdb_unlockall() after fork in tdb1 backend.
Rusty Russell [Wed, 31 Aug 2011 06:01:08 +0000 (15:31 +0930)]
tdb2: fix bogus error from tdb_unlockall() after fork in tdb1 backend.

We're always allowed to unlock after a fork; by setting the count to 0
before calling the generic unlock function we don't trigger the pid

9 years agotdb2: check lock owner in tdb1 backend.
Rusty Russell [Wed, 31 Aug 2011 06:01:08 +0000 (15:31 +0930)]
tdb2: check lock owner in tdb1 backend.

This reports errors if we fork() while holding a lock, or misuse a tdb
which we have dual-opened.

9 years agotdb2: return TDB_ERR_RDONLY from transactions on R/O databases, log nesting
Rusty Russell [Wed, 31 Aug 2011 06:01:08 +0000 (15:31 +0930)]
tdb2: return TDB_ERR_RDONLY from transactions on R/O databases, log nesting

Rather than rturning TDB_ERR_EINVAL, return TDB_ERR_RDONLY, and log
when we fail due to nesting.

9 years agotdb2: add stats to tdb1 backend.
Rusty Russell [Wed, 31 Aug 2011 06:01:08 +0000 (15:31 +0930)]
tdb2: add stats to tdb1 backend.

It's actually quite a good fit; we use compare_wrong_bucket for dead
records, which is kind of correct (they should be in the free list).

9 years agotdb2: increment seqnum on tdb_wipe_all in tdb1 backend.
Rusty Russell [Wed, 31 Aug 2011 06:01:07 +0000 (15:31 +0930)]
tdb2: increment seqnum on tdb_wipe_all in tdb1 backend.

9 years agotdb2: log an error when calling tdb_store() on read-only TDB in tdb1 backend.
Rusty Russell [Wed, 31 Aug 2011 06:01:07 +0000 (15:31 +0930)]
tdb2: log an error when calling tdb_store() on read-only TDB in tdb1 backend.

9 years agotdb2: catch errors in tdb1_needs_recovery()
Rusty Russell [Wed, 31 Aug 2011 06:01:07 +0000 (15:31 +0930)]
tdb2: catch errors in tdb1_needs_recovery()

The tdb1 backend simply returns "true" if there's an error determining
if a tdb needs recovery.  But this leads failtest down a rabbit hole;
it's better to return the error at this case (and makes for better for
diagnostics, since they will come from the first fault, not later in

9 years agotdb2: add tdb_attribute_tdb1_max_dead
Rusty Russell [Wed, 31 Aug 2011 06:01:07 +0000 (15:31 +0930)]
tdb2: add tdb_attribute_tdb1_max_dead

This allows us to simulate the old "volatile" flag for tdb1.  It's not
necessary for tdb2.

As this is the last function in tdb1.h, we remove that file.

9 years agotdb2: expose and document tdb1_incompatible_hash.
Rusty Russell [Wed, 31 Aug 2011 06:01:07 +0000 (15:31 +0930)]
tdb2: expose and document tdb1_incompatible_hash.

9 years agotdb2: make tdb1_null static.
Rusty Russell [Wed, 31 Aug 2011 06:01:07 +0000 (15:31 +0930)]
tdb2: make tdb1_null static.

It's only used in two files, make it static in one and do it manually
in the other.

9 years agotdb2: tdb_repack
Rusty Russell [Wed, 31 Aug 2011 06:01:07 +0000 (15:31 +0930)]
tdb2: tdb_repack

Move the tdb1_repack() code into the core, make it general, rename to

It's generic code: copy database into temporary, wipe it, copy back.

9 years agotdb2: unify tdb1_wipe into tdb_wipe.
Rusty Russell [Wed, 31 Aug 2011 06:01:07 +0000 (15:31 +0930)]
tdb2: unify tdb1_wipe into tdb_wipe.

Switch on the TDB_VERSION1 flag.

9 years agotdb2: unify tdb1_get_seqnum/tdb1_increment_seqnum into tdb_get_seqnum/tdb_inc_seqnum
Rusty Russell [Wed, 31 Aug 2011 06:01:07 +0000 (15:31 +0930)]
tdb2: unify tdb1_get_seqnum/tdb1_increment_seqnum into tdb_get_seqnum/tdb_inc_seqnum

Switch on the TDB_VERSION1 flag.

9 years agotdb2: unify tdb1_firstkey/tdb1_nextkey into tdb_firstkey/tdb_nextkey.
Rusty Russell [Wed, 31 Aug 2011 06:01:07 +0000 (15:31 +0930)]
tdb2: unify tdb1_firstkey/tdb1_nextkey into tdb_firstkey/tdb_nextkey.

Switch on the TDB_VERSION1 flag.

9 years agotdb2: unify tdb1_check and tdb1_summary into tdb_check and tdb_summary.
Rusty Russell [Wed, 31 Aug 2011 06:01:07 +0000 (15:31 +0930)]
tdb2: unify tdb1_check and tdb1_summary into tdb_check and tdb_summary.

Switch on the TDB_VERSION1 flag.  Also, change tdb1_check's checkfn argument
to return an error code (and set tdb->last_error accordingly).

9 years agotdb2: unify tdb1_transaction_start etc. into tdb_transaction_start.
Rusty Russell [Wed, 31 Aug 2011 06:01:07 +0000 (15:31 +0930)]
tdb2: unify tdb1_transaction_start etc. into tdb_transaction_start.

Switch on the TDB_VERSION1 flag.

9 years agotdb2: unify tdb1_parse_record into tdb_parse_record
Rusty Russell [Wed, 31 Aug 2011 06:01:06 +0000 (15:31 +0930)]
tdb2: unify tdb1_parse_record into tdb_parse_record

Switch on the TDB_VERSION1 flag.

9 years agotdb2: unify tdb1_chainlock et al. into tdb_chainlock
Rusty Russell [Wed, 31 Aug 2011 06:01:06 +0000 (15:31 +0930)]
tdb2: unify tdb1_chainlock et al. into tdb_chainlock

Switch on the TDB_VERSION1 flag.

9 years agotdb2: unify tdb1_traverse into tdb_traverse
Rusty Russell [Wed, 31 Aug 2011 06:01:06 +0000 (15:31 +0930)]
tdb2: unify tdb1_traverse into tdb_traverse

Switch on the TDB_VERSION1 flag; we now only do a tdb1_traverse_read on a
read-only database, as there is no tdb2 equivalent.

9 years agotdb2: unify tdb1_store into tdb_store
Rusty Russell [Wed, 31 Aug 2011 06:01:06 +0000 (15:31 +0930)]
tdb2: unify tdb1_store into tdb_store

Switch on the TDB_VERSION1 flag.

9 years agotdb2: unify tdb1_delete into tdb_delete.
Rusty Russell [Wed, 31 Aug 2011 06:01:06 +0000 (15:31 +0930)]
tdb2: unify tdb1_delete into tdb_delete.

Switch on the TDB_VERSION1 flag.

9 years agotdb2: unify tdb1_append into tdb_append
Rusty Russell [Wed, 31 Aug 2011 06:01:06 +0000 (15:31 +0930)]
tdb2: unify tdb1_append into tdb_append

Switch on the TDB_VERSION1 flag.

9 years agotdb2: unify tdb1_fetch into tdb_fetch
Rusty Russell [Wed, 31 Aug 2011 06:01:06 +0000 (15:31 +0930)]
tdb2: unify tdb1_fetch into tdb_fetch

Switch on the TDB_VERSION1 flag.

9 years agotdb2: unify tdb1_store into tdb_store
Rusty Russell [Wed, 31 Aug 2011 06:01:06 +0000 (15:31 +0930)]
tdb2: unify tdb1_store into tdb_store

Switch on the TDB_VERSION1 flag.

9 years agotdb2: unify tdb1_open into tdb_open
Rusty Russell [Wed, 31 Aug 2011 06:01:06 +0000 (15:31 +0930)]
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.

9 years agotdb2: disallow SEED attribute with TDB_VERSION1.
Rusty Russell [Wed, 31 Aug 2011 06:01:06 +0000 (15:31 +0930)]
tdb2: disallow SEED attribute with TDB_VERSION1.

It also only makes sense with O_CREAT.

9 years agotdb2: add TDB_ATTRIBUTE_TDB1_HASHSIZE
Rusty Russell [Wed, 31 Aug 2011 06:01:06 +0000 (15:31 +0930)]

This replaces the tdb1_open "hash_size" argument.  It will only be
valid when you call tdb_open() with O_CREAT in open_flags, and
TDB_VERSION1 in tdb_flags.

9 years agotdb2: make tdb1_open use attributes for logging, hash function.
Rusty Russell [Wed, 31 Aug 2011 06:01:06 +0000 (15:31 +0930)]
tdb2: make tdb1_open use attributes for logging, hash function.

This brings it closer to tdb_open(), so we can unify more easily.

9 years agotdb2: make jenkins_hash function non-static, rename to tdb_jenkins_hash.
Rusty Russell [Wed, 31 Aug 2011 06:01:05 +0000 (15:31 +0930)]
tdb2: make jenkins_hash function non-static, rename to tdb_jenkins_hash.

We're going to need access to it from tdb1_open, so expose it now.
It's better in hash.c anyway.

9 years agotdb2: remove double-open detection for TDB1 databases.
Rusty Russell [Wed, 31 Aug 2011 06:00:16 +0000 (15:30 +0930)]
tdb2: remove double-open detection for TDB1 databases.

This is a percursor to unifying with tdb_open() from tdb2, which handles
this itself.

9 years agotdb2: merge tdb1_context into tdb_context.
Rusty Russell [Wed, 31 Aug 2011 05:59:16 +0000 (15:29 +0930)]
tdb2: merge tdb1_context into tdb_context.

Finally, we split out the tdb2-specific parts of tdb_context, and put
them into a "tdb2" sub-struct; the tdb1 parts go into a "tdb1"
sub-struct.  We get rido of tdb1_context and use tdb_context

9 years agotdb2: use tdb->flags & TDB_RDONLY instead of tdb->read_only for TDB1 code.
Rusty Russell [Wed, 31 Aug 2011 05:58:16 +0000 (15:28 +0930)]
tdb2: use tdb->flags & TDB_RDONLY instead of tdb->read_only for TDB1 code.

There's also a semantic change here: for tdb1, being read-only meant no
locking, and it was an error to try to lock a r/o database.  For TDB2, you'd
need to specify TDB_NOLOCK, which suppresses locking silently.

9 years agotdb2: Make TDB1 use the same tdb_hash() wrapper as TDB2
Rusty Russell [Wed, 31 Aug 2011 05:57:16 +0000 (15:27 +0930)]
tdb2: Make TDB1 use the same tdb_hash() wrapper as TDB2

This means converting the tdb1 inbuilt hash functions to the
tdb2-style, so they return 64 bit.  We truncate to 32 bit everywhere
but in tdb_check() which needs to do so explicitly.

9 years agotdb2: don't cancel transactions on lock failures in tdb1 backend.
Rusty Russell [Wed, 31 Aug 2011 05:56:16 +0000 (15:26 +0930)]
tdb2: don't cancel transactions on lock failures in tdb1 backend.

In TDB2, the user can override locking functions, so they may
deliberarely fail (eg. be non-blocking) expecting to retry.

For this reason, the TDB2 API requires the caller to cancel the
transaction if tdb_transaction_prepare_commit() fails.

9 years agotdb2: suppress tdb1 backend logging when locking returns EINTR or EAGAIN
Rusty Russell [Wed, 31 Aug 2011 05:55:16 +0000 (15:25 +0930)]
tdb2: suppress tdb1 backend logging when locking returns EINTR or EAGAIN

The TDB1 code logs multiple times on errors; we must prevent that in
the limited case where locking fails.  With TDB2, this can happen due
to the lock function attribute, where the user supplies replacement
locking functions which are allowed to return with errno EAGAIN or
EINTR for various special-effects.  Flooding the logs for this is

9 years agotdb2: make tdb1 use same low-level lock functions.
Rusty Russell [Wed, 31 Aug 2011 05:54:16 +0000 (15:24 +0930)]
tdb2: make tdb1 use same low-level lock functions.

This means they will use the TDB_ATTRIBUTE_FLOCK functions, and get automatic
reopen support.

9 years agotdb2: Make tdb1 use the tdb_file structure.
Rusty Russell [Wed, 31 Aug 2011 05:53:16 +0000 (15:23 +0930)]
tdb2: Make tdb1 use the tdb_file structure.

Because tdb2 allows multiple opens of the same TDB, we separate out
the file information from the struct tdb_context.  Do the same for

9 years agotdb2: add TDB_VERSION1 flag.
Rusty Russell [Wed, 31 Aug 2011 05:52:16 +0000 (15:22 +0930)]
tdb2: add TDB_VERSION1 flag.

This will be set for old TDBs; we can start distinguishing paths based
on it now.

9 years agotdb2: Make TDB1 code use TDB2's open flags.
Rusty Russell [Wed, 31 Aug 2011 05:51:16 +0000 (15:21 +0930)]
tdb2: Make TDB1 code use TDB2's open flags.

This means getting rid of TDB_VOLATILE (perhaps we should use an
attribute for that?), TDB_INCOMPATIBLE_HASH (use the
tdb_attribute_hash for that) and TDB_CLEAR_IF_FIRST (use the
tdb_attribute_openhook for that).

We also get rid of TDB_DISALLOW_NESTING: that's the default for TDB2.

9 years agotdb2: approximate INCOMPATIBLE_HASH flag with tdb1_incompatible_hash()
Rusty Russell [Wed, 31 Aug 2011 05:50:16 +0000 (15:20 +0930)]
tdb2: approximate INCOMPATIBLE_HASH flag with tdb1_incompatible_hash()

Rather than leak TDB_INCOMPATIBLE_HASH through to the TDB2 API, we make
it that if they use the tdb1_incompatible_hash function as their hash,
then we treat it as if they had specified the TDB_INCOMPATIBLE_HASH
flag (ie. we mark the header so it's unusable by tdb < 1.2.6).

This precludes the possibility of using TDB_INCOMPATIBLE_HASH with a
custom hash function: that used to allow the user to ensure that old TDB
versions couldn't open the TDB file (and recent ones check the header to
ensure they're using the right hash).  But that's a small loss.

9 years agotdb2: Make tdb1 share tdb_store flags, struct tdb_data and TDB_MAGIC_FOOD.
Rusty Russell [Wed, 31 Aug 2011 05:49:16 +0000 (15:19 +0930)]
tdb2: Make tdb1 share tdb_store flags, struct tdb_data and TDB_MAGIC_FOOD.

9 years agotdb2: make TDB1 code use tdb2's TDB_ERROR and tdb_logerr()
Rusty Russell [Wed, 31 Aug 2011 05:48:16 +0000 (15:18 +0930)]
tdb2: make TDB1 code use tdb2's TDB_ERROR and tdb_logerr()

To do this, we make sure that the first few fields of tdb1_context and
tdb_context are the same.

This sweep also fixes up a few paths where we weren't setting
tdb->ecode before our old logging function.

9 years agotdb2: make tdb1 headers include tdb2 headers.
Rusty Russell [Wed, 31 Aug 2011 05:47:16 +0000 (15:17 +0930)]
tdb2: make tdb1 headers include tdb2 headers.

They're about to start sharing TDB2's definitions.

9 years agotdb2: rearrange tdb_context layout so tdb1_context can match
Rusty Russell [Wed, 31 Aug 2011 05:46:16 +0000 (15:16 +0930)]
tdb2: rearrange tdb_context layout so tdb1_context can match

By moving all the parts of struct tdb_context which logging and
locking use to the beginning of the structure, we can make
tdb1_context match, and thus pass that directly to the tdb_logerr()
function, and later the locking functions.

This is only necessary until we unify tdb1_context and tdb_context.

9 years agotdb2: remove TDB1 TDB_NO_FSYNC environment variable hack.
Rusty Russell [Wed, 31 Aug 2011 05:45:16 +0000 (15:15 +0930)]
tdb2: remove TDB1 TDB_NO_FSYNC environment variable hack.

The caller should do this: the SAMBA compatibility later does.

9 years agotdb2: get rid of TDB1 mark and nonblock functions.
Rusty Russell [Wed, 31 Aug 2011 05:44:16 +0000 (15:14 +0930)]
tdb2: get rid of TDB1 mark and nonblock functions.

We do this using hooks in tdb2.

9 years agotdb2: remove _PUBLIC_ in tdb1 functions.
Rusty Russell [Wed, 31 Aug 2011 05:43:16 +0000 (15:13 +0930)]
tdb2: remove _PUBLIC_ in tdb1 functions.

They'll all be accessed via the tdb2 API.

9 years agotdb2: Remove unused tdb1 functions.
Rusty Russell [Wed, 31 Aug 2011 05:42:16 +0000 (15:12 +0930)]
tdb2: Remove unused tdb1 functions.

We're going to use TDB2's API, so some TDB1 APIs are obviously unnecessary.
We also get rid of USE_RIGHT_MERGES and TRACE code.

9 years agotdb2: test: import tdb1's tests.
Rusty Russell [Wed, 31 Aug 2011 05:41:16 +0000 (15:11 +0930)]
tdb2: test: import tdb1's tests.

The main change is to s/tdb/tdb1_/ everywhere.

9 years agotdb2: include tdb1 source in tests.
Rusty Russell [Wed, 31 Aug 2011 05:40:16 +0000 (15:10 +0930)]
tdb2: include tdb1 source in tests.

Since we've renamed everything in tdb1, they won't clash.

9 years agotdb2: import TDB1 code.
Rusty Russell [Wed, 31 Aug 2011 05:39:16 +0000 (15:09 +0930)]
tdb2: import TDB1 code.

We import the entire codebase, putting a "tdb1_" prefix on the files
and changing the "tdb_" prefix to "tdb1_" everywhere.

The next patches will gradually merge it with the TDB2 code where

9 years agotdb2: make tests include a single mega-header to simplify future patches
Rusty Russell [Wed, 31 Aug 2011 05:38:16 +0000 (15:08 +0930)]
tdb2: make tests include a single mega-header to simplify future patches

This lets us add the new files to a single place.

9 years agotdb2: tdb_foreach()
Rusty Russell [Wed, 31 Aug 2011 05:37:16 +0000 (15:07 +0930)]
tdb2: tdb_foreach()

Create an iterator over every open tdb (not internal TDBs).  This is
useful for re-establishing the tdb1-style active lock for

9 years agotdb2: keep link of every non-internal tdb.
Rusty Russell [Wed, 31 Aug 2011 05:37:13 +0000 (15:07 +0930)]
tdb2: keep link of every non-internal tdb.

Instead of a per-file linked list, use a per-tdb list.  This is needed
for tdb_foreach().

9 years agotdb2: save openhook, allow tdb_get_attribute() on it.
Rusty Russell [Wed, 31 Aug 2011 05:36:25 +0000 (15:06 +0930)]
tdb2: save openhook, allow tdb_get_attribute() on it.

This makes it easy to call it again after a fork(), such as for
re-establishing the CLEAR_IF_FIRST files locks.

9 years agotdb2: add TDB_RDONLY flag, allow setting/unsetting it.
Rusty Russell [Wed, 31 Aug 2011 04:28:15 +0000 (13:58 +0930)]
tdb2: add TDB_RDONLY flag, allow setting/unsetting it.

You can only unset it if the TDB was originally opened O_RDWR.

Also, cleaned up error handling in tdb_allrecord_lock() so we only get
one log message on a r/o database.

9 years agotdb2: return TDB_ERR_RDONLY if trying to start a transaction on a R/O tdb.
Rusty Russell [Wed, 31 Aug 2011 04:27:15 +0000 (13:57 +0930)]
tdb2: return TDB_ERR_RDONLY if trying to start a transaction on a R/O tdb.

This is more accurate than returning TDB_ERR_EINVAL.

9 years agotdb2: save open_flags instead of mmap_flags.
Rusty Russell [Wed, 31 Aug 2011 04:26:15 +0000 (13:56 +0930)]
tdb2: save open_flags instead of mmap_flags.

It's more consistent with what tdb1 does, and slightly more encapsulated.

9 years agotdb2: Hand error code to logging function.
Rusty Russell [Wed, 31 Aug 2011 04:25:15 +0000 (13:55 +0930)]
tdb2: Hand error code to logging function.

Since we've deprecated tdb_error() function (and it didn't work right
from inside the logging function anyway, since we didn't set
tdb->ecode yet) we need to hand it to the log function.

9 years agotdb2: move transaction lock
Rusty Russell [Wed, 31 Aug 2011 01:15:12 +0000 (10:45 +0930)]
tdb2: move transaction lock

Make it the same offset as TDB1.  This isn't strictly necessary, but
it would allow for total unification later, since TDB1 and TDB2's
transaction code is otherwise completely compatible.

9 years agotdb2: enforce TDB_CONVERT
Rusty Russell [Wed, 31 Aug 2011 01:14:12 +0000 (10:44 +0930)]
tdb2: enforce TDB_CONVERT

If the caller actually specifies TDB_CONVERT, fail if the TDB does not
need conversion.  It's unusual for the user to specify TDB_CONVERT
(it's auto-detected) but better to be strict.

9 years agotdb2: cleanup oob handling.
Rusty Russell [Wed, 31 Aug 2011 01:13:12 +0000 (10:43 +0930)]
tdb2: cleanup oob handling.

The tdb_oob() function can fail due to errors, as well as because the length
asked for is greater than the size of the file.  Clean that up:

(1) If probe is true, only fail if there's an error, not if the length is
    too great.
(2) Exit tdb_open() if it tdb_oob() probe fails; this helps cut down
    test time for failtest.
(3) Don't set probe to true in tdb_direct() fail; a minor issue, but it means
    we log failure.

9 years agotdb2: fix tdb_lock offset.
Rusty Russell [Wed, 31 Aug 2011 01:12:12 +0000 (10:42 +0930)]
tdb2: fix tdb_lock offset.

It can be 64 bits, for huge databases.

9 years agotdb2: fix internal tdb_write_convert() error handling in tdb_open()
Rusty Russell [Wed, 31 Aug 2011 01:11:12 +0000 (10:41 +0930)]
tdb2: fix internal tdb_write_convert() error handling in tdb_open()

As noted, failtest was taking a long time, because a failure injected here
was not detected.

9 years agotdb2: Fix to always use 64-bit offset definition
Rusty Russell [Wed, 31 Aug 2011 01:10:12 +0000 (10:40 +0930)]
tdb2: Fix to always use 64-bit offset definition

We use off_t in the tdb2 interface (for tdb_attribute_flock); we need
to make sure that all callers agree on the size.

This also causes a problem in the tests: it's not enough to include
config.h first, we need the _FILE_OFFSET_BITS define from private.h.
Otherwise, we can disagree about the definitions of F_SETLK, F_SETLKW
and off_t, causing strange problems.

9 years agotally: Adapt tally_histogram to Samba coding conventions
Volker Lendecke [Wed, 10 Aug 2011 17:53:53 +0000 (19:53 +0200)]
tally: Adapt tally_histogram to Samba coding conventions

Autobuild-User: Volker Lendecke <>
Autobuild-Date: Wed Aug 10 21:12:59 CEST 2011 on sn-devel-104

(Imported from SAMBA commit f7b820c3590ac78dd0dea67ac882f53ae6f550d9)