]> git.hungrycats.org Git - linux/commit
btrfs: scrub: count the raid56 data repairs made by a parity scrub
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Wed, 21 Oct 2026 02:15:16 +0000 (22:15 -0400)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Wed, 21 Oct 2026 11:08:14 +0000 (07:08 -0400)
commit9970d7e44abf0e5a7c67c93228908af5a0303f86
treee5a9218472325b9b8060e7f74384a1459c20993a
parent302044132402f123134b510a46f366a1a1544135
btrfs: scrub: count the raid56 data repairs made by a parity scrub

The scrub of a RAID56 P/Q device reads every data stripe of each full
stripe it checks, verifies and repairs them, and writes the repairs back,
but counts nothing (SCRUB_STRIPE_FLAG_NO_REPORT): neither the scrub
progress nor the device stats.  When the P/Q device's scrub reaches a
full stripe before the data device's own scrub does, the data device's
scrub finds the sector already repaired, and the error is counted
nowhere.  With all devices scrubbed at once that is a large share of the
errors (one failing raid5 member: 25831 of 42371 damaged data sectors
counted; raid6: 7894 of 34146), and when the damaged device is scrubbed
last, none of them.

Count the sectors that the parity scrub repaired and wrote back, as the
data device's scrub would have: read, checksum and verify errors in the
device stats of the data stripe's own device, and in the parity scrub's
progress with corrected_errors.  To count each bad sector once:

- errors left unrepaired are not counted: they stay on disk for the data
  device's own scrub;
- a read-only scrub counts nothing here: nothing is written back, and the
  data device's own scrub will see the same errors;
- when the data device is being scrubbed at the same time (its
  scrub_ctx is set), that scrub repairs and counts its errors itself, so
  the parity scrub neither writes back nor counts them.  It still uses
  the repaired data for its parity check.  Crediting the data device's
  scrub from here instead would count a sector twice whenever both scrubs
  read it before either wrote the repair back, which is common when all
  devices are scrubbed at once, since they move through the full stripes
  together.

A missing data device is not counted against.

Test (raid56-wh-harness scrub-blame-test.sh): 8 damaged data sectors (or
whole damaged strips: 288 raid5, 224 raid6) on one member, all devices
scrubbed at once, the damaged one first, or last: every damaged sector
counted once in every order, the device stats charged to that member
only; read-only scrubs too.  Before: 7 of 8 (raid6 2 of 8) at once, 0
with the damaged member last.  failing-member-scrub-test.sh, one member
failing under load: raid5 36128 of 36128, raid6 30231 of 30231 damaged
sectors counted; before, 26519 of 40556 and 11049 of 30723.

Fixes: 1009254bf22a ("btrfs: scrub: use scrub_stripe to implement RAID56 P/Q scrub")
Assisted-by: Claude:claude-opus-5-5
fs/btrfs/scrub.c