ext4: kunit tests for higher level extent manipulation functions

Add more kunit tests to cover the high level caller
ext4_map_create_blocks(). We pass flags in a manner that covers
the below function:

1. ext4_ext_handle_unwritten_extents()
  1.1 - Split/Convert unwritten extent to written in endio convtext.
  1.2 - Split/Convert unwritten extent to written in non endio context.
  1.3 - Zeroout tests for the above 2 cases
2. convert_initialized_extent() - Convert written extent to unwritten
   during zero range

Reviewed-by: Zhang Yi <yi.zhang@huawei.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
Link: https://patch.msgid.link/9d8ad32cb62f44999c0fe3545b44fc3113546c70.1769149131.git.ojaswin@linux.ibm.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
This commit is contained in:
Ojaswin Mujoo 2026-01-23 11:55:33 +05:30 committed by Theodore Ts'o
parent cb1e0c1d1f
commit 4dff18488f
4 changed files with 365 additions and 9 deletions

View file

@ -3804,6 +3804,10 @@ extern int ext4_convert_unwritten_io_end_vec(handle_t *handle,
ext4_io_end_t *io_end);
extern int ext4_map_blocks(handle_t *handle, struct inode *inode,
struct ext4_map_blocks *map, int flags);
extern int ext4_map_query_blocks(handle_t *handle, struct inode *inode,
struct ext4_map_blocks *map, int flags);
extern int ext4_map_create_blocks(handle_t *handle, struct inode *inode,
struct ext4_map_blocks *map, int flags);
extern int ext4_ext_calc_credits_for_single_extent(struct inode *inode,
int num,
struct ext4_ext_path *path);

View file

