[PATCH v4 1/9] btrfs: calculate @physical_end using @dev_extent_len directly in scrub_stripe()

Qu Wenruo
2022-03-11T07:39:13Z

The variable @physical_end is the exclusive stripe end, currently it's
calculated using @physical + @dev_extent_len / map->stripe_len *
map->stripe_len.

And since at allocation time we ensured dev_extent_len is stripe_len
aligned, the result is the same as @physical + @dev_extent_len.

So this patch will just assign @physical and @physical_end early,
without using @nstripes.

This is especially helpful for any possible out: label user, as now we
only need to initialize @offset before going to out: label.

Since we're here, also make @physical_end constant.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
fs/btrfs/scrub.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 2316269cade0..c2bf7bbcee67 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -3183,10 +3183,10 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
int slot;
u64 nstripes;
struct extent_buffer *l;
- u64 physical;
+ u64 physical = map->stripes[stripe_index].physical;
u64 logical;
u64 logic_end;
- u64 physical_end;
+ const u64 physical_end = physical + dev_extent_len;
u64 generation;
int mirror_num;
struct btrfs_key key;
@@ -3205,7 +3205,6 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
int extent_mirror_num;
int stop_loop = 0;

- physical = map->stripes[stripe_index].physical;
offset = 0;
nstripes = div64_u64(dev_extent_len, map->stripe_len);
mirror_num = 1;
@@ -3242,7 +3241,6 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
path->reada = READA_FORWARD;

logical = chunk_logical + offset;
- physical_end = physical + nstripes * map->stripe_len;
if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) {
get_raid56_logic_offset(physical_end, stripe_index,
map, &logic_end, NULL);
--
2.35.1