]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
fs: use boolean to indicate anonymous mount namespace
authorChristian Brauner <brauner@kernel.org>
Mon, 10 Nov 2025 15:08:22 +0000 (16:08 +0100)
committerChristian Brauner <brauner@kernel.org>
Tue, 11 Nov 2025 09:01:31 +0000 (10:01 +0100)
Stop playing games with the namespace id and use a boolean instead:

* This will remove the special-casing we need to do everywhere for mount
  namespaces.

* It will allow us to use asserts on the namespace id for initial
  namespaces everywhere.

* It will allow us to put anonymous mount namespaces on the namespaces
  trees in the future and thus make them available to statmount() and
  listmount().

Link: https://patch.msgid.link/20251110-work-namespace-nstree-fixes-v1-10-e8a9264e0fb9@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/mount.h
fs/namespace.c

index f13a28752d0ba274089d5501f0f68819e8716965..2d28ef2a3aed67ec7e3efbf78e22f0b34591396b 100644 (file)
@@ -27,6 +27,7 @@ struct mnt_namespace {
        unsigned int            nr_mounts; /* # of mounts in the namespace */
        unsigned int            pending_mounts;
        refcount_t              passive; /* number references not pinning @mounts */
+       bool                    is_anon;
 } __randomize_layout;
 
 struct mnt_pcp {
@@ -175,7 +176,7 @@ static inline bool is_local_mountpoint(const struct dentry *dentry)
 
 static inline bool is_anon_ns(struct mnt_namespace *ns)
 {
-       return ns->ns.ns_id == 0;
+       return ns->is_anon;
 }
 
 static inline bool anon_ns_root(const struct mount *m)
index ad19530a13b225fc79c8716286cb84e152b1670a..efaff8680eafbd9542c5034e5753f4e5b3eadfad 100644 (file)
@@ -4093,8 +4093,9 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns, bool a
                dec_mnt_namespaces(ucounts);
                return ERR_PTR(ret);
        }
-       if (!anon)
-               ns_tree_gen_id(new_ns);
+       ns_tree_gen_id(new_ns);
+
+       new_ns->is_anon = anon;
        refcount_set(&new_ns->passive, 1);
        new_ns->mounts = RB_ROOT;
        init_waitqueue_head(&new_ns->poll);