X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb2%2Fsummary.c;h=42b1163e8b3fe25fc007e2b15d741fc0f5afa898;hp=dd6fa399e7e6cc38f9419e0ea96b73ac18df420a;hb=4e185ad8ab5a7e01edbbe12d11eb2f1577de7e8b;hpb=d70577b6aff24ccf6815896509dabb8c9ac07904 diff --git a/ccan/tdb2/summary.c b/ccan/tdb2/summary.c index dd6fa399..42b1163e 100644 --- a/ccan/tdb2/summary.c +++ b/ccan/tdb2/summary.c @@ -50,20 +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; - } pad, *p; - p = tdb_get(tdb, off, &pad, sizeof(pad)); + struct tdb_recovery_record r; + } *p; + /* We might not be able to get the whole thing. */ + p = tdb_access_read(tdb, off, sizeof(p->f), true); if (!p) return false; - if (rec_magic(&p->u) != TDB_MAGIC) { - len = p->f.data_len; + 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 (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 { + } else if (rec_magic(&p->u) == TDB_MAGIC) { if (unc) { tally_add(uncoal, unc); unc = 0; @@ -91,7 +100,9 @@ static bool summarize(struct tdb_context *tdb, tally_add(data, rec_data_length(&p->u)); } 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); @@ -153,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; }