X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb%2Fcheck.c;h=53fb286613a3e829e8f2aa159109124c3e182503;hp=c5469e9998122dc57eefcdb90ddb747cb99d684d;hb=a1ace0cd114e0c588d6ce1b9e7386af11716e0bd;hpb=550246bb457561fb8bffe909c54467090a11011a;ds=sidebyside diff --git a/ccan/tdb/check.c b/ccan/tdb/check.c index c5469e99..53fb2866 100644 --- a/ccan/tdb/check.c +++ b/ccan/tdb/check.c @@ -30,7 +30,7 @@ static bool tdb_check_header(struct tdb_context *tdb, tdb_off_t *recovery) { struct tdb_header hdr; - if (tdb->methods->tdb_read(tdb, 0, &hdr, sizeof(hdr), DOCONV()) == -1) + if (tdb->methods->tdb_read(tdb, 0, &hdr, sizeof(hdr), 0) == -1) return false; if (strcmp(hdr.magic_food, TDB_MAGIC_FOOD) != 0) goto corrupt; @@ -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; }