Skip to content

Commit 63447b7

Browse files
adam900710kdave
authored andcommitted
btrfs: scrub: update last_physical after scrubbing one stripe
Currently sctx->stat.last_physical only got updated in the following cases: - When the last stripe of a non-RAID56 chunk is scrubbed This implies a pitfall, if the last stripe is at the chunk boundary, and we finished the scrub of the whole chunk, we won't update last_physical at all until the next chunk. - When a P/Q stripe of a RAID56 chunk is scrubbed This leads the following two problems: - sctx->stat.last_physical is not updated for a almost full chunk This is especially bad, affecting scrub resume, as the resume would start from last_physical, causing unnecessary re-scrub. - "btrfs scrub status" will not report any progress for a long time Fix the problem by properly updating @last_physical after each stripe is scrubbed. And since we're here, for the sake of consistency, use spin lock to protect the update of @last_physical, just like all the remaining call sites touching sctx->stat. Reported-by: Michel Palleau <[email protected]> Link: https://lore.kernel.org/linux-btrfs/CAMFk-+igFTv2E8svg=cQ6o3e6CrR5QwgQ3Ok9EyRaEvvthpqCQ@mail.gmail.com/ Reviewed-by: Johannes Thumshirn <[email protected]> Signed-off-by: Qu Wenruo <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 33eb1e5 commit 63447b7

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

fs/btrfs/scrub.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,6 +1875,9 @@ static int flush_scrub_stripes(struct scrub_ctx *sctx)
18751875
stripe = &sctx->stripes[i];
18761876

18771877
wait_scrub_stripe_io(stripe);
1878+
spin_lock(&sctx->stat_lock);
1879+
sctx->stat.last_physical = stripe->physical + stripe_length(stripe);
1880+
spin_unlock(&sctx->stat_lock);
18781881
scrub_reset_stripe(stripe);
18791882
}
18801883
out:
@@ -2143,7 +2146,9 @@ static int scrub_simple_mirror(struct scrub_ctx *sctx,
21432146
cur_physical, &found_logical);
21442147
if (ret > 0) {
21452148
/* No more extent, just update the accounting */
2149+
spin_lock(&sctx->stat_lock);
21462150
sctx->stat.last_physical = physical + logical_length;
2151+
spin_unlock(&sctx->stat_lock);
21472152
ret = 0;
21482153
break;
21492154
}
@@ -2340,6 +2345,10 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
23402345
stripe_logical += chunk_logical;
23412346
ret = scrub_raid56_parity_stripe(sctx, scrub_dev, bg,
23422347
map, stripe_logical);
2348+
spin_lock(&sctx->stat_lock);
2349+
sctx->stat.last_physical = min(physical + BTRFS_STRIPE_LEN,
2350+
physical_end);
2351+
spin_unlock(&sctx->stat_lock);
23432352
if (ret)
23442353
goto out;
23452354
goto next;

0 commit comments

Comments
 (0)