summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorChristian Brauner <brauner@kernel.org>2025-10-29 13:20:28 +0100
committerChristian Brauner <brauner@kernel.org>2025-11-03 17:41:17 +0100
commit3760342fd6312416491d536144e39297fa5b1950 (patch)
tree5b25f598fc19abb03fee2b3371ac2d5a7e890e45 /kernel
parent04173501a69ed0387cceb190181ef8f7f1c54f0a (diff)
nstree: assign fixed ids to the initial namespaces
The initial set of namespace comes with fixed inode numbers making it easy for userspace to identify them solely based on that information. This has long preceeded anything here. Similarly, let's assign fixed namespace ids for the initial namespaces. Kill the cookie and use a sequentially increasing number. This has the nice side-effect that the owning user namespace will always have a namespace id that is smaller than any of it's descendant namespaces. Link: https://patch.msgid.link/20251029-work-namespace-nstree-listns-v4-15-2e6f823ebdc0@kernel.org Signed-off-by: Christian Brauner <brauner@kernel.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/nstree.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/kernel/nstree.c b/kernel/nstree.c
index bbb34b46b01b..cf102c5bb849 100644
--- a/kernel/nstree.c
+++ b/kernel/nstree.c
@@ -69,8 +69,6 @@ struct ns_tree time_ns_tree = {
.type = CLONE_NEWTIME,
};
-DEFINE_COOKIE(namespace_cookie);
-
static inline struct ns_common *node_to_ns(const struct rb_node *node)
{
if (!node)
@@ -285,15 +283,20 @@ struct ns_common *__ns_tree_adjoined_rcu(struct ns_common *ns,
/**
* ns_tree_gen_id - generate a new namespace id
* @ns: namespace to generate id for
+ * @id: if non-zero, this is the initial namespace and this is a fixed id
*
* Generates a new namespace id and assigns it to the namespace. All
* namespaces types share the same id space and thus can be compared
* directly. IOW, when two ids of two namespace are equal, they are
* identical.
*/
-u64 ns_tree_gen_id(struct ns_common *ns)
+u64 __ns_tree_gen_id(struct ns_common *ns, u64 id)
{
- guard(preempt)();
- ns->ns_id = gen_cookie_next(&namespace_cookie);
+ static atomic64_t namespace_cookie = ATOMIC64_INIT(NS_LAST_INIT_ID + 1);
+
+ if (id)
+ ns->ns_id = id;
+ else
+ ns->ns_id = atomic64_inc_return(&namespace_cookie);
return ns->ns_id;
}