From 82e5644c9dbf5c2e4b0c4183372e0a79203d32a5 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 13 Sep 2010 19:58:23 +0930 Subject: 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 --- lib/tdb/common/check.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'lib/tdb/common') 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; } -- cgit