diff mbox series

[v2,18/19] ext4: add some kunit stub for mballoc kunit test

Message ID 20230412172833.2317696-19-shikemeng@huaweicloud.com
State Superseded
Headers show
Series Fixes, cleanups and unit test for mballoc | expand

Commit Message

Kemeng Shi April 12, 2023, 5:28 p.m. UTC
Multiblocks allocation will read and write block bitmap and group
descriptor which reside on disk. Add kunit stub to function
ext4_get_group_desc, ext4_read_block_bitmap_nowait, ext4_wait_block_bitmap
and ext4_mb_mark_group_bb to avoid real IO to disk.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 fs/ext4/balloc.c  | 13 +++++++++++++
 fs/ext4/mballoc.c |  5 +++++
 2 files changed, 18 insertions(+)

Comments

kernel test robot April 12, 2023, 5:45 p.m. UTC | #1
Hi Kemeng,

kernel test robot noticed the following build warnings:

[auto build test WARNING on tytso-ext4/dev]
[also build test WARNING on next-20230412]
[cannot apply to linus/master v6.3-rc6]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Kemeng-Shi/ext4-fix-wrong-unit-use-in-ext4_mb_normalize_request/20230412-172757
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev
patch link:    https://lore.kernel.org/r/20230412172833.2317696-19-shikemeng%40huaweicloud.com
patch subject: [PATCH v2 18/19] ext4: add some kunit stub for mballoc kunit test
config: loongarch-randconfig-r004-20230409 (https://download.01.org/0day-ci/archive/20230413/202304130140.2kslXTgi-lkp@intel.com/config)
compiler: loongarch64-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/357d528a1ead868fa038c4bfe426744ac7c34ea6
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Kemeng-Shi/ext4-fix-wrong-unit-use-in-ext4_mb_normalize_request/20230412-172757
        git checkout 357d528a1ead868fa038c4bfe426744ac7c34ea6
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=loongarch olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=loongarch SHELL=/bin/bash fs/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202304130140.2kslXTgi-lkp@intel.com/

All warnings (new ones prefixed by >>):

   fs/ext4/mballoc.c: In function 'ext4_mb_mark_group_bb':
>> fs/ext4/mballoc.c:3752:9: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
    3752 |         handle_t *handle = mc->handle;
         |         ^~~~~~~~
--
   fs/ext4/balloc.c: In function 'ext4_get_group_desc':
>> fs/ext4/balloc.c:275:9: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
     275 |         unsigned int group_desc;
         |         ^~~~~~~~
   fs/ext4/balloc.c: In function 'ext4_read_block_bitmap_nowait':
   fs/ext4/balloc.c:435:9: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
     435 |         struct ext4_group_desc *desc;
         |         ^~~~~~
   fs/ext4/balloc.c: In function 'ext4_wait_block_bitmap':
   fs/ext4/balloc.c:538:9: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
     538 |         struct ext4_group_desc *desc;
         |         ^~~~~~


vim +3752 fs/ext4/mballoc.c

80cb2f14af5f5f Kemeng Shi 2023-04-13  3743  
80cb2f14af5f5f Kemeng Shi 2023-04-13  3744  static int
80cb2f14af5f5f Kemeng Shi 2023-04-13  3745  ext4_mb_mark_group_bb(struct ext4_mark_context *mc, ext4_group_t group,
a760807c4967d7 Kemeng Shi 2023-04-13  3746  		      ext4_grpblk_t blkoff, ext4_grpblk_t len, int flags)
80cb2f14af5f5f Kemeng Shi 2023-04-13  3747  {
357d528a1ead86 Kemeng Shi 2023-04-13  3748  #ifdef CONFIG_EXT4_KUNIT_TESTS
357d528a1ead86 Kemeng Shi 2023-04-13  3749  	KUNIT_STATIC_STUB_REDIRECT(ext4_mb_mark_group_bb,
357d528a1ead86 Kemeng Shi 2023-04-13  3750  				   mc, group, blkoff, len, flags);
357d528a1ead86 Kemeng Shi 2023-04-13  3751  #endif
a760807c4967d7 Kemeng Shi 2023-04-13 @3752  	handle_t *handle = mc->handle;
80cb2f14af5f5f Kemeng Shi 2023-04-13  3753  	struct super_block *sb = mc->sb;
80cb2f14af5f5f Kemeng Shi 2023-04-13  3754  	struct ext4_sb_info *sbi = EXT4_SB(sb);
80cb2f14af5f5f Kemeng Shi 2023-04-13  3755  	struct buffer_head *bitmap_bh = NULL;
80cb2f14af5f5f Kemeng Shi 2023-04-13  3756  	struct ext4_group_desc *gdp;
80cb2f14af5f5f Kemeng Shi 2023-04-13  3757  	struct buffer_head *gdp_bh;
80cb2f14af5f5f Kemeng Shi 2023-04-13  3758  	int err;
a760807c4967d7 Kemeng Shi 2023-04-13  3759  	unsigned int i, already, changed = len;
80cb2f14af5f5f Kemeng Shi 2023-04-13  3760  
a760807c4967d7 Kemeng Shi 2023-04-13  3761  	mc->changed = 0;
80cb2f14af5f5f Kemeng Shi 2023-04-13  3762  	bitmap_bh = ext4_read_block_bitmap(sb, group);
80cb2f14af5f5f Kemeng Shi 2023-04-13  3763  	if (IS_ERR(bitmap_bh))
80cb2f14af5f5f Kemeng Shi 2023-04-13  3764  		return PTR_ERR(bitmap_bh);
80cb2f14af5f5f Kemeng Shi 2023-04-13  3765  
a760807c4967d7 Kemeng Shi 2023-04-13  3766  	if (handle) {
a760807c4967d7 Kemeng Shi 2023-04-13  3767  		BUFFER_TRACE(bitmap_bh, "getting write access");
a760807c4967d7 Kemeng Shi 2023-04-13  3768  		err = ext4_journal_get_write_access(handle, sb, bitmap_bh,
a760807c4967d7 Kemeng Shi 2023-04-13  3769  						    EXT4_JTR_NONE);
a760807c4967d7 Kemeng Shi 2023-04-13  3770  		if (err)
a760807c4967d7 Kemeng Shi 2023-04-13  3771  			goto out_err;
a760807c4967d7 Kemeng Shi 2023-04-13  3772  	}
a760807c4967d7 Kemeng Shi 2023-04-13  3773  
80cb2f14af5f5f Kemeng Shi 2023-04-13  3774  	err = -EIO;
80cb2f14af5f5f Kemeng Shi 2023-04-13  3775  	gdp = ext4_get_group_desc(sb, group, &gdp_bh);
80cb2f14af5f5f Kemeng Shi 2023-04-13  3776  	if (!gdp)
80cb2f14af5f5f Kemeng Shi 2023-04-13  3777  		goto out_err;
80cb2f14af5f5f Kemeng Shi 2023-04-13  3778  
a760807c4967d7 Kemeng Shi 2023-04-13  3779  	if (handle) {
a760807c4967d7 Kemeng Shi 2023-04-13  3780  		BUFFER_TRACE(gdp_bh, "get_write_access");
a760807c4967d7 Kemeng Shi 2023-04-13  3781  		err = ext4_journal_get_write_access(handle, sb, gdp_bh,
a760807c4967d7 Kemeng Shi 2023-04-13  3782  						    EXT4_JTR_NONE);
a760807c4967d7 Kemeng Shi 2023-04-13  3783  		if (err)
a760807c4967d7 Kemeng Shi 2023-04-13  3784  			goto out_err;
a760807c4967d7 Kemeng Shi 2023-04-13  3785  	}
a760807c4967d7 Kemeng Shi 2023-04-13  3786  
80cb2f14af5f5f Kemeng Shi 2023-04-13  3787  	ext4_lock_group(sb, group);
80cb2f14af5f5f Kemeng Shi 2023-04-13  3788  	if (ext4_has_group_desc_csum(sb) &&
80cb2f14af5f5f Kemeng Shi 2023-04-13  3789  	    (gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT))) {
80cb2f14af5f5f Kemeng Shi 2023-04-13  3790  		gdp->bg_flags &= cpu_to_le16(~EXT4_BG_BLOCK_UNINIT);
80cb2f14af5f5f Kemeng Shi 2023-04-13  3791  		ext4_free_group_clusters_set(sb, gdp,
80cb2f14af5f5f Kemeng Shi 2023-04-13  3792  			ext4_free_clusters_after_init(sb, group, gdp));
80cb2f14af5f5f Kemeng Shi 2023-04-13  3793  	}
80cb2f14af5f5f Kemeng Shi 2023-04-13  3794  
a760807c4967d7 Kemeng Shi 2023-04-13  3795  	if (flags & EXT4_MB_BITMAP_MARKED_CHECK) {
80cb2f14af5f5f Kemeng Shi 2023-04-13  3796  		already = 0;
80cb2f14af5f5f Kemeng Shi 2023-04-13  3797  		for (i = 0; i < len; i++)
80cb2f14af5f5f Kemeng Shi 2023-04-13  3798  			if (mb_test_bit(blkoff + i, bitmap_bh->b_data) ==
80cb2f14af5f5f Kemeng Shi 2023-04-13  3799  					mc->state)
80cb2f14af5f5f Kemeng Shi 2023-04-13  3800  				already++;
80cb2f14af5f5f Kemeng Shi 2023-04-13  3801  		changed = len - already;
a760807c4967d7 Kemeng Shi 2023-04-13  3802  	}
80cb2f14af5f5f Kemeng Shi 2023-04-13  3803  
80cb2f14af5f5f Kemeng Shi 2023-04-13  3804  	if (mc->state) {
80cb2f14af5f5f Kemeng Shi 2023-04-13  3805  		mb_set_bits(bitmap_bh->b_data, blkoff, len);
80cb2f14af5f5f Kemeng Shi 2023-04-13  3806  		ext4_free_group_clusters_set(sb, gdp,
80cb2f14af5f5f Kemeng Shi 2023-04-13  3807  			ext4_free_group_clusters(sb, gdp) - changed);
80cb2f14af5f5f Kemeng Shi 2023-04-13  3808  	} else {
80cb2f14af5f5f Kemeng Shi 2023-04-13  3809  		mb_clear_bits(bitmap_bh->b_data, blkoff, len);
80cb2f14af5f5f Kemeng Shi 2023-04-13  3810  		ext4_free_group_clusters_set(sb, gdp,
80cb2f14af5f5f Kemeng Shi 2023-04-13  3811  			ext4_free_group_clusters(sb, gdp) + changed);
80cb2f14af5f5f Kemeng Shi 2023-04-13  3812  	}
80cb2f14af5f5f Kemeng Shi 2023-04-13  3813  
80cb2f14af5f5f Kemeng Shi 2023-04-13  3814  	ext4_block_bitmap_csum_set(sb, gdp, bitmap_bh);
80cb2f14af5f5f Kemeng Shi 2023-04-13  3815  	ext4_group_desc_csum_set(sb, group, gdp);
80cb2f14af5f5f Kemeng Shi 2023-04-13  3816  	ext4_unlock_group(sb, group);
a760807c4967d7 Kemeng Shi 2023-04-13  3817  	mc->changed = changed;
80cb2f14af5f5f Kemeng Shi 2023-04-13  3818  
80cb2f14af5f5f Kemeng Shi 2023-04-13  3819  	if (sbi->s_log_groups_per_flex) {
80cb2f14af5f5f Kemeng Shi 2023-04-13  3820  		ext4_group_t flex_group = ext4_flex_group(sbi, group);
80cb2f14af5f5f Kemeng Shi 2023-04-13  3821  		struct flex_groups *fg = sbi_array_rcu_deref(sbi,
80cb2f14af5f5f Kemeng Shi 2023-04-13  3822  					   s_flex_groups, flex_group);
80cb2f14af5f5f Kemeng Shi 2023-04-13  3823  
80cb2f14af5f5f Kemeng Shi 2023-04-13  3824  		if (mc->state)
80cb2f14af5f5f Kemeng Shi 2023-04-13  3825  			atomic64_sub(changed, &fg->free_clusters);
80cb2f14af5f5f Kemeng Shi 2023-04-13  3826  		else
80cb2f14af5f5f Kemeng Shi 2023-04-13  3827  			atomic64_add(changed, &fg->free_clusters);
80cb2f14af5f5f Kemeng Shi 2023-04-13  3828  	}
80cb2f14af5f5f Kemeng Shi 2023-04-13  3829  
a760807c4967d7 Kemeng Shi 2023-04-13  3830  	err = ext4_handle_dirty_metadata(handle, NULL, bitmap_bh);
80cb2f14af5f5f Kemeng Shi 2023-04-13  3831  	if (err)
80cb2f14af5f5f Kemeng Shi 2023-04-13  3832  		goto out_err;
a760807c4967d7 Kemeng Shi 2023-04-13  3833  	err = ext4_handle_dirty_metadata(handle, NULL, gdp_bh);
80cb2f14af5f5f Kemeng Shi 2023-04-13  3834  	if (err)
80cb2f14af5f5f Kemeng Shi 2023-04-13  3835  		goto out_err;
80cb2f14af5f5f Kemeng Shi 2023-04-13  3836  
a760807c4967d7 Kemeng Shi 2023-04-13  3837  	if (flags & EXT4_MB_SYNC_UPDATE) {
80cb2f14af5f5f Kemeng Shi 2023-04-13  3838  		sync_dirty_buffer(bitmap_bh);
80cb2f14af5f5f Kemeng Shi 2023-04-13  3839  		sync_dirty_buffer(gdp_bh);
a760807c4967d7 Kemeng Shi 2023-04-13  3840  	}
80cb2f14af5f5f Kemeng Shi 2023-04-13  3841  
80cb2f14af5f5f Kemeng Shi 2023-04-13  3842  out_err:
80cb2f14af5f5f Kemeng Shi 2023-04-13  3843  	brelse(bitmap_bh);
80cb2f14af5f5f Kemeng Shi 2023-04-13  3844  	return err;
80cb2f14af5f5f Kemeng Shi 2023-04-13  3845  }
c9de560ded61fa Alex Tomas 2008-01-29  3846
kernel test robot April 12, 2023, 6:16 p.m. UTC | #2
Hi Kemeng,

