[PATCHES] improvements to tdbtool info
Michael Adam
obnox at samba.org
Wed Aug 6 09:24:26 MDT 2014
Hi,
attached find three patches to improve precision and correctness
of "tdbtool info" when reporting dead space.
Review/push/comments appreciated.
Thanks - Michael
-------------- next part --------------
From bc2c74e2fa0be67043c76fbd3d52af14ca5a1ca1 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Wed, 6 Aug 2014 17:13:16 +0200
Subject: [PATCH 1/3] tdb: fix calculation of dead space in tdb_dead_space().
Pair-Programmed-With: Stefan Metzmacher <metze at samba.org>
Signed-off-by: Michael Adam <obnox at samba.org>
Signed-off-by: Stefan Metzmacher <metze at samba.org>
---
lib/tdb/common/check.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/tdb/common/check.c b/lib/tdb/common/check.c
index e632af5..d03d94d 100644
--- a/lib/tdb/common/check.c
+++ b/lib/tdb/common/check.c
@@ -316,7 +316,7 @@ size_t tdb_dead_space(struct tdb_context *tdb, tdb_off_t off)
for (len = 0; off + len < tdb->map_size; len++) {
char c;
- if (tdb->methods->tdb_read(tdb, off, &c, 1, 0))
+ if (tdb->methods->tdb_read(tdb, off + len, &c, 1, 0))
return 0;
if (c != 0 && c != 0x42)
break;
--
1.9.1
From 05509a396f9f9ac64fe113e1240c5e8ae95efedf Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Wed, 6 Aug 2014 17:15:46 +0200
Subject: [PATCH 2/3] tdb: in tdbtool info, separately print the size of the
recovery area.
This was previously counted in the "dead records" number and size.
Pair-Programmed-With: Stefan Metzmacher <metze at samba.org>
Signed-off-by: Michael Adam <obnox at samba.org>
Signed-off-by: Stefan Metzmacher <metze at samba.org>
---
lib/tdb/common/summary.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/lib/tdb/common/summary.c b/lib/tdb/common/summary.c
index d786132..4894e52 100644
--- a/lib/tdb/common/summary.c
+++ b/lib/tdb/common/summary.c
@@ -29,6 +29,8 @@
"Smallest/average/largest padding: %zu/%zu/%zu\n" \
"Number of dead records: %zu\n" \
"Smallest/average/largest dead records: %zu/%zu/%zu\n" \
+ "Number of recovery records: %zu\n" \
+ "Smallest/average/largest recovery records: %zu/%zu/%zu\n" \
"Number of free records: %zu\n" \
"Smallest/average/largest free records: %zu/%zu/%zu\n" \
"Number of hash chains: %zu\n" \
@@ -92,7 +94,7 @@ _PUBLIC_ char *tdb_summary(struct tdb_context *tdb)
{
off_t file_size;
tdb_off_t off, rec_off;
- struct tally freet, keys, data, dead, extra, hashval, uncoal;
+ struct tally freet, keys, data, dead, extra, hashval, uncoal, rcvry;
struct tdb_record rec;
char *ret = NULL;
bool locked;
@@ -121,6 +123,7 @@ _PUBLIC_ char *tdb_summary(struct tdb_context *tdb)
tally_init(&extra);
tally_init(&hashval);
tally_init(&uncoal);
+ tally_init(&rcvry);
for (off = TDB_DATA_START(tdb->hash_size);
off < tdb->map_size - 1;
@@ -144,6 +147,14 @@ _PUBLIC_ char *tdb_summary(struct tdb_context *tdb)
break;
/* If we crash after ftruncate, we can get zeroes or fill. */
case TDB_RECOVERY_INVALID_MAGIC:
+ tally_add(&rcvry, rec.rec_len);
+ unc++;
+ /* If it's a valid recovery, we can trust rec_len. */
+ if (off != rec_off) {
+ rec.rec_len = tdb_dead_space(tdb, off)
+ - sizeof(rec);
+ }
+ break;
case 0x42424242:
unc++;
/* If it's a valid recovery, we can trust rec_len. */
@@ -182,6 +193,8 @@ _PUBLIC_ char *tdb_summary(struct tdb_context *tdb)
extra.min, tally_mean(&extra), extra.max,
dead.num,
dead.min, tally_mean(&dead), dead.max,
+ rcvry.num,
+ rcvry.min, tally_mean(&rcvry), rcvry.max,
freet.num,
freet.min, tally_mean(&freet), freet.max,
hashval.num,
--
1.9.1
From 2912d6c99c64f8f9ac3e23ed94c160438bc67beb Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Wed, 6 Aug 2014 17:18:31 +0200
Subject: [PATCH 3/3] tdb: in tdbtool info, separately record the fill space
(magic 0x42424242)
This was previously counted along with the dead record number and space.
Pair-Programmed-With: Stefan Metzmacher <metze at samba.org>
Signed-off-by: Michael Adam <obnox at samba.org>
Signed-off-by: Stefan Metzmacher <metze at samba.org>
---
lib/tdb/common/summary.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/lib/tdb/common/summary.c b/lib/tdb/common/summary.c
index 4894e52..a9d63da0 100644
--- a/lib/tdb/common/summary.c
+++ b/lib/tdb/common/summary.c
@@ -31,6 +31,8 @@
"Smallest/average/largest dead records: %zu/%zu/%zu\n" \
"Number of recovery records: %zu\n" \
"Smallest/average/largest recovery records: %zu/%zu/%zu\n" \
+ "Number of fill records: %zu\n" \
+ "Smallest/average/largest fill records: %zu/%zu/%zu\n" \
"Number of free records: %zu\n" \
"Smallest/average/largest free records: %zu/%zu/%zu\n" \
"Number of hash chains: %zu\n" \
@@ -94,7 +96,7 @@ _PUBLIC_ char *tdb_summary(struct tdb_context *tdb)
{
off_t file_size;
tdb_off_t off, rec_off;
- struct tally freet, keys, data, dead, extra, hashval, uncoal, rcvry;
+ struct tally freet, keys, data, dead, extra, hashval, uncoal, rcvry, fill;
struct tdb_record rec;
char *ret = NULL;
bool locked;
@@ -124,6 +126,7 @@ _PUBLIC_ char *tdb_summary(struct tdb_context *tdb)
tally_init(&hashval);
tally_init(&uncoal);
tally_init(&rcvry);
+ tally_init(&fill);
for (off = TDB_DATA_START(tdb->hash_size);
off < tdb->map_size - 1;
@@ -156,13 +159,14 @@ _PUBLIC_ char *tdb_summary(struct tdb_context *tdb)
}
break;
case 0x42424242:
+ tally_add(&fill, rec.rec_len);
unc++;
/* If it's a valid recovery, we can trust rec_len. */
if (off != rec_off) {
rec.rec_len = tdb_dead_space(tdb, off)
- sizeof(rec);
}
- /* Fall through */
+ break;
case TDB_DEAD_MAGIC:
tally_add(&dead, rec.rec_len);
break;
@@ -195,6 +199,8 @@ _PUBLIC_ char *tdb_summary(struct tdb_context *tdb)
dead.min, tally_mean(&dead), dead.max,
rcvry.num,
rcvry.min, tally_mean(&rcvry), rcvry.max,
+ fill.num,
+ fill.min, tally_mean(&fill), fill.max,
freet.num,
freet.min, tally_mean(&freet), freet.max,
hashval.num,
--
1.9.1
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20140806/c97b6ec6/attachment.pgp>
More information about the samba-technical
mailing list