summaryrefslogtreecommitdiff
path: root/lib/ntdb/test
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2012-06-18 22:30:29 +0930
committerRusty Russell <rusty@rustcorp.com.au>2012-06-19 05:38:06 +0200
commit9396757676c304398a3e94ad01f2657e667b113c (patch)
treeca55222ca49c2d886f8717be73f3c403ed1a37c2 /lib/ntdb/test
parentdd4eed47591eeb6aafe5782690c1b550d0e3ebc4 (diff)
downloadsamba-9396757676c304398a3e94ad01f2657e667b113c.tar.gz
samba-9396757676c304398a3e94ad01f2657e667b113c.tar.bz2
samba-9396757676c304398a3e94ad01f2657e667b113c.zip
ntdb: make sure file is always a multiple of PAGESIZE (now NTDB_PGSIZE)
ntdb uses tdb's transaction code, and it has an undocumented but implicit assumption: that the transaction recovery area is always aligned to the transaction pagesize. This means that no block will overlap the recovery area. This is maintained by rounding the size of the database up, so do the same for ntdb. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'lib/ntdb/test')
-rw-r--r--lib/ntdb/test/run-30-exhaust-before-expand.c21
-rw-r--r--lib/ntdb/test/run-64-bit-tdb.c16
2 files changed, 27 insertions, 10 deletions
diff --git a/lib/ntdb/test/run-30-exhaust-before-expand.c b/lib/ntdb/test/run-30-exhaust-before-expand.c
index b94bc01bff..e3831f51a7 100644
--- a/lib/ntdb/test/run-30-exhaust-before-expand.c
+++ b/lib/ntdb/test/run-30-exhaust-before-expand.c
@@ -27,11 +27,11 @@ int main(int argc, char *argv[])
NTDB_INTERNAL|NTDB_CONVERT, NTDB_CONVERT,
NTDB_NOMMAP|NTDB_CONVERT };
- plan_tests(sizeof(flags) / sizeof(flags[0]) * 9 + 1);
+ plan_tests(sizeof(flags) / sizeof(flags[0]) * 11 + 1);
for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
- NTDB_DATA k;
- uint64_t size;
+ NTDB_DATA k, d;
+ uint64_t size, old_size;
bool was_empty = false;
k.dptr = (void *)&j;
@@ -43,6 +43,8 @@ int main(int argc, char *argv[])
if (!ntdb)
continue;
+ old_size = ntdb->file->map_size;
+
ok1(empty_freetable(ntdb));
/* Need some hash lock for expand. */
ok1(ntdb_lock_hashes(ntdb, 0, 1, F_WRLCK, NTDB_LOCK_WAIT) == 0);
@@ -53,8 +55,17 @@ int main(int argc, char *argv[])
ok1(!empty_freetable(ntdb));
size = ntdb->file->map_size;
- /* Insert minimal-length records until we expand. */
- for (j = 0; ntdb->file->map_size == size; j++) {
+
+ /* Create one record to chew up most space. */
+ d.dsize = (size - old_size - 32);
+ d.dptr = malloc(d.dsize);
+ j = 0;
+ ok1(ntdb_store(ntdb, k, d, NTDB_INSERT) == 0);
+ ok1(ntdb->file->map_size == size);
+ free(d.dptr);
+
+ /* Now insert minimal-length records until we expand. */
+ for (j = 1; ntdb->file->map_size == size; j++) {
was_empty = empty_freetable(ntdb);
if (ntdb_store(ntdb, k, k, NTDB_INSERT) != 0)
err(1, "Failed to store record %i", j);
diff --git a/lib/ntdb/test/run-64-bit-tdb.c b/lib/ntdb/test/run-64-bit-tdb.c
index 6a146cb1cf..b36f422a97 100644
--- a/lib/ntdb/test/run-64-bit-tdb.c
+++ b/lib/ntdb/test/run-64-bit-tdb.c
@@ -2,6 +2,11 @@
#include "tap-interface.h"
#include "logging.h"
+/* The largest 32-bit value which is still a multiple of NTDB_PGSIZE */
+#define ALMOST_4G ((uint32_t)-NTDB_PGSIZE)
+/* And this pushes it over 32 bits */
+#define A_LITTLE_BIT (NTDB_PGSIZE * 2)
+
int main(int argc, char *argv[])
{
unsigned int i;
@@ -33,13 +38,14 @@ int main(int argc, char *argv[])
old_size = ntdb->file->map_size;
/* This makes a sparse file */
- ok1(ftruncate(ntdb->file->fd, 0xFFFFFFF0) == 0);
- ok1(add_free_record(ntdb, old_size, 0xFFFFFFF0 - old_size,
+ ok1(ftruncate(ntdb->file->fd, ALMOST_4G) == 0);
+ ok1(add_free_record(ntdb, old_size, ALMOST_4G - old_size,
NTDB_LOCK_WAIT, false) == NTDB_SUCCESS);
/* Now add a little record past the 4G barrier. */
- ok1(ntdb_expand_file(ntdb, 100) == NTDB_SUCCESS);
- ok1(add_free_record(ntdb, 0xFFFFFFF0, 100, NTDB_LOCK_WAIT, false)
+ ok1(ntdb_expand_file(ntdb, A_LITTLE_BIT) == NTDB_SUCCESS);
+ ok1(add_free_record(ntdb, ALMOST_4G, A_LITTLE_BIT,
+ NTDB_LOCK_WAIT, false)
== NTDB_SUCCESS);
ok1(ntdb_check(ntdb, NULL, NULL) == NTDB_SUCCESS);
@@ -52,7 +58,7 @@ int main(int argc, char *argv[])
/* Make sure it put it at end as we expected. */
off = find_and_lock(ntdb, k, F_RDLCK, &h, &rec, NULL);
- ok1(off >= 0xFFFFFFF0);
+ ok1(off >= ALMOST_4G);
ntdb_unlock_hashes(ntdb, h.hlock_start, h.hlock_range, F_RDLCK);
ok1(ntdb_fetch(ntdb, k, &d) == 0);