Skip to contentSkip to conversation

ext4: kunit: use dynamic inode allocation

PATCH Applied Arnd Bergmann 3 participants 3 messages Feb 27, 2024 – Mar 14, 2024 ext4 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext4: kunit: use dynamic inode allocation

From: Arnd Bergmann <[email protected]>

Storing an inode structure on the stack pushes some functions over the warning limit for stack frame size:

In file included from fs/ext4/mballoc.c:7039:
fs/ext4/mballoc-test.c:506:13: error: stack frame size (1032) exceeds limit (1024) in 'test_mark_diskspace_used' [-Werror,-Wframe-larger-than]
506 | static void test_mark_diskspace_used(struct kunit *test)
| ^

Use kunit_kzalloc() for all inodes. There may be a better way to do it by preallocating the inode, which would result in a larger rework.

Fixes 2b81493f8eb6 ("ext4: Add unit test for ext4_mb_mark_diskspace_used")
---
 fs/ext4/mballoc-test.c | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)
fs/ext4/mballoc-test.c +21 -6
index 12d0b22cabe1..3b43301054b6 100644
@@ -332,14 +332,19 @@ static void mbt_kunit_exit(struct kunit *test)
 static void test_new_blocks_simple(struct kunit *test)
 {
 	struct super_block *sb = (struct super_block *)test->priv;
-	struct inode inode = { .i_sb = sb, };
+	struct inode *inode;
 	struct ext4_allocation_request ar;
 	ext4_group_t i, goal_group = TEST_GOAL_GROUP;
 	int err = 0;
 	ext4_fsblk_t found;
 	struct ext4_sb_info *sbi = EXT4_SB(sb);
 
-	ar.inode = &inode;
+	inode = kunit_kzalloc(test, sizeof(*inode), GFP_KERNEL);
+	if (!inode)
+		return;
+
+	inode->i_sb = sb;
+	ar.inode = inode;
 
 	/* get block at goal */
 	ar.goal = ext4_group_first_block_no(sb, goal_group);
@@ -441,15 +446,20 @@ test_free_blocks_simple_range(struct kunit *test, ext4_group_t goal_group,
 {
 	struct super_block *sb = (struct super_block *)test->priv;
 	struct ext4_sb_info *sbi = EXT4_SB(sb);
-	struct inode inode = { .i_sb = sb, };
+	struct inode *inode;
 	ext4_fsblk_t block;
 
+	inode = kunit_kzalloc(test, sizeof(*inode), GFP_KERNEL);
+	if (!inode)
+		return;
+	inode->i_sb = sb;
+
 	if (len == 0)
 		return;
 
 	block = ext4_group_first_block_no(sb, goal_group) +
 		EXT4_C2B(sbi, start);
-	ext4_free_blocks_simple(&inode, block, len);
+	ext4_free_blocks_simple(inode, block, len);
 	validate_free_blocks_simple(test, sb, goal_group, start, len);
 	mbt_ctx_mark_used(sb, goal_group, 0, EXT4_CLUSTERS_PER_GROUP(sb));
 }
@@ -506,16 +516,21 @@ test_mark_diskspace_used_range(struct kunit *test,
 static void test_mark_diskspace_used(struct kunit *test)
 {
 	struct super_block *sb = (struct super_block *)test->priv;
-	struct inode inode = { .i_sb = sb, };
+	struct inode *inode;
 	struct ext4_allocation_context ac;
 	struct test_range ranges[TEST_RANGE_COUNT];
 	int i;
 
 	mbt_generate_test_ranges(sb, ranges, TEST_RANGE_COUNT);
 
+	inode = kunit_kzalloc(test, sizeof(*inode), GFP_KERNEL);
+	if (!inode)
+		return;
+	inode->i_sb = sb;
+
 	ac.ac_status = AC_STATUS_FOUND;
 	ac.ac_sb = sb;
-	ac.ac_inode = &inode;
+	ac.ac_inode = inode;
 	for (i = 0; i < TEST_RANGE_COUNT; i++)
 		test_mark_diskspace_used_range(test, &ac, ranges[i].start,
 					       ranges[i].len);
Signature · 1 line
2.39.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 83 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

Storing an inode structure on the stack pushes some functions over the warning limit for stack frame size:

In file included from fs/ext4/mballoc.c:7039:
fs/ext4/mballoc-test.c:506:13: error: stack frame size (1032) exceeds limit (1024) in 'test_mark_diskspace_used' [-Werror,-Wframe-larger-than]
506 | static void test_mark_diskspace_used(struct kunit *test)
| ^

Use kunit_kzalloc() for all inodes. There may be a better way to do it by preallocating the inode, which would result in a larger rework.

Fixes 2b81493f8eb6 ("ext4: Add unit test for ext4_mb_mark_diskspace_used")
---
 fs/ext4/mballoc-test.c | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)
fs/ext4/mballoc-test.c +17 -5
index 12d0b22cabe1..3b43301054b6 100644
@@ -332,14 +332,19 @@ static void mbt_kunit_exit(struct kunit *test)
 static void test_new_blocks_simple(struct kunit *test)
 {
 	struct super_block *sb = (struct super_block *)test->priv;
-	struct inode inode = { .i_sb = sb, };
+	struct inode *inode;
 	struct ext4_allocation_request ar;
 	ext4_group_t i, goal_group = TEST_GOAL_GROUP;
 	int err = 0;
 	ext4_fsblk_t found;
 	struct ext4_sb_info *sbi = EXT4_SB(sb);
 
-	ar.inode = &inode;
+	inode = kunit_kzalloc(test, sizeof(*inode), GFP_KERNEL);
+	if (!inode)
+		return;
+
+	inode->i_sb = sb;
+	ar.inode = inode;
 
 	/* get block at goal */
 	ar.goal = ext4_group_first_block_no(sb, goal_group);
@@ -441,15 +446,20 @@ test_free_blocks_simple_range(struct kunit *test, ext4_group_t goal_group,
 {
 	struct super_block *sb = (struct super_block *)test->priv;
 	struct ext4_sb_info *sbi = EXT4_SB(sb);
-	struct inode inode = { .i_sb = sb, };
+	struct inode *inode;
 	ext4_fsblk_t block;
 
+	inode = kunit_kzalloc(test, sizeof(*inode), GFP_KERNEL);
+	if (!inode)
+		return;
+	inode->i_sb = sb;
+
 	if (len == 0)
 		return;
 
 	block = ext4_group_first_block_no(sb, goal_group) +
 		EXT4_C2B(sbi, start);
-	ext4_free_blocks_simple(&inode, block, len);
+	ext4_free_blocks_simple(inode, block, len);
 	validate_free_blocks_simple(test, sb, goal_group, start, len);
 	mbt_ctx_mark_used(sb, goal_group, 0, EXT4_CLUSTERS_PER_GROUP(sb));
 }
@@ -506,16 +516,21 @@ test_mark_diskspace_used_range(struct kunit *test,
 static void test_mark_diskspace_used(struct kunit *test)
 {
 	struct super_block *sb = (struct super_block *)test->priv;
-	struct inode inode = { .i_sb = sb, };
+	struct inode *inode;
 	struct ext4_allocation_context ac;
 	struct test_range ranges[TEST_RANGE_COUNT];
 	int i;
 
 	mbt_generate_test_ranges(sb, ranges, TEST_RANGE_COUNT);
 
+	inode = kunit_kzalloc(test, sizeof(*inode), GFP_KERNEL);
+	if (!inode)

fs/ext4/mballoc-test.c test_mark_diskspace_used_range(struct kunit *test, · line 536

Quoted 10 lines
fs/ext4/mballoc-test.c +4 -1
+		return;
+	inode->i_sb = sb;
+
 	ac.ac_status = AC_STATUS_FOUND;
 	ac.ac_sb = sb;
-	ac.ac_inode = &inode;
+	ac.ac_inode = inode;
 	for (i = 0; i < TEST_RANGE_COUNT; i++)
 		test_mark_diskspace_used_range(test, &ac, ranges[i].start,
 					       ranges[i].len);

Thanks for the fix. Feel free to add:

maintainer Applied
#2 lore raw
In reply to Arnd Bergmann
Quoted 9 lines · Arnd Bergmann

Storing an inode structure on the stack pushes some functions over the warning limit for stack frame size:

In file included from fs/ext4/mballoc.c:7039:
fs/ext4/mballoc-test.c:506:13: error: stack frame size (1032) exceeds limit (1024) in 'test_mark_diskspace_used' [-Werror,-Wframe-larger-than]
506 | static void test_mark_diskspace_used(struct kunit *test)
| ^

[...]

Applied, thanks!

[1/1] ext4: kunit: use dynamic inode allocation

      commit: d60c53694c6ff560963590971720d632bb3d481e

Best regards,

Signature · 1 line
Theodore Ts'o <[email protected]>