netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] nsfs: expose the stable inode numbers in a public header
@ 2025-06-06  9:45 Christian Brauner
  2025-06-06  9:45 ` [PATCH 1/3] nsfs: move root inode number to uapi Christian Brauner
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Christian Brauner @ 2025-06-06  9:45 UTC (permalink / raw)
  To: linux-fsdevel, netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Christian Brauner

Userspace heavily relies on the root inode numbers for namespaces to
identify the initial namespaces. That's already a hard dependency. So we
cannot change that anymore. Move the initial inode numbers to a public
header and align the only two namespaces that currently don't do that
with all the other namespaces.

Signed-off-by: Christian Brauner <brauner@kernel.org>
---
Christian Brauner (3):
      nsfs: move root inode number to uapi
      netns: use stable inode number for initial mount ns
      mntns: use stable inode number for initial mount ns

 fs/namespace.c            |  4 +++-
 include/linux/proc_ns.h   | 15 +++++++++------
 include/uapi/linux/nsfs.h | 11 +++++++++++
 net/core/net_namespace.c  |  8 ++++++++
 4 files changed, 31 insertions(+), 7 deletions(-)
---
base-commit: ec7714e4947909190ffb3041a03311a975350fe0
change-id: 20250606-work-nsfs-3e951f888309


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] nsfs: move root inode number to uapi
  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 ` Christian Brauner
  2025-06-06  9:45 ` [PATCH 2/3] netns: use stable inode number for initial mount ns Christian Brauner
  2025-06-06  9:45 ` [PATCH 3/3] mntns: " Christian Brauner
  2 siblings, 0 replies; 5+ messages in thread
From: Christian Brauner @ 2025-06-06  9:45 UTC (permalink / raw)
  To: linux-fsdevel, netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Christian Brauner

Userspace relies on the root inode numbers to identify the initial
namespaces. That's already a hard dependency. So we cannot change that
anymore. Move the initial inode numbers to a public header.

Link: https://github.com/systemd/systemd/commit/d293fade24b34ccc2f5716b0ff5513e9533cf0c4
Signed-off-by: Christian Brauner <brauner@kernel.org>
---
 include/linux/proc_ns.h   | 13 +++++++------
 include/uapi/linux/nsfs.h |  9 +++++++++
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
index 5ea470eb4d76..e77a37b23ca7 100644
--- a/include/linux/proc_ns.h
+++ b/include/linux/proc_ns.h
@@ -6,6 +6,7 @@
 #define _LINUX_PROC_NS_H
 
 #include <linux/ns_common.h>
+#include <uapi/linux/nsfs.h>
 
 struct pid_namespace;
 struct nsset;
@@ -40,12 +41,12 @@ extern const struct proc_ns_operations timens_for_children_operations;
  */
 enum {
 	PROC_ROOT_INO		= 1,
-	PROC_IPC_INIT_INO	= 0xEFFFFFFFU,
-	PROC_UTS_INIT_INO	= 0xEFFFFFFEU,
-	PROC_USER_INIT_INO	= 0xEFFFFFFDU,
-	PROC_PID_INIT_INO	= 0xEFFFFFFCU,
-	PROC_CGROUP_INIT_INO	= 0xEFFFFFFBU,
-	PROC_TIME_INIT_INO	= 0xEFFFFFFAU,
+	PROC_IPC_INIT_INO	= IPC_NS_INIT_INO,
+	PROC_UTS_INIT_INO	= UTS_NS_INIT_INO,
+	PROC_USER_INIT_INO	= USER_NS_INIT_INO,
+	PROC_PID_INIT_INO	= PID_NS_INIT_INO,
+	PROC_CGROUP_INIT_INO	= CGROUP_NS_INIT_INO,
+	PROC_TIME_INIT_INO	= TIME_NS_INIT_INO,
 };
 
 #ifdef CONFIG_PROC_FS
