X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb2%2Ftdb1_summary.c;h=b74b8f4474b87d8185aadde606f0635294cf2277;hp=a2d2ae8f2fdbb31884e1dc08750d85680855335a;hb=926996e88c32445c874ff9c4f47f159db6b45995;hpb=39f55294799c6443c0ad7bef09f1c113cf89d295 diff --git a/ccan/tdb2/tdb1_summary.c b/ccan/tdb2/tdb1_summary.c index a2d2ae8f..b74b8f44 100644 --- a/ccan/tdb2/tdb1_summary.c +++ b/ccan/tdb2/tdb1_summary.c @@ -65,7 +65,7 @@ static size_t tally1_mean(const struct tally *tally) return tally->total / tally->num; } -static size_t get_hash_length(struct tdb1_context *tdb, unsigned int i) +static size_t get_hash_length(struct tdb_context *tdb, unsigned int i) { tdb1_off_t rec_ptr; size_t count = 0; @@ -84,7 +84,7 @@ static size_t get_hash_length(struct tdb1_context *tdb, unsigned int i) return count; } -char *tdb1_summary(struct tdb1_context *tdb) +char *tdb1_summary(struct tdb_context *tdb) { tdb1_off_t off, rec_off; struct tally freet, keys, data, dead, extra, hash, uncoal; @@ -94,17 +94,16 @@ char *tdb1_summary(struct tdb1_context *tdb) size_t len, unc = 0; struct tdb1_record recovery; - /* Read-only databases use no locking at all: it's best-effort. - * We may have a write lock already, so skip that case too. */ - if (tdb->read_only || tdb->allrecord_lock.count != 0) { + /* We may have a write lock already, so don't lock. */ + if (tdb->file->allrecord_lock.count != 0) { locked = false; } else { - if (tdb1_lockall_read(tdb) == -1) + if (tdb_lockall_read(tdb) != TDB_SUCCESS) return NULL; locked = true; } - if (tdb1_recovery_area(tdb, tdb->methods, &rec_off, &recovery) != 0) { + if (tdb1_recovery_area(tdb, tdb->tdb1.io, &rec_off, &recovery) != 0) { goto unlock; } @@ -116,10 +115,10 @@ char *tdb1_summary(struct tdb1_context *tdb) tally1_init(&hash); tally1_init(&uncoal); - for (off = TDB1_DATA_START(tdb->header.hash_size); - off < tdb->map_size - 1; + for (off = TDB1_DATA_START(tdb->tdb1.header.hash_size); + off < tdb->file->map_size - 1; off += sizeof(rec) + rec.rec_len) { - if (tdb->methods->tdb1_read(tdb, off, &rec, sizeof(rec), + if (tdb->tdb1.io->tdb1_read(tdb, off, &rec, sizeof(rec), TDB1_DOCONV()) == -1) goto unlock; switch (rec.magic) { @@ -150,16 +149,18 @@ char *tdb1_summary(struct tdb1_context *tdb) tally1_add(&dead, rec.rec_len); break; default: - TDB1_LOG((tdb, TDB1_DEBUG_ERROR, - "Unexpected record magic 0x%x at offset %d\n", - rec.magic, off)); + tdb->last_error = tdb_logerr(tdb, TDB_ERR_CORRUPT, + TDB_LOG_ERROR, + "Unexpected record magic 0x%x" + " at offset %d", + rec.magic, off); goto unlock; } } if (unc > 1) tally1_add(&uncoal, unc - 1); - for (off = 0; off < tdb->header.hash_size; off++) + for (off = 0; off < tdb->tdb1.header.hash_size; off++) tally1_add(&hash, get_hash_length(tdb, off)); /* 20 is max length of a %zu. */ @@ -169,7 +170,7 @@ char *tdb1_summary(struct tdb1_context *tdb) goto unlock; snprintf(ret, len, SUMMARY_FORMAT1, - tdb->map_size, keys.total+data.total, + (tdb1_len_t)tdb->file->map_size, keys.total+data.total, keys.num, keys.min, tally1_mean(&keys), keys.max, data.min, tally1_mean(&data), data.max, @@ -182,20 +183,20 @@ char *tdb1_summary(struct tdb1_context *tdb) hash.min, tally1_mean(&hash), hash.max, uncoal.total, uncoal.min, tally1_mean(&uncoal), uncoal.max, - keys.total * 100.0 / tdb->map_size, - data.total * 100.0 / tdb->map_size, - extra.total * 100.0 / tdb->map_size, - freet.total * 100.0 / tdb->map_size, - dead.total * 100.0 / tdb->map_size, + keys.total * 100.0 / tdb->file->map_size, + data.total * 100.0 / tdb->file->map_size, + extra.total * 100.0 / tdb->file->map_size, + freet.total * 100.0 / tdb->file->map_size, + dead.total * 100.0 / tdb->file->map_size, (keys.num + freet.num + dead.num) * (sizeof(struct tdb1_record) + sizeof(uint32_t)) - * 100.0 / tdb->map_size, - tdb->header.hash_size * sizeof(tdb1_off_t) - * 100.0 / tdb->map_size); + * 100.0 / tdb->file->map_size, + tdb->tdb1.header.hash_size * sizeof(tdb1_off_t) + * 100.0 / (tdb1_len_t)tdb->file->map_size); unlock: if (locked) { - tdb1_unlockall_read(tdb); + tdb_unlockall_read(tdb); } return ret; }