kernel test robot noticed the following build warnings:

[auto build test WARNING on tytso-ext4/dev]
[also build test WARNING on next-20230412]
[cannot apply to linus/master v6.3-rc6]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Kemeng-Shi/ext4-fix-wrong-unit-use-in-ext4_mb_normalize_request/20230412-172757
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev
patch link:    https://lore.kernel.org/r/20230412172833.2317696-19-shikemeng%40huaweicloud.com
patch subject: [PATCH v2 18/19] ext4: add some kunit stub for mballoc kunit test
config: powerpc-randconfig-r006-20230409 (https://download.01.org/0day-ci/archive/20230413/202304130244.S0jqbqkn-lkp@intel.com/config)
compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project 2c57868e2e877f73c339796c3374ae660bb77f0d)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install powerpc cross compiling tool for clang build
        # apt-get install binutils-powerpc-linux-gnu
        # https://github.com/intel-lab-lkp/linux/commit/357d528a1ead868fa038c4bfe426744ac7c34ea6
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Kemeng-Shi/ext4-fix-wrong-unit-use-in-ext4_mb_normalize_request/20230412-172757
        git checkout 357d528a1ead868fa038c4bfe426744ac7c34ea6
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=powerpc olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=powerpc SHELL=/bin/bash fs/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202304130244.S0jqbqkn-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> fs/ext4/balloc.c:275:15: warning: mixing declarations and code is incompatible with standards before C99 [-Wdeclaration-after-statement]
           unsigned int group_desc;
                        ^
   fs/ext4/balloc.c:435:26: warning: mixing declarations and code is incompatible with standards before C99 [-Wdeclaration-after-statement]
           struct ext4_group_desc *desc;
                                   ^
   fs/ext4/balloc.c:538:26: warning: mixing declarations and code is incompatible with standards before C99 [-Wdeclaration-after-statement]
           struct ext4_group_desc *desc;
                                   ^
   3 warnings generated.
