Skip to content

Commit 71d883c

Browse files
author
Al Viro
committed
cgroup_do_mount(): massage calling conventions
pass it fs_context instead of fs_type/flags/root triple, have it return int instead of dentry and make it deal with setting fc->root. Signed-off-by: Al Viro <[email protected]>
1 parent cf6299b commit 71d883c

File tree

3 files changed

+29
-36
lines changed

3 files changed

+29
-36
lines changed

kernel/cgroup/cgroup-internal.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,7 @@ void cgroup_free_root(struct cgroup_root *root);
212212
void init_cgroup_root(struct cgroup_fs_context *ctx);
213213
int cgroup_setup_root(struct cgroup_root *root, u16 ss_mask);
214214
int rebind_subsystems(struct cgroup_root *dst_root, u16 ss_mask);
215-
struct dentry *cgroup_do_mount(struct file_system_type *fs_type, int flags,
216-
struct cgroup_root *root, unsigned long magic,
215+
int cgroup_do_mount(struct fs_context *fc, unsigned long magic,
217216
struct cgroup_namespace *ns);
218217

219218
int cgroup_migrate_vet_dst(struct cgroup *dst_cgrp);

kernel/cgroup/cgroup-v1.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,6 @@ int cgroup1_get_tree(struct fs_context *fc)
11411141
struct cgroup_fs_context *ctx = cgroup_fc2context(fc);
11421142
struct cgroup_root *root;
11431143
struct cgroup_subsys *ss;
1144-
struct dentry *dentry;
11451144
int i, ret;
11461145

11471146
/* Check if the caller has permission to mount. */
@@ -1253,21 +1252,15 @@ int cgroup1_get_tree(struct fs_context *fc)
12531252
if (ret)
12541253
return ret;
12551254

1256-
dentry = cgroup_do_mount(&cgroup_fs_type, fc->sb_flags, root,
1257-
CGROUP_SUPER_MAGIC, ns);
1258-
if (IS_ERR(dentry))
1259-
return PTR_ERR(dentry);
1260-
1261-
if (percpu_ref_is_dying(&root->cgrp.self.refcnt)) {
1262-
struct super_block *sb = dentry->d_sb;
1263-
dput(dentry);
1255+
ret = cgroup_do_mount(fc, CGROUP_SUPER_MAGIC, ns);
1256+
if (!ret && percpu_ref_is_dying(&root->cgrp.self.refcnt)) {
1257+
struct super_block *sb = fc->root->d_sb;
1258+
dput(fc->root);
12641259
deactivate_locked_super(sb);
12651260
msleep(10);
12661261
return restart_syscall();
12671262
}
1268-
1269-
fc->root = dentry;
1270-
return 0;
1263+
return ret;
12711264
}
12721265

12731266
static int __init cgroup1_wq_init(void)

kernel/cgroup/cgroup.c

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

2039-
struct dentry *cgroup_do_mount(struct file_system_type *fs_type, int flags,
2040-
struct cgroup_root *root, unsigned long magic,
2041-
struct cgroup_namespace *ns)
2039+
int cgroup_do_mount(struct fs_context *fc, unsigned long magic,
2040+
struct cgroup_namespace *ns)
20422041
{
2043-
struct dentry *dentry;
2042+
struct cgroup_fs_context *ctx = cgroup_fc2context(fc);
20442043
bool new_sb = false;
2044+
int ret = 0;
20452045

2046-
dentry = kernfs_mount(fs_type, flags, root->kf_root, magic, &new_sb);
2046+
fc->root = kernfs_mount(fc->fs_type, fc->sb_flags, ctx->root->kf_root,
2047+
magic, &new_sb);
2048+
if (IS_ERR(fc->root))
2049+
ret = PTR_ERR(fc->root);
20472050

20482051
/*
20492052
* In non-init cgroup namespace, instead of root cgroup's dentry,
20502053
* we return the dentry corresponding to the cgroupns->root_cgrp.
20512054
*/
2052-
if (!IS_ERR(dentry) && ns != &init_cgroup_ns) {
2055+
if (!ret && ns != &init_cgroup_ns) {
20532056
struct dentry *nsdentry;
2054-
struct super_block *sb = dentry->d_sb;
2057+
struct super_block *sb = fc->root->d_sb;
20552058
struct cgroup *cgrp;
20562059

20572060
mutex_lock(&cgroup_mutex);
20582061
spin_lock_irq(&css_set_lock);
20592062

2060-
cgrp = cset_cgroup_from_root(ns->root_cset, root);
2063+
cgrp = cset_cgroup_from_root(ns->root_cset, ctx->root);
20612064

20622065
spin_unlock_irq(&css_set_lock);
20632066
mutex_unlock(&cgroup_mutex);
20642067

20652068
nsdentry = kernfs_node_dentry(cgrp->kn, sb);
2066-
dput(dentry);
2067-
if (IS_ERR(nsdentry))
2069+
dput(fc->root);
2070+
fc->root = nsdentry;
2071+
if (IS_ERR(nsdentry)) {
2072+
ret = PTR_ERR(nsdentry);
20682073
deactivate_locked_super(sb);
2069-
dentry = nsdentry;
2074+
}
20702075
}
20712076

20722077
if (!new_sb)
2073-
cgroup_put(&root->cgrp);
2078+
cgroup_put(&ctx->root->cgrp);
20742079

2075-
return dentry;
2080+
return ret;
20762081
}
20772082

20782083
/*
@@ -2091,7 +2096,7 @@ static int cgroup_get_tree(struct fs_context *fc)
20912096
{
20922097
struct cgroup_namespace *ns = current->nsproxy->cgroup_ns;
20932098
struct cgroup_fs_context *ctx = cgroup_fc2context(fc);
2094-
struct dentry *root;
2099+
int ret;
20952100

20962101
/* Check if the caller has permission to mount. */
20972102
if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN))
@@ -2101,14 +2106,10 @@ static int cgroup_get_tree(struct fs_context *fc)
21012106
cgroup_get_live(&cgrp_dfl_root.cgrp);
21022107
ctx->root = &cgrp_dfl_root;
21032108

2104-
root = cgroup_do_mount(&cgroup2_fs_type, fc->sb_flags, &cgrp_dfl_root,
2105-
CGROUP2_SUPER_MAGIC, ns);
2106-
if (IS_ERR(root))
2107-
return PTR_ERR(root);
2108-
2109-
apply_cgroup_root_flags(ctx->flags);
2110-
fc->root = root;
2111-
return 0;
2109+
ret = cgroup_do_mount(fc, CGROUP2_SUPER_MAGIC, ns);
2110+
if (!ret)
2111+
apply_cgroup_root_flags(ctx->flags);
2112+
return ret;
21122113
}
21132114

21142115
static const struct fs_context_operations cgroup_fs_context_ops = {

0 commit comments

Comments
 (0)