diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2012-03-22 10:47:26 +1030 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2012-03-22 01:57:37 +0100 |
commit | fde694274e1e5a11d1473695e7ec7a97f95d39e4 (patch) | |
tree | eafd3e0a305aaf4f537fa359ae6f812d046bff9c /lib/tdb/test | |
parent | 584b996a1a27870dad30eb422d375bb08b57c64c (diff) | |
download | samba-fde694274e1e5a11d1473695e7ec7a97f95d39e4.tar.gz samba-fde694274e1e5a11d1473695e7ec7a97f95d39e4.tar.bz2 samba-fde694274e1e5a11d1473695e7ec7a97f95d39e4.zip |
lib/tdb: fix OpenBSD incoherent mmap.
This comment appears in two places in the code (commit
4c6a8273c6dd3e2aeda5a63c4a62aa55bc133099 from 2001):
/*
* We must ensure the file is unmapped before doing this
* to ensure consistency with systems like OpenBSD where
* writes and mmaps are not consistent.
*/
But this doesn't help, because if one process is using mmap and another
using pwrite, we get incoherent results. As demonstrated by OpenBSD's
failure on the tdb unit tests.
Rather than disable mmap on OpenBSD, we test for this issue and force mmap
to be enabled. This means that we will fail on very large TDBs on 32-bit
systems, but it's better than the horrendous performance penalty on every
OpenBSD system.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'lib/tdb/test')
-rw-r--r-- | lib/tdb/test/run-3G-file.c | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/lib/tdb/test/run-3G-file.c b/lib/tdb/test/run-3G-file.c index cc700c2676..3b4e45739a 100644 --- a/lib/tdb/test/run-3G-file.c +++ b/lib/tdb/test/run-3G-file.c @@ -70,6 +70,7 @@ int main(int argc, char *argv[]) uint32_t hash; tdb_off_t rec_ptr; struct tdb_record rec; + int ret; plan_tests(24); tdb = tdb_open_ex("run-36-file.tdb", 1024, TDB_CLEAR_IF_FIRST, @@ -78,15 +79,33 @@ int main(int argc, char *argv[]) ok1(tdb); tdb->methods = &large_io_methods; - /* Enlarge the file (internally multiplies by 2). */ - ok1(tdb_expand(tdb, 1500000000) == 0); - - /* Put an entry in, and check it. */ key.dsize = strlen("hi"); key.dptr = (void *)"hi"; orig_data.dsize = strlen("world"); orig_data.dptr = (void *)"world"; + /* Enlarge the file (internally multiplies by 2). */ + ret = tdb_expand(tdb, 1500000000); +#ifdef HAVE_INCOHERENT_MMAP + /* This can fail due to mmap failure on 32 bit systems. */ + if (ret == -1) { + /* These should now fail. */ + ok1(tdb_store(tdb, key, orig_data, TDB_INSERT) == -1); + data = tdb_fetch(tdb, key); + ok1(data.dptr == NULL); + ok1(tdb_traverse(tdb, test_traverse, &orig_data) == -1); + ok1(tdb_delete(tdb, key) == -1); + ok1(tdb_traverse(tdb, test_traverse, NULL) == -1); + /* Skip the rest... */ + for (ret = 0; ret < 24 - 6; ret++) + ok1(1); + tdb_close(tdb); + return exit_status(); + } +#endif + ok1(ret == 0); + + /* Put an entry in, and check it. */ ok1(tdb_store(tdb, key, orig_data, TDB_INSERT) == 0); data = tdb_fetch(tdb, key); |