CC: [email protected]
BCC: [email protected]
TO: David Sterba <[email protected]>
tree: git://git.infradead.org/users/hch/misc.git btrfs-bio-cleanup-part3
head: 50401c1bd218c77092656710b2fc11b3b246679f
commit: a5a1b794bfc6bb041a95bc86869a8c4540f193dd [153/174] btrfs: introduce
dedicated helper to scrub simple-mirror based range
:::::: branch date: 12 hours ago
:::::: commit date: 20 hours ago
compiler: microblaze-linux-gcc (GCC) 11.2.0
reproduce (cppcheck warning):
# apt-get install cppcheck
git checkout a5a1b794bfc6bb041a95bc86869a8c4540f193dd
cppcheck --quiet --enable=style,performance,portability --template=gcc
FILE
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>
cppcheck possible warnings: (new ones prefixed by >>, may not real problems)
fs/btrfs/scrub.c:1220:13: warning: Parameter 'raid_map' can be declared with
const [constParameter]
u64 *raid_map,
^
>> fs/btrfs/scrub.c:3416:9: warning: Uninitialized variable: ret [uninitvar]
return ret;
^
fs/btrfs/scrub.c:3314:21: note: Assuming condition is false
while (cur_logical < logical_end) {
^
fs/btrfs/scrub.c:3416:9: note: Uninitialized variable: ret
return ret;
^
vim +3416 fs/btrfs/scrub.c
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3281
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3282 /*
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3283 * Scrub one range which can only
has simple mirror based profile.
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3284 * (Including all range in
SINGLE/DUP/RAID1/RAID1C*, and each stripe in
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3285 * RAID0/RAID10).
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3286 *
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3287 * Since we may need to handle a
subset of block group, we need @logical_start
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3288 * and @logical_length parameter.
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3289 */
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3290 static int
scrub_simple_mirror(struct scrub_ctx *sctx,
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3291 struct
btrfs_root *extent_root,
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3292 struct
btrfs_root *csum_root,
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3293 struct
btrfs_block_group *bg,
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3294 struct
map_lookup *map,
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3295 u64
logical_start, u64 logical_length,
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3296 struct
btrfs_device *device,
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3297 u64
physical, int mirror_num)
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3298 {
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3299 struct btrfs_fs_info *fs_info =
sctx->fs_info;
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3300 const u64 logical_end =
logical_start + logical_length;
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3301 /* An artificial limit, inherit
from old scrub behavior */
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3302 const u32 max_length = SZ_64K;
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3303 struct btrfs_path path = {};
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3304 u64 cur_logical = logical_start;
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3305 int ret;
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3306
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3307 /* The range must be inside the
bg */
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3308 ASSERT(logical_start >=
bg->start &&
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3309 logical_end <= bg->start
+ bg->length);
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3310
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3311 path.search_commit_root = 1;
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3312 path.skip_locking = 1;
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3313 /* Go through each extent items
inside the logical range */
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3314 while (cur_logical <
logical_end) {
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3315 int cur_mirror =
mirror_num;
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3316 struct btrfs_device
*target_dev = device;
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3317 u64 extent_start;
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3318 u64 extent_len;
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3319 u64 extent_flags;
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3320 u64 extent_gen;
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3321 u64 scrub_len;
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3322 u64 cur_physical;
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3323
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3324 /* Canceled ? */
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3325 if
(atomic_read(&fs_info->scrub_cancel_req) ||
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3326
atomic_read(&sctx->cancel_req)) {
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3327 ret =
-ECANCELED;
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3328 break;
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3329 }
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3330 /* Paused ? */
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3331 if
(atomic_read(&fs_info->scrub_pause_req)) {
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3332 /* Push queued
extents */
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3333
sctx->flush_all_writes = true;
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3334
scrub_submit(sctx);
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3335
mutex_lock(&sctx->wr_lock);
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3336
scrub_wr_submit(sctx);
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3337
mutex_unlock(&sctx->wr_lock);
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3338
wait_event(sctx->list_wait,
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3339
atomic_read(&sctx->bios_in_flight) == 0);
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3340
sctx->flush_all_writes = false;
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3341
scrub_blocked_if_needed(fs_info);
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3342 }
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3343 /* Block group removed?
*/
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3344 spin_lock(&bg->lock);
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3345 if (bg->removed) {
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3346
spin_unlock(&bg->lock);
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3347 ret = 0;
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3348 break;
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3349 }
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3350 spin_unlock(&bg->lock);
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3351
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3352 ret =
find_first_extent_item(extent_root, &path, cur_logical,
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3353
logical_end - cur_logical);
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3354 if (ret > 0) {
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3355 /* No more
extent, just update the accounting */
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3356
sctx->stat.last_physical = physical + logical_length;
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3357 ret = 0;
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3358 break;
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3359 }
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3360 if (ret < 0)
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3361 break;
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3362 get_extent_info(&path,
&extent_start, &extent_len,
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3363
&extent_flags, &extent_gen);
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3364 /* Skip hole range
which doesn't have any extent */
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3365 cur_logical =
max(extent_start, cur_logical);
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3366
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3367 /*
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3368 * Scrub len has three
limits:
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3369 * - Extent size limit
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3370 * - Scrub range limit
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3371 * This is especially
imporatant for RAID0/RAID10 to reuse
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3372 * this function
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3373 * - Max scrub size
limit
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3374 */
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3375 scrub_len =
min(min(extent_start + extent_len,
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3376
logical_end), cur_logical + max_length) -
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3377 cur_logical;
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3378 cur_physical =
cur_logical - logical_start + physical;
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3379
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3380 if
(sctx->is_dev_replace)
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3381
scrub_remap_extent(fs_info, cur_logical, scrub_len,
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3382
&cur_physical, &target_dev, &cur_mirror);
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3383 if (extent_flags &
BTRFS_EXTENT_FLAG_DATA) {
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3384 ret =
btrfs_lookup_csums_range(csum_root, cur_logical,
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3385
cur_logical + scrub_len - 1,
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3386
&sctx->csum_list, 1);
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3387 if (ret)
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3388 break;
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3389 }
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3390 if ((extent_flags &
BTRFS_EXTENT_FLAG_TREE_BLOCK) &&
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3391
does_range_cross_boundary(extent_start, extent_len,
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3392
logical_start, logical_length)) {
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3393
btrfs_err(fs_info,
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3394 "scrub: tree block %llu spanning
boundaries, ignored. boundary=[%llu, %llu)",
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3395
extent_start, logical_start, logical_end);
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3396
spin_lock(&sctx->stat_lock);
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3397
sctx->stat.uncorrectable_errors++;
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3398
spin_unlock(&sctx->stat_lock);
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3399 cur_logical +=
scrub_len;
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3400 continue;
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3401 }
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3402 ret =
scrub_extent(sctx, map, cur_logical, scrub_len, cur_physical,
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3403
target_dev, extent_flags, extent_gen,
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3404
cur_mirror, cur_logical - logical_start +
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3405
physical);
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3406 scrub_free_csums(sctx);
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3407 if (ret)
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3408 break;
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3409 if
(sctx->is_dev_replace)
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3410
sync_replace_for_zoned(sctx);
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3411 cur_logical +=
scrub_len;
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3412 /* Don't hold CPU for
too long time */
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3413 cond_resched();
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3414 }
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3415 btrfs_release_path(&path);
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 @3416 return ret;
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3417 }
a5a1b794bfc6bb04 Qu Wenruo 2022-03-11 3418
--
0-DAY CI Kernel Test Service
https://01.org/lkp
_______________________________________________
kbuild mailing list -- [email protected]
To unsubscribe send an email to [email protected]