@ -77,10 +77,18 @@ struct kunit_ext_data_state {
ext4_lblk_t len_blk;
};
enum kunit_test_types {
TEST_SPLIT_CONVERT,
TEST_CREATE_BLOCKS,
};
struct kunit_ext_test_param {
/* description of test */
char *desc;
/* determines which function will be tested */
int type;
/* is extent unwrit at beginning of test */
bool is_unwrit_at_start;
@ -90,6 +98,9 @@ struct kunit_ext_test_param {
/* map describing range to split */
struct ext4_map_blocks split_map;
/* disable zeroout */
bool disable_zeroout;
/* no of extents expected after split */
int nr_exp_ext;
@ -131,6 +142,9 @@ static struct file_system_type ext_fs_type = {
static void extents_kunit_exit(struct kunit *test)
{
struct ext4_sb_info *sbi = k_ctx.k_ei->vfs_inode.i_sb->s_fs_info;
kfree(sbi);
kfree(k_ctx.k_ei);
kfree(k_ctx.k_data);
}
@ -162,6 +176,13 @@ static void ext4_es_remove_extent_stub(struct inode *inode, ext4_lblk_t lblk,
return;
}
void ext4_es_insert_extent_stub(struct inode *inode, ext4_lblk_t lblk,
ext4_lblk_t len, ext4_fsblk_t pblk,
unsigned int status, bool delalloc_reserve_used)
{
return;
}
static void ext4_zeroout_es_stub(struct inode *inode, struct ext4_extent *ex)
{
return;
@ -220,6 +241,7 @@ static int extents_kunit_init(struct kunit *test)
struct ext4_inode_info *ei;
struct inode *inode;
struct super_block *sb;
struct ext4_sb_info *sbi = NULL;
struct kunit_ext_test_param *param =
(struct kunit_ext_test_param *)(test->param_value);
@ -237,7 +259,20 @@ static int extents_kunit_init(struct kunit *test)
sb->s_blocksize = 4096;
sb->s_blocksize_bits = 12;
ei->i_disksize = (EXT_DATA_LBLK + EXT_DATA_LEN + 10) << sb->s_blocksize_bits;
sbi = kzalloc(sizeof(struct ext4_sb_info), GFP_KERNEL);
if (sbi == NULL)
return -ENOMEM;
sbi->s_sb = sb;
sb->s_fs_info = sbi;
if (!param || !param->disable_zeroout)
sbi->s_extent_max_zeroout_kb = 32;
ei->i_disksize = (EXT_DATA_LBLK + EXT_DATA_LEN + 10)
<< sb->s_blocksize_bits;
ei->i_flags = 0;
ext4_set_inode_flag(inode, EXT4_INODE_EXTENTS);
inode->i_sb = sb;
k_ctx.k_data = kzalloc(EXT_DATA_LEN * 4096, GFP_KERNEL);
@ -262,7 +297,9 @@ static int extents_kunit_init(struct kunit *test)
eh->eh_generation = 0;
/*
* add 1 extent in leaf node covering lblks [10,13) and pblk [100,103)
* add 1 extent in leaf node covering:
* - lblks: [EXT_DATA_LBLK, EXT_DATA_LBLK * + EXT_DATA_LEN)
* - pblks: [EXT_DATA_PBLK, EXT_DATA_PBLK + EXT_DATA_LEN)
*/
EXT_FIRST_EXTENT(eh)->ee_block = cpu_to_le32(EXT_DATA_LBLK);
EXT_FIRST_EXTENT(eh)->ee_len = cpu_to_le16(EXT_DATA_LEN);
@ -277,6 +314,8 @@ static int extents_kunit_init(struct kunit *test)
__ext4_ext_dirty_stub);
kunit_activate_static_stub(test, ext4_es_remove_extent,
ext4_es_remove_extent_stub);
kunit_activate_static_stub(test, ext4_es_insert_extent,
ext4_es_insert_extent_stub);
kunit_activate_static_stub(test, ext4_zeroout_es, ext4_zeroout_es_stub);
kunit_activate_static_stub(test, ext4_ext_zeroout, ext4_ext_zeroout_stub);
kunit_activate_static_stub(test, ext4_issue_zeroout,
@ -301,6 +340,30 @@ static int check_buffer(char *buf, int c, int size)
return 1;
}
/*
* Simulate a map block call by first calling ext4_map_query_blocks() to
* correctly populate map flags and pblk and then call the
* ext4_map_create_blocks() to do actual split and conversion. This is easier
* than calling ext4_map_blocks() because that needs mocking a lot of unrelated
* functions.
*/
static void ext4_map_create_blocks_helper(struct kunit *test,
struct inode *inode,
struct ext4_map_blocks *map,
int flags)
{
int retval = 0;
retval = ext4_map_query_blocks(NULL, inode, map, flags);
if (retval < 0) {
KUNIT_FAIL(test,
"ext4_map_query_blocks() failed. Cannot proceed\n");
return;
}
ext4_map_create_blocks(NULL, inode, map, flags);
}
static void test_split_convert(struct kunit *test)
{
struct ext4_ext_path *path;
@ -331,8 +394,18 @@ static void test_split_convert(struct kunit *test)
map.m_lblk = param->split_map.m_lblk;
map.m_len = param->split_map.m_len;
ext4_split_convert_extents(NULL, inode, &map, path,
param->split_flags, NULL);
switch (param->type) {
case TEST_SPLIT_CONVERT:
path = ext4_split_convert_extents(NULL, inode, &map, path,
param->split_flags, NULL);
break;
case TEST_CREATE_BLOCKS:
ext4_map_create_blocks_helper(test, inode, &map, param->split_flags);
break;
default:
KUNIT_FAIL(test, "param->type %d not support.", param->type);
}
path = ext4_find_extent(inode, EXT_DATA_LBLK, NULL, 0);
ex = path->p_ext;
@ -386,6 +459,7 @@ static void test_split_convert(struct kunit *test)
static const struct kunit_ext_test_param test_split_convert_params[] = {
/* unwrit to writ splits */
{ .desc = "split unwrit extent to 2 extents and convert 1st half writ",
.type = TEST_SPLIT_CONVERT,
.is_unwrit_at_start = 1,
.split_flags = EXT4_GET_BLOCKS_CONVERT,
.split_map = { .m_lblk = EXT_DATA_LBLK, .m_len = 1 },
@ -398,6 +472,7 @@ static const struct kunit_ext_test_param test_split_convert_params[] = {
.is_unwrit = 1 } },
.is_zeroout_test = 0 },
{ .desc = "split unwrit extent to 2 extents and convert 2nd half writ",
.type = TEST_SPLIT_CONVERT,
.is_unwrit_at_start = 1,
.split_flags = EXT4_GET_BLOCKS_CONVERT,
.split_map = { .m_lblk = EXT_DATA_LBLK + 1, .m_len = EXT_DATA_LEN - 1 },
@ -410,6 +485,7 @@ static const struct kunit_ext_test_param test_split_convert_params[] = {
.is_unwrit = 0 } },
.is_zeroout_test = 0 },
{ .desc = "split unwrit extent to 3 extents and convert 2nd half to writ",
.type = TEST_SPLIT_CONVERT,
.is_unwrit_at_start = 1,
.split_flags = EXT4_GET_BLOCKS_CONVERT,
.split_map = { .m_lblk = EXT_DATA_LBLK + 1, .m_len = EXT_DATA_LEN - 2 },
@ -427,6 +503,7 @@ static const struct kunit_ext_test_param test_split_convert_params[] = {
/* writ to unwrit splits */
{ .desc = "split writ extent to 2 extents and convert 1st half unwrit",
.type = TEST_SPLIT_CONVERT,
.is_unwrit_at_start = 0,
.split_flags = EXT4_GET_BLOCKS_CONVERT_UNWRITTEN,
.split_map = { .m_lblk = EXT_DATA_LBLK, .m_len = 1 },
@ -439,6 +516,7 @@ static const struct kunit_ext_test_param test_split_convert_params[] = {
.is_unwrit = 0 } },
.is_zeroout_test = 0 },
{ .desc = "split writ extent to 2 extents and convert 2nd half unwrit",
.type = TEST_SPLIT_CONVERT,
.is_unwrit_at_start = 0,
.split_flags = EXT4_GET_BLOCKS_CONVERT_UNWRITTEN,
.split_map = { .m_lblk = EXT_DATA_LBLK + 1, .m_len = EXT_DATA_LEN - 1 },
@ -451,6 +529,7 @@ static const struct kunit_ext_test_param test_split_convert_params[] = {
.is_unwrit = 1 } },
.is_zeroout_test = 0 },
{ .desc = "split writ extent to 3 extents and convert 2nd half to unwrit",
.type = TEST_SPLIT_CONVERT,
.is_unwrit_at_start = 0,
.split_flags = EXT4_GET_BLOCKS_CONVERT_UNWRITTEN,
.split_map = { .m_lblk = EXT_DATA_LBLK + 1, .m_len = EXT_DATA_LEN - 2 },
@ -471,6 +550,7 @@ static const struct kunit_ext_test_param test_split_convert_params[] = {
*/
/* unwrit to writ splits */
{ .desc = "split unwrit extent to 2 extents and convert 1st half writ (zeroout)",
.type = TEST_SPLIT_CONVERT,
.is_unwrit_at_start = 1,
.split_flags = EXT4_GET_BLOCKS_CONVERT,
.split_map = { .m_lblk = EXT_DATA_LBLK, .m_len = 1 },
@ -485,6 +565,7 @@ static const struct kunit_ext_test_param test_split_convert_params[] = {
.off_blk = 1,
.len_blk = EXT_DATA_LEN - 1 } } },
{ .desc = "split unwrit extent to 2 extents and convert 2nd half writ (zeroout)",
.type = TEST_SPLIT_CONVERT,
.is_unwrit_at_start = 1,
.split_flags = EXT4_GET_BLOCKS_CONVERT,
.split_map = { .m_lblk = EXT_DATA_LBLK + 1, .m_len = EXT_DATA_LEN - 1 },
@ -499,6 +580,7 @@ static const struct kunit_ext_test_param test_split_convert_params[] = {
.off_blk = 1,
.len_blk = EXT_DATA_LEN - 1 } } },
{ .desc = "split unwrit extent to 3 extents and convert 2nd half writ (zeroout)",
.type = TEST_SPLIT_CONVERT,
.is_unwrit_at_start = 1,
.split_flags = EXT4_GET_BLOCKS_CONVERT,
.split_map = { .m_lblk = EXT_DATA_LBLK + 1, .m_len = EXT_DATA_LEN - 2 },
@ -517,12 +599,257 @@ static const struct kunit_ext_test_param test_split_convert_params[] = {
.len_blk = 1 } } },
};
/* Tests to trigger ext4_ext_map_blocks() -> convert_initialized_extent() */
static const struct kunit_ext_test_param test_convert_initialized_params[] = {
/* writ to unwrit splits */
{ .desc = "split writ extent to 2 extents and convert 1st half unwrit",
.type = TEST_CREATE_BLOCKS,
.split_flags = EXT4_GET_BLOCKS_CONVERT_UNWRITTEN,
.is_unwrit_at_start = 0,
.split_map = { .m_lblk = EXT_DATA_LBLK, .m_len = 1 },
.nr_exp_ext = 2,
.exp_ext_state = { { .ex_lblk = EXT_DATA_LBLK,
.ex_len = 1,
.is_unwrit = 1 },
{ .ex_lblk = EXT_DATA_LBLK + 1,
.ex_len = EXT_DATA_LEN - 1,
.is_unwrit = 0 } },
.is_zeroout_test = 0 },
{ .desc = "split writ extent to 2 extents and convert 2nd half unwrit",
.type = TEST_CREATE_BLOCKS,
.split_flags = EXT4_GET_BLOCKS_CONVERT_UNWRITTEN,
.is_unwrit_at_start = 0,
.split_map = { .m_lblk = EXT_DATA_LBLK + 1, .m_len = EXT_DATA_LEN - 1 },
.nr_exp_ext = 2,
.exp_ext_state = { { .ex_lblk = EXT_DATA_LBLK,
.ex_len = 1,
.is_unwrit = 0 },
{ .ex_lblk = EXT_DATA_LBLK + 1,
.ex_len = EXT_DATA_LEN - 1,
.is_unwrit = 1 } },
.is_zeroout_test = 0 },
{ .desc = "split writ extent to 3 extents and convert 2nd half to unwrit",
.type = TEST_CREATE_BLOCKS,
.split_flags = EXT4_GET_BLOCKS_CONVERT_UNWRITTEN,
.is_unwrit_at_start = 0,
.split_map = { .m_lblk = EXT_DATA_LBLK + 1, .m_len = EXT_DATA_LEN - 2 },
.nr_exp_ext = 3,
.exp_ext_state = { { .ex_lblk = EXT_DATA_LBLK,
.ex_len = 1,
.is_unwrit = 0 },
{ .ex_lblk = EXT_DATA_LBLK + 1,
.ex_len = EXT_DATA_LEN - 2,
.is_unwrit = 1 },
{ .ex_lblk = EXT_DATA_LBLK + 1 + (EXT_DATA_LEN - 2),
.ex_len = 1,
.is_unwrit = 0 } },
.is_zeroout_test = 0 },
};
/* Tests to trigger ext4_ext_map_blocks() -> ext4_ext_handle_unwritten_exntents() */
static const struct kunit_ext_test_param test_handle_unwritten_params[] = {
/* unwrit to writ splits via endio path */
{ .desc = "split unwrit extent to 2 extents and convert 1st half writ (endio)",
.type = TEST_CREATE_BLOCKS,
.is_unwrit_at_start = 1,
.split_flags = EXT4_GET_BLOCKS_CONVERT,
.split_map = { .m_lblk = EXT_DATA_LBLK, .m_len = 1 },
.nr_exp_ext = 2,
.exp_ext_state = { { .ex_lblk = EXT_DATA_LBLK,
.ex_len = 1,
.is_unwrit = 0 },
{ .ex_lblk = EXT_DATA_LBLK + 1,
.ex_len = EXT_DATA_LEN - 1,
.is_unwrit = 1 } },
.is_zeroout_test = 0 },
{ .desc = "split unwrit extent to 2 extents and convert 2nd half writ (endio)",
.type = TEST_CREATE_BLOCKS,
.is_unwrit_at_start = 1,
.split_flags = EXT4_GET_BLOCKS_CONVERT,
.split_map = { .m_lblk = EXT_DATA_LBLK + 1, .m_len = EXT_DATA_LEN - 1 },
.nr_exp_ext = 2,
.exp_ext_state = { { .ex_lblk = EXT_DATA_LBLK,
.ex_len = 1,
.is_unwrit = 1 },
{ .ex_lblk = EXT_DATA_LBLK + 1,
.ex_len = EXT_DATA_LEN - 1,
.is_unwrit = 0 } },
.is_zeroout_test = 0 },
{ .desc = "split unwrit extent to 3 extents and convert 2nd half to writ (endio)",
.type = TEST_CREATE_BLOCKS,
.is_unwrit_at_start = 1,
.split_flags = EXT4_GET_BLOCKS_CONVERT,
.split_map = { .m_lblk = EXT_DATA_LBLK + 1, .m_len = EXT_DATA_LEN - 2 },
.nr_exp_ext = 3,
.exp_ext_state = { { .ex_lblk = EXT_DATA_LBLK,
.ex_len = 1,
.is_unwrit = 1 },
{ .ex_lblk = EXT_DATA_LBLK + 1,
.ex_len = EXT_DATA_LEN - 2,
.is_unwrit = 0 },
{ .ex_lblk = EXT_DATA_LBLK + 1 + (EXT_DATA_LEN - 2),
.ex_len = 1,
.is_unwrit = 1 } },
.is_zeroout_test = 0 },
/* unwrit to writ splits via non-endio path */
{ .desc = "split unwrit extent to 2 extents and convert 1st half writ (non endio)",
.type = TEST_CREATE_BLOCKS,
.is_unwrit_at_start = 1,
.split_flags = EXT4_GET_BLOCKS_CREATE,
.split_map = { .m_lblk = EXT_DATA_LBLK, .m_len = 1 },
.nr_exp_ext = 2,
.disable_zeroout = true,
.exp_ext_state = { { .ex_lblk = EXT_DATA_LBLK,
.ex_len = 1,
.is_unwrit = 0 },
{ .ex_lblk = EXT_DATA_LBLK + 1,
.ex_len = EXT_DATA_LEN - 1,
.is_unwrit = 1 } },
.is_zeroout_test = 0 },
{ .desc = "split unwrit extent to 2 extents and convert 2nd half writ (non endio)",
.type = TEST_CREATE_BLOCKS,
.is_unwrit_at_start = 1,
.split_flags = EXT4_GET_BLOCKS_CREATE,
.split_map = { .m_lblk = EXT_DATA_LBLK + 1, .m_len = EXT_DATA_LEN - 1 },
.nr_exp_ext = 2,
.disable_zeroout = true,
.exp_ext_state = { { .ex_lblk = EXT_DATA_LBLK,
.ex_len = 1,
.is_unwrit = 1 },
{ .ex_lblk = EXT_DATA_LBLK + 1,
.ex_len = EXT_DATA_LEN - 1,
.is_unwrit = 0 } },
.is_zeroout_test = 0 },
{ .desc = "split unwrit extent to 3 extents and convert 2nd half to writ (non endio)",
.type = TEST_CREATE_BLOCKS,
.is_unwrit_at_start = 1,
.split_flags = EXT4_GET_BLOCKS_CREATE,
.split_map = { .m_lblk = EXT_DATA_LBLK + 1, .m_len = EXT_DATA_LEN - 2 },
.nr_exp_ext = 3,
.disable_zeroout = true,
.exp_ext_state = { { .ex_lblk = EXT_DATA_LBLK,
.ex_len = 1,
.is_unwrit = 1 },
{ .ex_lblk = EXT_DATA_LBLK + 1,
.ex_len = EXT_DATA_LEN - 2,
.is_unwrit = 0 },
{ .ex_lblk = EXT_DATA_LBLK + 1 + (EXT_DATA_LEN - 2),
.ex_len = 1,
.is_unwrit = 1 } },
.is_zeroout_test = 0 },
/*
* ***** zeroout tests *****
*/
/* unwrit to writ splits (endio)*/
{ .desc = "split unwrit extent to 2 extents and convert 1st half writ (endio, zeroout)",
.type = TEST_CREATE_BLOCKS,
.is_unwrit_at_start = 1,
.split_flags = EXT4_GET_BLOCKS_CONVERT,
.split_map = { .m_lblk = EXT_DATA_LBLK, .m_len = 1 },
.nr_exp_ext = 1,
.exp_ext_state = { { .ex_lblk = EXT_DATA_LBLK,
.ex_len = EXT_DATA_LEN,
.is_unwrit = 0 } },
.is_zeroout_test = 1,
.nr_exp_data_segs = 2,
.exp_data_state = { { .exp_char = 'X', .off_blk = 0, .len_blk = 1 },
{ .exp_char = 0,
.off_blk = 1,
.len_blk = EXT_DATA_LEN - 1 } } },
{ .desc = "split unwrit extent to 2 extents and convert 2nd half writ (endio, zeroout)",
.type = TEST_CREATE_BLOCKS,
.is_unwrit_at_start = 1,
.split_flags = EXT4_GET_BLOCKS_CONVERT,
.split_map = { .m_lblk = EXT_DATA_LBLK + 1, .m_len = EXT_DATA_LEN - 1 },
.nr_exp_ext = 1,
.exp_ext_state = { { .ex_lblk = EXT_DATA_LBLK,
.ex_len = EXT_DATA_LEN,
.is_unwrit = 0 } },
.is_zeroout_test = 1,
.nr_exp_data_segs = 2,
.exp_data_state = { { .exp_char = 0, .off_blk = 0, .len_blk = 1 },
{ .exp_char = 'X',
.off_blk = 1,
.len_blk = EXT_DATA_LEN - 1 } } },
{ .desc = "split unwrit extent to 3 extents and convert 2nd half writ (endio, zeroout)",
.type = TEST_CREATE_BLOCKS,
.is_unwrit_at_start = 1,
.split_flags = EXT4_GET_BLOCKS_CONVERT,
.split_map = { .m_lblk = EXT_DATA_LBLK + 1, .m_len = EXT_DATA_LEN - 2 },
.nr_exp_ext = 1,
.exp_ext_state = { { .ex_lblk = EXT_DATA_LBLK,
.ex_len = EXT_DATA_LEN,
.is_unwrit = 0 } },
.is_zeroout_test = 1,
.nr_exp_data_segs = 3,
.exp_data_state = { { .exp_char = 0, .off_blk = 0, .len_blk = 1 },
{ .exp_char = 'X',
.off_blk = 1,
.len_blk = EXT_DATA_LEN - 2 },
{ .exp_char = 0,
.off_blk = EXT_DATA_LEN - 1,
.len_blk = 1 } } },
/* unwrit to writ splits (non-endio)*/
{ .desc = "split unwrit extent to 2 extents and convert 1st half writ (non-endio, zeroout)",
.type = TEST_CREATE_BLOCKS,
.is_unwrit_at_start = 1,
.split_flags = EXT4_GET_BLOCKS_CREATE,
.split_map = { .m_lblk = EXT_DATA_LBLK, .m_len = 1 },
.nr_exp_ext = 1,
.exp_ext_state = { { .ex_lblk = EXT_DATA_LBLK,
.ex_len = EXT_DATA_LEN,
.is_unwrit = 0 } },
.is_zeroout_test = 1,
.nr_exp_data_segs = 2,
.exp_data_state = { { .exp_char = 'X', .off_blk = 0, .len_blk = 1 },
{ .exp_char = 0,
.off_blk = 1,
.len_blk = EXT_DATA_LEN - 1 } } },
{ .desc = "split unwrit extent to 2 extents and convert 2nd half writ (non-endio, zeroout)",
.type = TEST_CREATE_BLOCKS,
.is_unwrit_at_start = 1,
.split_flags = EXT4_GET_BLOCKS_CREATE,
.split_map = { .m_lblk = EXT_DATA_LBLK + 1, .m_len = EXT_DATA_LEN - 1 },
.nr_exp_ext = 1,
.exp_ext_state = { { .ex_lblk = EXT_DATA_LBLK,
.ex_len = EXT_DATA_LEN,
.is_unwrit = 0 } },
.is_zeroout_test = 1,
.nr_exp_data_segs = 2,
.exp_data_state = { { .exp_char = 0, .off_blk = 0, .len_blk = 1 },
{ .exp_char = 'X',
.off_blk = 1,
.len_blk = EXT_DATA_LEN - 1 } } },
{ .desc = "split unwrit extent to 3 extents and convert 2nd half writ (non-endio, zeroout)",
.type = TEST_CREATE_BLOCKS,
.is_unwrit_at_start = 1,
.split_flags = EXT4_GET_BLOCKS_CREATE,
.split_map = { .m_lblk = EXT_DATA_LBLK + 1, .m_len = EXT_DATA_LEN - 2 },
.nr_exp_ext = 1,
.exp_ext_state = { { .ex_lblk = EXT_DATA_LBLK,
.ex_len = EXT_DATA_LEN,
.is_unwrit = 0 } },
.is_zeroout_test = 1,
.nr_exp_data_segs = 3,
.exp_data_state = { { .exp_char = 0, .off_blk = 0, .len_blk = 1 },
{ .exp_char = 'X',
.off_blk = 1,
.len_blk = EXT_DATA_LEN - 2 },
{ .exp_char = 0,
.off_blk = EXT_DATA_LEN - 1,
.len_blk = 1 } } },
};
static void ext_get_desc(struct kunit *test, const void *p, char *desc)
{
struct kunit_ext_test_param *param = (struct kunit_ext_test_param *)p;
snprintf(desc, KUNIT_PARAM_DESC_SIZE, "%s\n", param->desc);
snprintf(desc, KUNIT_PARAM_DESC_SIZE, "%s %s\n", param->desc,
(param->type & TEST_CREATE_BLOCKS) ? "(highlevel)" : "");
}
static int test_split_convert_param_init(struct kunit *test)
@ -534,6 +861,24 @@ static int test_split_convert_param_init(struct kunit *test)
return 0;
}
static int test_convert_initialized_param_init(struct kunit *test)
{
size_t arr_size = ARRAY_SIZE(test_convert_initialized_params);
kunit_register_params_array(test, test_convert_initialized_params,
arr_size, ext_get_desc);
return 0;
}
static int test_handle_unwritten_init(struct kunit *test)
{
size_t arr_size = ARRAY_SIZE(test_handle_unwritten_params);
kunit_register_params_array(test, test_handle_unwritten_params,
arr_size, ext_get_desc);
return 0;
}
/*
* Note that we use KUNIT_CASE_PARAM_WITH_INIT() instead of the more compact
* KUNIT_ARRAY_PARAM() because the later currently has a limitation causing the
@ -544,6 +889,10 @@ static int test_split_convert_param_init(struct kunit *test)
static struct kunit_case extents_test_cases[] = {
KUNIT_CASE_PARAM_WITH_INIT(test_split_convert, kunit_array_gen_params,
test_split_convert_param_init, NULL),
KUNIT_CASE_PARAM_WITH_INIT(test_split_convert, kunit_array_gen_params,
test_convert_initialized_param_init, NULL),
KUNIT_CASE_PARAM_WITH_INIT(test_split_convert, kunit_array_gen_params,
test_handle_unwritten_init, NULL),
{}
};

View file

@ -916,6 +916,9 @@ void ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk,
struct pending_reservation *pr = NULL;
bool revise_pending = false;
KUNIT_STATIC_STUB_REDIRECT(ext4_es_insert_extent, inode, lblk, len,
pblk, status, delalloc_reserve_used);
if (EXT4_SB(inode->i_sb)->s_mount_state & EXT4_FC_REPLAY)
return;

View file

@ -541,8 +541,8 @@ static int ext4_map_query_blocks_next_in_leaf(handle_t *handle,
return map->m_len;
}
static int ext4_map_query_blocks(handle_t *handle, struct inode *inode,
struct ext4_map_blocks *map, int flags)
int ext4_map_query_blocks(handle_t *handle, struct inode *inode,
struct ext4_map_blocks *map, int flags)
{
unsigned int status;
int retval;
@ -588,8 +588,8 @@ out:
return retval;
}
static int ext4_map_create_blocks(handle_t *handle, struct inode *inode,
struct ext4_map_blocks *map, int flags)
int ext4_map_create_blocks(handle_t *handle, struct inode *inode,
struct ext4_map_blocks *map, int flags)
{
unsigned int status;
int err, retval = 0;