X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb2%2Fcheck.c;h=e39e50837d31c92de88de9efe85d574fdfc8af2e;hp=f005a48de317ee80890e7b0d187948c49e8c46be;hb=ebdd6451e2d7aa185e62a59fa2c72ffe36772d9a;hpb=142afe327024262a0eaa0731bcf31def91c146e0 diff --git a/ccan/tdb2/check.c b/ccan/tdb2/check.c index f005a48d..e39e5083 100644 --- a/ccan/tdb2/check.c +++ b/ccan/tdb2/check.c @@ -187,7 +187,8 @@ static bool check_hash_list(struct tdb_context *tdb, num_nonzero++; } - if (num_found != num_used) { + /* free table and hash table are two of the used blocks. */ + if (num_found != num_used - 2) { tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv, "tdb_check: Not all entries are in hash\n"); return false; @@ -322,11 +323,10 @@ int tdb_check(struct tdb_context *tdb, size_t num_free = 0, num_used = 0; bool hash_found = false, free_found = false; + /* This always ensures the header is uptodate. */ if (tdb_allrecord_lock(tdb, F_RDLCK, TDB_LOCK_WAIT, false) != 0) return -1; - update_header(tdb); - if (!check_header(tdb)) goto fail; @@ -403,9 +403,9 @@ int tdb_check(struct tdb_context *tdb, goto fail; tdb_allrecord_unlock(tdb, F_RDLCK); - return true; + return 0; fail: tdb_allrecord_unlock(tdb, F_RDLCK); - return false; + return -1; }