diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2012-06-18 22:30:29 +0930 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2012-06-19 05:38:06 +0200 |
commit | db2508840d55842ebaf0c0d7a2fa3c855498e75f (patch) | |
tree | 6123390e0616ed98eb173422e94e8c5c0e862459 /lib/ntdb/test/run-expand-in-transaction.c | |
parent | 9396757676c304398a3e94ad01f2657e667b113c (diff) | |
download | samba-db2508840d55842ebaf0c0d7a2fa3c855498e75f.tar.gz samba-db2508840d55842ebaf0c0d7a2fa3c855498e75f.tar.bz2 samba-db2508840d55842ebaf0c0d7a2fa3c855498e75f.zip |
ntdb: create initial database to be multiple of NTDB_PGSIZE.
As copied from tdb1, there is logic in the transaction code to handle
a non-PGSIZE multiple db, but in fact this only happens for a
completely unused database: as soon as we add anything to it, it is
expanded to a NTDB_PGSIZE multiple.
If we create the database with a free record which pads it out to
NTDB_PGSIZE, we can remove this last-page-is-different logic.
Of course, the fake ntdbs we create in our tests now also need to be
multiples of NTDB_PGSIZE, so we change some numbers there too.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'lib/ntdb/test/run-expand-in-transaction.c')
-rw-r--r-- | lib/ntdb/test/run-expand-in-transaction.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/ntdb/test/run-expand-in-transaction.c b/lib/ntdb/test/run-expand-in-transaction.c index dadbec7922..54f9d81dec 100644 --- a/lib/ntdb/test/run-expand-in-transaction.c +++ b/lib/ntdb/test/run-expand-in-transaction.c @@ -11,10 +11,11 @@ int main(int argc, char *argv[]) NTDB_DATA key = ntdb_mkdata("key", 3); NTDB_DATA data = ntdb_mkdata("data", 4); - plan_tests(sizeof(flags) / sizeof(flags[0]) * 7 + 1); + plan_tests(sizeof(flags) / sizeof(flags[0]) * 9 + 1); for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) { size_t size; + NTDB_DATA k, d; ntdb = ntdb_open("run-expand-in-transaction.ntdb", flags[i], O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr); ok1(ntdb); @@ -22,6 +23,14 @@ int main(int argc, char *argv[]) continue; size = ntdb->file->map_size; + /* Add a fake record to chew up the existing free space. */ + k = ntdb_mkdata("fake", 4); + d.dsize = ntdb->file->map_size - sizeof(struct new_database)- 8; + d.dptr = malloc(d.dsize); + memset(d.dptr, 0, d.dsize); + ok1(ntdb_store(ntdb, k, d, NTDB_INSERT) == 0); + ok1(ntdb->file->map_size == size); + free(d.dptr); ok1(ntdb_transaction_start(ntdb) == 0); ok1(ntdb_store(ntdb, key, data, NTDB_INSERT) == 0); ok1(ntdb->file->map_size > size); |