summaryrefslogtreecommitdiff
path: root/source4/lib/tdb/common
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2008-01-18 15:45:22 +1100
committerAndrew Tridgell <tridge@samba.org>2008-01-18 15:45:22 +1100
commit61a015a786c52008f4471e62750ad93507bce518 (patch)
tree2942464148744495584b3495f4d325abc3a5d758 /source4/lib/tdb/common
parent524d280ad09c99bcbf63d789e909afdf7edb5860 (diff)
downloadsamba-61a015a786c52008f4471e62750ad93507bce518.tar.gz
samba-61a015a786c52008f4471e62750ad93507bce518.tar.bz2
samba-61a015a786c52008f4471e62750ad93507bce518.zip
merged changes from v3-2-test
(This used to be commit 7077df3e2e3f171532f6a5ac87d45201736c9c11)
Diffstat (limited to 'source4/lib/tdb/common')
-rw-r--r--source4/lib/tdb/common/open.c6
-rw-r--r--source4/lib/tdb/common/tdb.c42
-rw-r--r--source4/lib/tdb/common/tdb_private.h1
-rw-r--r--source4/lib/tdb/common/transaction.c7
-rw-r--r--source4/lib/tdb/common/traverse.c3
5 files changed, 11 insertions, 48 deletions
diff --git a/source4/lib/tdb/common/open.c b/source4/lib/tdb/common/open.c
index 6bd8fda2bf..b19e4cea29 100644
--- a/source4/lib/tdb/common/open.c
+++ b/source4/lib/tdb/common/open.c
@@ -179,9 +179,7 @@ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
tdb->page_size = 0x2000;
}
- if (open_flags & TDB_VOLATILE) {
- tdb->max_dead_records = 5;
- }
+ tdb->max_dead_records = (tdb_flags & TDB_VOLATILE) ? 5 : 0;
if ((open_flags & O_ACCMODE) == O_WRONLY) {
TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: can't open tdb %s write-only\n",
@@ -229,6 +227,7 @@ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
/* we need to zero database if we are the only one with it open */
if ((tdb_flags & TDB_CLEAR_IF_FIRST) &&
+ (!tdb->read_only) &&
(locked = (tdb->methods->tdb_brlock(tdb, ACTIVE_LOCK, F_WRLCK, F_SETLK, 0, 1) == 0))) {
open_flags |= O_CREAT;
if (ftruncate(tdb->fd, 0) == -1) {
@@ -288,7 +287,6 @@ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
tdb->map_size = st.st_size;
tdb->device = st.st_dev;
tdb->inode = st.st_ino;
- tdb->max_dead_records = 0;
tdb_mmap(tdb);
if (locked) {
if (tdb->methods->tdb_brlock(tdb, ACTIVE_LOCK, F_UNLCK, F_SETLK, 0, 1) == -1) {
diff --git a/source4/lib/tdb/common/tdb.c b/source4/lib/tdb/common/tdb.c
index fd4e1cc8af..ea5d9ccc60 100644
--- a/source4/lib/tdb/common/tdb.c
+++ b/source4/lib/tdb/common/tdb.c
@@ -743,45 +743,3 @@ failed:
tdb_unlockall(tdb);
return -1;
}
-
-
-/*
- validate the integrity of all tdb hash chains. Useful when debugging
- */
-int tdb_validate(struct tdb_context *tdb)
-{
- int h;
- for (h=-1;h<(int)tdb->header.hash_size;h++) {
- tdb_off_t rec_ptr;
- uint32_t count = 0;
- if (tdb_ofs_read(tdb, TDB_HASH_TOP(h), &rec_ptr) == -1) {
- TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_validate: failed ofs_read at top of hash %d\n", h));
- return -1;
- }
- while (rec_ptr) {
- struct list_struct r;
- tdb_off_t size;
-
- if (tdb_rec_read(tdb, rec_ptr, &r) == -1) {
- TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_validate: failed rec_read h=%d rec_ptr=%u count=%u\n",
- h, rec_ptr, count));
- return -1;
- }
- if (tdb_ofs_read(tdb, rec_ptr + sizeof(r) + r.rec_len - sizeof(tdb_off_t), &size) == -1) {
- TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_validate: failed ofs_read h=%d rec_ptr=%u count=%u\n",
- h, rec_ptr, count));
- return -1;
- }
- if (size != r.rec_len + sizeof(r)) {
- TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_validate: failed size check size=%u h=%d rec_ptr=%u count=%u\n",
- size, h, rec_ptr, count));
- return -1;
- }
- rec_ptr = r.next;
- count++;
- }
- }
- return 0;
-}
-
-
diff --git a/source4/lib/tdb/common/tdb_private.h b/source4/lib/tdb/common/tdb_private.h
index 0d3f10582e..ffac89ff0e 100644
--- a/source4/lib/tdb/common/tdb_private.h
+++ b/source4/lib/tdb/common/tdb_private.h
@@ -177,6 +177,7 @@ struct tdb_context {
int tdb_munmap(struct tdb_context *tdb);
void tdb_mmap(struct tdb_context *tdb);
int tdb_lock(struct tdb_context *tdb, int list, int ltype);
+int tdb_lock_nonblock(struct tdb_context *tdb, int list, int ltype);
int tdb_unlock(struct tdb_context *tdb, int list, int ltype);
int tdb_brlock(struct tdb_context *tdb, tdb_off_t offset, int rw_type, int lck_type, int probe, size_t len);
int tdb_transaction_lock(struct tdb_context *tdb, int ltype);
diff --git a/source4/lib/tdb/common/transaction.c b/source4/lib/tdb/common/transaction.c
index ea0e3a93f3..c3e7a4e2c0 100644
--- a/source4/lib/tdb/common/transaction.c
+++ b/source4/lib/tdb/common/transaction.c
@@ -219,9 +219,12 @@ static int transaction_write(struct tdb_context *tdb, tdb_off_t off,
uint8_t **new_blocks;
/* expand the blocks array */
if (tdb->transaction->blocks == NULL) {
- new_blocks = malloc((blk+1)*sizeof(uint8_t *));
+ new_blocks = (uint8_t **)malloc(
+ (blk+1)*sizeof(uint8_t *));
} else {
- new_blocks = realloc(tdb->transaction->blocks, (blk+1)*sizeof(uint8_t *));
+ new_blocks = (uint8_t **)realloc(
+ tdb->transaction->blocks,
+ (blk+1)*sizeof(uint8_t *));
}
if (new_blocks == NULL) {
tdb->ecode = TDB_ERR_OOM;
diff --git a/source4/lib/tdb/common/traverse.c b/source4/lib/tdb/common/traverse.c
index 2bde1270a0..07b0c23858 100644
--- a/source4/lib/tdb/common/traverse.c
+++ b/source4/lib/tdb/common/traverse.c
@@ -223,6 +223,9 @@ int tdb_traverse_read(struct tdb_context *tdb,
/*
a write style traverse - needs to get the transaction lock to
prevent deadlocks
+
+ WARNING: The data buffer given to the callback fn does NOT meet the
+ alignment restrictions malloc gives you.
*/
int tdb_traverse(struct tdb_context *tdb,
tdb_traverse_func fn, void *private_data)