Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ext4: add some kunit stub for mballoc kunit test

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_context to avoid real IO to disk.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
Reviewed-by: "Ritesh Harjani (IBM)" <ritesh.list@gmail.com>
Link: https://lore.kernel.org/r/20230928160407.142069-11-shikemeng@huaweicloud.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>

authored by

Kemeng Shi and committed by
Theodore Ts'o
bdefd689 5c657db4

+15
+10
fs/ext4/balloc.c
··· 22 22 #include "mballoc.h" 23 23 24 24 #include <trace/events/ext4.h> 25 + #include <kunit/static_stub.h> 25 26 26 27 static unsigned ext4_num_base_meta_clusters(struct super_block *sb, 27 28 ext4_group_t block_group); ··· 273 272 struct ext4_sb_info *sbi = EXT4_SB(sb); 274 273 struct buffer_head *bh_p; 275 274 275 + KUNIT_STATIC_STUB_REDIRECT(ext4_get_group_desc, 276 + sb, block_group, bh); 277 + 276 278 if (block_group >= ngroups) { 277 279 ext4_error(sb, "block_group >= groups_count - block_group = %u," 278 280 " groups_count = %u", block_group, ngroups); ··· 470 466 ext4_fsblk_t bitmap_blk; 471 467 int err; 472 468 469 + KUNIT_STATIC_STUB_REDIRECT(ext4_read_block_bitmap_nowait, 470 + sb, block_group, ignore_locked); 471 + 473 472 desc = ext4_get_group_desc(sb, block_group, NULL); 474 473 if (!desc) 475 474 return ERR_PTR(-EFSCORRUPTED); ··· 567 560 struct buffer_head *bh) 568 561 { 569 562 struct ext4_group_desc *desc; 563 + 564 + KUNIT_STATIC_STUB_REDIRECT(ext4_wait_block_bitmap, 565 + sb, block_group, bh); 570 566 571 567 if (!buffer_new(bh)) 572 568 return 0;
+5
fs/ext4/mballoc.c
··· 18 18 #include <linux/backing-dev.h> 19 19 #include <linux/freezer.h> 20 20 #include <trace/events/ext4.h> 21 + #include <kunit/static_stub.h> 21 22 22 23 /* 23 24 * MUSTDO: ··· 3957 3956 struct buffer_head *gdp_bh; 3958 3957 int err; 3959 3958 unsigned int i, already, changed = len; 3959 + 3960 + KUNIT_STATIC_STUB_REDIRECT(ext4_mb_mark_context, 3961 + handle, sb, state, group, blkoff, len, 3962 + flags, ret_changed); 3960 3963 3961 3964 if (ret_changed) 3962 3965 *ret_changed = 0;