ccan
9 years agoccanlint: test for C++ reserved words in headers.
Rusty Russell [Tue, 19 Apr 2011 10:56:13 +0000 (20:26 +0930)]
ccanlint: test for C++ reserved words in headers.

Don't check the whole source, but it's nice for headers to be C++-clean.

9 years agoconfigurator: HAVE_FILE_OFFSET_BITS
Rusty Russell [Tue, 19 Apr 2011 07:23:39 +0000 (16:53 +0930)]
configurator: HAVE_FILE_OFFSET_BITS

Defines whether it's useful to do #define _FILE_OFFSET_BITS 64 to get a
larger off_t.

9 years agojunkcode: upload via website.
Rusty Russell [Tue, 19 Apr 2011 00:54:27 +0000 (10:24 +0930)]
junkcode: upload via website.

9 years agoconfigurator: Remove the now unneeded test for nested functions.
Andreas Schlick [Sat, 2 Apr 2011 01:31:51 +0000 (12:01 +1030)]
configurator: Remove the now unneeded test for nested functions.

9 years agoasort: Remove the trampoline version.
Andreas Schlick [Sat, 2 Apr 2011 01:30:36 +0000 (12:00 +1030)]
asort: Remove the trampoline version.

Most Linux systems use glibc and therefore have qsort_r() and for the others an
implementation is provided, therefore there is no need to have a third case in
asort.

9 years agofailtest: Change mode_t to int.
Andreas Schlick [Sat, 2 Apr 2011 01:13:52 +0000 (11:43 +1030)]
failtest: Change mode_t to int.

This avoids a warning on systems that have a 16bit wide mode_t.

9 years agohash: use config.h settings for endian.
Rusty Russell [Sat, 2 Apr 2011 01:36:49 +0000 (12:06 +1030)]
hash: use config.h settings for endian.

Leave old hacky #ifdef tests there for reference.

9 years agohash: Extend the byte order check to cover x86_64.
Andreas Schlick [Sat, 2 Apr 2011 01:13:52 +0000 (11:43 +1030)]
hash: Extend the byte order check to cover x86_64.

9 years agoTo compile ccan under DragonFly BSD some additional includes are required.
Andreas Schlick [Sat, 2 Apr 2011 01:13:52 +0000 (11:43 +1030)]
To compile ccan under DragonFly BSD some additional includes are required.

9 years agoasort: Use qsort_r if the system provides it.
Andreas Schlick [Sat, 2 Apr 2011 01:30:08 +0000 (12:00 +1030)]
asort: Use qsort_r if the system provides it.

tools/ccanlint/file_analysis.c needs to include config.h to set _GNU_SOURCE
before any other header file includes stdlib.h.

9 years agoconfigurator: Add test for glibc's qsort_r.
Andreas Schlick [Sat, 2 Apr 2011 01:30:51 +0000 (12:00 +1030)]
configurator: Add test for glibc's qsort_r.

9 years agofailtest: fix fascist warn_unused_result warnings
Rusty Russell [Mon, 28 Mar 2011 04:14:40 +0000 (14:44 +1030)]
failtest: fix fascist warn_unused_result warnings

9 years agofailtest: fix void * arithmetic in example.
Rusty Russell [Mon, 28 Mar 2011 04:00:56 +0000 (14:30 +1030)]
failtest: fix void * arithmetic in example.

9 years agofailtest: continue (without failing) if we run off end of --failpath=
Rusty Russell [Mon, 28 Mar 2011 03:58:22 +0000 (14:28 +1030)]
failtest: continue (without failing) if we run off end of --failpath=

This is important because we tell people to use --failpath to reproduce a
failure, but the fail path we list only goes up to the last failure injection
if the child dies, for example.

Thanks to David Gibson for prodding me to fix this...

9 years agotdb2: make head of free list point to last entry.
Rusty Russell [Mon, 28 Mar 2011 03:48:49 +0000 (14:18 +1030)]
tdb2: make head of free list point to last entry.

