xref: /linux/include/linux/cgroup_namespace.h (revision 18b19abc3709b109676ffd1f48dcd332c2e477d4)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_CGROUP_NAMESPACE_H
3 #define _LINUX_CGROUP_NAMESPACE_H
4 
5 #include <linux/ns_common.h>
6 
7 struct cgroup_namespace {
8 	struct ns_common	ns;
9 	struct user_namespace	*user_ns;
10 	struct ucounts		*ucounts;
11 	struct css_set          *root_cset;
12 };
13 
14 extern struct cgroup_namespace init_cgroup_ns;
15 
16 #ifdef CONFIG_CGROUPS
17 
to_cg_ns(struct ns_common * ns)18 static inline struct cgroup_namespace *to_cg_ns(struct ns_common *ns)
19 {
20 	return container_of(ns, struct cgroup_namespace, ns);
21 }
22 
23 void free_cgroup_ns(struct cgroup_namespace *ns);
24 
25 struct cgroup_namespace *copy_cgroup_ns(u64 flags,
26 					struct user_namespace *user_ns,
27 					struct cgroup_namespace *old_ns);
28 
29 int cgroup_path_ns(struct cgroup *cgrp, char *buf, size_t buflen,
30 		   struct cgroup_namespace *ns);
31 
get_cgroup_ns(struct cgroup_namespace * ns)32 static inline void get_cgroup_ns(struct cgroup_namespace *ns)
33 {
34 	ns_ref_inc(ns);
35 }
36 
put_cgroup_ns(struct cgroup_namespace * ns)37 static inline void put_cgroup_ns(struct cgroup_namespace *ns)
38 {
39 	if (ns_ref_put(ns))
40 		free_cgroup_ns(ns);
41 }
42 
43 #else /* !CONFIG_CGROUPS */
44 
free_cgroup_ns(struct cgroup_namespace * ns)45 static inline void free_cgroup_ns(struct cgroup_namespace *ns) { }
46 static inline struct cgroup_namespace *
copy_cgroup_ns(u64 flags,struct user_namespace * user_ns,struct cgroup_namespace * old_ns)47 copy_cgroup_ns(u64 flags, struct user_namespace *user_ns,
48 	       struct cgroup_namespace *old_ns)
49 {
50 	return old_ns;
51 }
52 
get_cgroup_ns(struct cgroup_namespace * ns)53 static inline void get_cgroup_ns(struct cgroup_namespace *ns) { }
put_cgroup_ns(struct cgroup_namespace * ns)54 static inline void put_cgroup_ns(struct cgroup_namespace *ns) { }
55 
56 #endif /* !CONFIG_CGROUPS */
57 
58 #endif /* _LINUX_CGROUP_NAMESPACE_H */
59