Skip to content

Commit 2ae8ae3

Browse files
adam900710kdave
authored andcommitted
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: Qu Wenruo <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent d04fbe1 commit 2ae8ae3

File tree

1 file changed

+35
-32
lines changed

1 file changed

+35
-32
lines changed

fs/btrfs/scrub.c

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3166,17 +3166,18 @@ static int sync_write_pointer_for_zoned(struct scrub_ctx *sctx, u64 logical,
31663166
}
31673167

31683168
static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
3169+
struct btrfs_block_group *bg,
31693170
struct map_lookup *map,
31703171
struct btrfs_device *scrub_dev,
3171-
int num, u64 base, u64 length,
3172-
struct btrfs_block_group *cache)
3172+
int stripe_index, u64 dev_extent_len)
31733173
{
31743174
struct btrfs_path *path;
31753175
struct btrfs_fs_info *fs_info = sctx->fs_info;
31763176
struct btrfs_root *root;
31773177
struct btrfs_root *csum_root;
31783178
struct btrfs_extent_item *extent;
31793179
struct blk_plug plug;
3180+
const u64 chunk_logical = bg->start;
31803181
u64 flags;
31813182
int ret;
31823183
int slot;
@@ -3204,25 +3205,26 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
32043205
int extent_mirror_num;
32053206
int stop_loop = 0;
32063207

3207-
physical = map->stripes[num].physical;
3208+
physical = map->stripes[stripe_index].physical;
32083209
offset = 0;
3209-
nstripes = div64_u64(length, map->stripe_len);
3210+
nstripes = div64_u64(dev_extent_len, map->stripe_len);
32103211
mirror_num = 1;
32113212
increment = map->stripe_len;
32123213
if (map->type & BTRFS_BLOCK_GROUP_RAID0) {
3213-
offset = map->stripe_len * num;
3214+
offset = map->stripe_len * stripe_index;
32143215
increment = map->stripe_len * map->num_stripes;
32153216
} else if (map->type & BTRFS_BLOCK_GROUP_RAID10) {
32163217
int factor = map->num_stripes / map->sub_stripes;
3217-
offset = map->stripe_len * (num / map->sub_stripes);
3218+
offset = map->stripe_len * (stripe_index / map->sub_stripes);
32183219
increment = map->stripe_len * factor;
3219-
mirror_num = num % map->sub_stripes + 1;
3220+
mirror_num = stripe_index % map->sub_stripes + 1;
32203221
} else if (map->type & BTRFS_BLOCK_GROUP_RAID1_MASK) {
3221-
mirror_num = num % map->num_stripes + 1;
3222+
mirror_num = stripe_index % map->num_stripes + 1;
32223223
} else if (map->type & BTRFS_BLOCK_GROUP_DUP) {
3223-
mirror_num = num % map->num_stripes + 1;
3224+
mirror_num = stripe_index % map->num_stripes + 1;
32243225
} else if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) {
3225-
get_raid56_logic_offset(physical, num, map, &offset, NULL);
3226+
get_raid56_logic_offset(physical, stripe_index, map, &offset,
3227+
NULL);
32263228
increment = map->stripe_len * nr_data_stripes(map);
32273229
}
32283230

@@ -3239,12 +3241,12 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
32393241
path->skip_locking = 1;
32403242
path->reada = READA_FORWARD;
32413243

3242-
logical = base + offset;
3244+
logical = chunk_logical + offset;
32433245
physical_end = physical + nstripes * map->stripe_len;
32443246
if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) {
3245-
get_raid56_logic_offset(physical_end, num,
3247+
get_raid56_logic_offset(physical_end, stripe_index,
32463248
map, &logic_end, NULL);
3247-
logic_end += base;
3249+
logic_end += chunk_logical;
32483250
} else {
32493251
logic_end = logical + increment * nstripes;
32503252
}
@@ -3299,13 +3301,13 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
32993301
}
33003302

33013303
if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) {
3302-
ret = get_raid56_logic_offset(physical, num, map,
3303-
&logical,
3304+
ret = get_raid56_logic_offset(physical, stripe_index,
3305+
map, &logical,
33043306
&stripe_logical);
3305-
logical += base;
3307+
logical += chunk_logical;
33063308
if (ret) {
33073309
/* it is parity strip */
3308-
stripe_logical += base;
3310+
stripe_logical += chunk_logical;
33093311
stripe_end = stripe_logical + increment;
33103312
ret = scrub_raid56_parity(sctx, map, scrub_dev,
33113313
stripe_logical,
@@ -3385,13 +3387,13 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
33853387
* Continuing would prevent reusing its device extents
33863388
* for new block groups for a long time.
33873389
*/
3388-
spin_lock(&cache->lock);
3389-
if (cache->removed) {
3390-
spin_unlock(&cache->lock);
3390+
spin_lock(&bg->lock);
3391+
if (bg->removed) {
3392+
spin_unlock(&bg->lock);
33913393
ret = 0;
33923394
goto out;
33933395
}
3394-
spin_unlock(&cache->lock);
3396+
spin_unlock(&bg->lock);
33953397

33963398
extent = btrfs_item_ptr(l, slot,
33973399
struct btrfs_extent_item);
@@ -3470,12 +3472,12 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
34703472
loop:
34713473
physical += map->stripe_len;
34723474
ret = get_raid56_logic_offset(physical,
3473-
num, map, &logical,
3474-
&stripe_logical);
3475-
logical += base;
3475+
stripe_index, map,
3476+
&logical, &stripe_logical);
3477+
logical += chunk_logical;
34763478

34773479
if (ret && physical < physical_end) {
3478-
stripe_logical += base;
3480+
stripe_logical += chunk_logical;
34793481
stripe_end = stripe_logical +
34803482
increment;
34813483
ret = scrub_raid56_parity(sctx,
@@ -3509,8 +3511,8 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
35093511
physical += map->stripe_len;
35103512
spin_lock(&sctx->stat_lock);
35113513
if (stop_loop)
3512-
sctx->stat.last_physical = map->stripes[num].physical +
3513-
length;
3514+
sctx->stat.last_physical = map->stripes[stripe_index].physical +
3515+
dev_extent_len;
35143516
else
35153517
sctx->stat.last_physical = physical;
35163518
spin_unlock(&sctx->stat_lock);
@@ -3530,9 +3532,10 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
35303532
if (sctx->is_dev_replace && ret >= 0) {
35313533
int ret2;
35323534

3533-
ret2 = sync_write_pointer_for_zoned(sctx, base + offset,
3534-
map->stripes[num].physical,
3535-
physical_end);
3535+
ret2 = sync_write_pointer_for_zoned(sctx,
3536+
chunk_logical + offset,
3537+
map->stripes[stripe_index].physical,
3538+
physical_end);
35363539
if (ret2)
35373540
ret = ret2;
35383541
}
@@ -3578,8 +3581,8 @@ static noinline_for_stack int scrub_chunk(struct scrub_ctx *sctx,
35783581
for (i = 0; i < map->num_stripes; ++i) {
35793582
if (map->stripes[i].dev->bdev == scrub_dev->bdev &&
35803583
map->stripes[i].physical == dev_offset) {
3581-
ret = scrub_stripe(sctx, map, scrub_dev, i,
3582-
bg->start, dev_extent_len, bg);
3584+
ret = scrub_stripe(sctx, bg, map, scrub_dev, i,
3585+
dev_extent_len);
35833586
if (ret)
35843587
goto out;
35853588
}

0 commit comments

Comments
 (0)