]> git.hungrycats.org Git - linux/commit
btrfs: stripe_alloc: gate data admission on claimable whole-stripe supply topics/stripe-alloc
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Fri, 14 Aug 2026 01:12:04 +0000 (21:12 -0400)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Fri, 14 Aug 2026 01:12:04 +0000 (21:12 -0400)
commite31ca73dfa49fe3627cff61e653ddb9989c8d38a
tree5b5cb55446f0615e82fa51d89aca891d4aca5ea3
parentf77bf1fa3993a9394dddb9b24019c7cfc0bfb082
btrfs: stripe_alloc: gate data admission on claimable whole-stripe supply

Wire stripe_claimable into the DATA reservation path so write() returns -ENOSPC
when there is no fully-free whole stripe to place the write crash-safely --
matching statfs f_bavail, which already subtracts the trapped partial-stripe
space.  Add stripe_claimable_admit() and AND it into the two data-admit sites:
__reserve_bytes() and btrfs_try_granting_tickets() (the latter is required, or a
flushed data ticket would be granted by the plain used<=total rule, bypassing the
gate).  Scoped to raid56 stripe_alloc DATA (stripe_margin_unit != 0); metadata,
non-raid56 and zoned space_infos are unaffected.

The gate refuses at reservation time, before the range becomes delalloc and later
parks at writeback with nowhere to land -- so ENOSPC is clean and there is no
fill-edge parking collapse.

Phase 1 is pessimistic: it gates on bytes_stripe_claimable alone, which errs LOW,
so it can refuse a write that would have landed in a partially-open stripe
(over-refuses by the open remainder, healed by the commit rescan raising claimable
and the FLUSH_DATA ticket retry).  A later change adds bytes_stripe_open to the
bound for statfs-exact behavior.

Assisted-by: Claude:claude-opus-4-8
fs/btrfs/space-info.c