]> git.ozlabs.org Git - ccan/log
ccan
13 years agoforeach: allow a single argument to foreach_int() and foreach_ptr().
Rusty Russell [Mon, 21 Mar 2011 02:43:51 +0000 (13:13 +1030)]
foreach: allow a single argument to foreach_int() and foreach_ptr().

David Gibson noted that foreach requires more than one argument.
There's no particularly good reason for this, other than lack of
imagination on my part.

13 years agoforeach: fix HAVE_FOR_LOOP_DECLARATION case.
Rusty Russell [Mon, 21 Mar 2011 02:42:46 +0000 (13:12 +1030)]
foreach: fix HAVE_FOR_LOOP_DECLARATION case.

13 years agotdb2: merge changes in design document.
Rusty Russell [Thu, 17 Mar 2011 11:42:20 +0000 (22:12 +1030)]
tdb2: merge changes in design document.

13 years agotdb2: tdb_error()
Rusty Russell [Thu, 17 Mar 2011 11:42:20 +0000 (22:12 +1030)]
tdb2: tdb_error()

This makes transition from tdb1 much simpler.

13 years agotdb2: TDB_SEQNUM and tdb_get_seqnum support.
Rusty Russell [Thu, 17 Mar 2011 11:42:20 +0000 (22:12 +1030)]
tdb2: TDB_SEQNUM and tdb_get_seqnum support.

As per TDB1, except that the sequence number is 63 bit.

13 years agotdb2: tdb_name and tdb_fd functions.
Rusty Russell [Thu, 17 Mar 2011 11:42:20 +0000 (22:12 +1030)]
tdb2: tdb_name and tdb_fd functions.

As per TDB1, with one enhancement: a non-NULL name argument passed to
tdb_open() with the TDB_INTERNAL flag is preserved so you can identify
internal TDBs too.

13 years agotdb2: remove tdb_null
Rusty Russell [Thu, 17 Mar 2011 11:42:21 +0000 (22:12 +1030)]
tdb2: remove tdb_null

We don't need this now, since we use explicit error numbers.

13 years agotdb2: tdb_deq: inline helper for comparing two struct tdb_data
Rusty Russell [Thu, 17 Mar 2011 11:42:21 +0000 (22:12 +1030)]
tdb2: tdb_deq: inline helper for comparing two struct tdb_data

Everyone writes their own, so provide a standard one.

13 years agotdb2: implement tdb_exists and tdb_parse_record
Rusty Russell [Thu, 17 Mar 2011 11:42:21 +0000 (22:12 +1030)]
tdb2: implement tdb_exists and tdb_parse_record

These are the same as the TDB1 functions; but note that there is no reliable
way to tell if tdb_exists() fails due to an error.  This simplifies the API,
but means you have to use tdb_fetch() if you really care.

13 years agotdb2: begin tdb1 to tdb2 porting guide.
Rusty Russell [Thu, 17 Mar 2011 11:42:21 +0000 (22:12 +1030)]
tdb2: begin tdb1 to tdb2 porting guide.

13 years agotdb2: allow multiple opens of the same file.
Rusty Russell [Thu, 17 Mar 2011 11:42:21 +0000 (22:12 +1030)]
tdb2: allow multiple opens of the same file.

Finally, we enable sharing of the struct tdb_file.  We add a reference count
so we can free the struct tdb_file when the last tdb is closed.

13 years agotdb2: set owner for locks
Rusty Russell [Thu, 17 Mar 2011 11:42:21 +0000 (22:12 +1030)]
tdb2: set owner for locks

The last step before sharing struct tdb_file is to add a field to
identify which tdb context is holding each lock, so we can fail when
they conflict.

13 years agotdb2: rename tdb_lock_type to tdb_lock
Rusty Russell [Thu, 17 Mar 2011 11:42:21 +0000 (22:12 +1030)]
tdb2: rename tdb_lock_type to tdb_lock

Internal reshuffle which makes things shorter and neater.

13 years agotdb2: move mmap into struct tdb_file
Rusty Russell [Thu, 17 Mar 2011 11:42:21 +0000 (22:12 +1030)]
tdb2: move mmap into struct tdb_file

It makes sense to share the mmap between multiple openers.

13 years agotdb2: move file operations into separate structure
Rusty Russell [Thu, 17 Mar 2011 11:42:21 +0000 (22:12 +1030)]
tdb2: move file operations into separate structure

This moves the fd and locking information into a new 'struct tdb_file',
opening the way for it to be shared by multiple tdb_open calls on the
same file.

