X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Ftdb%2Fcheck.c;fp=ccan%2Ftdb%2Fcheck.c;h=a9a9ece0da37c01eb87c0dbf3e4ac6ee05250d07;hb=ba2cc03f0648101ca0be687ae70947e7ae331f4c;hp=c5469e9998122dc57eefcdb90ddb747cb99d684d;hpb=550246bb457561fb8bffe909c54467090a11011a;p=ccan diff --git a/ccan/tdb/check.c b/ccan/tdb/check.c index c5469e99..a9a9ece0 100644 --- a/ccan/tdb/check.c +++ b/ccan/tdb/check.c @@ -327,9 +327,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); @@ -444,12 +452,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; }