Skip to content

Commit ad94375

Browse files
Kemeng Shitytso
authored andcommitted
ext4: hold group lock in ext4 kunit test
Although there is no concurrent block allocation/free in unit test, internal functions mb_mark_used and mb_free_blocks assert group lock is always held. Acquire group before calling mb_mark_used and mb_free_blocks in unit test to avoid the assertion. Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com> Reported-by: Guenter Roeck <linux@roeck-us.net> Tested-by: Guenter Roeck <linux@roeck-us.net> Link: https://lore.kernel.org/r/20240304163543.6700-3-shikemeng@huaweicloud.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent 8ffc0cd commit ad94375

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

fs/ext4/mballoc-test.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,10 @@ test_mb_mark_used_range(struct kunit *test, struct ext4_buddy *e4b,
716716
ex.fe_start = start;
717717
ex.fe_len = len;
718718
ex.fe_group = TEST_GOAL_GROUP;
719+
720+
ext4_lock_group(sb, TEST_GOAL_GROUP);
719721
mb_mark_used(e4b, &ex);
722+
ext4_unlock_group(sb, TEST_GOAL_GROUP);
720723

721724
mb_set_bits(bitmap, start, len);
722725
/* bypass bb_free validatoin in ext4_mb_generate_buddy */
@@ -776,7 +779,9 @@ test_mb_free_blocks_range(struct kunit *test, struct ext4_buddy *e4b,
776779
if (len == 0)
777780
return;
778781

782+
ext4_lock_group(sb, e4b->bd_group);
779783
mb_free_blocks(NULL, e4b, start, len);
784+
ext4_unlock_group(sb, e4b->bd_group);
780785

781786
mb_clear_bits(bitmap, start, len);
782787
/* bypass bb_free validatoin in ext4_mb_generate_buddy */
@@ -820,7 +825,11 @@ static void test_mb_free_blocks(struct kunit *test)
820825
ex.fe_start = 0;
821826
ex.fe_len = EXT4_CLUSTERS_PER_GROUP(sb);
822827
ex.fe_group = TEST_GOAL_GROUP;
828+
829+
ext4_lock_group(sb, TEST_GOAL_GROUP);
823830
mb_mark_used(&e4b, &ex);
831+
ext4_unlock_group(sb, TEST_GOAL_GROUP);
832+
824833
grp->bb_free = 0;
825834
memset(bitmap, 0xff, sb->s_blocksize);
826835

0 commit comments

Comments
 (0)