RFC btrfs: refactor scrub entrances for each profile
Get series with b4
b4 am [email protected]Versions newest first
- v1 RFC Latest4 patches 2 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/4 | btrfs: introduce a helper to locate an extent itemfs/ | +108 | 0 replies | |
| 2/4 | btrfs: introduce dedicated helper to scrub simple-mirror based rangefs/ | +190 | 0 replies | |
| 3/4 | btrfs: introduce dedicated helper to scrub simple-stripe based rangefs/ | +57 | 2 replies | |
| 4/4 | btrfs: use scrub_simple_mirror() to handle RAID56 data stripe scrubfs/ | +49 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [PATCH RFC 0/4] btrfs: refactor scrub entrances for each profile
Merry Chrismas and happy new year!
The branch is based on several recent submitted small cleanups, thus it's better to fetch the branch from github:
https://github.com/adam900710/linux/tree/refactor_scrub
[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
[RFC]
- Whether this refactor is preferred
As one entrance, scrub_simple_mirror(), gets reused in other entrances, not sure if this is layer breakage.
- More testing in the real world
Although it passes all known scrub/replace tests. I'm not yet confident in the RAID56 coverage.
Qu Wenruo (4):
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: use scrub_simple_mirror() to handle RAID56 data stripe scrub
fs/btrfs/scrub.c | 680 ++++++++++++++++++++++++++++------------------- 1 file changed, 400 insertions(+), 280 deletions(-)
Signature · 1 line
2.34.1