@@ -2036,43 +2036,48 @@ int cgroup_setup_root(struct cgroup_root *root, u16 ss_mask)
2036
2036
return ret ;
2037
2037
}
2038
2038
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 )
2042
2041
{
2043
- struct dentry * dentry ;
2042
+ struct cgroup_fs_context * ctx = cgroup_fc2context ( fc ) ;
2044
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
2052
* In non-init cgroup namespace, instead of root cgroup's dentry,
2050
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
2056
struct dentry * nsdentry ;
2054
- struct super_block * sb = dentry -> d_sb ;
2057
+ struct super_block * sb = fc -> root -> d_sb ;
2055
2058
struct cgroup * cgrp ;
2056
2059
2057
2060
mutex_lock (& cgroup_mutex );
2058
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
2065
spin_unlock_irq (& css_set_lock );
2063
2066
mutex_unlock (& cgroup_mutex );
2064
2067
2065
2068
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 );
2068
2073
deactivate_locked_super (sb );
2069
- dentry = nsdentry ;
2074
+ }
2070
2075
}
2071
2076
2072
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
2097
struct cgroup_namespace * ns = current -> nsproxy -> cgroup_ns ;
2093
2098
struct cgroup_fs_context * ctx = cgroup_fc2context (fc );
2094
- struct dentry * root ;
2099
+ int ret ;
2095
2100
2096
2101
/* Check if the caller has permission to mount. */
2097
2102
if (!ns_capable (ns -> user_ns , CAP_SYS_ADMIN ))
@@ -2101,14 +2106,10 @@ static int cgroup_get_tree(struct fs_context *fc)
2101
2106
cgroup_get_live (& cgrp_dfl_root .cgrp );
2102
2107
ctx -> root = & cgrp_dfl_root ;
2103
2108
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 ;
2112
2113
}
2113
2114
2114
2115
static const struct fs_context_operations cgroup_fs_context_ops = {
0 commit comments