@@ -3166,17 +3166,18 @@ static int sync_write_pointer_for_zoned(struct scrub_ctx *sctx, u64 logical,
3166
3166
}
3167
3167
3168
3168
static noinline_for_stack int scrub_stripe (struct scrub_ctx * sctx ,
3169
+ struct btrfs_block_group * bg ,
3169
3170
struct map_lookup * map ,
3170
3171
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 )
3173
3173
{
3174
3174
struct btrfs_path * path ;
3175
3175
struct btrfs_fs_info * fs_info = sctx -> fs_info ;
3176
3176
struct btrfs_root * root ;
3177
3177
struct btrfs_root * csum_root ;
3178
3178
struct btrfs_extent_item * extent ;
3179
3179
struct blk_plug plug ;
3180
+ const u64 chunk_logical = bg -> start ;
3180
3181
u64 flags ;
3181
3182
int ret ;
3182
3183
int slot ;
@@ -3204,25 +3205,26 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
3204
3205
int extent_mirror_num ;
3205
3206
int stop_loop = 0 ;
3206
3207
3207
- physical = map -> stripes [num ].physical ;
3208
+ physical = map -> stripes [stripe_index ].physical ;
3208
3209
offset = 0 ;
3209
- nstripes = div64_u64 (length , map -> stripe_len );
3210
+ nstripes = div64_u64 (dev_extent_len , map -> stripe_len );
3210
3211
mirror_num = 1 ;
3211
3212
increment = map -> stripe_len ;
3212
3213
if (map -> type & BTRFS_BLOCK_GROUP_RAID0 ) {
3213
- offset = map -> stripe_len * num ;
3214
+ offset = map -> stripe_len * stripe_index ;
3214
3215
increment = map -> stripe_len * map -> num_stripes ;
3215
3216
} else if (map -> type & BTRFS_BLOCK_GROUP_RAID10 ) {
3216
3217
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 );
3218
3219
increment = map -> stripe_len * factor ;
3219
- mirror_num = num % map -> sub_stripes + 1 ;
3220
+ mirror_num = stripe_index % map -> sub_stripes + 1 ;
3220
3221
} 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 ;
3222
3223
} 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 ;
3224
3225
} 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 );
3226
3228
increment = map -> stripe_len * nr_data_stripes (map );
3227
3229
}
3228
3230
@@ -3239,12 +3241,12 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
3239
3241
path -> skip_locking = 1 ;
3240
3242
path -> reada = READA_FORWARD ;
3241
3243
3242
- logical = base + offset ;
3244
+ logical = chunk_logical + offset ;
3243
3245
physical_end = physical + nstripes * map -> stripe_len ;
3244
3246
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 ,
3246
3248
map , & logic_end , NULL );
3247
- logic_end += base ;
3249
+ logic_end += chunk_logical ;
3248
3250
} else {
3249
3251
logic_end = logical + increment * nstripes ;
3250
3252
}
@@ -3299,13 +3301,13 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
3299
3301
}
3300
3302
3301
3303
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 ,
3304
3306
& stripe_logical );
3305
- logical += base ;
3307
+ logical += chunk_logical ;
3306
3308
if (ret ) {
3307
3309
/* it is parity strip */
3308
- stripe_logical += base ;
3310
+ stripe_logical += chunk_logical ;
3309
3311
stripe_end = stripe_logical + increment ;
3310
3312
ret = scrub_raid56_parity (sctx , map , scrub_dev ,
3311
3313
stripe_logical ,
@@ -3385,13 +3387,13 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
3385
3387
* Continuing would prevent reusing its device extents
3386
3388
* for new block groups for a long time.
3387
3389
*/
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 );
3391
3393
ret = 0 ;
3392
3394
goto out ;
3393
3395
}
3394
- spin_unlock (& cache -> lock );
3396
+ spin_unlock (& bg -> lock );
3395
3397
3396
3398
extent = btrfs_item_ptr (l , slot ,
3397
3399
struct btrfs_extent_item );
@@ -3470,12 +3472,12 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
3470
3472
loop :
3471
3473
physical += map -> stripe_len ;
3472
3474
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 ;
3476
3478
3477
3479
if (ret && physical < physical_end ) {
3478
- stripe_logical += base ;
3480
+ stripe_logical += chunk_logical ;
3479
3481
stripe_end = stripe_logical +
3480
3482
increment ;
3481
3483
ret = scrub_raid56_parity (sctx ,
@@ -3509,8 +3511,8 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
3509
3511
physical += map -> stripe_len ;
3510
3512
spin_lock (& sctx -> stat_lock );
3511
3513
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 ;
3514
3516
else
3515
3517
sctx -> stat .last_physical = physical ;
3516
3518
spin_unlock (& sctx -> stat_lock );
@@ -3530,9 +3532,10 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
3530
3532
if (sctx -> is_dev_replace && ret >= 0 ) {
3531
3533
int ret2 ;
3532
3534
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 );
3536
3539
if (ret2 )
3537
3540
ret = ret2 ;
3538
3541
}
@@ -3578,8 +3581,8 @@ static noinline_for_stack int scrub_chunk(struct scrub_ctx *sctx,
3578
3581
for (i = 0 ; i < map -> num_stripes ; ++ i ) {
3579
3582
if (map -> stripes [i ].dev -> bdev == scrub_dev -> bdev &&
3580
3583
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 );
3583
3586
if (ret )
3584
3587
goto out ;
3585
3588
}
0 commit comments