13 years agotdb2: fix leak in test/run-remap-in-read_traverse.c
Rusty Russell [Thu, 17 Mar 2011 11:42:21 +0000 (22:12 +1030)]
tdb2: fix leak in test/run-remap-in-read_traverse.c

13 years agotdb2: move open routines into a separate file (open.c)
Rusty Russell [Thu, 17 Mar 2011 11:42:21 +0000 (22:12 +1030)]
tdb2: move open routines into a separate file (open.c)

Simply tidying up.

13 years agotdb2: Implement tdb_get_flags, tdb_add_flag and tdb_remove_flag.
Rusty Russell [Thu, 17 Mar 2011 11:42:21 +0000 (22:12 +1030)]
tdb2: Implement tdb_get_flags, tdb_add_flag and tdb_remove_flag.

13 years agotdb2: make sure records with extra padding have a 0 byte.
Rusty Russell [Thu, 17 Mar 2011 11:42:21 +0000 (22:12 +1030)]
tdb2: make sure records with extra padding have a 0 byte.

As detailed in doc/design.lyx section 2.16 "Record Headers Are Not
Expandible", we make sure that if there is padding at the end of a record,
the first byte of padding is a zero.

13 years agotdb2: avoid writing uninitialized bytes in test/layout.c
Rusty Russell [Thu, 17 Mar 2011 11:42:21 +0000 (22:12 +1030)]
tdb2: avoid writing uninitialized bytes in test/layout.c

13 years agotdb2: feature support.
Rusty Russell [Thu, 17 Mar 2011 11:42:21 +0000 (22:12 +1030)]
tdb2: feature support.

As detailed in doc/design.lyx section 2.15 "Extending The Header Is
Difficult"; we add features_used and features_offered fields to the
header, so we can identify if we add new features, and then if someone
opens it who doesn't understand that feature.

13 years agotdb2: make tdb_check typesafe.
Rusty Russell [Thu, 17 Mar 2011 11:42:21 +0000 (22:12 +1030)]
tdb2: make tdb_check typesafe.

13 years agotdb2: typesafe traverse function
Rusty Russell [Thu, 17 Mar 2011 11:42:21 +0000 (22:12 +1030)]
tdb2: typesafe traverse function

This make sure that the data being handed to the function in tdb_traverse
is the correct type.

13 years agotdb2: check for invalid flags in tdb_open.
Rusty Russell [Thu, 17 Mar 2011 11:42:21 +0000 (22:12 +1030)]
tdb2: check for invalid flags in tdb_open.

This is vitally important for forwards compatibility.

13 years agotdb2: fix two bogus returns in check.c
Rusty Russell [Thu, 17 Mar 2011 11:42:21 +0000 (22:12 +1030)]
tdb2: fix two bogus returns in check.c

Two missed cases in b21004624683 (tdb2: change API to return the error
value.)

13 years agotdb2: use vasprintf.
Rusty Russell [Thu, 17 Mar 2011 11:42:21 +0000 (22:12 +1030)]
tdb2: use vasprintf.

13 years agotdb2: use config.h instead of setting _XOPEN_SOURCE etc.
Rusty Russell [Thu, 17 Mar 2011 11:42:22 +0000 (22:12 +1030)]
tdb2: use config.h instead of setting _XOPEN_SOURCE etc.

13 years agotdb2: update tools/speed.c, tools/tdbtool.c and tools/tdbtorture.c to new API
Rusty Russell [Thu, 17 Mar 2011 11:42:22 +0000 (22:12 +1030)]
tdb2: update tools/speed.c, tools/tdbtool.c and tools/tdbtorture.c to new API

13 years agotdb2: clear bogus gcc uninitialized warnings with -O3
Rusty Russell [Thu, 17 Mar 2011 11:42:22 +0000 (22:12 +1030)]
tdb2: clear bogus gcc uninitialized warnings with -O3

13 years agofailtest: include config.h first
Rusty Russell [Thu, 17 Mar 2011 11:42:22 +0000 (22:12 +1030)]
failtest: include config.h first

It's now important, since it defines _GNU_SOURCE.

13 years agoccanlint: fix gdb line in tests_pass helper.
Rusty Russell [Thu, 17 Mar 2011 11:42:22 +0000 (22:12 +1030)]
ccanlint: fix gdb line in tests_pass helper.

Recent changes shifted line numbers in tap.c, so the break is now in
the wrong place.  We should probably have an explicit function we can
breakpoint instead.

