44
55#include <linux/refcount.h>
66#include <linux/rbtree.h>
7+ #include <uapi/linux/sched.h>
78
89struct proc_ns_operations ;
910
@@ -37,6 +38,7 @@ extern const struct proc_ns_operations timens_operations;
3738extern const struct proc_ns_operations timens_for_children_operations ;
3839
3940struct ns_common {
41+ u32 ns_type ;
4042 struct dentry * stashed ;
4143 const struct proc_ns_operations * ops ;
4244 unsigned int inum ;
@@ -51,7 +53,7 @@ struct ns_common {
5153 };
5254};
5355
54- int __ns_common_init (struct ns_common * ns , const struct proc_ns_operations * ops , int inum );
56+ int __ns_common_init (struct ns_common * ns , u32 ns_type , const struct proc_ns_operations * ops , int inum );
5557void __ns_common_free (struct ns_common * ns );
5658
5759#define to_ns_common (__ns ) \
@@ -106,10 +108,28 @@ void __ns_common_free(struct ns_common *ns);
106108 struct user_namespace *: (IS_ENABLED(CONFIG_USER_NS) ? &userns_operations : NULL), \
107109 struct uts_namespace *: (IS_ENABLED(CONFIG_UTS_NS) ? &utsns_operations : NULL))
108110
109- #define ns_common_init (__ns ) \
110- __ns_common_init(to_ns_common(__ns), to_ns_operations(__ns), (((__ns) == ns_init_ns(__ns)) ? ns_init_inum(__ns) : 0))
111-
112- #define ns_common_init_inum (__ns , __inum ) __ns_common_init(to_ns_common(__ns), to_ns_operations(__ns), __inum)
111+ #define ns_common_type (__ns ) \
112+ _Generic((__ns), \
113+ struct cgroup_namespace *: CLONE_NEWCGROUP, \
114+ struct ipc_namespace *: CLONE_NEWIPC, \
115+ struct mnt_namespace *: CLONE_NEWNS, \
116+ struct net *: CLONE_NEWNET, \
117+ struct pid_namespace *: CLONE_NEWPID, \
118+ struct time_namespace *: CLONE_NEWTIME, \
119+ struct user_namespace *: CLONE_NEWUSER, \
120+ struct uts_namespace *: CLONE_NEWUTS)
121+
122+ #define ns_common_init (__ns ) \
123+ __ns_common_init(to_ns_common(__ns), \
124+ ns_common_type(__ns), \
125+ to_ns_operations(__ns), \
126+ (((__ns) == ns_init_ns(__ns)) ? ns_init_inum(__ns) : 0))
127+
128+ #define ns_common_init_inum (__ns , __inum ) \
129+ __ns_common_init(to_ns_common(__ns), \
130+ ns_common_type(__ns), \
131+ to_ns_operations(__ns), \
132+ __inum)
113133
114134#define ns_common_free (__ns ) __ns_common_free(to_ns_common((__ns)))
115135
0 commit comments