aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2019-01-17 02:44:07 -0500
committerAl Viro <viro@zeniv.linux.org.uk>2019-02-28 03:29:33 -0500
commit71d883c37e8d4484207708af56685abb39703b04 (patch)
tree6832158277340fa8de0508aad96495930eb26bc8 /kernel
parentcf6299b1d00555cd10dc30d95b300d7084128a2c (diff)
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 <viro@zeniv.linux.org.uk>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/cgroup/cgroup-internal.h3
-rw-r--r--kernel/cgroup/cgroup-v1.c17
-rw-r--r--kernel/cgroup/cgroup.c45
3 files changed, 29 insertions, 36 deletions
diff --git a/kernel/cgroup/cgroup-internal.h b/kernel/cgroup/cgroup-internal.h
index 3c1613a7648c..f7fd54f2973f 100644
--- a/kernel/cgroup/cgroup-internal.h
+++ b/kernel/cgroup/cgroup-internal.h
@@ -212,8 +212,7 @@ void cgroup_free_root(struct cgroup_root *root);
212void init_cgroup_root(struct cgroup_fs_context *ctx); 212void init_cgroup_root(struct cgroup_fs_context *ctx);
213int cgroup_setup_root(struct cgroup_root *root, u16 ss_mask); 213int cgroup_setup_root(struct cgroup_root *root, u16 ss_mask);
214int rebind_subsystems(struct cgroup_root *dst_root, u16 ss_mask); 214int rebind_subsystems(struct cgroup_root *dst_root, u16 ss_mask);
215struct dentry *cgroup_do_mount(struct file_system_type *fs_type, int flags, 215int cgroup_do_mount(struct fs_context *fc, unsigned long magic,
216 struct cgroup_root *root, unsigned long magic,
217 struct cgroup_namespace *ns); 216 struct cgroup_namespace *ns);
218 217
219int cgroup_migrate_vet_dst(struct cgroup *dst_cgrp); 218int cgroup_migrate_vet_dst(struct cgroup *dst_cgrp);
diff --git a/kernel/cgroup/cgroup-v1.c b/kernel/cgroup/cgroup-v1.c
index 45a198c63d6e..05f05d773adf 100644
--- a/kernel/cgroup/cgroup-v1.c
+++ b/kernel/cgroup/cgroup-v1.c
@@ -1141,7 +1141,6 @@ int cgroup1_get_tree(struct fs_context *fc)
1141 struct cgroup_fs_context *ctx = cgroup_fc2context(fc); 1141 struct cgroup_fs_context *ctx = cgroup_fc2context(fc);
1142 struct cgroup_root *root; 1142 struct cgroup_root *root;
1143 struct cgroup_subsys *ss; 1143 struct cgroup_subsys *ss;
1144 struct dentry *dentry;
1145 int i, ret; 1144 int i, ret;
1146 1145
1147 /* Check if the caller has permission to mount. */ 1146 /* Check if the caller has permission to mount. */
@@ -1253,21 +1252,15 @@ out_free:
1253 if (ret) 1252 if (ret)
1254 return ret; 1253 return ret;
1255 1254
1256 dentry = cgroup_do_mount(&cgroup_fs_type, fc->sb_flags, root, 1255 ret = cgroup_do_mount(fc, CGROUP_SUPER_MAGIC, ns);
1257 CGROUP_SUPER_MAGIC, ns); 1256 if (!ret && percpu_ref_is_dying(&root->cgrp.self.refcnt)) {
1258 if (IS_ERR(dentry)) 1257 struct super_block *sb = fc->root->d_sb;
1259 return PTR_ERR(dentry); 1258 dput(fc->root);
1260
1261 if (percpu_ref_is_dying(&root->cgrp.self.refcnt)) {
1262 struct super_block *sb = dentry->d_sb;
1263 dput(dentry);
1264 deactivate_locked_super(sb); 1259 deactivate_locked_super(sb);
1265 msleep(10); 1260 msleep(10);
1266 return restart_syscall(); 1261 return restart_syscall();
1267 } 1262 }
1268 1263 return ret;
1269 fc->root = dentry;
1270 return 0;
1271} 1264}
1272 1265
1273static int __init cgroup1_wq_init(void) 1266static int __init cgroup1_wq_init(void)
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index 57f43f63363a..64360a46d4df 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -2036,43 +2036,48 @@ out:
2036 return ret; 2036 return ret;
2037} 2037}
2038 2038
2039struct dentry *cgroup_do_mount(struct file_system_type *fs_type, int flags, 2039int cgroup_do_mount(struct fs_context *fc, unsigned long magic,
2040 struct cgroup_root *root, unsigned long magic, 2040 struct cgroup_namespace *ns)
2041 struct cgroup_namespace *ns)
2042{ 2041{
2043 struct dentry *dentry; 2042 struct cgroup_fs_context *ctx = cgroup_fc2context(fc);
2044 bool new_sb = false; 2043 bool new_sb = false;
2044 int ret = 0;
2045 2045
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);
2047 2050
2048 /* 2051 /*
2049 * In non-init cgroup namespace, instead of root cgroup's dentry, 2052 * In non-init cgroup namespace, instead of root cgroup's dentry,
2050 * we return the dentry corresponding to the cgroupns->root_cgrp. 2053 * we return the dentry corresponding to the cgroupns->root_cgrp.
2051 */ 2054 */
2052 if (!IS_ERR(dentry) && ns != &init_cgroup_ns) { 2055 if (!ret && ns != &init_cgroup_ns) {
2053 struct dentry *nsdentry; 2056 struct dentry *nsdentry;
2054 struct super_block *sb = dentry->d_sb; 2057 struct super_block *sb = fc->root->d_sb;
2055 struct cgroup *cgrp; 2058 struct cgroup *cgrp;
2056 2059
2057 mutex_lock(&cgroup_mutex); 2060 mutex_lock(&cgroup_mutex);
2058 spin_lock_irq(&css_set_lock); 2061 spin_lock_irq(&css_set_lock);
2059 2062
2060 cgrp = cset_cgroup_from_root(ns->root_cset, root); 2063 cgrp = cset_cgroup_from_root(ns->root_cset, ctx->root);
2061 2064
2062 spin_unlock_irq(&css_set_lock); 2065 spin_unlock_irq(&css_set_lock);
2063 mutex_unlock(&cgroup_mutex); 2066 mutex_unlock(&cgroup_mutex);
2064 2067
2065 nsdentry = kernfs_node_dentry(cgrp->kn, sb); 2068 nsdentry = kernfs_node_dentry(cgrp->kn, sb);
2066 dput(dentry); 2069 dput(fc->root);
2067 if (IS_ERR(nsdentry)) 2070 fc->root = nsdentry;
2071 if (IS_ERR(nsdentry)) {
2072 ret = PTR_ERR(nsdentry);
2068 deactivate_locked_super(sb); 2073 deactivate_locked_super(sb);
2069 dentry = nsdentry; 2074 }
2070 } 2075 }
2071 2076
2072 if (!new_sb) 2077 if (!new_sb)
2073 cgroup_put(&root->cgrp); 2078 cgroup_put(&ctx->root->cgrp);
2074 2079
2075 return dentry; 2080 return ret;
2076} 2081}
2077 2082
2078/* 2083/*
@@ -2091,7 +2096,7 @@ static int cgroup_get_tree(struct fs_context *fc)
2091{ 2096{
2092 struct cgroup_namespace *ns = current->nsproxy->cgroup_ns; 2097 struct cgroup_namespace *ns = current->nsproxy->cgroup_ns;
2093 struct cgroup_fs_context *ctx = cgroup_fc2context(fc); 2098 struct cgroup_fs_context *ctx = cgroup_fc2context(fc);
2094 struct dentry *root; 2099 int ret;
2095 2100
2096 /* Check if the caller has permission to mount. */ 2101 /* Check if the caller has permission to mount. */
2097 if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN)) 2102 if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN))
@@ -2101,14 +2106,10 @@ static int cgroup_get_tree(struct fs_context *fc)
2101 cgroup_get_live(&cgrp_dfl_root.cgrp); 2106 cgroup_get_live(&cgrp_dfl_root.cgrp);
2102 ctx->root = &cgrp_dfl_root; 2107 ctx->root = &cgrp_dfl_root;
2103 2108
2104 root = cgroup_do_mount(&cgroup2_fs_type, fc->sb_flags, &cgrp_dfl_root, 2109 ret = cgroup_do_mount(fc, CGROUP2_SUPER_MAGIC, ns);
2105 CGROUP2_SUPER_MAGIC, ns); 2110 if (!ret)
2106 if (IS_ERR(root)) 2111 apply_cgroup_root_flags(ctx->flags);
2107 return PTR_ERR(root); 2112 return ret;
2108
2109 apply_cgroup_root_flags(ctx->flags);
2110 fc->root = root;
2111 return 0;
2112} 2113}
2113 2114
2114static const struct fs_context_operations cgroup_fs_context_ops = { 2115static const struct fs_context_operations cgroup_fs_context_ops = {