diff --git a/include/uapi/linux/nsfs.h b/include/uapi/linux/nsfs.h
index 34127653fd00..6683e7ca3996 100644
--- a/include/uapi/linux/nsfs.h
+++ b/include/uapi/linux/nsfs.h
@@ -42,4 +42,13 @@ struct mnt_ns_info {
 /* Get previous namespace. */
 #define NS_MNT_GET_PREV		_IOR(NSIO, 12, struct mnt_ns_info)
 
+enum init_ns_ino {
+	IPC_NS_INIT_INO		= 0xEFFFFFFFU,
+	UTS_NS_INIT_INO		= 0xEFFFFFFEU,
+	USER_NS_INIT_INO	= 0xEFFFFFFDU,
+	PID_NS_INIT_INO		= 0xEFFFFFFCU,
+	CGROUP_NS_INIT_INO	= 0xEFFFFFFBU,
+	TIME_NS_INIT_INO	= 0xEFFFFFFAU,
+};
+
 #endif /* __LINUX_NSFS_H */

-- 
2.47.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] netns: use stable inode number for initial mount ns
  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
  2025-06-09 22:46   ` Jakub Kicinski
  2025-06-06  9:45 ` [PATCH 3/3] mntns: " Christian Brauner
  2 siblings, 1 reply; 5+ messages in thread
From: Christian Brauner @ 2025-06-06  9:45 UTC (permalink / raw)
  To: linux-fsdevel, netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Christian Brauner

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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] mntns: use stable inode number for initial mount ns
  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 ` [PATCH 2/3] netns: use stable inode number for initial mount ns Christian Brauner
@ 2025-06-06  9:45 ` Christian Brauner
  2 siblings, 0 replies; 5+ messages in thread
From: Christian Brauner @ 2025-06-06  9:45 UTC (permalink / raw)
  To: linux-fsdevel, netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Christian Brauner

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 mount
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>
---
 fs/namespace.c            | 4 +++-
 include/linux/proc_ns.h   | 1 +
 include/uapi/linux/nsfs.h | 1 +
 3 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/fs/namespace.c b/fs/namespace.c
index 2f2e93927f46..1829ab9a0a52 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -6174,9 +6174,11 @@ static void __init init_mount_tree(void)
 	if (IS_ERR(mnt))
 		panic("Can't create rootfs");
 
-	ns = alloc_mnt_ns(&init_user_ns, false);
+	ns = alloc_mnt_ns(&init_user_ns, true);
 	if (IS_ERR(ns))
 		panic("Can't allocate initial namespace");
+	ns->seq = atomic64_inc_return(&mnt_ns_seq);
+	ns->ns.inum = PROC_MNT_INIT_INO;
 	m = real_mount(mnt);
 	ns->root = m;
 	ns->nr_mounts = 1;
diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
index 3ff0bd381704..6258455e49a4 100644
--- a/include/linux/proc_ns.h
+++ b/include/linux/proc_ns.h
@@ -48,6 +48,7 @@ enum {
 	PROC_CGROUP_INIT_INO	= CGROUP_NS_INIT_INO,
 	PROC_TIME_INIT_INO	= TIME_NS_INIT_INO,
 	PROC_NET_INIT_INO	= NET_NS_INIT_INO,
+	PROC_MNT_INIT_INO	= MNT_NS_INIT_INO,
 };
 
 #ifdef CONFIG_PROC_FS
diff --git a/include/uapi/linux/nsfs.h b/include/uapi/linux/nsfs.h
index 393778489d85..97d8d80d139f 100644
--- a/include/uapi/linux/nsfs.h
+++ b/include/uapi/linux/nsfs.h
@@ -50,6 +50,7 @@ enum init_ns_ino {
 	CGROUP_NS_INIT_INO	= 0xEFFFFFFBU,
 	TIME_NS_INIT_INO	= 0xEFFFFFFAU,
 	NET_NS_INIT_INO		= 0xEFFFFFF9U,
+	MNT_NS_INIT_INO		= 0xEFFFFFF8U,
 };
 
 #endif /* __LINUX_NSFS_H */

-- 
2.47.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/3] netns: use stable inode number for initial mount ns
  2025-06-06  9:45 ` [PATCH 2/3] netns: use stable inode number for initial mount ns Christian Brauner
@ 2025-06-09 22:46   ` Jakub Kicinski
  0 siblings, 0 replies; 5+ messages in thread
From: Jakub Kicinski @ 2025-06-09 22:46 UTC (permalink / raw)
  To: Christian Brauner; +Cc: linux-fsdevel, netdev, David S. Miller, Eric Dumazet

On Fri, 06 Jun 2025 11:45:08 +0200 Christian Brauner wrote:
> 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.

Nice!

Reviewed-by: Jakub Kicinski <kuba@kernel.org>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-06-09 22:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 2/3] netns: use stable inode number for initial mount ns Christian Brauner
2025-06-09 22:46   ` Jakub Kicinski
2025-06-06  9:45 ` [PATCH 3/3] mntns: " Christian Brauner

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).