This allows for access to the end of the list, in case we need it
later (eg. moving free list entries to the end of the list after
failed coalescing?).

9 years agotdb2: speed up transaction code by making page size a constant.
Rusty Russell [Fri, 25 Mar 2011 05:42:03 +0000 (16:12 +1030)]
tdb2: speed up transaction code by making page size a constant.

Turning getpagesize() into a constant 4096 really helps gcc optimize, and
not just on 64 bit.

Here are the results of running "tools/speed --transaction --no-sync 2000000":

i386 with gcc 4.4.5:
Before:
$ ./speed --transaction --no-sync 2000000
Adding 2000000 records:  1195 ns (93594224 bytes)
Finding 2000000 records:  719 ns (93594224 bytes)
Missing 2000000 records:  429 ns (93594224 bytes)
Traversing 2000000 records:  523 ns (93594224 bytes)
Deleting 2000000 records:  901 ns (93594224 bytes)
Re-adding 2000000 records:  1032 ns (93594224 bytes)
Appending 2000000 records:  1711 ns (182801232 bytes)
Churning 2000000 records:  3233 ns (182801232 bytes)

After:
Adding 2000000 records:  868 ns (93594224 bytes)
Finding 2000000 records:  569 ns (93594224 bytes)
Missing 2000000 records:  369 ns (93594224 bytes)
Traversing 2000000 records:  406 ns (93594224 bytes)
Deleting 2000000 records:  674 ns (93594224 bytes)
Re-adding 2000000 records:  730 ns (93594224 bytes)
Appending 2000000 records:  1144 ns (182801232 bytes)
Churning 2000000 records:  2085 ns (182801232 bytes)

Here's the effect (average of 10) on x8664 with gcc 4.1.2, with an earlier
tree and 1000000:
Before:
Adding 830.1ns
Finding 428.3ns
Missing 250.3ns
Traversing 387.4ns
Deleting 588.8ns
Re-adding 737.2ns
Appending 1141.4ns
Churning 1792ns

After:
Adding 562.8ns
Finding 362.1ns
Missing 226.4ns
Traversing 276.5ns
Deleting 426.7ns
Re-adding 489.8ns
Appending 736.4ns
Churning 1112.7ns

9 years agotdb2: fix traversal bug in free list lock_and_alloc()
Rusty Russell [Fri, 25 Mar 2011 05:39:05 +0000 (16:09 +1030)]
tdb2: fix traversal bug in free list lock_and_alloc()

We keep looking even if the current best is exactly right.  This is
really bad, because our smaller free lists hold exactly one size: with
this bug we iterate to the end of the list before hitting the end and
deciding we can use it after all.

Before:
$ ./speed --transaction --no-sync 2000000
Adding 2000000 records:  1179 ns (93594224 bytes)
Finding 2000000 records:  694 ns (93594224 bytes)
Missing 2000000 records:  429 ns (93594224 bytes)
Traversing 2000000 records:  519 ns (93594224 bytes)
Deleting 2000000 records:  896 ns (93594224 bytes)
Re-adding 2000000 records:  1129 ns (93594224 bytes)
Appending 2000000 records:  1713 ns (182801232 bytes)
Churning 2000000 records:  32612 ns (182801232 bytes)

After:
$ ./speed --transaction --no-sync 2000000
Adding 2000000 records:  1195 ns (93594224 bytes)
Finding 2000000 records:  719 ns (93594224 bytes)
Missing 2000000 records:  429 ns (93594224 bytes)
Traversing 2000000 records:  523 ns (93594224 bytes)
Deleting 2000000 records:  901 ns (93594224 bytes)
Re-adding 2000000 records:  1032 ns (93594224 bytes)
Appending 2000000 records:  1711 ns (182801232 bytes)
Churning 2000000 records:  3233 ns (182801232 bytes)

