@@ -25,6 +25,17 @@ extern struct time_namespace init_time_ns;
2525extern struct user_namespace init_user_ns ;
2626extern struct uts_namespace init_uts_ns ;
2727
28+ extern const struct proc_ns_operations netns_operations ;
29+ extern const struct proc_ns_operations utsns_operations ;
30+ extern const struct proc_ns_operations ipcns_operations ;
31+ extern const struct proc_ns_operations pidns_operations ;
32+ extern const struct proc_ns_operations pidns_for_children_operations ;
33+ extern const struct proc_ns_operations userns_operations ;
34+ extern const struct proc_ns_operations mntns_operations ;
35+ extern const struct proc_ns_operations cgroupns_operations ;
36+ extern const struct proc_ns_operations timens_operations ;
37+ extern const struct proc_ns_operations timens_for_children_operations ;
38+
2839struct ns_common {
2940 struct dentry * stashed ;
3041 const struct proc_ns_operations * ops ;
@@ -84,10 +95,21 @@ void __ns_common_free(struct ns_common *ns);
8495 struct user_namespace *: &init_user_ns, \
8596 struct uts_namespace *: &init_uts_ns)
8697
87- #define ns_common_init (__ns , __ops ) \
88- __ns_common_init(to_ns_common(__ns), __ops, (((__ns) == ns_init_ns(__ns)) ? ns_init_inum(__ns) : 0))
89-
90- #define ns_common_init_inum (__ns , __ops , __inum ) __ns_common_init(to_ns_common(__ns), __ops, __inum)
98+ #define to_ns_operations (__ns ) \
99+ _Generic((__ns), \
100+ struct cgroup_namespace *: (IS_ENABLED(CONFIG_CGROUPS) ? &cgroupns_operations : NULL), \
101+ struct ipc_namespace *: (IS_ENABLED(CONFIG_IPC_NS) ? &ipcns_operations : NULL), \
102+ struct mnt_namespace *: &mntns_operations, \
103+ struct net *: (IS_ENABLED(CONFIG_NET_NS) ? &netns_operations : NULL), \
104+ struct pid_namespace *: (IS_ENABLED(CONFIG_PID_NS) ? &pidns_operations : NULL), \
105+ struct time_namespace *: (IS_ENABLED(CONFIG_TIME_NS) ? &timens_operations : NULL), \
106+ struct user_namespace *: (IS_ENABLED(CONFIG_USER_NS) ? &userns_operations : NULL), \
107+ struct uts_namespace *: (IS_ENABLED(CONFIG_UTS_NS) ? &utsns_operations : NULL))
108+
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)
91113
92114#define ns_common_free (__ns ) __ns_common_free(to_ns_common((__ns)))
93115
0 commit comments