13 years agotools: fix ctype.h and string usage.
Rusty Russell [Thu, 17 Mar 2011 11:45:13 +0000 (22:15 +1030)]
tools: fix ctype.h and string usage.

Enable CCAN_STR_DEBUG in the default flags, so our tools get checked,
and fix up the resulting errors.

13 years agostr: replacements for ctype functions.
Rusty Russell [Thu, 17 Mar 2011 11:42:22 +0000 (22:12 +1030)]
str: replacements for ctype functions.

The standard ctype.h variants will make you go insane if you
contemplate them for too long.

13 years agotap: fix isdigit and isspace usage.
Rusty Russell [Thu, 17 Mar 2011 11:42:22 +0000 (22:12 +1030)]
tap: fix isdigit and isspace usage.

isspace() and isdigit() want an unsigned value.

13 years agociniparser: fix ctype.h usage, and lazy strrchr.
Rusty Russell [Thu, 17 Mar 2011 11:42:22 +0000 (22:12 +1030)]
ciniparser: fix ctype.h usage, and lazy strrchr.

tolower(), toupper() and isupper want an unsigned value.  Also, fix
lazy cost-discarding inside strrchr for extra safety.

13 years agoccanlint: objects_build_with_stringchecks
Rusty Russell [Thu, 17 Mar 2011 11:42:22 +0000 (22:12 +1030)]
ccanlint: objects_build_with_stringchecks

If we detect any mention of a problematic string function, try compiling
the entire module with string debugging enabled.

13 years agostr: provide checks for ctype.h char functions, and strstr and strchr functions.
Rusty Russell [Thu, 17 Mar 2011 11:42:22 +0000 (22:12 +1030)]
str: provide checks for ctype.h char functions, and strstr and strchr functions.

In the former case, we were bitten by the fact that you don't pass a char
to isalpha() et al: you pass an int.  This means on most platforms you want
to do:

   if (isalpha((unsigned char)c)) ...

Insane?  Yes, but I assure you I'm not making this up.

Similarly, I've always wanted strstr, strchr and strrchr to return
const char * when given a const char * argument to search, to avoid
constness leak.

In both cases, the actual versions from the headers may be macros, so
we need to be very careful overriding them.  The result is that they
become out-of-line functions which is unacceptable for general
performance.

So we only activate these when CCAN_STR_DEBUG is defined.

13 years agobuild_assert: rename EXPR_BUILD_ASSERT to BUILD_ASSERT_OR_ZERO
Rusty Russell [Thu, 17 Mar 2011 11:42:22 +0000 (22:12 +1030)]
build_assert: rename EXPR_BUILD_ASSERT to BUILD_ASSERT_OR_ZERO

Same thing (a BUILD_ASSERT which evaluates to zero), but there's a
strong preference for all modules to stick with their own names as
prefixes.

13 years agoccanlint: don't ever used pre-built modules as dependencies.
Rusty Russell [Thu, 17 Mar 2011 11:42:22 +0000 (22:12 +1030)]
ccanlint: don't ever used pre-built modules as dependencies.

They're often out-of-date, and we're about to do special things to the
str module compile flags, so we don't *ever* want the default.

It doesn't add much to build times, and it eliminates a nasty source
of weird errors.

13 years agoccanlint: fix mangled output for 'make scores'
Rusty Russell [Thu, 17 Mar 2011 11:42:22 +0000 (22:12 +1030)]
ccanlint: fix mangled output for 'make scores'

We need to flush stdout before forking.

13 years agotools: avoid needless post increment on size
Brad Hards [Tue, 8 Mar 2011 09:28:13 +0000 (20:28 +1100)]
tools: avoid needless post increment on size

Also add a note about a possible segfault.

13 years agotools: actually add non-source files to other_files in manifest
Rusty Russell [Wed, 16 Mar 2011 04:22:21 +0000 (14:52 +1030)]
tools: actually add non-source files to other_files in manifest

We don't use it for the moment, but Brad Hards noted that assigning to
dest ten continuing was pointless, revealing this bug.

13 years agoalloc: avoid dead store to hdrlen
Brad Hards [Tue, 8 Mar 2011 09:28:11 +0000 (20:28 +1100)]
alloc: avoid dead store to hdrlen

We only ever write to this variable, so can just be removed.

13 years agociniparser: avoid dead store to sta
Brad Hards [Tue, 8 Mar 2011 09:28:10 +0000 (20:28 +1100)]
ciniparser: avoid dead store to sta

