Changed to a shifted mid=bid.rid representation for debugging

This only matters for developers, not users, but it still helps a lot to
get debug representations right.

Since the exact mid encoding depends on the block_size in an unintuitive
manner, it's tricky to render in a debug-friendly way that is useful
both with and without tools.

Previously, I avoided shifting the bid representation, since this would
be closer to the value in the device, but this hides the actual
structure of the mtree. Now the bid is shifted, showing the underlying
mtree/mdir structure, at the cost of needing to know the number of mbits
to encode the mid back into an integer.

So for example, on a device with 4KiB blocks, or 8 mbits:

  mid=1
  mid=258
  mid=515

Becomes:

  mid=0.1
  mid=1.2
  mid=2.3

This continues to make the mbits a more fundamental part of littlefs,
but that's probably just how that's going to be.
This commit is contained in:
Christopher Haster
2023-09-11 01:59:19 -05:00
parent f9bd2c56e3
commit 900ea807ae
4 changed files with 81 additions and 82 deletions
+22 -29
View File
@@ -5289,12 +5289,11 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir,
// adjust our sibling's mid after committing attrs
msibling_.mid += lfsr_mweight(lfs);
LFS_DEBUG("Splitting mdir %"PRId32".%"PRId32" "
LFS_DEBUG("Splitting mdir %"PRId32" "
"0x{%"PRIx32",%"PRIx32"} "
"-> 0x{%"PRIx32",%"PRIx32"}, "
"0x{%"PRIx32",%"PRIx32"}",
mid & lfsr_mbidmask(lfs),
mid & lfsr_mridmask(lfs),
mid >> lfs->mbits,
mdir->u.m.blocks[0], mdir->u.m.blocks[1],
mdir_.u.m.blocks[0], mdir_.u.m.blocks[1],
msibling_.u.m.blocks[0], msibling_.u.m.blocks[1]);
@@ -5304,33 +5303,29 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir,
// both siblings reduced to zero
if (mdir_.u.m.weight == 0 && msibling_.u.m.weight == 0) {
LFS_DEBUG("Dropping mdir %"PRId32".%"PRId32" "
LFS_DEBUG("Dropping mdir %"PRId32" "
"0x{%"PRIx32",%"PRIx32"}",
mdir_.mid & lfsr_mbidmask(lfs),
mdir_.mid & lfsr_mridmask(lfs),
mdir_.mid >> lfs->mbits,
mdir_.u.m.blocks[0], mdir_.u.m.blocks[1]);
LFS_DEBUG("Dropping mdir %"PRId32".%"PRId32" "
LFS_DEBUG("Dropping mdir %"PRId32" "
"0x{%"PRIx32",%"PRIx32"}",
msibling_.mid & lfsr_mbidmask(lfs),
msibling_.mid & lfsr_mridmask(lfs),
msibling_.mid >> lfs->mbits,
msibling_.u.m.blocks[0], msibling_.u.m.blocks[1]);
goto drop;
// one sibling reduced to zero
} else if (msibling_.u.m.weight == 0) {
LFS_DEBUG("Dropping mdir %"PRId32".%"PRId32" "
LFS_DEBUG("Dropping mdir %"PRId32" "
"0x{%"PRIx32",%"PRIx32"}",
msibling_.mid & lfsr_mbidmask(lfs),
msibling_.mid & lfsr_mridmask(lfs),
msibling_.mid >> lfs->mbits,
msibling_.u.m.blocks[0], msibling_.u.m.blocks[1]);
goto relocate;
// other sibling reduced to zero
} else if (mdir_.u.m.weight == 0) {
LFS_DEBUG("Dropping mdir %"PRId32".%"PRId32" "
LFS_DEBUG("Dropping mdir %"PRId32" "
"0x{%"PRIx32",%"PRIx32"}",
mdir_.mid & lfsr_mbidmask(lfs),
mdir_.mid & lfsr_mridmask(lfs),
mdir_.mid >> lfs->mbits,
mdir_.u.m.blocks[0], mdir_.u.m.blocks[1]);
mdir_.u.m = msibling_.u.m;
msibling_.u.m.weight = 0;
@@ -5380,10 +5375,9 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir,
// mdir reduced to zero? need to drop?
} else if (err == LFS_ERR_NOENT) {
LFS_DEBUG("Dropping mdir %"PRId32".%"PRId32" "
LFS_DEBUG("Dropping mdir %"PRId32" "
"0x{%"PRIx32",%"PRIx32"}",
mid & lfsr_mbidmask(lfs),
mid & lfsr_mridmask(lfs),
mid >> lfs->mbits,
mdir->u.m.blocks[0], mdir->u.m.blocks[1]);
// consume gstate so we don't lose any info
@@ -5407,10 +5401,9 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir,
// need to relocate?
} else if (lfsr_mdir_cmp(mdir, &mdir_) != 0
&& !(mid == -1 || lfsr_mtree_isinlined(lfs))) {
LFS_DEBUG("Relocating mdir %"PRId32".%"PRId32" "
LFS_DEBUG("Relocating mdir %"PRId32" "
"0x{%"PRIx32",%"PRIx32"} -> 0x{%"PRIx32",%"PRIx32"}",
mid & lfsr_mbidmask(lfs),
mid & lfsr_mridmask(lfs),
mid >> lfs->mbits,
mdir->u.m.blocks[0], mdir->u.m.blocks[1],
mdir_.u.m.blocks[0], mdir_.u.m.blocks[1]);
@@ -6618,13 +6611,13 @@ static int lfsr_mountinited(lfs_t *lfs) {
if (lfsr_grm_count(&lfs->grm) == 2) {
LFS_DEBUG("Found pending grm "
"%"PRId32".%"PRId32" %"PRId32".%"PRId32,
lfs->grm.rms[0] & lfsr_mbidmask(lfs),
lfs->grm.rms[0] >> lfs->mbits,
lfs->grm.rms[0] & lfsr_mridmask(lfs),
lfs->grm.rms[0] & lfsr_mbidmask(lfs),
lfs->grm.rms[0] & lfsr_mridmask(lfs));
lfs->grm.rms[1] >> lfs->mbits,
lfs->grm.rms[1] & lfsr_mridmask(lfs));
} else if (lfsr_grm_count(&lfs->grm) == 1) {
LFS_DEBUG("Found pending grm %"PRId32".%"PRId32,
lfs->grm.rms[0] & lfsr_mbidmask(lfs),
lfs->grm.rms[0] >> lfs->mbits,
lfs->grm.rms[0] & lfsr_mridmask(lfs));
}
}
@@ -7448,13 +7441,13 @@ static int lfsr_fs_preparemutation(lfs_t *lfs) {
if (lfsr_grm_count(&lfs->grm) == 2) {
LFS_DEBUG("Fixing pending grm "
"%"PRId32".%"PRId32" %"PRId32".%"PRId32,
lfs->grm.rms[0] & lfsr_mbidmask(lfs),
lfs->grm.rms[0] >> lfs->mbits,
lfs->grm.rms[0] & lfsr_mridmask(lfs),
lfs->grm.rms[0] & lfsr_mbidmask(lfs),
lfs->grm.rms[0] & lfsr_mridmask(lfs));
lfs->grm.rms[1] >> lfs->mbits,
lfs->grm.rms[1] & lfsr_mridmask(lfs));
} else if (lfsr_grm_count(&lfs->grm) == 1) {
LFS_DEBUG("Fixing pending grm %"PRId32".%"PRId32,
lfs->grm.rms[0] & lfsr_mbidmask(lfs),
lfs->grm.rms[0] >> lfs->mbits,
lfs->grm.rms[0] & lfsr_mridmask(lfs));
}