--
>> fs/ext4/mballoc.c:3752:12: warning: mixing declarations and code is incompatible with standards before C99 [-Wdeclaration-after-statement]
           handle_t *handle = mc->handle;
                     ^
   1 warning generated.


vim +275 fs/ext4/balloc.c

717d50e4971b81 Andreas Dilger    2007-10-16  248  
ac27a0ec112a08 Dave Kleikamp     2006-10-11  249  /*
ac27a0ec112a08 Dave Kleikamp     2006-10-11  250   * The free blocks are managed by bitmaps.  A file system contains several
ac27a0ec112a08 Dave Kleikamp     2006-10-11  251   * blocks groups.  Each group contains 1 bitmap block for blocks, 1 bitmap
ac27a0ec112a08 Dave Kleikamp     2006-10-11  252   * block for inodes, N blocks for the inode table and data blocks.
ac27a0ec112a08 Dave Kleikamp     2006-10-11  253   *
ac27a0ec112a08 Dave Kleikamp     2006-10-11  254   * The file system contains group descriptors which are located after the
ac27a0ec112a08 Dave Kleikamp     2006-10-11  255   * super block.  Each descriptor contains the number of the bitmap block and
ac27a0ec112a08 Dave Kleikamp     2006-10-11  256   * the free blocks count in the block.  The descriptors are loaded in memory
e627432c2948d5 Aneesh Kumar K.V  2007-02-20  257   * when a file system is mounted (see ext4_fill_super).
ac27a0ec112a08 Dave Kleikamp     2006-10-11  258   */
ac27a0ec112a08 Dave Kleikamp     2006-10-11  259  
ac27a0ec112a08 Dave Kleikamp     2006-10-11  260  /**
617ba13b31fbf5 Mingming Cao      2006-10-11  261   * ext4_get_group_desc() -- load group descriptor from disk
ac27a0ec112a08 Dave Kleikamp     2006-10-11  262   * @sb:			super block
ac27a0ec112a08 Dave Kleikamp     2006-10-11  263   * @block_group:	given block group
ac27a0ec112a08 Dave Kleikamp     2006-10-11  264   * @bh:			pointer to the buffer head to store the block
ac27a0ec112a08 Dave Kleikamp     2006-10-11  265   *			group descriptor
ac27a0ec112a08 Dave Kleikamp     2006-10-11  266   */
617ba13b31fbf5 Mingming Cao      2006-10-11  267  struct ext4_group_desc * ext4_get_group_desc(struct super_block *sb,
fd2d42912f9f09 Avantika Mathur   2008-01-28  268  					     ext4_group_t block_group,
ac27a0ec112a08 Dave Kleikamp     2006-10-11  269  					     struct buffer_head **bh)
ac27a0ec112a08 Dave Kleikamp     2006-10-11  270  {
357d528a1ead86 Kemeng Shi        2023-04-13  271  #ifdef CONFIG_EXT4_KUNIT_TESTS
357d528a1ead86 Kemeng Shi        2023-04-13  272  	KUNIT_STATIC_STUB_REDIRECT(ext4_get_group_desc,
357d528a1ead86 Kemeng Shi        2023-04-13  273  				   sb, block_group, bh);
357d528a1ead86 Kemeng Shi        2023-04-13  274  #endif
498e5f24158da7 Theodore Ts'o     2008-11-05 @275  	unsigned int group_desc;
498e5f24158da7 Theodore Ts'o     2008-11-05  276  	unsigned int offset;
8df9675f8b498d Theodore Ts'o     2009-05-01  277  	ext4_group_t ngroups = ext4_get_groups_count(sb);
617ba13b31fbf5 Mingming Cao      2006-10-11  278  	struct ext4_group_desc *desc;
617ba13b31fbf5 Mingming Cao      2006-10-11  279  	struct ext4_sb_info *sbi = EXT4_SB(sb);
1d0c3924a92e69 Theodore Ts'o     2020-02-15  280  	struct buffer_head *bh_p;
ac27a0ec112a08 Dave Kleikamp     2006-10-11  281  
8df9675f8b498d Theodore Ts'o     2009-05-01  282  	if (block_group >= ngroups) {
12062dddda4509 Eric Sandeen      2010-02-15  283  		ext4_error(sb, "block_group >= groups_count - block_group = %u,"
12062dddda4509 Eric Sandeen      2010-02-15  284  			   " groups_count = %u", block_group, ngroups);
ac27a0ec112a08 Dave Kleikamp     2006-10-11  285  
ac27a0ec112a08 Dave Kleikamp     2006-10-11  286  		return NULL;
ac27a0ec112a08 Dave Kleikamp     2006-10-11  287  	}
ac27a0ec112a08 Dave Kleikamp     2006-10-11  288  
617ba13b31fbf5 Mingming Cao      2006-10-11  289  	group_desc = block_group >> EXT4_DESC_PER_BLOCK_BITS(sb);
617ba13b31fbf5 Mingming Cao      2006-10-11  290  	offset = block_group & (EXT4_DESC_PER_BLOCK(sb) - 1);
1d0c3924a92e69 Theodore Ts'o     2020-02-15  291  	bh_p = sbi_array_rcu_deref(sbi, s_group_desc, group_desc);
1d0c3924a92e69 Theodore Ts'o     2020-02-15  292  	/*
1d0c3924a92e69 Theodore Ts'o     2020-02-15  293  	 * sbi_array_rcu_deref returns with rcu unlocked, this is ok since
1d0c3924a92e69 Theodore Ts'o     2020-02-15  294  	 * the pointer being dereferenced won't be dereferenced again. By
1d0c3924a92e69 Theodore Ts'o     2020-02-15  295  	 * looking at the usage in add_new_gdb() the value isn't modified,
1d0c3924a92e69 Theodore Ts'o     2020-02-15  296  	 * just the pointer, and so it remains valid.
1d0c3924a92e69 Theodore Ts'o     2020-02-15  297  	 */
1d0c3924a92e69 Theodore Ts'o     2020-02-15  298  	if (!bh_p) {
12062dddda4509 Eric Sandeen      2010-02-15  299  		ext4_error(sb, "Group descriptor not loaded - "
498e5f24158da7 Theodore Ts'o     2008-11-05  300  			   "block_group = %u, group_desc = %u, desc = %u",
ac27a0ec112a08 Dave Kleikamp     2006-10-11  301  			   block_group, group_desc, offset);
ac27a0ec112a08 Dave Kleikamp     2006-10-11  302  		return NULL;
ac27a0ec112a08 Dave Kleikamp     2006-10-11  303  	}
ac27a0ec112a08 Dave Kleikamp     2006-10-11  304  
0d1ee42f27d30e Alexandre Ratchov 2006-10-11  305  	desc = (struct ext4_group_desc *)(
1d0c3924a92e69 Theodore Ts'o     2020-02-15  306  		(__u8 *)bh_p->b_data +
0d1ee42f27d30e Alexandre Ratchov 2006-10-11  307  		offset * EXT4_DESC_SIZE(sb));
ac27a0ec112a08 Dave Kleikamp     2006-10-11  308  	if (bh)
1d0c3924a92e69 Theodore Ts'o     2020-02-15  309  		*bh = bh_p;
0d1ee42f27d30e Alexandre Ratchov 2006-10-11  310  	return desc;
ac27a0ec112a08 Dave Kleikamp     2006-10-11  311  }
ac27a0ec112a08 Dave Kleikamp     2006-10-11  312
diff mbox series

