]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
nsproxy: add helper to go from arbitrary namespace to ns_common
authorChristian Brauner <brauner@kernel.org>
Fri, 28 Jun 2024 08:05:19 +0000 (10:05 +0200)
committerChristian Brauner <brauner@kernel.org>
Fri, 28 Jun 2024 08:37:29 +0000 (10:37 +0200)
They all contains struct ns_common ns and if there ever is one where
that isn't the case we'll catch it here at build time.

Signed-off-by: Christian Brauner <brauner@kernel.org>
include/linux/nsproxy.h

index e6bec522b1391fc2ea0c5d0082f818c02c87b77d..dab6a1734a2265d4e75997a9da00810a7ef832ec 100644 (file)
@@ -42,6 +42,17 @@ struct nsproxy {
 };
 extern struct nsproxy init_nsproxy;
 
+#define to_ns_common(__ns)                              \
+       _Generic((__ns),                                \
+               struct cgroup_namespace *: &(__ns->ns), \
+               struct ipc_namespace *:    &(__ns->ns), \
+               struct net *:              &(__ns->ns), \
+               struct pid_namespace *:    &(__ns->ns), \
+               struct mnt_namespace *:    &(__ns->ns), \
+               struct time_namespace *:   &(__ns->ns), \
+               struct user_namespace *:   &(__ns->ns), \
+               struct uts_namespace *:    &(__ns->ns))
+
 /*
  * A structure to encompass all bits needed to install
  * a partial or complete new set of namespaces.