Skip to content

Commit 7192833

Browse files
naotakdave
authored andcommitted
btrfs: scrub: run relocation repair when/only needed
When btrfs scrub finds an error, it reads mirrors to find correct data. If all the errors are fixed, sctx->error_bitmap is cleared for the stripe range. However, in the zoned mode, it runs relocation to repair scrub errors when the bitmap is *not* empty, which is a flipped condition. Also, it runs the relocation even if the scrub is read-only. This was missed by a fix in commit 1f2030f ("btrfs: scrub: respect the read-only flag during repair"). The repair is only necessary when there is a repaired sector and should be done on read-write scrub. So, tweak the condition for both regular and zoned case. Fixes: 5476539 ("btrfs: scrub: introduce helper to queue a stripe for scrub") Fixes: 1f2030f ("btrfs: scrub: respect the read-only flag during repair") CC: [email protected] # 6.6+ Reviewed-by: Qu Wenruo <[email protected]> Reviewed-by: Johannes Thumshirn <[email protected]> Signed-off-by: Naohiro Aota <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent e5a78fd commit 7192833

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

fs/btrfs/scrub.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,7 @@ static void scrub_stripe_read_repair_worker(struct work_struct *work)
10121012
struct btrfs_fs_info *fs_info = sctx->fs_info;
10131013
int num_copies = btrfs_num_copies(fs_info, stripe->bg->start,
10141014
stripe->bg->length);
1015+
unsigned long repaired;
10151016
int mirror;
10161017
int i;
10171018

@@ -1078,16 +1079,15 @@ static void scrub_stripe_read_repair_worker(struct work_struct *work)
10781079
* Submit the repaired sectors. For zoned case, we cannot do repair
10791080
* in-place, but queue the bg to be relocated.
10801081
*/
1081-
if (btrfs_is_zoned(fs_info)) {
1082-
if (!bitmap_empty(&stripe->error_bitmap, stripe->nr_sectors))
1082+
bitmap_andnot(&repaired, &stripe->init_error_bitmap, &stripe->error_bitmap,
1083+
stripe->nr_sectors);
1084+
if (!sctx->readonly && !bitmap_empty(&repaired, stripe->nr_sectors)) {
1085+
if (btrfs_is_zoned(fs_info)) {
10831086
btrfs_repair_one_zone(fs_info, sctx->stripes[0].bg->start);
1084-
} else if (!sctx->readonly) {
1085-
unsigned long repaired;
1086-
1087-
bitmap_andnot(&repaired, &stripe->init_error_bitmap,
1088-
&stripe->error_bitmap, stripe->nr_sectors);
1089-
scrub_write_sectors(sctx, stripe, repaired, false);
1090-
wait_scrub_stripe_io(stripe);
1087+
} else {
1088+
scrub_write_sectors(sctx, stripe, repaired, false);
1089+
wait_scrub_stripe_io(stripe);
1090+
}
10911091
}
10921092

10931093
scrub_stripe_report_errors(sctx, stripe);

0 commit comments

Comments
 (0)