Skip to content

Commit cca8f32

Browse files
author
Al Viro
committed
cgroup: store a reference to cgroup_ns into cgroup_fs_context
... and trim cgroup_do_mount() arguments (renaming it to cgroup_do_get_tree()) Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 6678889 commit cca8f32

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

kernel/cgroup/cgroup-internal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ extern void __init enable_debug_cgroup(void);
4242
*/
4343
struct cgroup_fs_context {
4444
struct cgroup_root *root;
45+
struct cgroup_namespace *ns;
4546
unsigned int flags; /* CGRP_ROOT_* flags */
4647

4748
/* cgroup1 bits */
@@ -212,8 +213,7 @@ void cgroup_free_root(struct cgroup_root *root);
212213
void init_cgroup_root(struct cgroup_fs_context *ctx);
213214
int cgroup_setup_root(struct cgroup_root *root, u16 ss_mask);
214215
int rebind_subsystems(struct cgroup_root *dst_root, u16 ss_mask);
215-
int cgroup_do_mount(struct fs_context *fc, unsigned long magic,
216-
struct cgroup_namespace *ns);
216+
int cgroup_do_get_tree(struct fs_context *fc);
217217

218218
int cgroup_migrate_vet_dst(struct cgroup *dst_cgrp);
219219
void cgroup_migrate_finish(struct cgroup_mgctx *mgctx);

kernel/cgroup/cgroup-v1.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,6 @@ struct kernfs_syscall_ops cgroup1_kf_syscall_ops = {
11451145
*/
11461146
static int cgroup1_root_to_use(struct fs_context *fc)
11471147
{
1148-
struct cgroup_namespace *ns = current->nsproxy->cgroup_ns;
11491148
struct cgroup_fs_context *ctx = cgroup_fc2context(fc);
11501149
struct cgroup_root *root;
11511150
struct cgroup_subsys *ss;
@@ -1217,7 +1216,7 @@ static int cgroup1_root_to_use(struct fs_context *fc)
12171216
return cg_invalf(fc, "cgroup1: No subsys list or none specified");
12181217

12191218
/* Hierarchies may only be created in the initial cgroup namespace. */
1220-
if (ns != &init_cgroup_ns)
1219+
if (ctx->ns != &init_cgroup_ns)
12211220
return -EPERM;
12221221

12231222
root = kzalloc(sizeof(*root), GFP_KERNEL);
@@ -1235,12 +1234,11 @@ static int cgroup1_root_to_use(struct fs_context *fc)
12351234

12361235
int cgroup1_get_tree(struct fs_context *fc)
12371236
{
1238-
struct cgroup_namespace *ns = current->nsproxy->cgroup_ns;
12391237
struct cgroup_fs_context *ctx = cgroup_fc2context(fc);
12401238
int ret;
12411239

12421240
/* Check if the caller has permission to mount. */
1243-
if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN))
1241+
if (!ns_capable(ctx->ns->user_ns, CAP_SYS_ADMIN))
12441242
return -EPERM;
12451243

12461244
cgroup_lock_and_drain_offline(&cgrp_dfl_root.cgrp);
@@ -1252,7 +1250,7 @@ int cgroup1_get_tree(struct fs_context *fc)
12521250
mutex_unlock(&cgroup_mutex);
12531251

12541252
if (!ret)
1255-
ret = cgroup_do_mount(fc, CGROUP_SUPER_MAGIC, ns);
1253+
ret = cgroup_do_get_tree(fc);
12561254

12571255
if (!ret && percpu_ref_is_dying(&ctx->root->cgrp.self.refcnt)) {
12581256
struct super_block *sb = fc->root->d_sb;

kernel/cgroup/cgroup.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2036,13 +2036,17 @@ int cgroup_setup_root(struct cgroup_root *root, u16 ss_mask)
20362036
return ret;
20372037
}
20382038

2039-
int cgroup_do_mount(struct fs_context *fc, unsigned long magic,
2040-
struct cgroup_namespace *ns)
2039+
int cgroup_do_get_tree(struct fs_context *fc)
20412040
{
20422041
struct cgroup_fs_context *ctx = cgroup_fc2context(fc);
20432042
bool new_sb = false;
2043+
unsigned long magic;
20442044
int ret = 0;
20452045

2046+
if (fc->fs_type == &cgroup2_fs_type)
2047+
magic = CGROUP2_SUPER_MAGIC;
2048+
else
2049+
magic = CGROUP_SUPER_MAGIC;
20462050
fc->root = kernfs_mount(fc->fs_type, fc->sb_flags, ctx->root->kf_root,
20472051
magic, &new_sb);
20482052
if (IS_ERR(fc->root))
@@ -2052,15 +2056,15 @@ int cgroup_do_mount(struct fs_context *fc, unsigned long magic,
20522056
* In non-init cgroup namespace, instead of root cgroup's dentry,
20532057
* we return the dentry corresponding to the cgroupns->root_cgrp.
20542058
*/
2055-
if (!ret && ns != &init_cgroup_ns) {
2059+
if (!ret && ctx->ns != &init_cgroup_ns) {
20562060
struct dentry *nsdentry;
20572061
struct super_block *sb = fc->root->d_sb;
20582062
struct cgroup *cgrp;
20592063

20602064
mutex_lock(&cgroup_mutex);
20612065
spin_lock_irq(&css_set_lock);
20622066

2063-
cgrp = cset_cgroup_from_root(ns->root_cset, ctx->root);
2067+
cgrp = cset_cgroup_from_root(ctx->ns->root_cset, ctx->root);
20642068

20652069
spin_unlock_irq(&css_set_lock);
20662070
mutex_unlock(&cgroup_mutex);
@@ -2089,6 +2093,7 @@ static void cgroup_fs_context_free(struct fs_context *fc)
20892093

20902094
kfree(ctx->name);
20912095
kfree(ctx->release_agent);
2096+
put_cgroup_ns(ctx->ns);
20922097
kfree(ctx);
20932098
}
20942099

@@ -2106,7 +2111,7 @@ static int cgroup_get_tree(struct fs_context *fc)
21062111
cgroup_get_live(&cgrp_dfl_root.cgrp);
21072112
ctx->root = &cgrp_dfl_root;
21082113

2109-
ret = cgroup_do_mount(fc, CGROUP2_SUPER_MAGIC, ns);
2114+
ret = cgroup_do_get_tree(fc);
21102115
if (!ret)
21112116
apply_cgroup_root_flags(ctx->flags);
21122117
return ret;
@@ -2144,6 +2149,8 @@ static int cgroup_init_fs_context(struct fs_context *fc)
21442149
if (!use_task_css_set_links)
21452150
cgroup_enable_task_cg_lists();
21462151

2152+
ctx->ns = current->nsproxy->cgroup_ns;
2153+
get_cgroup_ns(ctx->ns);
21472154
fc->fs_private = ctx;
21482155
if (fc->fs_type == &cgroup2_fs_type)
21492156
fc->ops = &cgroup_fs_context_ops;

0 commit comments

Comments
 (0)