Patch

diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
index 094269488183..682336d3dac1 100644
--- a/fs/ext4/balloc.c
+++ b/fs/ext4/balloc.c
@@ -22,6 +22,7 @@ 
 #include "mballoc.h"
 
 #include <trace/events/ext4.h>
+#include <kunit/static_stub.h>
 
 static unsigned ext4_num_base_meta_clusters(struct super_block *sb,
 					    ext4_group_t block_group);
@@ -267,6 +268,10 @@  struct ext4_group_desc * ext4_get_group_desc(struct super_block *sb,
 					     ext4_group_t block_group,
 					     struct buffer_head **bh)
 {
+#ifdef CONFIG_EXT4_KUNIT_TESTS
+	KUNIT_STATIC_STUB_REDIRECT(ext4_get_group_desc,
+				   sb, block_group, bh);
+#endif
 	unsigned int group_desc;
 	unsigned int offset;
 	ext4_group_t ngroups = ext4_get_groups_count(sb);
@@ -423,6 +428,10 @@  struct buffer_head *
 ext4_read_block_bitmap_nowait(struct super_block *sb, ext4_group_t block_group,
 			      bool ignore_locked)
 {
+#ifdef CONFIG_EXT4_KUNIT_TESTS
+	KUNIT_STATIC_STUB_REDIRECT(ext4_read_block_bitmap_nowait,
+				   sb, block_group, ignore_locked);
+#endif
 	struct ext4_group_desc *desc;
 	struct ext4_sb_info *sbi = EXT4_SB(sb);
 	struct buffer_head *bh;
@@ -522,6 +531,10 @@  ext4_read_block_bitmap_nowait(struct super_block *sb, ext4_group_t block_group,
 int ext4_wait_block_bitmap(struct super_block *sb, ext4_group_t block_group,
 			   struct buffer_head *bh)
 {
+#ifdef CONFIG_EXT4_KUNIT_TESTS
+	KUNIT_STATIC_STUB_REDIRECT(ext4_wait_block_bitmap,
+				   sb, block_group, bh);
+#endif
 	struct ext4_group_desc *desc;
 
 	if (!buffer_new(bh))
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 64860341ef2d..f95a48bc8e31 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -17,6 +17,7 @@ 
 #include <linux/nospec.h>
 #include <linux/backing-dev.h>
 #include <trace/events/ext4.h>
+#include <kunit/static_stub.h>
 
 /*
  * MUSTDO:
@@ -3744,6 +3745,10 @@  static int
 ext4_mb_mark_group_bb(struct ext4_mark_context *mc, ext4_group_t group,
 		      ext4_grpblk_t blkoff, ext4_grpblk_t len, int flags)
 {
+#ifdef CONFIG_EXT4_KUNIT_TESTS
+	KUNIT_STATIC_STUB_REDIRECT(ext4_mb_mark_group_bb,
+				   mc, group, blkoff, len, flags);
+#endif
 	handle_t *handle = mc->handle;
 	struct super_block *sb = mc->sb;
 	struct ext4_sb_info *sbi = EXT4_SB(sb);