9 years agotdb2: add --summary and logging to tools/speed.
Rusty Russell [Fri, 25 Mar 2011 05:21:08 +0000 (15:51 +1030)]
tdb2: add --summary and logging to tools/speed.

This helps us see where the problems are.

9 years agotdb2: add --no-sync argument to speed.
Rusty Russell [Mon, 28 Mar 2011 03:51:55 +0000 (14:21 +1030)]
tdb2: add --no-sync argument to speed.

Running speed with --transaction --no-sync means no locking or syncs
are done, so we can measure raw TDB speed.

9 years agotdb2: fix use after free on error message
Rusty Russell [Thu, 24 Mar 2011 03:40:22 +0000 (14:10 +1030)]
tdb2: fix use after free on error message

We use "r" after we call tdb_access_release() when we find corruption
in the free list.  "r" may be a pointer into malloced memory, freed
by tdb_access_release().

9 years agotdb2: fix two transaction bugs.
Rusty Russell [Thu, 24 Mar 2011 01:12:21 +0000 (11:42 +1030)]
tdb2: fix two transaction bugs.

One but were we didn't update the map_size if we expanded the
transaction but didn't create a new recovery area (most easily
reproduced by setting the TDB_NOSYNC flag).

Another out-by-one bug in transaction_direct where we would give
read-access to the underlying file despite the last block having been
modified.

Both these were found by tdbtorture.

9 years agotdb2: cleanups for tdbtorture, add more debugging and -S flag.
Rusty Russell [Wed, 23 Mar 2011 22:47:58 +0000 (09:17 +1030)]
tdb2: cleanups for tdbtorture, add more debugging and -S flag.

9 years agotdb2: actually implement tdb_error().
Rusty Russell [Thu, 24 Mar 2011 01:26:38 +0000 (11:56 +1030)]
tdb2: actually implement tdb_error().

I'm still not sure it'll last into the final version, but finish the
implementation.

9 years agotdb2: fix tools warnings with -Wshadow and -Wcast-qual.
Rusty Russell [Wed, 23 Mar 2011 05:02:01 +0000 (15:32 +1030)]
tdb2: fix tools warnings with -Wshadow and -Wcast-qual.

Samba uses these flags, so be friendly.

9 years agotdb2: avoid C++ reserved words (ie. private)
Rusty Russell [Wed, 23 Mar 2011 05:00:37 +0000 (15:30 +1030)]
tdb2: avoid C++ reserved words (ie. private)

9 years agotdb2: check PID if we are holding a lock.
Rusty Russell [Thu, 24 Mar 2011 01:24:43 +0000 (11:54 +1030)]
tdb2: check PID if we are holding a lock.

tdb1 has tdb_reopen/tdb_reopen_all, which you are supposed to call
after a fork().  But we can detect PID changes whenever we grab a lock,
which is to say, before we do anything.

We currently assume that pread and pwrite work, so the only problem
with fork() is if we are holding locks and expect them to still be
there in the child.  This is unusual, but most likely caused by a
fork() inside a transaction.  In such cases, allow the child to unlock
without complaint; they can then use the TDB as expected.

Performance before and after shows no measurable speed difference:

Total of 5 runs of tools/speed 100000:
Before:
Adding: 18899ns
Finding: 7040ns
Missing: 5802ns
Traversing: 6466ns
Deleting: 12607ns
Re-adding: 14185ns
Appending: 20770ns
Churning: 93845ns

After:
Adding: 18073ns
Finding: 6795ns
Missing: 5549ns
Traversing: 6333ns
Deleting: 12313ns
Re-adding: 13835ns
Appending: 20343ns
Churning: 92208ns

9 years agotdb2: tdb_lockall() and tdb_lockall_read() support.
Rusty Russell [Tue, 22 Mar 2011 07:51:27 +0000 (18:21 +1030)]
tdb2: tdb_lockall() and tdb_lockall_read() support.

