Linux filesystem development
 help / color / mirror / Atom feed
From: David Disseldorp <ddiss@suse.de>
To: Christian Brauner <brauner@kernel.org>
Cc: linux-fsdevel@vger.kernel.org, Mark Brown <broonie@kernel.org>,
	Alexander Viro <viro@zeniv.linux.org.uk>, Jan Kara <jack@suse.cz>
Subject: Re: [PATCH] kunit: use scoped_with_init_fs() in tests that resolve paths
Date: Fri, 17 Jul 2026 00:52:31 +1000	[thread overview]
Message-ID: <20260717005231.4720378d.ddiss@suse.de> (raw)
In-Reply-To: <20260701-work-kunit-nullfs-v1-1-dfa60270434f@kernel.org>

Hi Christian,

Sorry for the late response, I missed this...

On Wed, 01 Jul 2026 16:54:23 +0200, Christian Brauner wrote:

> KUnit runs each test in a kthread (kunit_generic_run_threadfn_adapter()).
...
> The initramfs tests hit the same
> wall: they call unpack_to_rootfs() (init_mkdir()/init_mknod() under the
> hood) and then verify with relative-name init_stat()/init_unlink()/
> filp_open(), all of which resolve against the nullfs root and pwd.
> 
> Wrap the path-resolving regions of both suites in scoped_with_init_fs(),
> which borrows the userspace init fs_struct (set up by init_userspace_fs()
> before kunit_run_all_tests()) for the duration. This is the same opt-in
> the rest of the tree uses for kthread path resolution. Doing it per test
> rather than blanket-wrapping the KUnit runner keeps the nullfs isolation
> in place for the many tests that should never touch the filesystem.

Doing it per-test certainly makes sense, but for initramfs I think it'd
be a little cleaner to just use the existing per-test init() callback
instead. I.e.:

diff --git a/init/initramfs_test.c b/init/initramfs_test.c
index bc55306d226dc..9cf316c13ffa5 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);

What do you think?

Cheers, David

      parent reply	other threads:[~2026-07-16 14:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-01 14:54 [PATCH] kunit: use scoped_with_init_fs() in tests that resolve paths Christian Brauner
2026-07-02  6:53 ` Christian Brauner
2026-07-16 14:52 ` David Disseldorp [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260717005231.4720378d.ddiss@suse.de \
    --to=ddiss@suse.de \
    --cc=brauner@kernel.org \
    --cc=broonie@kernel.org \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox