X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb2%2Fcheck.c;h=f8abfc1fad4e30f20829e96cb6e557e0630efc45;hp=f005a48de317ee80890e7b0d187948c49e8c46be;hb=453d3fe2bdec8e430b85f4cd595a9ad2f8ebcbb3;hpb=39f01834db9b6a21d076e67d1e3143ab99aaf43e diff --git a/ccan/tdb2/check.c b/ccan/tdb2/check.c index f005a48d..f8abfc1f 100644 --- a/ccan/tdb2/check.c +++ b/ccan/tdb2/check.c @@ -71,8 +71,8 @@ static bool check_header(struct tdb_context *tdb) < tdb->map_size) { tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv, "check: %llu zones size %llu don't cover %llu\n", - (long long)(1ULL << tdb->header.v.zone_bits), (long long)tdb->header.v.num_zones, + (long long)(1ULL << tdb->header.v.zone_bits), (long long)tdb->map_size); return false; } @@ -86,8 +86,8 @@ static bool check_header(struct tdb_context *tdb) static int off_cmp(const tdb_off_t *a, const tdb_off_t *b) { /* Can overflow an int. */ - return a > b ? 1 - : a < b ? -1 + return *a > *b ? 1 + : *a < *b ? -1 : 0; } @@ -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; }