We also change tdb_chainunlock not to return an error (as per the
other locking functions: we log a message, but don't return an error).

9 years agoconfigure.h: HAVE_ISBLANK
Rusty Russell [Mon, 28 Mar 2011 03:50:38 +0000 (14:20 +1030)]
configure.h: HAVE_ISBLANK

This isn't on RHEL4, for example: isascii() and isblank() are not in
C89.

9 years agofailtest: handle EINTR from poll.
Rusty Russell [Fri, 25 Mar 2011 01:16:17 +0000 (11:46 +1030)]
failtest: handle EINTR from poll.

I don't quite know why, but this started happening to me.  We should
handle it anyway.

9 years agoccanlint: fix listing of dependencies
Rusty Russell [Fri, 25 Mar 2011 03:21:20 +0000 (13:51 +1030)]
ccanlint: fix listing of dependencies

gcc gave a warning:
tools/ccanlint/ccanlint.c:230:19: error: ā€˜cā€™ may be used uninitialized in this function

Which indicated that test dependency printing was broken: we need to
loop through the tests!  Also, we haven't parsed options yet, so
verbose is never true: move it to later and make it depend on -vvv.

9 years agoAdd configurator test for memmem()
David Gibson [Fri, 18 Mar 2011 08:29:16 +0000 (19:29 +1100)]
Add configurator test for memmem()

memmem(), which searches for one bytestring in a longer
bytestring is one of those functions that should be standard, but
isn't.  This patch adds a ccan configurator test for the function
so that modules can use or replace it as necessary.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
9 years agoiscsi: fix warnings with -Wwrite-strings
Rusty Russell [Tue, 22 Mar 2011 01:51:39 +0000 (12:21 +1030)]
iscsi: fix warnings with -Wwrite-strings

Simplest fix is to use const where possible, and use a different var for
asprintf and string literals in login.c.

9 years agodarray: handle case where we don't have typeof.
Rusty Russell [Tue, 22 Mar 2011 04:19:40 +0000 (14:49 +1030)]
darray: handle case where we don't have typeof.

Tests don't compile otherwise, so fix that up (ccanlint now tests with
reduced features, so this became clear).

9 years agotap: ccanlint fixups
Rusty Russell [Tue, 22 Mar 2011 04:16:04 +0000 (14:46 +1030)]
tap: ccanlint fixups

