Unverified Commit d7afdf88 authored by Christian Brauner's avatar Christian Brauner
Browse files

ns: add to_<type>_ns() to respective headers



Every namespace type has a container_of(ns, <ns_type>, ns) static inline
function that is currently not exposed in the header. So we have a bunch
of places that open-code it via container_of(). Move it to the headers
so we can use it directly.

Reviewed-by: default avatarAleksa Sarai <cyphar@cyphar.com>
Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
parent 58f976d4
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -794,6 +794,11 @@ extern struct cgroup_namespace init_cgroup_ns;

#ifdef CONFIG_CGROUPS

static inline struct cgroup_namespace *to_cg_ns(struct ns_common *ns)
{
	return container_of(ns, struct cgroup_namespace, ns);
}

void free_cgroup_ns(struct cgroup_namespace *ns);

struct cgroup_namespace *copy_cgroup_ns(unsigned long flags,
+5 −0
Original line number Diff line number Diff line
@@ -129,6 +129,11 @@ static inline int mq_init_ns(struct ipc_namespace *ns) { return 0; }
#endif

#if defined(CONFIG_IPC_NS)
static inline struct ipc_namespace *to_ipc_ns(struct ns_common *ns)
{
	return container_of(ns, struct ipc_namespace, ns);
}

extern struct ipc_namespace *copy_ipcs(unsigned long flags,
	struct user_namespace *user_ns, struct ipc_namespace *ns);

+5 −0
Original line number Diff line number Diff line
@@ -54,6 +54,11 @@ extern struct pid_namespace init_pid_ns;
#define PIDNS_ADDING (1U << 31)

#ifdef CONFIG_PID_NS
static inline struct pid_namespace *to_pid_ns(struct ns_common *ns)
{
	return container_of(ns, struct pid_namespace, ns);
}

static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
{
	if (ns != &init_pid_ns)
+4 −0
Original line number Diff line number Diff line
@@ -33,6 +33,10 @@ struct time_namespace {
extern struct time_namespace init_time_ns;

#ifdef CONFIG_TIME_NS
static inline struct time_namespace *to_time_ns(struct ns_common *ns)
{
	return container_of(ns, struct time_namespace, ns);
}
void __init time_ns_init(void);
extern int vdso_join_timens(struct task_struct *task,
			    struct time_namespace *ns);
+5 −0
Original line number Diff line number Diff line
@@ -168,6 +168,11 @@ static inline void set_userns_rlimit_max(struct user_namespace *ns,

#ifdef CONFIG_USER_NS

static inline struct user_namespace *to_user_ns(struct ns_common *ns)
{
	return container_of(ns, struct user_namespace, ns);
}

static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
{
	if (ns)
Loading