Skip to content

Commit 2ec537f

Browse files
committed
Added several more LFS_DEBUG* options
To help with debugging. These all seem useful, though the exact output will probably be worth messing around with: - LFS_DEBUGRBYDFETCHES - Debug every rbyd fetch - LFS_DEBUGRBYDCOMMITS - Debug every rbyd commit - LFS_DEBUGBTREEFETCHES - Debug every btree/bshrub fetch (though we currently don't fetch bshrubs...) - LFS_DEBUGBTREECOMMITS - Debug every btree/bshrub commit - LFS_DEBUGMDIRFETCHES - Debug every mdir fetch - LFS_DEBUGMDIRCOMMITS - Debug every mdir commit - LFS_DEBUGALLOCS - Debug every block allocation Let's see if you can match these to each debug output: lfs.c:2942:debug: Fetched rbyd 0xe.d80 w77, eoff 3536, cksum 862283c6 lfs.c:4233:debug: Committed rbyd 0xe.dd0 w78, eoff 3616, cksum 38ae1347 lfs.c:4950:debug: Fetched btree 0x9f.806 w2048, cksum 7fb89b1b lfs.c:6609:debug: Committed btree 0x9f.806 w2048, cksum 7fb89b1b lfs.c:6603:debug: Committed bshrub 0x{0,1}.b06 w1747 lfs.c:7290:debug: Fetched mdir -1 0x{1,0}.8f w0, cksum 7846be7a lfs.c:9022:debug: Committed mdir 0 0x{0,1}.a10 w2, cksum 4d2ccb29 lfs.c:10083:debug: Allocated block 0x8f, lookahead 125/253/256 Also tweaked LFSR_DEBUGRBYDBALANCE to be a bit more readable when LFS_DEBUGRBYDFETCHES is enabled, and tweaked the out-of-space error message to show the same lookahead info as LFS_DEBUGALLOCS: lfs.c:10101:error: No more free space (lookahead 0/0/256) ^ ^ ^ lookahead remaining --' | | ckpoint remaining ------' | block count ---------------' No code changes.
1 parent 5da8f3e commit 2ec537f

File tree

2 files changed

+102
-14
lines changed

2 files changed

+102
-14
lines changed

lfs.c

Lines changed: 102 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2938,6 +2938,17 @@ static int lfsr_rbyd_fetch_(lfs_t *lfs,
29382938
rbyd->eoff = -1;
29392939
}
29402940

2941+
#ifdef LFS_DEBUGRBYDFETCHES
2942+
LFS_DEBUG("Fetched rbyd 0x%"PRIx32".%"PRIx32" w%"PRId32", "
2943+
"eoff %"PRId32", cksum %"PRIx32,
2944+
rbyd->blocks[0], lfsr_rbyd_trunk(rbyd),
2945+
rbyd->weight,
2946+
(lfsr_rbyd_eoff(rbyd) >= lfs->cfg->block_size)
2947+
? -1
2948+
: (lfs_ssize_t)lfsr_rbyd_eoff(rbyd),
2949+
rbyd->cksum);
2950+
#endif
2951+
29412952
// debugging rbyd balance? check that all branches in the rbyd have
29422953
// the same height
29432954
#ifdef LFS_DEBUGRBYDBALANCE
@@ -2967,10 +2978,11 @@ static int lfsr_rbyd_fetch_(lfs_t *lfs,
29672978
min_bheight = (min_bheight) ? lfs_min(min_bheight, bheight) : bheight;
29682979
max_bheight = (max_bheight) ? lfs_max(max_bheight, bheight) : bheight;
29692980
}
2970-
LFS_DEBUG("rbyd 0x%"PRIx32".%"PRIx32": "
2981+
LFS_DEBUG("Fetched rbyd 0x%"PRIx32".%"PRIx32" w%"PRId32", "
29712982
"height %"PRId32"-%"PRId32", "
29722983
"bheight %"PRId32"-%"PRId32,
29732984
rbyd->blocks[0], lfsr_rbyd_trunk(rbyd),
2985+
rbyd->weight,
29742986
min_height, max_height,
29752987
min_bheight, max_bheight);
29762988
// all branches in the rbyd should have the same bheight
@@ -4216,6 +4228,17 @@ static int lfsr_rbyd_appendcksum_(lfs_t *lfs, lfsr_rbyd_t *rbyd,
42164228
| off_;
42174229
// revert to canonical checksum
42184230
rbyd->cksum = cksum;
4231+
4232+
#ifdef LFS_DEBUGRBYDCOMMITS
4233+
LFS_DEBUG("Committed rbyd 0x%"PRIx32".%"PRIx32" w%"PRId32", "
4234+
"eoff %"PRId32", cksum %"PRIx32,
4235+
rbyd->blocks[0], lfsr_rbyd_trunk(rbyd),
4236+
rbyd->weight,
4237+
(lfsr_rbyd_eoff(rbyd) >= lfs->cfg->block_size)
4238+
? -1
4239+
: (lfs_ssize_t)lfsr_rbyd_eoff(rbyd),
4240+
rbyd->cksum);
4241+
#endif
42194242
return 0;
42204243
}
42214244

@@ -4916,9 +4939,21 @@ static int lfsr_btree_fetch(lfs_t *lfs, lfsr_btree_t *btree,
49164939
lfs_block_t block, lfs_size_t trunk, lfsr_bid_t weight,
49174940
uint32_t cksum) {
49184941
// btree/branch fetch really are the same once we know the weight
4919-
return lfsr_branch_fetch(lfs, btree,
4942+
int err = lfsr_branch_fetch(lfs, btree,
49204943
block, trunk, weight,
49214944
cksum);
4945+
if (err) {
4946+
return err;
4947+
}
4948+
4949+
#ifdef LFS_DEBUGBTREEFETCHES
4950+
LFS_DEBUG("Fetched btree 0x%"PRIx32".%"PRIx32" w%"PRId32", "
4951+
"cksum %"PRIx32,
4952+
btree->blocks[0], lfsr_rbyd_trunk(btree),
4953+
btree->weight,
4954+
btree->cksum);
4955+
#endif
4956+
return 0;
49224957
}
49234958

49244959
static int lfsr_data_fetchbtree(lfs_t *lfs, lfsr_data_t *data,
@@ -5700,6 +5735,13 @@ static int lfsr_btree_commit_(lfs_t *lfs, lfsr_btree_t *btree,
57005735
}
57015736

57025737
LFS_ASSERT(lfsr_rbyd_trunk(btree));
5738+
#ifdef LFS_DEBUGBTREECOMMITS
5739+
LFS_DEBUG("Committed btree 0x%"PRIx32".%"PRIx32" w%"PRId32", "
5740+
"cksum %"PRIx32,
5741+
btree->blocks[0], lfsr_rbyd_trunk(btree),
5742+
btree->weight,
5743+
btree->cksum);
5744+
#endif
57035745
return 0;
57045746
}
57055747

@@ -6479,7 +6521,7 @@ static int lfsr_bshrub_commit_(lfs_t *lfs,
64796521
LFS_ASSERT(!err || rat_count > 0);
64806522
bool alloc = (err == LFS_ERR_RANGE);
64816523

6482-
// when btree is shrubbed, lfsr_btree_commit_ stops at the root
6524+
// when btree is shrubbed, lfsr_btree_commit__ stops at the root
64836525
// and returns with pending rats
64846526
if (rat_count > 0) {
64856527
// we need to prevent our shrub from overflowing our mdir somehow
@@ -6553,11 +6595,24 @@ static int lfsr_bshrub_commit_(lfs_t *lfs,
65536595
}
65546596
}
65556597
LFS_ASSERT(bshrub->u.bshrub.estimate == (lfs_size_t)estimate);
6556-
6557-
return 0;
65586598
}
65596599

65606600
LFS_ASSERT(lfsr_shrub_trunk(&bshrub->u.bshrub));
6601+
#ifdef LFS_DEBUGBTREECOMMITS
6602+
if (lfsr_bshrub_isbshrub(mdir, bshrub)) {
6603+
LFS_DEBUG("Committed bshrub "
6604+
"0x{%"PRIx32",%"PRIx32"}.%"PRIx32" w%"PRId32,
6605+
mdir->rbyd.blocks[0], mdir->rbyd.blocks[1],
6606+
lfsr_shrub_trunk(&bshrub->u.bshrub),
6607+
bshrub->u.bshrub.weight);
6608+
} else {
6609+
LFS_DEBUG("Committed btree 0x%"PRIx32".%"PRIx32" w%"PRId32", "
6610+
"cksum %"PRIx32,
6611+
bshrub->u.btree.blocks[0], lfsr_rbyd_trunk(&bshrub->u.btree),
6612+
bshrub->u.btree.weight,
6613+
bshrub->u.btree.cksum);
6614+
}
6615+
#endif
65616616
return 0;
65626617

65636618
relocate:;
@@ -6592,6 +6647,15 @@ relocate:;
65926647
}
65936648

65946649
bshrub->u.btree = rbyd_;
6650+
6651+
LFS_ASSERT(lfsr_rbyd_trunk(&bshrub->u.btree));
6652+
#ifdef LFS_DEBUGBTREECOMMITS
6653+
LFS_DEBUG("Committed btree 0x%"PRIx32".%"PRIx32" w%"PRId32", "
6654+
"cksum %"PRIx32,
6655+
bshrub->u.btree.blocks[0], lfsr_rbyd_trunk(&bshrub->u.btree),
6656+
bshrub->u.btree.weight,
6657+
bshrub->u.btree.cksum);
6658+
#endif
65956659
return 0;
65966660
}
65976661

@@ -7222,6 +7286,16 @@ static int lfsr_mdir_fetch(lfs_t *lfs, lfsr_mdir_t *mdir,
72227286
mdir->mid = mid;
72237287
// keep track of other block for compactions
72247288
mdir->rbyd.blocks[1] = blocks[1];
7289+
#ifdef LFS_DEBUGMDIRFETCHES
7290+
LFS_DEBUG("Fetched mdir %"PRId32" "
7291+
"0x{%"PRIx32",%"PRIx32"}.%"PRIx32" w%"PRId32", "
7292+
"cksum %"PRIx32,
7293+
mdir->mid >> lfs->mdir_bits,
7294+
mdir->rbyd.blocks[0], mdir->rbyd.blocks[1],
7295+
lfsr_rbyd_trunk(&mdir->rbyd),
7296+
mdir->rbyd.weight,
7297+
mdir->rbyd.cksum);
7298+
#endif
72257299
return 0;
72267300
}
72277301

@@ -8944,6 +9018,16 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir,
89449018
lfsr_mdir_sync(&lfs->mroot, &mroot_);
89459019
lfs->mtree = mtree_;
89469020

9021+
#ifdef LFS_DEBUGMDIRCOMMITS
9022+
LFS_DEBUG("Committed mdir %"PRId32" "
9023+
"0x{%"PRIx32",%"PRIx32"}.%"PRIx32" w%"PRId32", "
9024+
"cksum %"PRIx32,
9025+
mdir->mid >> lfs->mdir_bits,
9026+
mdir->rbyd.blocks[0], mdir->rbyd.blocks[1],
9027+
lfsr_rbyd_trunk(&mdir->rbyd),
9028+
mdir->rbyd.weight,
9029+
mdir->rbyd.cksum);
9030+
#endif
89479031
return 0;
89489032

89499033
failed:;
@@ -9995,6 +10079,14 @@ static lfs_sblock_t lfs_alloc(lfs_t *lfs, bool erase) {
999510079
lfs_alloc_inc(lfs);
999610080
lfs_alloc_findfree(lfs);
999710081

10082+
#ifdef LFS_DEBUGALLOCS
10083+
LFS_DEBUG("Allocated block 0x%"PRIx32", "
10084+
"lookahead %"PRId32"/%"PRId32"/%"PRId32,
10085+
block,
10086+
lfs->lookahead.size,
10087+
lfs->lookahead.ckpoint,
10088+
lfs->cfg->block_count);
10089+
#endif
999810090
return block;
999910091
}
1000010092

@@ -10006,9 +10098,11 @@ static lfs_sblock_t lfs_alloc(lfs_t *lfs, bool erase) {
1000610098
// the filesystem as out of storage
1000710099
//
1000810100
if (lfs->lookahead.ckpoint <= 0) {
10009-
LFS_ERROR("No more free space (0x%"PRIx32")",
10010-
(lfs->lookahead.window + lfs->lookahead.off)
10011-
% lfs->block_count);
10101+
LFS_ERROR("No more free space "
10102+
"(lookahead %"PRId32"/%"PRId32"/%"PRId32")",
10103+
lfs->lookahead.size,
10104+
lfs->lookahead.ckpoint,
10105+
lfs->cfg->block_count);
1001210106
return LFS_ERR_NOSPC;
1001310107
}
1001410108

lfs_util.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,6 @@ extern "C"
204204
#define LFS_IFDEF_GC(a, b) (b)
205205
#endif
206206

207-
#ifdef LFS_DEBUGRBYDBALANCE
208-
#define LFS_IFDEF_DEBUGRBYDBALANCE(a, b) (a)
209-
#else
210-
#define LFS_IFDEF_DEBUGRBYDBALANCE(a, b) (b)
211-
#endif
212-
213207

214208
// Builtin functions, these may be replaced by more efficient
215209
// toolchain-specific implementations. LFS_NO_BUILTINS falls back to a more

0 commit comments

Comments
 (0)