Skip to content

Commit 5fc6bef

Browse files
committed
cgroup: split namespace into separate header
We have dedicated headers for all namespace types. Add one for the cgroup namespace as well. Now it's consistent for all namespace types and easy to figure out what to include. Acked-by: Tejun Heo <tj@kernel.org> Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent f74ca6d commit 5fc6bef

2 files changed

Lines changed: 57 additions & 50 deletions

File tree

include/linux/cgroup.h

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/kernel_stat.h>
2828

2929
#include <linux/cgroup-defs.h>
30+
#include <linux/cgroup_namespace.h>
3031

3132
struct kernel_clone_args;
3233

@@ -783,56 +784,6 @@ static inline void cgroup_sk_free(struct sock_cgroup_data *skcd) {}
783784

784785
#endif /* CONFIG_CGROUP_DATA */
785786

786-
struct cgroup_namespace {
787-
struct ns_common ns;
788-
struct user_namespace *user_ns;
789-
struct ucounts *ucounts;
790-
struct css_set *root_cset;
791-
};
792-
793-
extern struct cgroup_namespace init_cgroup_ns;
794-
795-
#ifdef CONFIG_CGROUPS
796-
797-
static inline struct cgroup_namespace *to_cg_ns(struct ns_common *ns)
798-
{
799-
return container_of(ns, struct cgroup_namespace, ns);
800-
}
801-
802-
void free_cgroup_ns(struct cgroup_namespace *ns);
803-
804-
struct cgroup_namespace *copy_cgroup_ns(unsigned long flags,
805-
struct user_namespace *user_ns,
806-
struct cgroup_namespace *old_ns);
807-
808-
int cgroup_path_ns(struct cgroup *cgrp, char *buf, size_t buflen,
809-
struct cgroup_namespace *ns);
810-
811-
static inline void get_cgroup_ns(struct cgroup_namespace *ns)
812-
{
813-
refcount_inc(&ns->ns.count);
814-
}
815-
816-
static inline void put_cgroup_ns(struct cgroup_namespace *ns)
817-
{
818-
if (refcount_dec_and_test(&ns->ns.count))
819-
free_cgroup_ns(ns);
820-
}
821-
822-
#else /* !CONFIG_CGROUPS */
823-
824-
static inline void free_cgroup_ns(struct cgroup_namespace *ns) { }
825-
static inline struct cgroup_namespace *
826-
copy_cgroup_ns(unsigned long flags, struct user_namespace *user_ns,
827-
struct cgroup_namespace *old_ns)
828-
{
829-
return old_ns;
830-
}
831-
832-
static inline void get_cgroup_ns(struct cgroup_namespace *ns) { }
833-
static inline void put_cgroup_ns(struct cgroup_namespace *ns) { }
834-
835-
#endif /* !CONFIG_CGROUPS */
836787

837788
#ifdef CONFIG_CGROUPS
838789

include/linux/cgroup_namespace.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _LINUX_CGROUP_NAMESPACE_H
3+
#define _LINUX_CGROUP_NAMESPACE_H
4+
5+
struct cgroup_namespace {
6+
struct ns_common ns;
7+
struct user_namespace *user_ns;
8+
struct ucounts *ucounts;
9+
struct css_set *root_cset;
10+
};
11+
12+
extern struct cgroup_namespace init_cgroup_ns;
13+
14+
#ifdef CONFIG_CGROUPS
15+
16+
static inline struct cgroup_namespace *to_cg_ns(struct ns_common *ns)
17+
{
18+
return container_of(ns, struct cgroup_namespace, ns);
19+
}
20+
21+
void free_cgroup_ns(struct cgroup_namespace *ns);
22+
23+
struct cgroup_namespace *copy_cgroup_ns(unsigned long flags,
24+
struct user_namespace *user_ns,
25+
struct cgroup_namespace *old_ns);
26+
27+
int cgroup_path_ns(struct cgroup *cgrp, char *buf, size_t buflen,
28+
struct cgroup_namespace *ns);
29+
30+
static inline void get_cgroup_ns(struct cgroup_namespace *ns)
31+
{
32+
refcount_inc(&ns->ns.count);
33+
}
34+
35+
static inline void put_cgroup_ns(struct cgroup_namespace *ns)
36+
{
37+
if (refcount_dec_and_test(&ns->ns.count))
38+
free_cgroup_ns(ns);
39+
}
40+
41+
#else /* !CONFIG_CGROUPS */
42+
43+
static inline void free_cgroup_ns(struct cgroup_namespace *ns) { }
44+
static inline struct cgroup_namespace *
45+
copy_cgroup_ns(unsigned long flags, struct user_namespace *user_ns,
46+
struct cgroup_namespace *old_ns)
47+
{
48+
return old_ns;
49+
}
50+
51+
static inline void get_cgroup_ns(struct cgroup_namespace *ns) { }
52+
static inline void put_cgroup_ns(struct cgroup_namespace *ns) { }
53+
54+
#endif /* !CONFIG_CGROUPS */
55+
56+
#endif /* _LINUX_CGROUP_NAMESPACE_H */

0 commit comments

Comments
 (0)