Skip to content

Commit d9a4408

Browse files
committed
fs: use boolean to indicate anonymous mount namespace
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>
1 parent 6bf2538 commit d9a4408

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

fs/mount.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ struct mnt_namespace {
2727
unsigned int nr_mounts; /* # of mounts in the namespace */
2828
unsigned int pending_mounts;
2929
refcount_t passive; /* number references not pinning @mounts */
30+
bool is_anon;
3031
} __randomize_layout;
3132

3233
struct mnt_pcp {
@@ -175,7 +176,7 @@ static inline bool is_local_mountpoint(const struct dentry *dentry)
175176

176177
static inline bool is_anon_ns(struct mnt_namespace *ns)
177178
{
178-
return ns->ns.ns_id == 0;
179+
return ns->is_anon;
179180
}
180181

181182
static inline bool anon_ns_root(const struct mount *m)

fs/namespace.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4093,8 +4093,9 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns, bool a
40934093
dec_mnt_namespaces(ucounts);
40944094
return ERR_PTR(ret);
40954095
}
4096-
if (!anon)
4097-
ns_tree_gen_id(new_ns);
4096+
ns_tree_gen_id(new_ns);
4097+
4098+
new_ns->is_anon = anon;
40984099
refcount_set(&new_ns->passive, 1);
40994100
new_ns->mounts = RB_ROOT;
41004101
init_waitqueue_head(&new_ns->poll);

0 commit comments

Comments
 (0)