Commit 2ae8ae3d authored by Qu Wenruo's avatar Qu Wenruo Committed by David Sterba

btrfs: scrub: cleanup the argument list of scrub_stripe()

The argument list of btrfs_stripe() has similar problems of
scrub_chunk():

- Duplicated and ambiguous @base argument
  Can be fetched from btrfs_block_group::bg.

- Ambiguous argument @length
  It's again device extent length

- Ambiguous argument @num
  The instinctive guess would be mirror number, but in fact it's stripe
  index.

Fix it by:

- Remove @base parameter

- Rename @length to @dev_extent_len

- Rename @num to @stripe_index
Signed-off-by: default avatarQu Wenruo <wqu@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent d04fbe19
...@@ -3166,10 +3166,10 @@ static int sync_write_pointer_for_zoned(struct scrub_ctx *sctx, u64 logical, ...@@ -3166,10 +3166,10 @@ static int sync_write_pointer_for_zoned(struct scrub_ctx *sctx, u64 logical,
} }
static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx, static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
struct btrfs_block_group *bg,
struct map_lookup *map, struct map_lookup *map,
struct btrfs_device *scrub_dev, struct btrfs_device *scrub_dev,
int num, u64 base, u64 length, int stripe_index, u64 dev_extent_len)
struct btrfs_block_group *cache)
{ {
struct btrfs_path *path; struct btrfs_path *path;
struct btrfs_fs_info *fs_info = sctx->fs_info; struct btrfs_fs_info *fs_info = sctx->fs_info;
...@@ -3177,6 +3177,7 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx, ...@@ -3177,6 +3177,7 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
struct btrfs_root *csum_root; struct btrfs_root *csum_root;
struct btrfs_extent_item *extent; struct btrfs_extent_item *extent;
struct blk_plug plug; struct blk_plug plug;
const u64 chunk_logical = bg->start;
u64 flags; u64 flags;
int ret; int ret;
int slot; int slot;
...@@ -3204,25 +3205,26 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx, ...@@ -3204,25 +3205,26 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
int extent_mirror_num; int extent_mirror_num;
int stop_loop = 0; int stop_loop = 0;
physical = map->stripes[num].physical; physical = map->stripes[stripe_index].physical;
offset = 0; offset = 0;
nstripes = div64_u64(length, map->stripe_len); nstripes = div64_u64(dev_extent_len, map->stripe_len);
mirror_num = 1; mirror_num = 1;
increment = map->stripe_len; increment = map->stripe_len;
if (map->type & BTRFS_BLOCK_GROUP_RAID0) { if (map->type & BTRFS_BLOCK_GROUP_RAID0) {
offset = map->stripe_len * num; offset = map->stripe_len * stripe_index;
increment = map->stripe_len * map->num_stripes; increment = map->stripe_len * map->num_stripes;
} else if (map->type & BTRFS_BLOCK_GROUP_RAID10) { } else if (map->type & BTRFS_BLOCK_GROUP_RAID10) {
int factor = map->num_stripes / map->sub_stripes; int factor = map->num_stripes / map->sub_stripes;
offset = map->stripe_len * (num / map->sub_stripes); offset = map->stripe_len * (stripe_index / map->sub_stripes);
increment = map->stripe_len * factor; increment = map->stripe_len * factor;
mirror_num = num % map->sub_stripes + 1; mirror_num = stripe_index % map->sub_stripes + 1;
} else if (map->type & BTRFS_BLOCK_GROUP_RAID1_MASK) { } else if (map->type & BTRFS_BLOCK_GROUP_RAID1_MASK) {
mirror_num = num % map->num_stripes + 1; mirror_num = stripe_index % map->num_stripes + 1;
} else if (map->type & BTRFS_BLOCK_GROUP_DUP) { } else if (map->type & BTRFS_BLOCK_GROUP_DUP) {
mirror_num = num % map->num_stripes + 1; mirror_num = stripe_index % map->num_stripes + 1;
} else if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) { } else if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) {
get_raid56_logic_offset(physical, num, map, &offset, NULL); get_raid56_logic_offset(physical, stripe_index, map, &offset,
NULL);
increment = map->stripe_len * nr_data_stripes(map); increment = map->stripe_len * nr_data_stripes(map);
} }
...@@ -3239,12 +3241,12 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx, ...@@ -3239,12 +3241,12 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
path->skip_locking = 1; path->skip_locking = 1;
path->reada = READA_FORWARD; path->reada = READA_FORWARD;
logical = base + offset; logical = chunk_logical + offset;
physical_end = physical + nstripes * map->stripe_len; physical_end = physical + nstripes * map->stripe_len;
if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) { if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) {
get_raid56_logic_offset(physical_end, num, get_raid56_logic_offset(physical_end, stripe_index,
map, &logic_end, NULL); map, &logic_end, NULL);
logic_end += base; logic_end += chunk_logical;
} else { } else {
logic_end = logical + increment * nstripes; logic_end = logical + increment * nstripes;
} }
...@@ -3299,13 +3301,13 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx, ...@@ -3299,13 +3301,13 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
} }
if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) { if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) {
ret = get_raid56_logic_offset(physical, num, map, ret = get_raid56_logic_offset(physical, stripe_index,
&logical, map, &logical,
&stripe_logical); &stripe_logical);
logical += base; logical += chunk_logical;
if (ret) { if (ret) {
/* it is parity strip */ /* it is parity strip */
stripe_logical += base; stripe_logical += chunk_logical;
stripe_end = stripe_logical + increment; stripe_end = stripe_logical + increment;
ret = scrub_raid56_parity(sctx, map, scrub_dev, ret = scrub_raid56_parity(sctx, map, scrub_dev,
stripe_logical, stripe_logical,
...@@ -3385,13 +3387,13 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx, ...@@ -3385,13 +3387,13 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
* Continuing would prevent reusing its device extents * Continuing would prevent reusing its device extents
* for new block groups for a long time. * for new block groups for a long time.
*/ */
spin_lock(&cache->lock); spin_lock(&bg->lock);
if (cache->removed) { if (bg->removed) {
spin_unlock(&cache->lock); spin_unlock(&bg->lock);
ret = 0; ret = 0;
goto out; goto out;
} }
spin_unlock(&cache->lock); spin_unlock(&bg->lock);
extent = btrfs_item_ptr(l, slot, extent = btrfs_item_ptr(l, slot,
struct btrfs_extent_item); struct btrfs_extent_item);
...@@ -3470,12 +3472,12 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx, ...@@ -3470,12 +3472,12 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
loop: loop:
physical += map->stripe_len; physical += map->stripe_len;
ret = get_raid56_logic_offset(physical, ret = get_raid56_logic_offset(physical,
num, map, &logical, stripe_index, map,
&stripe_logical); &logical, &stripe_logical);
logical += base; logical += chunk_logical;
if (ret && physical < physical_end) { if (ret && physical < physical_end) {
stripe_logical += base; stripe_logical += chunk_logical;
stripe_end = stripe_logical + stripe_end = stripe_logical +
increment; increment;
ret = scrub_raid56_parity(sctx, ret = scrub_raid56_parity(sctx,
...@@ -3509,8 +3511,8 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx, ...@@ -3509,8 +3511,8 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
physical += map->stripe_len; physical += map->stripe_len;
spin_lock(&sctx->stat_lock); spin_lock(&sctx->stat_lock);
if (stop_loop) if (stop_loop)
sctx->stat.last_physical = map->stripes[num].physical + sctx->stat.last_physical = map->stripes[stripe_index].physical +
length; dev_extent_len;
else else
sctx->stat.last_physical = physical; sctx->stat.last_physical = physical;
spin_unlock(&sctx->stat_lock); spin_unlock(&sctx->stat_lock);
...@@ -3530,9 +3532,10 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx, ...@@ -3530,9 +3532,10 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
if (sctx->is_dev_replace && ret >= 0) { if (sctx->is_dev_replace && ret >= 0) {
int ret2; int ret2;
ret2 = sync_write_pointer_for_zoned(sctx, base + offset, ret2 = sync_write_pointer_for_zoned(sctx,
map->stripes[num].physical, chunk_logical + offset,
physical_end); map->stripes[stripe_index].physical,
physical_end);
if (ret2) if (ret2)
ret = ret2; ret = ret2;
} }
...@@ -3578,8 +3581,8 @@ static noinline_for_stack int scrub_chunk(struct scrub_ctx *sctx, ...@@ -3578,8 +3581,8 @@ static noinline_for_stack int scrub_chunk(struct scrub_ctx *sctx,
for (i = 0; i < map->num_stripes; ++i) { for (i = 0; i < map->num_stripes; ++i) {
if (map->stripes[i].dev->bdev == scrub_dev->bdev && if (map->stripes[i].dev->bdev == scrub_dev->bdev &&
map->stripes[i].physical == dev_offset) { map->stripes[i].physical == dev_offset) {
ret = scrub_stripe(sctx, map, scrub_dev, i, ret = scrub_stripe(sctx, bg, map, scrub_dev, i,
bg->start, dev_extent_len, bg); dev_extent_len);
if (ret) if (ret)
goto out; goto out;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment