Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

nsfs: add current_in_namespace()

Add a helper to easily check whether a given namespace is the caller's
current namespace. This is currently open-coded in a lot of places.
Simply switch on the type and compare the results.

Reviewed-by: Aleksa Sarai <cyphar@cyphar.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>

+15 -1
+15 -1
include/linux/nsfs.h
··· 5 5 #define _LINUX_NSFS_H 6 6 7 7 #include <linux/ns_common.h> 8 + #include <linux/cred.h> 9 + #include <linux/pid_namespace.h> 8 10 9 11 struct path; 10 12 struct task_struct; ··· 24 22 const struct proc_ns_operations *ns_ops); 25 23 void nsfs_init(void); 26 24 27 - #endif /* _LINUX_NSFS_H */ 25 + #define __current_namespace_from_type(__ns) \ 26 + _Generic((__ns), \ 27 + struct cgroup_namespace *: current->nsproxy->cgroup_ns, \ 28 + struct ipc_namespace *: current->nsproxy->ipc_ns, \ 29 + struct net *: current->nsproxy->net_ns, \ 30 + struct pid_namespace *: task_active_pid_ns(current), \ 31 + struct mnt_namespace *: current->nsproxy->mnt_ns, \ 32 + struct time_namespace *: current->nsproxy->time_ns, \ 33 + struct user_namespace *: current_user_ns(), \ 34 + struct uts_namespace *: current->nsproxy->uts_ns) 28 35 36 + #define current_in_namespace(__ns) (__current_namespace_from_type(__ns) == __ns) 37 + 38 + #endif /* _LINUX_NSFS_H */