Files
Christopher Haster 26e8bc2e9e Fixed writes bypassing/not updating holes in tracked file leaves
Turns out we were using a slightly wrong condition for when to discard
file leaves in lfs3_file_flush_. An unsurprising mistake given size vs
weight subtleties. As a result, it was possible for a write to bypass
the leaf, leaving it with an outdated weight, resulting in an unexpected
hole in the file.

This was surprisingly hard to find as most writes don't leave the leaf
with hole information, only reads.

Fortunately a solution is easy. Just don't use the bptr size here,
instead use the full leaf weight to decide when to discard tracked file
leaves.

Code changes humorously canceling out the Valgrind fix:

           code          stack          ctx
  before: 35260           2136          660
  after:  35256 (-0.0%)   2136 (+0.0%)  660 (+0.0%)

---

This was found by test_fsync_rwtfrwtf_sparse_fuzz, but only by luck
after the CRYSTAL_THRESH/8 -> CRYSTAL_THRESH/16 tweak.

To prevent a regression, and hopefully catch other bugs like this
(something something cache coherency hard problem), I added a couple
"clip" tests that try to force the cache/leaf bypassing behavior:

- test_fwrite_clip_cache - try clipping the file cache
- test_fwrite_clip_leaf - try clipping the file leaf
- test_fwrite_clip_hole - try clipping the file leaf+hole

test_fwrite_clip_hole does reproduce the bug.
2026-03-09 22:51:58 -05:00
..
2025-07-18 18:29:41 -05:00