trv: Fixed issue with not clobbering mroot chain mdirs

This was introduced with the simplified traversal clobbering logic.

Previously, traversal clobbering was a bit more aggressive, relying on
the explicit tstate state machine. This was replaced by implicit
mid-related state, which looks like it may have introduced some holes.

In this case, lfs3_mdir_commit was failing to clobber non-active mroot
chain mdirs. Non-active mroots are particularly tricky because we
(1) don't track these in-RAM, (2) only reach them during traversals,
and (3) require heavy wear-leveling writes for them to even appear in
in system.

---

The solution here is an extra check in lfs3_mdir_commit_'s post-commit
state updates to update any mid<=-1 mroots to the new active mroot.

This clobbers mroot chain traversals by skipping non-active mroots, but
this is unavoidable since lfs3_mdir_commit_ could always introduce
new/relocate mroot chain mroots. Note this should match the previous
state-machine dependent behavior.

Code changes:

                    code          stack          ctx
  before:          35144           2136          660
  after:           35152 (+0.0%)   2136 (+0.0%)  660 (+0.0%)

                    code          stack          ctx
  gbmap before:    38380           2144          776
  gbmap after:     38392 (+0.0%)   2144 (+0.0%)  776 (+0.0%)

                    code          stack          ctx
  preerase before: 38920           2168          796
  preerase after:  38928 (+0.0%)   2168 (+0.0%)  796 (+0.0%)
This commit is contained in:
Christopher Haster
2025-12-30 01:37:54 -06:00
parent 21ac03cb1b
commit dbc457bde1
2 changed files with 12 additions and 10 deletions
+3
View File
@@ -9371,6 +9371,9 @@ static int lfs3_mdir_commit_(lfs3_t *lfs3, lfs3_mdir_t *mdir,
}
} else if (h->mdir.mid > mdir->mid) {
h->mdir.mid += mdelta;
// and any mroot updates, though this clobbers chain mroots
} else if (h->mdir.mid <= -1) {
lfs3_mdir_sync(&h->mdir, &mroot_);
}
}