Commit 6b7c3c84 authored by Rusty Russell's avatar Rusty Russell

tdb2: save open_flags instead of mmap_flags.

It's more consistent with what tdb1 does, and slightly more encapsulated.
parent 6e3d9e8a
...@@ -42,16 +42,23 @@ void tdb_munmap(struct tdb_file *file) ...@@ -42,16 +42,23 @@ void tdb_munmap(struct tdb_file *file)
void tdb_mmap(struct tdb_context *tdb) void tdb_mmap(struct tdb_context *tdb)
{ {
int mmap_flags;
if (tdb->flags & TDB_INTERNAL) if (tdb->flags & TDB_INTERNAL)
return; return;
if (tdb->flags & TDB_NOMMAP) if (tdb->flags & TDB_NOMMAP)
return; return;
if ((tdb->open_flags & O_ACCMODE) == O_RDONLY)
mmap_flags = PROT_READ;
else
mmap_flags = PROT_READ | PROT_WRITE;
/* size_t can be smaller than off_t. */ /* size_t can be smaller than off_t. */
if ((size_t)tdb->file->map_size == tdb->file->map_size) { if ((size_t)tdb->file->map_size == tdb->file->map_size) {
tdb->file->map_ptr = mmap(NULL, tdb->file->map_size, tdb->file->map_ptr = mmap(NULL, tdb->file->map_size,
tdb->mmap_flags, mmap_flags,
MAP_SHARED, tdb->file->fd, 0); MAP_SHARED, tdb->file->fd, 0);
} else } else
tdb->file->map_ptr = MAP_FAILED; tdb->file->map_ptr = MAP_FAILED;
......
...@@ -369,6 +369,7 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags, ...@@ -369,6 +369,7 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags,
tdb->log_fn = NULL; tdb->log_fn = NULL;
tdb->transaction = NULL; tdb->transaction = NULL;
tdb->access = NULL; tdb->access = NULL;
tdb->open_flags = open_flags;
tdb->last_error = TDB_SUCCESS; tdb->last_error = TDB_SUCCESS;
tdb->file = NULL; tdb->file = NULL;
tdb->lock_fn = tdb_fcntl_lock; tdb->lock_fn = tdb_fcntl_lock;
...@@ -416,11 +417,9 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags, ...@@ -416,11 +417,9 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags,
if ((open_flags & O_ACCMODE) == O_RDONLY) { if ((open_flags & O_ACCMODE) == O_RDONLY) {
tdb->read_only = true; tdb->read_only = true;
tdb->mmap_flags = PROT_READ;
openlock = F_RDLCK; openlock = F_RDLCK;
} else { } else {
tdb->read_only = false; tdb->read_only = false;
tdb->mmap_flags = PROT_READ | PROT_WRITE;
openlock = F_WRLCK; openlock = F_WRLCK;
} }
......
...@@ -334,8 +334,8 @@ struct tdb_context { ...@@ -334,8 +334,8 @@ struct tdb_context {
/* Operating read-only? (Opened O_RDONLY, or in traverse_read) */ /* Operating read-only? (Opened O_RDONLY, or in traverse_read) */
bool read_only; bool read_only;
/* mmap read only? */ /* Open flags passed to tdb_open. */
int mmap_flags; int open_flags;
/* the flags passed to tdb_open, for tdb_reopen. */ /* the flags passed to tdb_open, for tdb_reopen. */
uint32_t flags; uint32_t flags;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment