Files
littlefs/tests
Christopher Haster 9e4bbdf0ad trv: Added test_gc_nospc, fixed pcache bug and trv-repop-conflict bug
This adds test_gc_nospc with more aggressive testing of gc/traversal
operations in low-space conditions. The original intention was to test
the new soft-ENOSPC traversal behavior, but instead it found a couple
unrelated bugs.

In my defense these involve some rather subtle filesystem interactions
and went unnoticed because we don't usually check data checksums:

1. lfs3_bd_flush had a rare chance where it could corrupt our
   prog-aligned pcksum when (1) we bypass the pcache, allowing any
   previous contents to stay there until flush/pcksum, and (2) some
   other failed prog, in this case failing repopgbmaps due to the
   low-space condition, leaves garbage in the pcache. When we flush
   we corrupt the pcksum even though the old data belongs to an
   unrelated block.

   This resulted in CKDATA failing, though the failed check is a false
   positive.

   As a workaround, lfs3_bd_prog and lfs3_bd_prognext now discard _any_
   unrelated pcache, even if bypassing the pcache. This should ensure
   consistent behavior in all cases. Note we do something similar for
   with the file cache in lfs3_file_write.

   This means progs may not complete unless lfs3_bd_flush is called, but
   I think we need to call lfs3_bd_flush in all cases anyways to ensure
   power-loss safe behavior.

   The end result should be a more reliable internal bd prog API.

2. On a successful traversal with LFS3_T_REPOPLOOKAHEAD and
   LFS3_T_REPOPGBMAP we adopt both the new gbmap and lookahead buffer.

   This is wrong! The lookahead buffer is not aware of the gbmap during
   the traversal, and _can't_ be aware as the gbmap changes during
   repopulation work. This is the whole reason we have the alloc
   ckpoints and the in-flight window.

   To fix, adopting the lookahead buffer is now conditional on _not_
   adopting a new gbmap.

   It makes the code a bit more messy, but this is the correct behavior.
   Populating both the gbmap and lookahead buffere requires at least two
   passes.

Code changes minimal:

                 code          stack          ctx
  before:       37248           2352          688
  after:        37260 (+0.0%)   2352 (+0.0%)  688 (+0.0%)

                 code          stack          ctx
  gbmap before: 40204           2368          856
  gbmap after:  40220 (+0.0%)   2368 (+0.0%)  856 (+0.0%)
2025-10-24 00:02:15 -05:00
..
2025-10-23 23:53:02 -05:00
2025-07-18 18:29:41 -05:00
2025-07-18 18:29:41 -05:00