Skip to content

Commit 9e1b143

Browse files
Ye Bintytso
authored andcommitted
ext4: fix extents-test.c is not compiled when EXT4_KUNIT_TESTS=M
Now, only EXT4_KUNIT_TESTS=Y testcase will be compiled in 'extents.c'. To solve this issue, the ext4 test code needs to be decoupled. The 'extents-test' module is compiled into 'ext4-test' module. Fixes: cb1e0c1 ("ext4: kunit tests for extent splitting and conversion") Signed-off-by: Ye Bin <yebin10@huawei.com> Reviewed-by: Jan Kara <jack@suse.cz> Link: https://patch.msgid.link/20260314075258.1317579-4-yebin@huaweicloud.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent 519b76a commit 9e1b143

4 files changed

Lines changed: 51 additions & 11 deletions

File tree

fs/ext4/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ ext4-y := balloc.o bitmap.o block_validity.o dir.o ext4_jbd2.o extents.o \
1414

1515
ext4-$(CONFIG_EXT4_FS_POSIX_ACL) += acl.o
1616
ext4-$(CONFIG_EXT4_FS_SECURITY) += xattr_security.o
17-
ext4-test-objs += inode-test.o mballoc-test.o
17+
ext4-test-objs += inode-test.o mballoc-test.o \
18+
extents-test.o
1819
obj-$(CONFIG_EXT4_KUNIT_TESTS) += ext4-test.o
1920
ext4-$(CONFIG_FS_VERITY) += verity.o
2021
ext4-$(CONFIG_FS_ENCRYPTION) += crypto.o

fs/ext4/ext4_extents.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,5 +264,17 @@ static inline void ext4_idx_store_pblock(struct ext4_extent_idx *ix,
264264
0xffff);
265265
}
266266

267+
extern int __ext4_ext_dirty(const char *where, unsigned int line,
268+
handle_t *handle, struct inode *inode,
269+
struct ext4_ext_path *path);
270+
extern int ext4_ext_zeroout(struct inode *inode, struct ext4_extent *ex);
271+
#if IS_ENABLED(CONFIG_EXT4_KUNIT_TESTS)
272+
extern int ext4_ext_space_root_idx_test(struct inode *inode, int check);
273+
extern struct ext4_ext_path *ext4_split_convert_extents_test(
274+
handle_t *handle, struct inode *inode,
275+
struct ext4_map_blocks *map,
276+
struct ext4_ext_path *path,
277+
int flags, unsigned int *allocated);
278+
#endif
267279
#endif /* _EXT4_EXTENTS */
268280

fs/ext4/extents-test.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,8 @@ static int extents_kunit_init(struct kunit *test)
282282
eh->eh_depth = 0;
283283
eh->eh_entries = cpu_to_le16(1);
284284
eh->eh_magic = EXT4_EXT_MAGIC;
285-
eh->eh_max =
286-
cpu_to_le16(ext4_ext_space_root_idx(&k_ctx.k_ei->vfs_inode, 0));
285+
eh->eh_max = cpu_to_le16(ext4_ext_space_root_idx_test(
286+
&k_ctx.k_ei->vfs_inode, 0));
287287
eh->eh_generation = 0;
288288

289289
/*
@@ -386,8 +386,8 @@ static void test_split_convert(struct kunit *test)
386386

387387
switch (param->type) {
388388
case TEST_SPLIT_CONVERT:
389-
path = ext4_split_convert_extents(NULL, inode, &map, path,
390-
param->split_flags, NULL);
389+
path = ext4_split_convert_extents_test(NULL, inode, &map,
390+
path, param->split_flags, NULL);
391391
break;
392392
case TEST_CREATE_BLOCKS:
393393
ext4_map_create_blocks_helper(test, inode, &map, param->split_flags);

fs/ext4/extents.c

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,9 @@ static int ext4_ext_get_access(handle_t *handle, struct inode *inode,
184184
* - ENOMEM
185185
* - EIO
186186
*/
187-
static int __ext4_ext_dirty(const char *where, unsigned int line,
188-
handle_t *handle, struct inode *inode,
189-
struct ext4_ext_path *path)
187+
int __ext4_ext_dirty(const char *where, unsigned int line,
188+
handle_t *handle, struct inode *inode,
189+
struct ext4_ext_path *path)
190190
{
191191
int err;
192192

@@ -3159,7 +3159,7 @@ static void ext4_zeroout_es(struct inode *inode, struct ext4_extent *ex)
31593159
}
31603160

31613161
/* FIXME!! we need to try to merge to left or right after zero-out */
3162-
static int ext4_ext_zeroout(struct inode *inode, struct ext4_extent *ex)
3162+
int ext4_ext_zeroout(struct inode *inode, struct ext4_extent *ex)
31633163
{
31643164
ext4_fsblk_t ee_pblock;
31653165
unsigned int ee_len;
@@ -6257,6 +6257,33 @@ int ext4_ext_clear_bb(struct inode *inode)
62576257
return 0;
62586258
}
62596259

6260-
#ifdef CONFIG_EXT4_KUNIT_TESTS
6261-
#include "extents-test.c"
6260+
#if IS_ENABLED(CONFIG_EXT4_KUNIT_TESTS)
6261+
int ext4_ext_space_root_idx_test(struct inode *inode, int check)
6262+
{
6263+
return ext4_ext_space_root_idx(inode, check);
6264+
}
6265+
EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_ext_space_root_idx_test);
6266+
6267+
struct ext4_ext_path *ext4_split_convert_extents_test(handle_t *handle,
6268+
struct inode *inode, struct ext4_map_blocks *map,
6269+
struct ext4_ext_path *path, int flags,
6270+
unsigned int *allocated)
6271+
{
6272+
return ext4_split_convert_extents(handle, inode, map, path,
6273+
flags, allocated);
6274+
}
6275+
EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_split_convert_extents_test);
6276+
6277+
EXPORT_SYMBOL_FOR_EXT4_TEST(__ext4_ext_dirty);
6278+
EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_ext_zeroout);
6279+
EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_register_shrinker);
6280+
EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_unregister_shrinker);
6281+
EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_map_create_blocks);
6282+
EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_init_tree);
6283+
EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_lookup_extent);
6284+
EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_insert_extent);
6285+
EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_ext_insert_extent);
6286+
EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_find_extent);
6287+
EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_issue_zeroout);
6288+
EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_map_query_blocks);
62626289
#endif

0 commit comments

Comments
 (0)