This is always overwritten later in the function.

13 years agoccan_tokenizer: avoid dead store
Brad Hards [Tue, 8 Mar 2011 09:28:09 +0000 (20:28 +1100)]
ccan_tokenizer: avoid dead store

obe is always overwritten later.

13 years agotdb2: trivial spelling fixes
Brad Hards [Tue, 8 Mar 2011 09:28:08 +0000 (20:28 +1100)]
tdb2: trivial spelling fixes

13 years agotdb: remove unused last_ptr
Brad Hards [Tue, 8 Mar 2011 09:28:06 +0000 (20:28 +1100)]
tdb: remove unused last_ptr

13 years agociniparser: remove dead store
Brad Hards [Tue, 8 Mar 2011 09:28:05 +0000 (20:28 +1100)]
ciniparser: remove dead store

last is unconditionally set to zero later in this function.

13 years agoalloc: remove unused variable
Brad Hards [Tue, 8 Mar 2011 09:28:04 +0000 (20:28 +1100)]
alloc: remove unused variable

lp_bits was only ever written to.

13 years agoasprintf: new asprintf module.
Rusty Russell [Tue, 1 Mar 2011 13:01:09 +0000 (23:31 +1030)]
asprintf: new asprintf module.

asprintf is a PITA to use, and it's not in POSIX anyway.  Provide
replacements, and also provide a nicer-to-use afmt() wrapper.

13 years agotools: Fixed unchecked *strrchr in a couple places.
Joey Adams [Fri, 25 Feb 2011 04:24:36 +0000 (23:24 -0500)]
tools: Fixed unchecked *strrchr in a couple places.

tools/ccan_depends --compile ccan/module (without a trailing slash)
results in a segfault.

13 years agotools: Added "-I." to fix ccan_depends --compile
Joey Adams [Tue, 8 Mar 2011 00:20:20 +0000 (10:50 +1030)]
tools: Added "-I." to fix ccan_depends --compile

(Patched forward by Rusty)

13 years agoasort: Remove constness from ctx pointer.
Andreas Schlick [Fri, 4 Mar 2011 16:08:06 +0000 (17:08 +0100)]
asort: Remove constness from ctx pointer.

13 years agotdb2: Correct the comment explaining tdb_brlock().
Andreas Schlick [Fri, 4 Mar 2011 15:41:53 +0000 (16:41 +0100)]
tdb2: Correct the comment explaining tdb_brlock().

13 years agocast: new limited cast package inspired by Jan Engelhardt's libhx.
Rusty Russell [Wed, 2 Mar 2011 03:57:07 +0000 (14:27 +1030)]
cast: new limited cast package inspired by Jan Engelhardt's libhx.

13 years agoccanlint: give a point per compile_ok/compile_fail test
Rusty Russell [Wed, 2 Mar 2011 03:54:02 +0000 (14:24 +1030)]
ccanlint: give a point per compile_ok/compile_fail test

We get a point for every run or api test, rather than 1 point for all of them,
so be consistent.

13 years agoccanlint: don't fail just because we don't have positive tests.
Rusty Russell [Wed, 2 Mar 2011 03:53:21 +0000 (14:23 +1030)]
ccanlint: don't fail just because we don't have positive tests.

cast package has all negative tests, plus testable examples.

13 years agoconfigurator: more robust test for HAVE_NESTED_FUNCTIONS
Rusty Russell [Wed, 2 Mar 2011 00:15:51 +0000 (10:45 +1030)]
configurator: more robust test for HAVE_NESTED_FUNCTIONS

