X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb2%2Fsummary.c;h=42b1163e8b3fe25fc007e2b15d741fc0f5afa898;hp=97052608fc866735156ab5938bf827ea8f653242;hb=115648946c7a78e87fb45eac6c1759a347d4c7f8;hpb=ec88af5dd11a003beb8cd3fbe420f9d5e5dcf5d9 diff --git a/ccan/tdb2/summary.c b/ccan/tdb2/summary.c index 97052608..42b1163e 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) { - len = p->f.data_len; + } 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); @@ -159,7 +164,8 @@ char *tdb_summary(struct tdb_context *tdb, enum tdb_summary_flags flags) buckets = tally_new(HISTO_HEIGHT); if (!flists || !hashes || !freet || !keys || !data || !extra || !uncoal || !buckets) { - tdb->ecode = TDB_ERR_OOM; + tdb_logerr(tdb, TDB_ERR_OOM, TDB_DEBUG_ERROR, + "tdb_summary: failed to allocate tally structures"); goto unlock; }