trv: Moved fixgrm into lfs3_mtree_gc

Whoops, we still need the low-level grm check in lfs3_mtree_gc.

This is not an optimization, we simply don't support deleting
files/orphans with pending grms as those grms will likely fall
out-of-date. So we need to flush the grm queue before any fixorphan
work.

And the check in lfs3_trv_read does not handle the other gc APIs.

This correctly fails tests when ran with LFS3_GC=1.

---

Code changes minimal:

           code          stack          ctx
  before: 35292           2136          660
  after:  35296 (+0.0%)   2136 (+0.0%)  660 (+0.0%)
This commit is contained in:
Christopher Haster
2026-03-04 01:19:29 -06:00
parent 3c28281809
commit be509bcc91
+17 -19
View File
@@ -10179,6 +10179,7 @@ eot:;
}
// needed in lfs3_mtree_gc
static int lfs3_fs_fixgrm(lfs3_t *lfs3);
static int lfs3_mdir_mkconsistent(lfs3_t *lfs3, lfs3_mdir_t *mdir);
static inline void lfs3_alloc_ckpoint_(lfs3_t *lfs3);
static inline bool lfs3_alloc_canlookahead(const lfs3_t *lfs3);
@@ -10196,6 +10197,22 @@ static int lfs3_alloc_adoptgbmap(lfs3_t *lfs3,
// mutation here
static lfs3_stag_t lfs3_mtree_gc(lfs3_t *lfs3, lfs3_mgc_t *mgc,
lfs3_bptr_t *bptr_) {
// check for pending grms every step, just in case some other
// operation introduced new grms
#ifndef LFS3_RDONLY
if (lfs3_t_ismkconsistent(mgc->t.h.flags)
&& lfs3_grm_count(lfs3) > 0) {
// fix pending grms
uint32_t dirty = mgc->t.h.flags;
int err = lfs3_fs_fixgrm(lfs3);
if (err) {
return err;
}
// reset dirty flag
mgc->t.h.flags &= ~LFS3_t_DIRTY | dirty;
}
#endif
// start of traversal?
if (mgc->t.h.mdir.mid == LFS3_MID_MROOTANCHOR) {
#ifndef LFS3_RDONLY
@@ -11692,9 +11709,6 @@ empty:;
}
#endif
// needed in lfs3_remove
static int lfs3_fs_fixgrm(lfs3_t *lfs3);
#ifndef LFS3_RDONLY
int lfs3_remove(lfs3_t *lfs3, const char *path) {
// prepare our filesystem for writing
@@ -17159,22 +17173,6 @@ int lfs3_trv_read(lfs3_t *lfs3, lfs3_trv_t *trv,
return LFS3_ERR_BUSY;
}
// check for pending grms every step, just in case some other
// operation introduced new grms
#ifndef LFS3_RDONLY
if (lfs3_t_ismkconsistent(trv->gc.t.h.flags)
&& lfs3_grm_count(lfs3) > 0) {
// fix pending grms
uint32_t dirty = trv->gc.t.h.flags;
int err = lfs3_fs_fixgrm(lfs3);
if (err) {
return err;
}
// reset dirty flag
trv->gc.t.h.flags &= ~LFS3_t_DIRTY | dirty;
}
#endif
// discard current block queue?
if (lfs3_t_isstale(trv->gc.t.h.flags)) {
trv->blocks[0] = -1;