summaryrefslogtreecommitdiff
path: root/source4/lib/tdb/common
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-09-24 03:43:02 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:38:49 -0500
commit5860aef9cd53da572bef1b86a62a3a5e86da84b0 (patch)
treeceef07b8fdd5763db9077d157351f5bc58a3d761 /source4/lib/tdb/common
parent5a770bf72061e6b57f88e28fc585ff3c015ace49 (diff)
downloadsamba-5860aef9cd53da572bef1b86a62a3a5e86da84b0.tar.gz
samba-5860aef9cd53da572bef1b86a62a3a5e86da84b0.tar.bz2
samba-5860aef9cd53da572bef1b86a62a3a5e86da84b0.zip
r10465: separate out a read_only db from a read-only traversal to ensure we
don't end up doing a mmap read only (This used to be commit 294ccfd46a0c4e1af9365d028acdabec03c41ad3)
Diffstat (limited to 'source4/lib/tdb/common')
-rw-r--r--source4/lib/tdb/common/io.c4
-rw-r--r--source4/lib/tdb/common/lock.c4
-rw-r--r--source4/lib/tdb/common/tdb.c4
-rw-r--r--source4/lib/tdb/common/tdb_private.h1
-rw-r--r--source4/lib/tdb/common/transaction.c2
-rw-r--r--source4/lib/tdb/common/traverse.c10
6 files changed, 13 insertions, 12 deletions
diff --git a/source4/lib/tdb/common/io.c b/source4/lib/tdb/common/io.c
index c1f6f55bc4..a276a8c291 100644
--- a/source4/lib/tdb/common/io.c
+++ b/source4/lib/tdb/common/io.c
@@ -97,7 +97,7 @@ static int tdb_oob(struct tdb_context *tdb, tdb_off_t len, int probe)
static int tdb_write(struct tdb_context *tdb, tdb_off_t off,
const void *buf, tdb_len_t len)
{
- if (tdb->read_only) {
+ if (tdb->read_only || tdb->traverse_read) {
tdb->ecode = TDB_ERR_RDONLY;
return -1;
}
@@ -230,7 +230,7 @@ static int tdb_expand_file(struct tdb_context *tdb, tdb_off_t size, tdb_off_t ad
{
char buf[1024];
- if (tdb->read_only) {
+ if (tdb->read_only || tdb->traverse_read) {
tdb->ecode = TDB_ERR_RDONLY;
return -1;
}
diff --git a/source4/lib/tdb/common/lock.c b/source4/lib/tdb/common/lock.c
index 7a76bd3d9b..703cfe9dc5 100644
--- a/source4/lib/tdb/common/lock.c
+++ b/source4/lib/tdb/common/lock.c
@@ -46,7 +46,7 @@ int tdb_brlock_len(struct tdb_context *tdb, tdb_off_t offset,
return 0;
}
- if ((rw_type == F_WRLCK) && (tdb->read_only)) {
+ if ((rw_type == F_WRLCK) && (tdb->read_only || tdb->traverse_read)) {
tdb->ecode = TDB_ERR_RDONLY;
return -1;
}
@@ -161,7 +161,7 @@ int tdb_lockall(struct tdb_context *tdb)
u32 i;
/* There are no locks on read-only dbs */
- if (tdb->read_only)
+ if (tdb->read_only || tdb->traverse_read)
return TDB_ERRCODE(TDB_ERR_LOCK, -1);
for (i = 0; i < tdb->header.hash_size; i++)
if (tdb_lock(tdb, i, F_WRLCK))
diff --git a/source4/lib/tdb/common/tdb.c b/source4/lib/tdb/common/tdb.c
index 2e229e88cc..4b0d4a31c5 100644
--- a/source4/lib/tdb/common/tdb.c
+++ b/source4/lib/tdb/common/tdb.c
@@ -164,7 +164,7 @@ int tdb_do_delete(struct tdb_context *tdb, tdb_off_t rec_ptr, struct list_struct
tdb_off_t last_ptr, i;
struct list_struct lastrec;
- if (tdb->read_only) return -1;
+ if (tdb->read_only || tdb->traverse_read) return -1;
if (tdb_write_lock_record(tdb, rec_ptr) == -1) {
/* Someone traversing here: mark it as dead */
@@ -227,7 +227,7 @@ int tdb_store(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf, int flag)
char *p = NULL;
int ret = 0;
- if (tdb->read_only) {
+ if (tdb->read_only || tdb->traverse_read) {
tdb->ecode = TDB_ERR_RDONLY;
return -1;
}
diff --git a/source4/lib/tdb/common/tdb_private.h b/source4/lib/tdb/common/tdb_private.h
index 9eeaea4cb0..2b2d6de411 100644
--- a/source4/lib/tdb/common/tdb_private.h
+++ b/source4/lib/tdb/common/tdb_private.h
@@ -183,6 +183,7 @@ struct tdb_context {
int fd; /* open file descriptor for the database */
tdb_len_t map_size; /* how much space has been mapped */
int read_only; /* opened read-only */
+ int traverse_read; /* read-only traversal */
struct tdb_lock_type *locked; /* array of chain locks */
enum TDB_ERROR ecode; /* error code for last tdb error */
struct tdb_header header; /* a cached copy of the header */
diff --git a/source4/lib/tdb/common/transaction.c b/source4/lib/tdb/common/transaction.c
index 5f281ca4da..a01f8307e9 100644
--- a/source4/lib/tdb/common/transaction.c
+++ b/source4/lib/tdb/common/transaction.c
@@ -349,7 +349,7 @@ static const struct tdb_methods transaction_methods = {
int tdb_transaction_start(struct tdb_context *tdb)
{
/* some sanity checks */
- if (tdb->read_only || (tdb->flags & TDB_INTERNAL)) {
+ if (tdb->read_only || (tdb->flags & TDB_INTERNAL) || tdb->traverse_read) {
TDB_LOG((tdb, 0, "tdb_transaction_start: cannot start a transaction on a read-only or internal db\n"));
tdb->ecode = TDB_ERR_EINVAL;
return -1;
diff --git a/source4/lib/tdb/common/traverse.c b/source4/lib/tdb/common/traverse.c
index f8315f5770..9271b75aa8 100644
--- a/source4/lib/tdb/common/traverse.c
+++ b/source4/lib/tdb/common/traverse.c
@@ -114,7 +114,7 @@ static int tdb_next_lock(struct tdb_context *tdb, struct tdb_traverse_lock *tloc
/* Try to clean dead ones from old traverses */
current = tlock->off;
tlock->off = rec->next;
- if (!tdb->read_only &&
+ if (!(tdb->read_only || tdb->traverse_read) &&
tdb_do_delete(tdb, current, rec) != 0)
goto fail;
}
@@ -204,10 +204,10 @@ int tdb_traverse_read(struct tdb_context *tdb,
tdb_traverse_func fn, void *private)
{
struct tdb_traverse_lock tl = { NULL, 0, 0, F_RDLCK };
- int ret, read_only = tdb->read_only;
- tdb->read_only = 1;
+ int ret;
+ tdb->traverse_read++;
ret = tdb_traverse_internal(tdb, fn, private, &tl);
- tdb->read_only = read_only;
+ tdb->traverse_read--;
return ret;
}
@@ -221,7 +221,7 @@ int tdb_traverse(struct tdb_context *tdb,
struct tdb_traverse_lock tl = { NULL, 0, 0, F_WRLCK };
int ret;
- if (tdb->read_only) {
+ if (tdb->read_only || tdb->traverse_read) {
return tdb_traverse_read(tdb, fn, private);
}