Thanks to Andreas Schlick, we have a nicer test for when gcc warns about
trampolines (gcc 4.6's -Wtrampolines).  This works at any optimization level,
and means when that warning is enabled we recognize that we shouldn't allow
nested functions.

13 years agoiscsi, nfs, opt, tap: use config.h instead of defining _GNU_SOURCE.
Rusty Russell [Tue, 1 Mar 2011 13:10:21 +0000 (23:40 +1030)]
iscsi, nfs, opt, tap: use config.h instead of defining _GNU_SOURCE.

13 years agotdb2: update design.lyx
Rusty Russell [Tue, 1 Mar 2011 12:49:18 +0000 (23:19 +1030)]
tdb2: update design.lyx

13 years agotdb2: failtest on tdb_fetch
Rusty Russell [Tue, 1 Mar 2011 12:49:18 +0000 (23:19 +1030)]
tdb2: failtest on tdb_fetch

Increase from:
1985 of 2553 lines covered
to:
2020 of 2552 lines covered

13 years agotdb2: failtest on tdb_store
Rusty Russell [Tue, 1 Mar 2011 12:49:18 +0000 (23:19 +1030)]
tdb2: failtest on tdb_store

Increase from:
1985 of 2553 lines covered
to:
2018 of 2552 lines covered

13 years agotdb2: failtest on tdb_expand
Rusty Russell [Tue, 1 Mar 2011 12:54:29 +0000 (23:24 +1030)]
tdb2: failtest on tdb_expand

Increase from:
1962 of 2553 lines covered
to:
1985 of 2553 lines covered

13 years agotdb2: fix pread/pwrite error handling in fill and tdb_write.
Rusty Russell [Tue, 1 Mar 2011 12:49:18 +0000 (23:19 +1030)]
tdb2: fix pread/pwrite error handling in fill and tdb_write.

The "ret < n" was done as an unsigned comparison, so it didn't work as
expected when ret was negative.

Simplest fix is to do an equals comparison everywhere, which is also
slightly stricter.

13 years agotdb2: allow read-only databases to use locking.
Rusty Russell [Tue, 1 Mar 2011 12:49:18 +0000 (23:19 +1030)]
tdb2: allow read-only databases to use locking.

You can always specify the TDB_NOLOCK flag along with O_RDONLY for the old
behaviour.

13 years agotdb2: remove zero-length write optimization.
Rusty Russell [Tue, 1 Mar 2011 12:49:18 +0000 (23:19 +1030)]
tdb2: remove zero-length write optimization.

If benchmarking indicates a problem later, we can restore it.

13 years agotdb2: change API to return the error value.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: change API to return the error value.

Mostly a fairly simple transformation, since 0 still means success.

One new twist is that tdb_nextkey now frees the .dptr of the key; this
us usually what we want but does cause issues for our weird test code.

13 years agotdb2: rework tdb.c internal functions to return enum TDB_ERROR.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: rework tdb.c internal functions to return enum TDB_ERROR.

13 years agotdb2: rework summary.c internal functions to return enum TDB_ERROR.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: rework summary.c internal functions to return enum TDB_ERROR.

13 years agotdb2: rework check.c internal functions to return enum TDB_ERROR.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: rework check.c internal functions to return enum TDB_ERROR.

Of course, we leave the API the same, but percolate error codes all the
way back to tdb_check().

13 years agotdb2: rework transaction.c internal functions to return enum TDB_ERROR.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: rework transaction.c internal functions to return enum TDB_ERROR.

In particular, tdb_needs_recovery() can now indicate an error occurred,
rather than returning true.

13 years agotdb2: rework free.c functions to return enum TDB_ERROR.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: rework free.c functions to return enum TDB_ERROR.

13 years agotdb2: rework hash.c functions to return enum TDB_ERROR.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: rework hash.c functions to return enum TDB_ERROR.

This time we have to use our tri-value "tdb_bool_err" type to indicate
true, false, or error, which now allows us to correctly handle errors
in key matching (rather than treating it as a non-match).

13 years agotdb2: rework remaining io.c functions to return enum TDB_ERROR.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: rework remaining io.c functions to return enum TDB_ERROR.

In particular, we replace the TDB_OFF_ERR ((off_t)-1) with a range of
negative error values.

13 years agotdb2: rework some io.c functions to encode errors in their pointer returns.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: rework some io.c functions to encode errors in their pointer returns.

This causes a subtle enhancement in tdb_direct(): it previously
returned NULL on both "can't use direct access" or "some error
occurred", as the caller always uses read/write functions as a
fallback anyway.  Now we distinguish the error case.

13 years agotdb2: rework some io.c functions to return enum TDB_ERROR.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: rework some io.c functions to return enum TDB_ERROR.

13 years agotdb2: rework io functions to return enum TDB_ERROR.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: rework io functions to return enum TDB_ERROR.

We have a series of I/O functions which change depending on whether we're
inside a transaction or not.  This makes them return enum TDB_ERROR instead
of int.

13 years agotdb2: restore file filling code.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: restore file filling code.

This snuck in fe55330a which added the stats attribute.  Without it,
TDB works but is vulnerable to segmenation faults or write errors when
disk is exhausted.

13 years agotdb2: rework lock.c functions to return enum TDB_ERROR.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: rework lock.c functions to return enum TDB_ERROR.

Make the other functions in lock.s return an error code, too.

13 years agotdb2: rework lock.c static functions to return enum TDB_ERROR.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: rework lock.c static functions to return enum TDB_ERROR.

We make tdb_brlock() and tdb_lock_gradual() return an error code directly:
the callers have to set tdb->ecode.

13 years agotdb2: Internal error helpers.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: Internal error helpers.

I use the "high pointers hold error numbers" trick, and also make
tdb_logerr return the error code, which enables the common case of
"return tdb_logerr(...)".

13 years agotdb2: make error numbers negative.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: make error numbers negative.

This prepares us for changing function returns over.

13 years agotdb2: remove tdb_traverse_read
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: remove tdb_traverse_read

It's not actually different from tdb_traverse().  We can re-add it later if
it makes sense.

13 years agotdb2: add comments to tdb2.h, reorder for maximum readability.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: add comments to tdb2.h, reorder for maximum readability.

13 years agotdb2: remove redundant pending transaction error check.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: remove redundant pending transaction error check.

We do this lower down anyway.

13 years agotdb2: remove tdb_hashfn_t prototype
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: remove tdb_hashfn_t prototype

It doesn't help the user, since they can't use it to declare their hash
function, and it just adds a level of mental indirection for us.

13 years agotdb2: remove nesting support.
Rusty Russell [Tue, 1 Mar 2011 12:49:19 +0000 (23:19 +1030)]
tdb2: remove nesting support.

We don't actually support it, so take it away for the moment.  If you
try to nmest you get a TDB_LOG_USE_ERROR message.

13 years agotdb2: simplify logging levels, rename TDB_DEBUG_* to TDB_LOG_*
Rusty Russell [Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)]
tdb2: simplify logging levels, rename TDB_DEBUG_* to TDB_LOG_*

