]> git.hungrycats.org Git - linux/commit
btrfs: add a write-hole invariant checker to the raid56 write path
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Sat, 19 Sep 2026 17:17:27 +0000 (13:17 -0400)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Mon, 2 Nov 2026 02:16:30 +0000 (21:16 -0500)
commitc2147e33141c52ee8d21b8d2b15feada14455129
tree7241d523ffeb1d535cd9f3111b49c7399bfacd3f
parent0971c7b283c1b8caca963c160edd41d19d67135c
btrfs: add a write-hole invariant checker to the raid56 write path

With stripe-exclusive allocation, a raid56 data stripe may only be
written while an open or draining stripe run covers it: after its run
retires and drains at a transaction commit, nothing may ever write to
it again, and a write outside any run means an allocation bypassed the
policy.  Both cases are the write hole about to happen.

Check the invariant (under CONFIG_BTRFS_DEBUG) for every raid56 write
operation, full-stripe and sub-stripe alike, at rmw_rbio() time.  This
turns every upstream violation -- a missed allocation path, a
retirement ordering bug, an accounting leak -- into a deterministic
WARN at the moment of the offending write, instead of silent damage
that needs a crash plus a device failure plus a scrub to observe.  The
bios gathered in an rbio have not reported their IO done yet, so their
runs cannot drain under the check: no false positives from completion
races.

Block groups that ever hosted relocation-class runs are skipped
(sticky, debug-only flag): relocation legitimately overwrites its
preallocated extents in place after their runs drain, and the write
path cannot tell those writes from violations.

A runtime enable of the policy (the btrfs.stripe_alloc property set on a
live filesystem) flips it while the legacy allocator may still have writes
in flight, in partly used stripes that no run covers, and the check would
warn on the first of them.  So a runtime enable holds the check off until
a worker has started delalloc on all roots and waited for every ordered
extent (the property is applied inside a transaction, where that cannot
wait); the same wait writes any delalloc tail a writeback racing the
enable left unsubmitted.  A mount-time enable has nothing in flight.
close_ctree() flushes the worker.

Assisted-by: Claude:claude-fable-5
Assisted-by: Claude:claude-fable-5-1
Assisted-by: Claude:claude-opus-5-5
fs/btrfs/block-group.c
fs/btrfs/block-group.h
fs/btrfs/disk-io.c
fs/btrfs/extent-tree.c
fs/btrfs/fs.h
fs/btrfs/raid56.c