X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb2%2Fsummary.c;h=b54b56e7a712239a74efa87de8a6bde0cce023dc;hp=c04fa76f945b809a701b77f1df428dc9b693b76b;hb=96b169e986cda1de9ffbbdc98042e1099515ca34;hpb=afc3c1e723b4eca0b32f7c5b656f5b070eb1c9fb diff --git a/ccan/tdb2/summary.c b/ccan/tdb2/summary.c index c04fa76f..b54b56e7 100644 --- a/ccan/tdb2/summary.c +++ b/ccan/tdb2/summary.c @@ -50,25 +50,29 @@ static bool summarize(struct tdb_context *tdb, tdb_len_t unc = 0; for (off = sizeof(struct tdb_header); off < tdb->map_size; off += len) { - union { + const union { struct tdb_used_record u; struct tdb_free_record f; struct tdb_recovery_record r; - } pad, *p; + } *p; /* We might not be able to get the whole thing. */ - p = tdb_get(tdb, off, &pad, sizeof(p->f)); + p = tdb_access_read(tdb, off, sizeof(p->f), true); if (!p) return false; if (p->r.magic == TDB_RECOVERY_INVALID_MAGIC || p->r.magic == TDB_RECOVERY_MAGIC) { + if (unc) { + tally_add(uncoal, unc); + unc = 0; + } len = sizeof(p->r) + p->r.max_len; - } else if (rec_magic(&p->u) != TDB_MAGIC) { + } else if (frec_magic(&p->f) == TDB_FREE_MAGIC) { len = frec_len(&p->f); tally_add(free, len); tally_add(buckets, size_to_bucket(len)); len += sizeof(p->u); unc++; - } else if (frec_magic(&p->f) == TDB_FREE_MAGIC) { + } else if (rec_magic(&p->u) == TDB_MAGIC) { if (unc) { tally_add(uncoal, unc); unc = 0; @@ -98,6 +102,7 @@ static bool summarize(struct tdb_context *tdb, tally_add(extra, rec_extra_padding(&p->u)); } else len = dead_space(tdb, off); + tdb_access_release(tdb, p); } if (unc) tally_add(uncoal, unc);