]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
mnt: simplify ns_common_init() handling
authorChristian Brauner <brauner@kernel.org>
Wed, 17 Sep 2025 10:28:05 +0000 (12:28 +0200)
committerChristian Brauner <brauner@kernel.org>
Fri, 19 Sep 2025 12:26:18 +0000 (14:26 +0200)
Assign the reserved MNT_NS_ANON_INO sentinel to anonymous mount
namespaces and cleanup the initial mount ns allocation. This is just a
preparatory patch and the ns->inum check in ns_common_init() will be
dropped in the next patch.

Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/namespace.c
kernel/nscommon.c

index f0bddc9cf2a6d55de3ffdfa6c263131ec24ad692..b2fcb901ad8c1e3f7b78055f1d4c858a71eb3de1 100644 (file)
@@ -4103,6 +4103,8 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns, bool a
                return ERR_PTR(-ENOMEM);
        }
 
+       if (anon)
+               new_ns->ns.inum = MNT_NS_ANON_INO;
        ret = ns_common_init(&new_ns->ns, &mntns_operations, !anon);
        if (ret) {
                kfree(new_ns);
index ebf4783d050540d44c5673a5222fb07238a94fd9..e10fad8afe61b745e74c5d0b984a645ebecebae3 100644 (file)
@@ -5,7 +5,7 @@
 int ns_common_init(struct ns_common *ns, const struct proc_ns_operations *ops,
                   bool alloc_inum)
 {
-       if (alloc_inum) {
+       if (alloc_inum && !ns->inum) {
                int ret;
                ret = proc_alloc_inum(&ns->inum);
                if (ret)