diff options
| author | Christian Brauner <brauner@kernel.org> | 2026-07-01 16:54:23 +0200 |
|---|---|---|
| committer | Christian Brauner <brauner@kernel.org> | 2026-07-31 12:56:51 +0200 |
| commit | b4343aebd3a4dd255b15b2e5b1363d6399da302f (patch) | |
| tree | 5aa98648e3b012c66f23c97d17afa81d716e98bc /init | |
| parent | 1b8a585da1b50b3db0e7bbd073ca274875539ea8 (diff) | |
initramfs_test: use test init/exit hooks to override init fs
Most initramfs kunit tests interact with initramfs via
unpack_to_rootfs() and subsequently init_stat(), init_unlink(), etc.
It's cleaner and less error-prone to override current->fs with
userspace_init_fs for all initramfs_test_suite tests.
Link: https://patch.msgid.link/20260701-work-kunit-nullfs-v1-1-dfa60270434f@kernel.org [1]
Link: https://patch.msgid.link/20260729151320.21001-2-ddiss@suse.de # folded into [1]
Fixes: 32750c77e811 ("fs: start all kthreads in nullfs")
Reported-by: Mark Brown <broonie@kernel.org>
Closes: https://lore.kernel.org/r/akOrbOsKUqgZarGw@sirena.org.uk
Signed-off-by: David Disseldorp <ddiss@suse.de>
Co-developed-by: David Disseldorp <ddiss@suse.de>
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Diffstat (limited to 'init')
| -rw-r--r-- | init/initramfs_test.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/init/initramfs_test.c b/init/initramfs_test.c index bc55306d226d..9cf316c13ffa 100644 --- a/init/initramfs_test.c +++ b/init/initramfs_test.c @@ -3,6 +3,7 @@ #include <linux/fcntl.h> #include <linux/file.h> #include <linux/fs.h> +#include <linux/fs_struct.h> #include <linux/init.h> #include <linux/init_syscalls.h> #include <linux/initrd.h> @@ -562,7 +563,7 @@ static struct kunit_case __refdata initramfs_test_cases[] = { {}, }; -static int __init initramfs_test_init(struct kunit_suite *suite) +static int __init initramfs_suite_init(struct kunit_suite *suite) { /* * unpack_to_rootfs() uses module-static state (victim, byte_count, @@ -574,9 +575,23 @@ static int __init initramfs_test_init(struct kunit_suite *suite) return 0; } +/* Tests run in a nullfs kthread; always use the init fs for path resolution. */ +static int __init initramfs_test_init(struct kunit *test) +{ + test->priv = __override_init_fs(); + return 0; +} + +static void __init initramfs_test_exit(struct kunit *test) +{ + __revert_init_fs(test->priv); +} + static struct kunit_suite __refdata initramfs_test_suite = { .name = "initramfs", - .suite_init = initramfs_test_init, + .suite_init = initramfs_suite_init, + .init = initramfs_test_init, + .exit = initramfs_test_exit, .test_cases = initramfs_test_cases, }; kunit_test_init_section_suites(&initramfs_test_suite); |