It was never clear to me which levels should be used for what cases.
I can only usefully distinguish three at the moment:
(1) TDB errors, which render the TDB unreliable.
(2) TDB user errors, caused by API misuse.
(3) TDB notifications of strange behaviour, from which we have recovered.

13 years agotdb2: remove extraneous whitespace.
Rusty Russell [Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)]
tdb2: remove extraneous whitespace.

Gets us one extra ccanlint point, too.

13 years agotdb2: fix leak on lock failure during open.
Rusty Russell [Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)]
tdb2: fix leak on lock failure during open.

13 years agotdb2: log as a ERROR (not as TRACE) when unlocking fails.
Rusty Russell [Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)]
tdb2: log as a ERROR (not as TRACE) when unlocking fails.

This should never happen.

13 years agotdb2: log a message on allocation failure in tdb_check()
Rusty Russell [Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)]
tdb2: log a message on allocation failure in tdb_check()

13 years agotdb2: log an error when out of memory formatting message.
Rusty Russell [Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)]
tdb2: log an error when out of memory formatting message.

Log it at level ERROR and log the raw unformatted message at the requested
level.

13 years agotdb2: close memory leak in traverse.
Rusty Russell [Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)]
tdb2: close memory leak in traverse.

13 years agotdb2: close memory leak in tdb_check()
Rusty Russell [Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)]
tdb2: close memory leak in tdb_check()

13 years agotdb2: use failtest for opening and checking database.
Rusty Russell [Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)]
tdb2: use failtest for opening and checking database.

This is a fairly sophisticated use of failtest:
1) There are a few places where we can inject failures without revealing it
   at the API level, eg. opening /dev/urandom, or allocation failure in logging.
2) We want to be sure that (almost) all failures cause a message to be logged.
3) We need to exit as soon as possible when a failure is injected, to avoid
   combinatorial explosion.
4) We don't want to simply exit on any log message, since we want to be sure
   that cleanup happens.

This test found four different bugs failure paths.  Erk!

13 years agotdb2: fix leak in tests.
Rusty Russell [Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)]
tdb2: fix leak in tests.

13 years agotdb2: rename ->read and ->write functions.
Rusty Russell [Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)]
tdb2: rename ->read and ->write functions.

Since failtest uses macros to override read and write, we need to avoid
those names, even inside our ops structure.

13 years agotdb2: remove looping for write
Rusty Russell [Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)]
tdb2: remove looping for write

On normal files, pwrite and write should never return short except on error.
As we never create sparse files, so any short write is an I/O error.

13 years agotdb2: remove looping for read on normal files.
Rusty Russell [Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)]
tdb2: remove looping for read on normal files.

Simply assume that any short read on a TDB in an I/O error.