From: Christian Brauner <brauner@kernel.org>
To: linux-fsdevel@vger.kernel.org, netdev@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
Christian Brauner <brauner@kernel.org>
Subject: [PATCH 2/3] netns: use stable inode number for initial mount ns
Date: Fri, 06 Jun 2025 11:45:08 +0200 [thread overview]
Message-ID: <20250606-work-nsfs-v1-2-b8749c9a8844@kernel.org> (raw)
In-Reply-To: <20250606-work-nsfs-v1-0-b8749c9a8844@kernel.org>
Apart from the network and mount namespace all other namespaces expose a
stable inode number and userspace has been relying on that for a very
long time now. It's very much heavily used API. Align the network
namespace and use a stable inode number from the reserved procfs inode
number space so this is consistent across all namespaces.
Signed-off-by: Christian Brauner <brauner@kernel.org>
---
include/linux/proc_ns.h | 1 +
include/uapi/linux/nsfs.h | 1 +
net/core/net_namespace.c | 8 ++++++++
3 files changed, 10 insertions(+)
diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
index e77a37b23ca7..3ff0bd381704 100644
--- a/include/linux/proc_ns.h
+++ b/include/linux/proc_ns.h
@@ -47,6 +47,7 @@ enum {
PROC_PID_INIT_INO = PID_NS_INIT_INO,
PROC_CGROUP_INIT_INO = CGROUP_NS_INIT_INO,
PROC_TIME_INIT_INO = TIME_NS_INIT_INO,
+ PROC_NET_INIT_INO = NET_NS_INIT_INO,
};
#ifdef CONFIG_PROC_FS
diff --git a/include/uapi/linux/nsfs.h b/include/uapi/linux/nsfs.h
index 6683e7ca3996..393778489d85 100644
--- a/include/uapi/linux/nsfs.h
+++ b/include/uapi/linux/nsfs.h
@@ -49,6 +49,7 @@ enum init_ns_ino {
PID_NS_INIT_INO = 0xEFFFFFFCU,
CGROUP_NS_INIT_INO = 0xEFFFFFFBU,
TIME_NS_INIT_INO = 0xEFFFFFFAU,
+ NET_NS_INIT_INO = 0xEFFFFFF9U,
};
#endif /* __LINUX_NSFS_H */
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index 42ee7fce3d95..3a962b74080b 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -796,11 +796,19 @@ static __net_init int net_ns_net_init(struct net *net)
#ifdef CONFIG_NET_NS
net->ns.ops = &netns_operations;
#endif
+ if (net == &init_net) {
+ net->ns.inum = PROC_NET_INIT_INO;
+ return 0;
+ }
return ns_alloc_inum(&net->ns);
}
static __net_exit void net_ns_net_exit(struct net *net)
{
+ /*
+ * Initial network namespace doesn't exit so we don't need any
+ * special checks here.
+ */
ns_free_inum(&net->ns);
}
--
2.47.2
next prev parent reply other threads:[~2025-06-06 9:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-06 9:45 [PATCH 0/3] nsfs: expose the stable inode numbers in a public header Christian Brauner
2025-06-06 9:45 ` [PATCH 1/3] nsfs: move root inode number to uapi Christian Brauner
2025-06-06 9:45 ` Christian Brauner [this message]
2025-06-09 22:46 ` [PATCH 2/3] netns: use stable inode number for initial mount ns Jakub Kicinski
2025-06-06 9:45 ` [PATCH 3/3] mntns: " Christian Brauner
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=20250606-work-nsfs-v1-2-b8749c9a8844@kernel.org \
--to=brauner@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).