]> git.hungrycats.org Git - linux/commit
btrfs: stripe_alloc: optionally audit data read-modify-writes against the committed...
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Wed, 30 Sep 2026 22:07:56 +0000 (18:07 -0400)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Mon, 2 Nov 2026 02:16:30 +0000 (21:16 -0500)
commita6bed3c0717de0c077a40b8ab81a52fdcf1d86ea
tree1249b2dc76b6d92abf763f2af95b0998c8373cc8
parent4082272623d8ba81ce1b3ccea684162a154598b9
btrfs: stripe_alloc: optionally audit data read-modify-writes against the committed extent tree

The attribution counters say which RMWs the allocator's design explains;
they do not show that an RMW put nothing at risk.  That depends on what
the uncovered sectors hold: an RMW recomputes parity under them while
they stay put, so a crash mid-write can tear them, and that matters
only if a committed transaction references them and the owner is not
relocation's own orphaned copy.

Add an audit that answers it from the tree.  For every data RMW, walk
the commit root of the extent tree (no locking, as
rmw_block_referenced() does; and like it, cached blocks only and
commit_root_sem only when it is free, because the full stripe lock is
held: a miss counts in audit_err, and mixed block groups, whose tree
blocks share the stripe, are not audited) for extents overlapping the
stripe's uncovered sectors, and read each one's data backrefs, inline
and keyed. An extent owned only by the data reloc tree counts as
relocation's (data_rmw_hole_reloc_only); any other owner, a shared ref
(owner unknown), or no ref at all is foreign and counts as a write hole
(data_rmw_hole_no_run / _uncovered / _other, by pad verdict).  Log the
writer of every foreign hole and of every NO_RUN RMW, rate-limited from
separate call sites so a flood of the second cannot starve the first:
root, inode, file offset, ordered extent flags, disk bytenr, stripe run
sequence, and the covering run as the pad oracle saw it.  The commit
root switches just before the super lands, so the check can report a
hole early, never hide one.

A tree search per RMW is not free (a stock raid5 filesystem does
thousands a minute), so the audit is built only with CONFIG_BTRFS_DEBUG
and runs only while /sys/fs/btrfs/<uuid>/debug/stripe_rmw_audit is set,
which it is not by default.  Its counters are in
debug/stripe_rmw_audit_stats, with data_rmw_audited so a reader can
tell an audit that found nothing from one that never ran.

Assisted-by: Claude:claude-opus-5-5
fs/btrfs/block-group.c
fs/btrfs/block-group.h
fs/btrfs/fs.h
fs/btrfs/raid56.c
fs/btrfs/raid56.h
fs/btrfs/sysfs.c