diff options
-rw-r--r-- | lib/tdb/common/check.c | 22 |
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; } |