Add a license tag (though it's a weird BSD variant), remove whitespace, and
avoid void pointer arithmetic.

9 years agoccanlint: fix compilation of API tests with coverage
Rusty Russell [Tue, 22 Mar 2011 03:52:28 +0000 (14:22 +1030)]
ccanlint: fix compilation of API tests with coverage

They expect to be linked against the module objects.

9 years agocrcsync: avoid arithmetic on void pointers
Rusty Russell [Tue, 22 Mar 2011 03:41:32 +0000 (14:11 +1030)]
crcsync: avoid arithmetic on void pointers

9 years agoccanlint: roughly handle multiple conditions on #if line.
Rusty Russell [Tue, 22 Mar 2011 01:13:00 +0000 (11:43 +1030)]
ccanlint: roughly handle multiple conditions on #if line.

Just grab the tokens for the simple case: this allows the ccanlint
reduce_features test to work on eg. ccan/cast.

9 years agoccanlint: exit with non-zero exit status if a test fails.
Rusty Russell [Tue, 22 Mar 2011 04:22:13 +0000 (14:52 +1030)]
ccanlint: exit with non-zero exit status if a test fails.

This means we change some minor tests to "never fail", eg. whitespace
or documentation tests.  Note that pass/fail is independent of the
score for a test.

9 years agocompiler: fix -Wwrite-strings warning in example.
Rusty Russell [Tue, 22 Mar 2011 02:12:43 +0000 (12:42 +1030)]
compiler: fix -Wwrite-strings warning in example.

9 years agoantithread: fix -Wwrite-strings warning in test, and trailing whitespace.
Rusty Russell [Tue, 22 Mar 2011 02:13:03 +0000 (12:43 +1030)]
antithread: fix -Wwrite-strings warning in test, and trailing whitespace.

9 years agoalloc: dont clash with libc's fls, avoid void pointer arithmetic
Rusty Russell [Tue, 22 Mar 2011 02:14:03 +0000 (12:44 +1030)]
alloc: dont clash with libc's fls, avoid void pointer arithmetic

9 years agoantithread: avoid arithmetic on void pointers
Rusty Russell [Tue, 22 Mar 2011 01:50:49 +0000 (12:20 +1030)]
antithread: avoid arithmetic on void pointers

9 years agotools: fix up warnings with -Wwrite-strings.
Rusty Russell [Tue, 22 Mar 2011 03:37:45 +0000 (14:07 +1030)]
tools: fix up warnings with -Wwrite-strings.

Be a little more careful with const.

9 years agoforeach: more const iteration fixes.
Rusty Russell [Tue, 22 Mar 2011 03:35:33 +0000 (14:05 +1030)]
foreach: more const iteration fixes.

Shown up by -Wwrite-strings.

9 years agoccan: add -Wpointer-arith and -Wwrite-strings by default
Rusty Russell [Tue, 22 Mar 2011 01:21:00 +0000 (11:51 +1030)]
ccan: add -Wpointer-arith and -Wwrite-strings by default

Wpointer-arith is useful for spotting GCC-isms which do arithmetic on
void pointers.  Wwrite-strings treats string constants as const char *,
which is sane (but bad for legacy code).

9 years agoalloc: avoid arithmetic on void pointers.
Rusty Russell [Tue, 22 Mar 2011 01:50:19 +0000 (12:20 +1030)]
alloc: avoid arithmetic on void pointers.

9 years agoread_write_all: avoid arithmetic on void pointers.
Rusty Russell [Tue, 22 Mar 2011 01:20:34 +0000 (11:50 +1030)]
read_write_all: avoid arithmetic on void pointers.

9 years agoopt: avoid function pointer arithmetic
Rusty Russell [Tue, 22 Mar 2011 01:20:08 +0000 (11:50 +1030)]
opt: avoid function pointer arithmetic

Same fix as we used for ccan/typesafe_cb.

9 years agoopt: fix memory leak in tests.
Rusty Russell [Tue, 22 Mar 2011 01:19:36 +0000 (11:49 +1030)]
opt: fix memory leak in tests.

No only does this give us one more ccanlint point, it clears the way
to see if we introduce a *real* memory leak later.

9 years agoopt: allow const arguments.
Rusty Russell [Tue, 22 Mar 2011 01:18:43 +0000 (11:48 +1030)]
opt: allow const arguments.

This need shows up most clearly with opt_usage_and_exit and gcc's
-Wwrite-strings, where string literals become "const char *".  Our
callbacks should take const void *: since we overload the arg field
already (to hold table size) it make sense to turn it into a proper
union.

9 years agoopt: define NULL
Rusty Russell [Tue, 22 Mar 2011 01:17:42 +0000 (11:47 +1030)]
opt: define NULL

Headers should stand alone; we use NULL, so we should make sure it's defined.

9 years agocast: fix cast of void * when we don't have GCC features.
Rusty Russell [Tue, 22 Mar 2011 01:23:17 +0000 (11:53 +1030)]
cast: fix cast of void * when we don't have GCC features.

I thought using sizeof() comparison to compare the types was clever,
but it doesn't work on void pointers, as sizeof(void) is illegal.

9 years agoarray_size: make sure tests work even without GCC features.
Rusty Russell [Tue, 22 Mar 2011 01:36:40 +0000 (12:06 +1030)]
array_size: make sure tests work even without GCC features.

In this case, "work" means "fail to compile cleanly".

9 years agotalloc: fix leak in test/run-set_allocator.c
Rusty Russell [Tue, 22 Mar 2011 02:44:23 +0000 (13:14 +1030)]
talloc: fix leak in test/run-set_allocator.c

9 years agofailtest: print complete history when we detect a leak.
Rusty Russell [Tue, 22 Mar 2011 02:44:04 +0000 (13:14 +1030)]
failtest: print complete history when we detect a leak.

9 years agotdb2: fix arithmetic on void * pointer.
Rusty Russell [Mon, 21 Mar 2011 11:48:48 +0000 (22:18 +1030)]
tdb2: fix arithmetic on void * pointer.

9 years agotypesafe: fix warnings with gcc's -Wcast-qual
Rusty Russell [Mon, 21 Mar 2011 10:32:24 +0000 (21:02 +1030)]
typesafe: fix warnings with gcc's -Wcast-qual

Don't implicitly cast away const in the tests.

9 years agotypesafe: fix warnings with gcc's -Wpointer-arith
Rusty Russell [Mon, 21 Mar 2011 10:31:35 +0000 (21:01 +1030)]
typesafe: fix warnings with gcc's -Wpointer-arith

In particular, avoid doing arithmetic on NULL; decay the function to a
pointer using a trinary conditional instead.

9 years agotdb2: tdb_mkdata
Rusty Russell [Mon, 21 Mar 2011 11:42:17 +0000 (22:12 +1030)]
tdb2: tdb_mkdata

It's common to want to create a struct tdb_data which contains a const
pointer, so add a helper to do so, and use it to clean up other -Wcast-qual
warnings.

9 years agotdb2: fix warnings with -Wcast-qual using ccan/cast.
Rusty Russell [Mon, 21 Mar 2011 11:34:30 +0000 (22:04 +1030)]
tdb2: fix warnings with -Wcast-qual using ccan/cast.

9 years agocast: fix compilation with GCC's -Wcast-qual
Rusty Russell [Mon, 21 Mar 2011 11:47:42 +0000 (22:17 +1030)]
cast: fix compilation with GCC's -Wcast-qual

Samba uses -Wcast-qual to warn about casting away const.  The kind of
coders who care about const correctness are likely to turn that option
on, so we should make sure it's compatible with cast_const().

9 years agotdb2: fix tools compilation.
Rusty Russell [Mon, 21 Mar 2011 10:20:22 +0000 (20:50 +1030)]
tdb2: fix tools compilation.

9 years agotdb2: fix compile of test/run-check-callback.c
Rusty Russell [Mon, 21 Mar 2011 10:19:49 +0000 (20:49 +1030)]
tdb2: fix compile of test/run-check-callback.c

9 years agoforeach: fix case where iterators are not on the stack.
Rusty Russell [Mon, 21 Mar 2011 03:14:22 +0000 (13:44 +1030)]
foreach: fix case where iterators are not on the stack.

The foreach garbage collection assumed that iterators were all on the
stack, but they could be on the heap or a global (or static) variable.
We can prevent the heap case by tricky use of macros to complain on
any iterator which isn't a single token, but we can't prevent
globals/statics.

So, if an iterator already seems to be "off" the stack, mark it as
such and simply never free it.

9 years agoconfigurator: HAVE_STACK_GROWS_UPWARDS
Rusty Russell [Mon, 21 Mar 2011 02:44:03 +0000 (13:14 +1030)]
configurator: HAVE_STACK_GROWS_UPWARDS

9 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.

9 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.

9 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.

9 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.

9 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.

9 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.

9 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.

9 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.

9 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.

9 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.

9 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.

9 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.

9 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.

9 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.

9 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.

9 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

9 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.

9 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.

9 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.

9 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

9 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.

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

9 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.

9 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.

9 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.)

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

9 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.

9 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

9 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

9 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.

9 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.

9 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.

9 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.

9 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.

9 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.