r10465: separate out a read_only db from a read-only traversal to ensure we
authorAndrew Tridgell <tridge@samba.org>
Sat, 24 Sep 2005 03:43:02 +0000 (03:43 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:38:49 +0000 (13:38 -0500)
don't end up doing a mmap read only

source/lib/tdb/common/io.c
source/lib/tdb/common/lock.c
source/lib/tdb/common/tdb.c
source/lib/tdb/common/tdb_private.h
source/lib/tdb/common/transaction.c
source/lib/tdb/common/traverse.c

index c1f6f55bc48a086aacd1a1bb930090a16e6ffa4b..a276a8c291af695ca97f65966e24650ff2d1808c 100644 (file)
@@ -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;
        }
index 7a76bd3d9b3a3f034fe07a6a3dcad08e59404d96..703cfe9dc5f79e3a5fbf574c452afec14ec46214 100644 (file)
@@ -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))
index 2e229e88ccb1d56da6cbc179c9dabeb8edf15630..4b0d4a31c5d93bed8b7157d286e2022c4b7f9488 100644 (file)
@@ -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;
        }
index 9eeaea4cb08ec8ac11b6d8ae61ff4c37ed73827e..2b2d6de4112d52a56a935afcc854e06b68cba620 100644 (file)
@@ -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 */
index 5f281ca4dafc0b32cdd7d6de104dd9868e3e969b..a01f8307e9d42fa0d094537c1f8ba4c85b7f9721 100644 (file)
@@ -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;
index f8315f5770e71860af48a4866f5a8d8d88833545..9271b75aa81512948d0b01f72e8a745b6c0662cd 100644 (file)
@@ -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);
        }