CC: [email protected]
CC: Linux Memory Management List <[email protected]>
TO: Qu Wenruo <[email protected]>
CC: David Sterba <[email protected]>

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git 
master
head:   d25ee88530253138d0b20d43511ca5acbda4e9f7
commit: fa676286533c1c414da23d5ef8ae452c7f66e9b7 [1591/1734] btrfs: use 
scrub_simple_mirror() to handle RAID56 data stripe scrub
:::::: branch date: 2 days ago
:::::: commit date: 2 days ago
config: openrisc-randconfig-m031-20220124 
(https://download.01.org/0day-ci/archive/20220127/[email protected]/config)
compiler: or1k-linux-gcc (GCC) 11.2.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>
Reported-by: Dan Carpenter <[email protected]>

New smatch warnings:
fs/btrfs/scrub.c:3678 scrub_stripe() error: uninitialized symbol 'offset'.
fs/btrfs/scrub.c:3680 scrub_stripe() error: uninitialized symbol 'physical_end'.

Old smatch warnings:
fs/btrfs/scrub.c:3439 scrub_simple_mirror() error: uninitialized symbol 'ret'.

vim +/offset +3678 fs/btrfs/scrub.c

38d2dda468be859 Qu Wenruo       2022-01-07  3512  
d9d181c1ba7aa09 Stefan Behrens  2012-11-02  3513  static noinline_for_stack int 
scrub_stripe(struct scrub_ctx *sctx,
2ae8ae3d3def4c3 Qu Wenruo       2021-12-15  3514                                
           struct btrfs_block_group *bg,
a36cf8b8933e4a7 Stefan Behrens  2012-11-02  3515                                
           struct map_lookup *map,
a36cf8b8933e4a7 Stefan Behrens  2012-11-02  3516                                
           struct btrfs_device *scrub_dev,
2ae8ae3d3def4c3 Qu Wenruo       2021-12-15  3517                                
           int stripe_index, u64 dev_extent_len)
a2de733c78fa7af Arne Jansen     2011-03-08  3518  {
2522dbe86b54ff0 Qu Wenruo       2021-12-14  3519        struct btrfs_path *path;
fb456252d3d9c05 Jeff Mahoney    2016-06-22  3520        struct btrfs_fs_info 
*fs_info = sctx->fs_info;
29cbcf401793f4e Josef Bacik     2021-11-05  3521        struct btrfs_root *root;
fc28b25e1f42865 Josef Bacik     2021-11-05  3522        struct btrfs_root 
*csum_root;
e7786c3ae517b2c Arne Jansen     2011-05-28  3523        struct blk_plug plug;
b5b99b1e02969dd Qu Wenruo       2022-01-07  3524        const u64 profile = 
map->type & BTRFS_BLOCK_GROUP_PROFILE_MASK;
2ae8ae3d3def4c3 Qu Wenruo       2021-12-15  3525        const u64 chunk_logical 
= bg->start;
a2de733c78fa7af Arne Jansen     2011-03-08  3526        int ret;
a2de733c78fa7af Arne Jansen     2011-03-08  3527        u64 nstripes;
a2de733c78fa7af Arne Jansen     2011-03-08  3528        u64 physical;
a2de733c78fa7af Arne Jansen     2011-03-08  3529        u64 logical;
625f1c8dc66d778 Liu Bo          2013-04-27  3530        u64 logic_end;
3b080b2564287be Wang Shilong    2014-04-01  3531        u64 physical_end;
fa676286533c1c4 Qu Wenruo       2022-01-07  3532        u64 increment;  /* The 
logical increment after finishing one stripe */
fa676286533c1c4 Qu Wenruo       2022-01-07  3533        u64 offset;     /* 
Offset inside the chunk */
5a6ac9eacb49143 Miao Xie        2014-11-06  3534        u64 stripe_logical;
5a6ac9eacb49143 Miao Xie        2014-11-06  3535        u64 stripe_end;
3b080b2564287be Wang Shilong    2014-04-01  3536        int stop_loop = 0;
53b381b3abeb86f David Woodhouse 2013-01-29  3537  
a2de733c78fa7af Arne Jansen     2011-03-08  3538        path = 
btrfs_alloc_path();
a2de733c78fa7af Arne Jansen     2011-03-08  3539        if (!path)
a2de733c78fa7af Arne Jansen     2011-03-08  3540                return -ENOMEM;
a2de733c78fa7af Arne Jansen     2011-03-08  3541  
b5d67f64f9bc656 Stefan Behrens  2012-03-27  3542        /*
fa676286533c1c4 Qu Wenruo       2022-01-07  3543         * Work on commit root. 
The related disk blocks are static as
b5d67f64f9bc656 Stefan Behrens  2012-03-27  3544         * long as COW is 
applied. This means, it is save to rewrite
b5d67f64f9bc656 Stefan Behrens  2012-03-27  3545         * them to repair disk 
errors without any race conditions
b5d67f64f9bc656 Stefan Behrens  2012-03-27  3546         */
a2de733c78fa7af Arne Jansen     2011-03-08  3547        
path->search_commit_root = 1;
a2de733c78fa7af Arne Jansen     2011-03-08  3548        path->skip_locking = 1;
dcf62b204c06ac2 Qu Wenruo       2021-12-14  3549        path->reada = 
READA_FORWARD;
a2de733c78fa7af Arne Jansen     2011-03-08  3550  
d9d181c1ba7aa09 Stefan Behrens  2012-11-02  3551        
wait_event(sctx->list_wait,
b6bfebc13218f1f Stefan Behrens  2012-11-02  3552                   
atomic_read(&sctx->bios_in_flight) == 0);
cb7ab02156e4ba9 Wang Shilong    2013-12-04  3553        
scrub_blocked_if_needed(fs_info);
a2de733c78fa7af Arne Jansen     2011-03-08  3554  
fa676286533c1c4 Qu Wenruo       2022-01-07  3555        root = 
btrfs_extent_root(fs_info, bg->start);
fa676286533c1c4 Qu Wenruo       2022-01-07  3556        csum_root = 
btrfs_csum_root(fs_info, bg->start);
fc28b25e1f42865 Josef Bacik     2021-11-05  3557  
a2de733c78fa7af Arne Jansen     2011-03-08  3558        /*
fa676286533c1c4 Qu Wenruo       2022-01-07  3559         * Collect all data 
csums for the stripe to avoid seeking during
a2de733c78fa7af Arne Jansen     2011-03-08  3560         * the scrub. This 
might currently (crc32) end up to be about 1MB
a2de733c78fa7af Arne Jansen     2011-03-08  3561         */
e7786c3ae517b2c Arne Jansen     2011-05-28  3562        blk_start_plug(&plug);
a2de733c78fa7af Arne Jansen     2011-03-08  3563  
de17addce7a20db Naohiro Aota    2021-02-04  3564        if 
(sctx->is_dev_replace &&
fa676286533c1c4 Qu Wenruo       2022-01-07  3565            
btrfs_dev_is_sequential(sctx->wr_tgtdev,
fa676286533c1c4 Qu Wenruo       2022-01-07  3566                                
    map->stripes[stripe_index].physical)) {
de17addce7a20db Naohiro Aota    2021-02-04  3567                
mutex_lock(&sctx->wr_lock);
fa676286533c1c4 Qu Wenruo       2022-01-07  3568                
sctx->write_pointer = map->stripes[stripe_index].physical;
de17addce7a20db Naohiro Aota    2021-02-04  3569                
mutex_unlock(&sctx->wr_lock);
de17addce7a20db Naohiro Aota    2021-02-04  3570                
sctx->flush_all_writes = true;
de17addce7a20db Naohiro Aota    2021-02-04  3571        }
de17addce7a20db Naohiro Aota    2021-02-04  3572  
b5b99b1e02969dd Qu Wenruo       2022-01-07  3573        /*
b5b99b1e02969dd Qu Wenruo       2022-01-07  3574         * There used to be a 
big double loop to handle all profiles using the
b5b99b1e02969dd Qu Wenruo       2022-01-07  3575         * same routine, which 
grows larger and more gross over time.
b5b99b1e02969dd Qu Wenruo       2022-01-07  3576         *
b5b99b1e02969dd Qu Wenruo       2022-01-07  3577         * So here we handle 
each profile differently, so simpler profiles
b5b99b1e02969dd Qu Wenruo       2022-01-07  3578         * have simpler 
scrubing function.
b5b99b1e02969dd Qu Wenruo       2022-01-07  3579         */
b5b99b1e02969dd Qu Wenruo       2022-01-07  3580        if (!(profile & 
(BTRFS_BLOCK_GROUP_RAID0 | BTRFS_BLOCK_GROUP_RAID10 |
b5b99b1e02969dd Qu Wenruo       2022-01-07  3581                         
BTRFS_BLOCK_GROUP_RAID56_MASK))) {
b5b99b1e02969dd Qu Wenruo       2022-01-07  3582                /*
b5b99b1e02969dd Qu Wenruo       2022-01-07  3583                 * Above check 
rules out all complex profile, the remaining
b5b99b1e02969dd Qu Wenruo       2022-01-07  3584                 * profiles are 
SINGLE|DUP|RAID1|RAID1C*, which is simple
b5b99b1e02969dd Qu Wenruo       2022-01-07  3585                 * mirrored 
duplication without stripe.
b5b99b1e02969dd Qu Wenruo       2022-01-07  3586                 *
b5b99b1e02969dd Qu Wenruo       2022-01-07  3587                 * Only 
@phsyical and @mirror_num needs to calculated using
b5b99b1e02969dd Qu Wenruo       2022-01-07  3588                 * 
@stripe_index.
b5b99b1e02969dd Qu Wenruo       2022-01-07  3589                 */
b5b99b1e02969dd Qu Wenruo       2022-01-07  3590                ret = 
scrub_simple_mirror(sctx, root, csum_root, bg, map,
b5b99b1e02969dd Qu Wenruo       2022-01-07  3591                                
bg->start, bg->length, scrub_dev,
b5b99b1e02969dd Qu Wenruo       2022-01-07  3592                                
map->stripes[stripe_index].physical,
b5b99b1e02969dd Qu Wenruo       2022-01-07  3593                                
stripe_index + 1);
b5b99b1e02969dd Qu Wenruo       2022-01-07  3594                goto out;
b5b99b1e02969dd Qu Wenruo       2022-01-07  3595        }
38d2dda468be859 Qu Wenruo       2022-01-07  3596        if (profile & 
(BTRFS_BLOCK_GROUP_RAID0 | BTRFS_BLOCK_GROUP_RAID10)) {
38d2dda468be859 Qu Wenruo       2022-01-07  3597                ret = 
scrub_simple_stripe(sctx, root, csum_root, bg, map,
38d2dda468be859 Qu Wenruo       2022-01-07  3598                                
          scrub_dev, stripe_index);
38d2dda468be859 Qu Wenruo       2022-01-07  3599                goto out;
38d2dda468be859 Qu Wenruo       2022-01-07  3600        }
38d2dda468be859 Qu Wenruo       2022-01-07  3601  
38d2dda468be859 Qu Wenruo       2022-01-07  3602        /* Only RAID56 goes 
through the old code */
38d2dda468be859 Qu Wenruo       2022-01-07  3603        ASSERT(map->type & 
BTRFS_BLOCK_GROUP_RAID56_MASK);
fa676286533c1c4 Qu Wenruo       2022-01-07  3604  
fa676286533c1c4 Qu Wenruo       2022-01-07  3605        physical = 
map->stripes[stripe_index].physical;
fa676286533c1c4 Qu Wenruo       2022-01-07  3606        offset = 0;
fa676286533c1c4 Qu Wenruo       2022-01-07  3607        nstripes = 
div64_u64(dev_extent_len, map->stripe_len);
fa676286533c1c4 Qu Wenruo       2022-01-07  3608        
get_raid56_logic_offset(physical, stripe_index, map, &offset, NULL);
fa676286533c1c4 Qu Wenruo       2022-01-07  3609        increment = 
map->stripe_len * nr_data_stripes(map);
fa676286533c1c4 Qu Wenruo       2022-01-07  3610  
fa676286533c1c4 Qu Wenruo       2022-01-07  3611        logical = chunk_logical 
+ offset;
fa676286533c1c4 Qu Wenruo       2022-01-07  3612        physical_end = physical 
+ nstripes * map->stripe_len;
fa676286533c1c4 Qu Wenruo       2022-01-07  3613        
get_raid56_logic_offset(physical_end, stripe_index, map, &logic_end,
fa676286533c1c4 Qu Wenruo       2022-01-07  3614                                
NULL);
fa676286533c1c4 Qu Wenruo       2022-01-07  3615        logic_end += 
chunk_logical;
fa676286533c1c4 Qu Wenruo       2022-01-07  3616  
a2de733c78fa7af Arne Jansen     2011-03-08  3617        ret = 0;
a2de733c78fa7af Arne Jansen     2011-03-08  3618        /*
fa676286533c1c4 Qu Wenruo       2022-01-07  3619         * Due to the rotation, 
for RAID56 it's better to iterate each stripe
fa676286533c1c4 Qu Wenruo       2022-01-07  3620         * using their physical 
offset.
a2de733c78fa7af Arne Jansen     2011-03-08  3621         */
fa676286533c1c4 Qu Wenruo       2022-01-07  3622        while (physical < 
physical_end) {
fa676286533c1c4 Qu Wenruo       2022-01-07  3623                ret = 
get_raid56_logic_offset(physical, stripe_index, map,
fa676286533c1c4 Qu Wenruo       2022-01-07  3624                                
              &logical, &stripe_logical);
2ae8ae3d3def4c3 Qu Wenruo       2021-12-15  3625                logical += 
chunk_logical;
f2f66a2f886383f Zhao Lei        2015-07-21  3626                if (ret) {
fa676286533c1c4 Qu Wenruo       2022-01-07  3627                        /* It 
is parity strip */
2ae8ae3d3def4c3 Qu Wenruo       2021-12-15  3628                        
stripe_logical += chunk_logical;
a0dd59de3c73fbb Zhao Lei        2015-07-21  3629                        
stripe_end = stripe_logical + increment;
f2f66a2f886383f Zhao Lei        2015-07-21  3630                        ret = 
scrub_raid56_parity(sctx, map, scrub_dev,
2522dbe86b54ff0 Qu Wenruo       2021-12-14  3631                                
                  stripe_logical,
f2f66a2f886383f Zhao Lei        2015-07-21  3632                                
                  stripe_end);
f2f66a2f886383f Zhao Lei        2015-07-21  3633                        if (ret)
f2f66a2f886383f Zhao Lei        2015-07-21  3634                                
goto out;
a2de733c78fa7af Arne Jansen     2011-03-08  3635                        goto 
next;
a2de733c78fa7af Arne Jansen     2011-03-08  3636                }
a2de733c78fa7af Arne Jansen     2011-03-08  3637  
a2de733c78fa7af Arne Jansen     2011-03-08  3638                /*
fa676286533c1c4 Qu Wenruo       2022-01-07  3639                 * Now we're at 
data stripes, scrub each extents in the range.
fa676286533c1c4 Qu Wenruo       2022-01-07  3640                 *
fa676286533c1c4 Qu Wenruo       2022-01-07  3641                 * At this 
stage, if we ignore the repair part, each data stripe
fa676286533c1c4 Qu Wenruo       2022-01-07  3642                 * is no 
different than SINGLE profile.
fa676286533c1c4 Qu Wenruo       2022-01-07  3643                 * We can reuse 
scrub_simple_mirror() here, as the repair part
fa676286533c1c4 Qu Wenruo       2022-01-07  3644                 * is still 
based on @mirror_num.
3b080b2564287be Wang Shilong    2014-04-01  3645                 */
fa676286533c1c4 Qu Wenruo       2022-01-07  3646                ret = 
scrub_simple_mirror(sctx, root, csum_root, bg, map,
fa676286533c1c4 Qu Wenruo       2022-01-07  3647                                
          logical, map->stripe_len,
fa676286533c1c4 Qu Wenruo       2022-01-07  3648                                
          scrub_dev, physical, 1);
fa676286533c1c4 Qu Wenruo       2022-01-07  3649                if (ret < 0)
5a6ac9eacb49143 Miao Xie        2014-11-06  3650                        goto 
out;
a2de733c78fa7af Arne Jansen     2011-03-08  3651  next:
a2de733c78fa7af Arne Jansen     2011-03-08  3652                logical += 
increment;
a2de733c78fa7af Arne Jansen     2011-03-08  3653                physical += 
map->stripe_len;
d9d181c1ba7aa09 Stefan Behrens  2012-11-02  3654                
spin_lock(&sctx->stat_lock);
625f1c8dc66d778 Liu Bo          2013-04-27  3655                if (stop_loop)
2ae8ae3d3def4c3 Qu Wenruo       2021-12-15  3656                        
sctx->stat.last_physical = map->stripes[stripe_index].physical +
2ae8ae3d3def4c3 Qu Wenruo       2021-12-15  3657                                
                   dev_extent_len;
625f1c8dc66d778 Liu Bo          2013-04-27  3658                else
d9d181c1ba7aa09 Stefan Behrens  2012-11-02  3659                        
sctx->stat.last_physical = physical;
d9d181c1ba7aa09 Stefan Behrens  2012-11-02  3660                
spin_unlock(&sctx->stat_lock);
625f1c8dc66d778 Liu Bo          2013-04-27  3661                if (stop_loop)
625f1c8dc66d778 Liu Bo          2013-04-27  3662                        break;
a2de733c78fa7af Arne Jansen     2011-03-08  3663        }
ff023aac31198e8 Stefan Behrens  2012-11-06  3664  out:
a2de733c78fa7af Arne Jansen     2011-03-08  3665        /* push queued extents 
*/
d9d181c1ba7aa09 Stefan Behrens  2012-11-02  3666        scrub_submit(sctx);
3fb99303c64e31f David Sterba    2017-05-16  3667        
mutex_lock(&sctx->wr_lock);
ff023aac31198e8 Stefan Behrens  2012-11-06  3668        scrub_wr_submit(sctx);
3fb99303c64e31f David Sterba    2017-05-16  3669        
mutex_unlock(&sctx->wr_lock);
a2de733c78fa7af Arne Jansen     2011-03-08  3670  
e7786c3ae517b2c Arne Jansen     2011-05-28  3671        blk_finish_plug(&plug);
a2de733c78fa7af Arne Jansen     2011-03-08  3672        btrfs_free_path(path);
7db1c5d14dcd521 Naohiro Aota    2021-02-04  3673  
7db1c5d14dcd521 Naohiro Aota    2021-02-04  3674        if 
(sctx->is_dev_replace && ret >= 0) {
7db1c5d14dcd521 Naohiro Aota    2021-02-04  3675                int ret2;
7db1c5d14dcd521 Naohiro Aota    2021-02-04  3676  
2ae8ae3d3def4c3 Qu Wenruo       2021-12-15  3677                ret2 = 
sync_write_pointer_for_zoned(sctx,
2ae8ae3d3def4c3 Qu Wenruo       2021-12-15 @3678                                
chunk_logical + offset,
2ae8ae3d3def4c3 Qu Wenruo       2021-12-15  3679                                
map->stripes[stripe_index].physical,
7db1c5d14dcd521 Naohiro Aota    2021-02-04 @3680                                
physical_end);
7db1c5d14dcd521 Naohiro Aota    2021-02-04  3681                if (ret2)
7db1c5d14dcd521 Naohiro Aota    2021-02-04  3682                        ret = 
ret2;
7db1c5d14dcd521 Naohiro Aota    2021-02-04  3683        }
7db1c5d14dcd521 Naohiro Aota    2021-02-04  3684  
a2de733c78fa7af Arne Jansen     2011-03-08  3685        return ret < 0 ? ret : 
0;
a2de733c78fa7af Arne Jansen     2011-03-08  3686  }
a2de733c78fa7af Arne Jansen     2011-03-08  3687  

:::::: The code at line 3678 was first introduced by commit
:::::: 2ae8ae3d3def4c3ba73a58cc2531c42f0916f14e btrfs: scrub: cleanup the 
argument list of scrub_stripe()

:::::: TO: Qu Wenruo <[email protected]>
:::::: CC: David Sterba <[email protected]>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]
_______________________________________________
kbuild mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to