summaryrefslogtreecommitdiff
path: root/lib/ntdb/free.c
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/free.c
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/free.c')
-rw-r--r--lib/ntdb/free.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/ntdb/free.c b/lib/ntdb/free.c
index 0fe6c73775..f51aa5bc33 100644
--- a/lib/ntdb/free.c
+++ b/lib/ntdb/free.c
@@ -899,9 +899,14 @@ ntdb_off_t ntdb_expand_adjust(ntdb_off_t map_size, ntdb_off_t size)
new_size = map_size * 1.25;
}
- /* Round the database up to a multiple of the page size */
if (new_size < top_size)
new_size = top_size;
+
+ /* We always make the file a multiple of transaction page
+ * size. This guarantees that the transaction recovery area
+ * is always aligned, otherwise the transaction code can overwrite
+ * itself. */
+ new_size = (new_size + NTDB_PGSIZE-1) & ~(NTDB_PGSIZE-1);
return new_size - map_size;
}
@@ -933,10 +938,10 @@ static enum NTDB_ERROR ntdb_expand(struct ntdb_context *ntdb, ntdb_len_t size)
return NTDB_SUCCESS;
}
+ /* We need room for the record header too. */
+ size = adjust_size(0, sizeof(struct ntdb_used_record) + size);
/* Overallocate. */
wanted = ntdb_expand_adjust(old_size, size);
- /* We need room for the record header too. */
- wanted = adjust_size(0, sizeof(struct ntdb_used_record) + wanted);
ecode = ntdb->io->expand_file(ntdb, wanted);
if (ecode != NTDB_SUCCESS) {