From 0a34f342c3facace0767ff08f05532c9f161e305 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 22 Jun 2012 09:44:40 +0930 Subject: ntdb: enhancement to allow direct access to the ntdb map during expansion. This means keeping the old mmap around when we expand the database. We could revert to read/write, except for platforms with incoherent mmap (ie. OpenBSD), where we need to use mmap for all accesses. Thus we keep a linked list of old maps, and unmap them when the last access finally goes away. This is required if we want ntdb_parse_record() callbacks to be able to expand the database. Signed-off-by: Rusty Russell --- lib/ntdb/private.h | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'lib/ntdb/private.h') diff --git a/lib/ntdb/private.h b/lib/ntdb/private.h index 90b782d303..5efd2e0d92 100644 --- a/lib/ntdb/private.h +++ b/lib/ntdb/private.h @@ -301,6 +301,14 @@ struct ntdb_access_hdr { bool convert; }; +/* mmaps we are keeping around because they are still direct accessed */ +struct ntdb_old_mmap { + struct ntdb_old_mmap *next; + + void *map_ptr; + ntdb_len_t map_size; +}; + struct ntdb_file { /* How many are sharing us? */ unsigned int refcnt; @@ -314,6 +322,12 @@ struct ntdb_file { /* The file descriptor (-1 for NTDB_INTERNAL). */ int fd; + /* How many are accessing directly? */ + unsigned int direct_count; + + /* Old maps, still direct accessed. */ + struct ntdb_old_mmap *old_mmaps; + /* Lock information */ pid_t locker; struct ntdb_lock allrecord_lock; @@ -429,7 +443,7 @@ void ntdb_io_init(struct ntdb_context *ntdb); void *ntdb_convert(const struct ntdb_context *ntdb, void *buf, ntdb_len_t size); /* Unmap and try to map the ntdb. */ -void ntdb_munmap(struct ntdb_file *file); +enum NTDB_ERROR ntdb_munmap(struct ntdb_context *ntdb); enum NTDB_ERROR ntdb_mmap(struct ntdb_context *ntdb); /* Either alloc a copy, or give direct access. Release frees or noop. */ @@ -576,9 +590,6 @@ struct ntdb_context { enum NTDB_ERROR (*openhook)(int fd, void *data); void *openhook_data; - /* Are we accessing directly? (debugging check). */ - int direct_access; - /* Set if we are in a transaction. */ struct ntdb_transaction *transaction; -- cgit