summaryrefslogtreecommitdiff
path: root/lib/tdb/common
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2010-09-13 19:58:23 +0930
committerRusty Russell <rusty@rustcorp.com.au>2010-09-13 19:58:23 +0930
commit82e5644c9dbf5c2e4b0c4183372e0a79203d32a5 (patch)
treea5a6222bc9ba7da944650b7858a423b8037d50b4 /lib/tdb/common
parent9e0deff904877068d19b41e965732f145c2554b9 (diff)
downloadsamba-82e5644c9dbf5c2e4b0c4183372e0a79203d32a5.tar.gz
samba-82e5644c9dbf5c2e4b0c4183372e0a79203d32a5.tar.bz2
samba-82e5644c9dbf5c2e4b0c4183372e0a79203d32a5.zip
tdb: fix tdb_check() on read-only TDBs to actually work.
Commit bc1c82ea137 "Fix tdb_check() to work with read-only tdb databases." claimed to do this, but tdb_lockall_read() fails on read-only databases. Also make sure we can still do tdb_check() inside a transaction (weird, but we previously allowed it so don't break the API). Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'lib/tdb/common')
-rw-r--r--lib/tdb/common/check.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/lib/tdb/common/check.c b/lib/tdb/common/check.c
index 3be8a0c48b..3ac2eb5105 100644
--- a/lib/tdb/common/check.c
+++ b/lib/tdb/common/check.c
@@ -326,9 +326,17 @@ int tdb_check(struct tdb_context *tdb,
struct tdb_record rec;
bool found_recovery = false;
tdb_len_t dead;
-
- if (tdb_lockall_read(tdb) == -1)
- return -1;
+ bool locked;
+
+ /* Read-only databases use no locking at all: it's best-effort.
+ * We may have a write lock already, so skip that case too. */
+ if (tdb->read_only || tdb->allrecord_lock.count != 0) {
+ locked = false;
+ } else {
+ if (tdb_lockall_read(tdb) == -1)
+ return -1;
+ locked = true;
+ }
/* Make sure we know true size of the underlying file. */
tdb->methods->tdb_oob(tdb, tdb->map_size + 1, 1);
@@ -443,12 +451,16 @@ int tdb_check(struct tdb_context *tdb,
}
free(hashes);
- tdb_unlockall_read(tdb);
+ if (locked) {
+ tdb_unlockall_read(tdb);
+ }
return 0;
free:
free(hashes);
unlock:
- tdb_unlockall_read(tdb);
+ if (locked) {
+ tdb_unlockall_read(tdb);
+ }
return -1;
}