summaryrefslogtreecommitdiff
path: root/include/linux/ns_common.h
diff options
context:
space:
mode:
authorChristian Brauner <brauner@kernel.org>2025-09-19 10:14:45 +0200
committerChristian Brauner <brauner@kernel.org>2025-09-19 16:22:36 +0200
commitbb57289f0ce1bab7c9ea2106a29088088dc95229 (patch)
treea40d44f79e5762729dee07a3ee2373eb74568ec5 /include/linux/ns_common.h
parent3ab378cfa793c648d4edf02bbfff3af8715aca91 (diff)
parentbe5f21d3985f00827e09b798f7a07ebd6dd7f54a (diff)
Merge patch series "ns: rework common initialization"
Christian Brauner <brauner@kernel.org> says: The current scheme still involves a lot of open-coding and copy-pasing and bleeds a lot of unnecessary details into actual namespace implementers. Encapsulate it in the common helpers and simplify it all. * patches from https://lore.kernel.org/20250917-work-namespace-ns_common-v1-0-1b3bda8ef8f2@kernel.org: ns: add ns_common_free() nscommon: simplify initialization net: centralize ns_common initialization mnt: simplify ns_common_init() handling nsfs: add inode number for anon namespace cgroup: split namespace into separate header nscommon: move to separate file mnt: expose pointer to init_mnt_ns uts: split namespace into separate header Signed-off-by: Christian Brauner <brauner@kernel.org>
Diffstat (limited to 'include/linux/ns_common.h')
-rw-r--r--include/linux/ns_common.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/include/linux/ns_common.h b/include/linux/ns_common.h
index 7224072cccc5..19833ac547f9 100644
--- a/include/linux/ns_common.h
+++ b/include/linux/ns_common.h
@@ -16,6 +16,15 @@ struct time_namespace;
struct user_namespace;
struct uts_namespace;
+extern struct cgroup_namespace init_cgroup_ns;
+extern struct ipc_namespace init_ipc_ns;
+extern struct mnt_namespace init_mnt_ns;
+extern struct net init_net;
+extern struct pid_namespace init_pid_ns;
+extern struct time_namespace init_time_ns;
+extern struct user_namespace init_user_ns;
+extern struct uts_namespace init_uts_ns;
+
struct ns_common {
struct dentry *stashed;
const struct proc_ns_operations *ops;
@@ -31,6 +40,9 @@ struct ns_common {
};
};
+int __ns_common_init(struct ns_common *ns, const struct proc_ns_operations *ops, int inum);
+void __ns_common_free(struct ns_common *ns);
+
#define to_ns_common(__ns) \
_Generic((__ns), \
struct cgroup_namespace *: &(__ns)->ns, \
@@ -42,4 +54,33 @@ struct ns_common {
struct user_namespace *: &(__ns)->ns, \
struct uts_namespace *: &(__ns)->ns)
+#define ns_init_inum(__ns) \
+ _Generic((__ns), \
+ struct cgroup_namespace *: CGROUP_NS_INIT_INO, \
+ struct ipc_namespace *: IPC_NS_INIT_INO, \
+ struct mnt_namespace *: MNT_NS_INIT_INO, \
+ struct net *: NET_NS_INIT_INO, \
+ struct pid_namespace *: PID_NS_INIT_INO, \
+ struct time_namespace *: TIME_NS_INIT_INO, \
+ struct user_namespace *: USER_NS_INIT_INO, \
+ struct uts_namespace *: UTS_NS_INIT_INO)
+
+#define ns_init_ns(__ns) \
+ _Generic((__ns), \
+ struct cgroup_namespace *: &init_cgroup_ns, \
+ struct ipc_namespace *: &init_ipc_ns, \
+ struct mnt_namespace *: &init_mnt_ns, \
+ struct net *: &init_net, \
+ struct pid_namespace *: &init_pid_ns, \
+ struct time_namespace *: &init_time_ns, \
+ struct user_namespace *: &init_user_ns, \
+ struct uts_namespace *: &init_uts_ns)
+
+#define ns_common_init(__ns, __ops) \
+ __ns_common_init(to_ns_common(__ns), __ops, (((__ns) == ns_init_ns(__ns)) ? ns_init_inum(__ns) : 0))
+
+#define ns_common_init_inum(__ns, __ops, __inum) __ns_common_init(to_ns_common(__ns), __ops, __inum)
+
+#define ns_common_free(__ns) __ns_common_free(to_ns_common((__ns)))
+
#endif