Skip to content

btrfs: refactor scrub entrances for each profile

Qu Wenruo linux-btrfs 4 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest9 patches 6 repliesIn review
  2. v39 patches 0 repliesSuperseded
  3. v27 patches 0 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v14 patches5 repliesSuperseded

Changes in v4 from the cover letter

- Rebased after scrub renaming patchset
Only minor conflicts.

- Fix uninitialized variable in patch 6 and 7
Now there should be no uninitialized even only patches 1~6 are applied.

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/9btrfs: calculate @physical_end using @dev_extent_len directly in scrub_stripe()fs/btrfs/scrub.c+2 -41 reply
2/9btrfs: introduce a helper to locate an extent itemfs/btrfs/scrub.c+108 -02 replies
3/9btrfs: introduce dedicated helper to scrub simple-mirror based rangefs/btrfs/scrub.c+190 -00 replies
4/9btrfs: introduce dedicated helper to scrub simple-stripe based rangefs/btrfs/scrub.c+88 -120 replies
5/9btrfs: scrub: cleanup the non-RAID56 branches in scrub_stripe()fs/btrfs/scrub.c+51 -770 replies
6/9btrfs: use scrub_simple_mirror() to handle RAID56 data stripe scrubfs/btrfs/scrub.c+24 -2310 replies
7/9btrfs: refactor scrub_raid56_parity()fs/btrfs/scrub.c+164 -1810 replies
8/9btrfs: use find_first_extent_item() to replace the open-coded extent item searchfs/btrfs/scrub.c+25 -740 replies
9/9btrfs: move scrub_remap_extent() call into scrub_extent() with more commentsfs/btrfs/scrub.c+35 -270 replies

Reviews trailers per patch

1 of 9 patches has a Reviewed-by or Acked-by.

PatchChristoph Hellwig
1/9R-b
2/9
3/9
4/9
5/9
6/9
7/9
8/9
9/9

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v4 thread

Cover letter [PATCH v4 0/9] btrfs: refactor scrub entrances for each profile

This patchset is cherry-picked from my github repo:
https://github.com/adam900710/linux/tree/refactor_scrub

[Changelog]
v2:
- Rebased to latest misc-next

- Fix several uninitialized variables in the 2nd and 3rd patch This is because @physical, @physical_end and @offset are also used for zoned device sync.

Initial those values early to fix the problem.

v3:
- Add two patches to better split cleanups from refactors One to change the timing of initialization of @physical and @physical_end

One to remove dead non-RAID56 branches after making scrub_stripe() to work on RAID56 only.

- Fix an unfinished comment in scrub_simple_mirror()

v4:
- Rebased after scrub renaming patchset
Only minor conflicts.

- Fix uninitialized variable in patch 6 and 7
Now there should be no uninitialized even only patches 1~6 are applied.

[CRAP-BUT-IT-WORKS(TM)]

Scrub is one of the area we seldom touch because:

- It's a mess
Just check scrub_stripe() function.
It's a function scrubbing a stripe for *all* profiles.

It's near 400 lines for a single complex function, with double while() loop and several different jumps inside the loop.

Not to mention the lack of comments for various structures.

This should and will never happen under our current code standard.

- It just works
I have hit more than 10 bugs during development, and I just want to give up the refactor, as even the code is crap, it works, passing the existing scrub/replace group.
While no matter how small code change I'm doing, it always fails to pass the same tests.

[REFACTOR-IDEA]

The core idea here, is to get rid of one-fit-all solution for scrub_stripe().

Instead, we explicitly separate the scrub into 3 groups (the idea is from my btrfs-fuse project):

- Simple-mirror based profiles
This includes SINGLE/DUP/RAID1/RAID1C* profiles. They have no stripe, and their repair is purely mirror based.

- Simple-stripe based profiles
This includes RAID0/RAID10 profiles.
They are just simple stripe (without P/Q nor rotation), with extra mirrors to support their repair.

- RAID56
The most complex profiles, they have extra P/Q, and have rotation.

[REFACTOR-IMPLEMENTATION]

So we have 3 entrances for all those supported profiles:

- scrub_simple_mirror()
For SINGLE/DUP/RAID1/RAID1C* profiles. Just go through each extent and scrub the extent.

- scrub_simple_stripe()
For RAID0/RAID10 profiles.
Instead we go each data stripe first, then inside each data stripe, we can call scrub_simple_mirror(), since after stripe split, RAID0 is just SINGLE and RAID10 is just RAID1.

- scrub_stripe() untouched for RAID56
RAID56 still has all the complex things to do, but they can still be split into two types (already done by the original code)

* data stripes
They are no different in the verification part, RAID56 is just SINGLE if we ignore the repair path.
It's only in repair path that our path divides.

So we can reuse scrub_simple_mirror() again.

* P/Q stripes
They already have a dedicated function handling the case.

With all these refactors, although we have several more functions, we get rid of:

- A double while () loop
- Several jumps inside the double loop
- Complex calculation to try to fit all profiles

And we get:

- Better comments
- More dedicated functions
- A better basis for further refactors

[FUTURE CLEANUPS]
- Refactor scrub_pages/scrub_parity/... structures
- Further cleanup RAID56 codes

Changelog:
v2:
- Rebased to latest misc-next

- Fix several uninitialized variables in the 2nd and 3rd patch This is because @physical, @physical_end and @offset are also used for zoned device sync.

Initial those values early to fix the problem.

v3:
- Add two patches to better split cleanups from refactors One to change the timing of initialization of @physical and @physical_end

One to remove dead non-RAID56 branches after making scrub_stripe() to work on RAID56 only.

- Fix an unfinished comment in scrub_simple_mirror()

Qu Wenruo (9):
btrfs: calculate @physical_end using @dev_extent_len directly in
scrub_stripe()
btrfs: introduce a helper to locate an extent item
btrfs: introduce dedicated helper to scrub simple-mirror based range
btrfs: introduce dedicated helper to scrub simple-stripe based range
btrfs: scrub: cleanup the non-RAID56 branches in scrub_stripe()
btrfs: use scrub_simple_mirror() to handle RAID56 data stripe scrub
btrfs: refactor scrub_raid56_parity()
btrfs: use find_first_extent_item() to replace the open-coded extent
item search
btrfs: move scrub_remap_extent() call into scrub_extent() with more
comments

 fs/btrfs/scrub.c | 1037 +++++++++++++++++++++++++---------------------
 1 file changed, 559 insertions(+), 478 deletions(-)
Signature · 1 line
2.35.1