@@ -180,7 +180,8 @@ static u64 css_serial_nr_next = 1;
180180 */
181181static int need_forkexit_callback __read_mostly ;
182182
183- static struct cftype cgroup_base_files [];
183+ static struct cftype cgroup_dfl_base_files [];
184+ static struct cftype cgroup_legacy_base_files [];
184185
185186static void cgroup_put (struct cgroup * cgrp );
186187static int rebind_subsystems (struct cgroup_root * dst_root ,
@@ -1614,6 +1615,7 @@ static int cgroup_setup_root(struct cgroup_root *root, unsigned int ss_mask)
16141615{
16151616 LIST_HEAD (tmp_links );
16161617 struct cgroup * root_cgrp = & root -> cgrp ;
1618+ struct cftype * base_files ;
16171619 struct css_set * cset ;
16181620 int i , ret ;
16191621
@@ -1651,7 +1653,12 @@ static int cgroup_setup_root(struct cgroup_root *root, unsigned int ss_mask)
16511653 }
16521654 root_cgrp -> kn = root -> kf_root -> kn ;
16531655
1654- ret = cgroup_addrm_files (root_cgrp , cgroup_base_files , true);
1656+ if (root == & cgrp_dfl_root )
1657+ base_files = cgroup_dfl_base_files ;
1658+ else
1659+ base_files = cgroup_legacy_base_files ;
1660+
1661+ ret = cgroup_addrm_files (root_cgrp , base_files , true);
16551662 if (ret )
16561663 goto destroy_root ;
16571664
@@ -4095,7 +4102,8 @@ static int cgroup_clone_children_write(struct cgroup_subsys_state *css,
40954102 return 0 ;
40964103}
40974104
4098- static struct cftype cgroup_base_files [ ] = {
4105+ /* cgroup core interface files for the default hierarchy */
4106+ static struct cftype cgroup_dfl_base_files [ ] = {
40994107 {
41004108 .name = "cgroup.procs" ,
41014109 .seq_start = cgroup_pidlist_start ,
@@ -4106,47 +4114,53 @@ static struct cftype cgroup_base_files[] = {
41064114 .write = cgroup_procs_write ,
41074115 .mode = S_IRUGO | S_IWUSR ,
41084116 },
4109- {
4110- .name = "cgroup.clone_children" ,
4111- .flags = CFTYPE_INSANE ,
4112- .read_u64 = cgroup_clone_children_read ,
4113- .write_u64 = cgroup_clone_children_write ,
4114- },
4115- {
4116- .name = "cgroup.sane_behavior" ,
4117- .flags = CFTYPE_INSANE | CFTYPE_ONLY_ON_ROOT ,
4118- .seq_show = cgroup_sane_behavior_show ,
4119- },
41204117 {
41214118 .name = "cgroup.controllers" ,
4122- .flags = CFTYPE_ONLY_ON_DFL | CFTYPE_ONLY_ON_ROOT ,
4119+ .flags = CFTYPE_ONLY_ON_ROOT ,
41234120 .seq_show = cgroup_root_controllers_show ,
41244121 },
41254122 {
41264123 .name = "cgroup.controllers" ,
4127- .flags = CFTYPE_ONLY_ON_DFL | CFTYPE_NOT_ON_ROOT ,
4124+ .flags = CFTYPE_NOT_ON_ROOT ,
41284125 .seq_show = cgroup_controllers_show ,
41294126 },
41304127 {
41314128 .name = "cgroup.subtree_control" ,
4132- .flags = CFTYPE_ONLY_ON_DFL ,
41334129 .seq_show = cgroup_subtree_control_show ,
41344130 .write = cgroup_subtree_control_write ,
41354131 },
41364132 {
41374133 .name = "cgroup.populated" ,
4138- .flags = CFTYPE_ONLY_ON_DFL | CFTYPE_NOT_ON_ROOT ,
4134+ .flags = CFTYPE_NOT_ON_ROOT ,
41394135 .seq_show = cgroup_populated_show ,
41404136 },
4137+ { } /* terminate */
4138+ };
41414139
4142- /*
4143- * Historical crazy stuff. These don't have "cgroup." prefix and
4144- * don't exist if sane_behavior. If you're depending on these, be
4145- * prepared to be burned.
4146- */
4140+ /* cgroup core interface files for the legacy hierarchies */
4141+ static struct cftype cgroup_legacy_base_files [] = {
4142+ {
4143+ .name = "cgroup.procs" ,
4144+ .seq_start = cgroup_pidlist_start ,
4145+ .seq_next = cgroup_pidlist_next ,
4146+ .seq_stop = cgroup_pidlist_stop ,
4147+ .seq_show = cgroup_pidlist_show ,
4148+ .private = CGROUP_FILE_PROCS ,
4149+ .write = cgroup_procs_write ,
4150+ .mode = S_IRUGO | S_IWUSR ,
4151+ },
4152+ {
4153+ .name = "cgroup.clone_children" ,
4154+ .read_u64 = cgroup_clone_children_read ,
4155+ .write_u64 = cgroup_clone_children_write ,
4156+ },
4157+ {
4158+ .name = "cgroup.sane_behavior" ,
4159+ .flags = CFTYPE_ONLY_ON_ROOT ,
4160+ .seq_show = cgroup_sane_behavior_show ,
4161+ },
41474162 {
41484163 .name = "tasks" ,
4149- .flags = CFTYPE_INSANE , /* use "procs" instead */
41504164 .seq_start = cgroup_pidlist_start ,
41514165 .seq_next = cgroup_pidlist_next ,
41524166 .seq_stop = cgroup_pidlist_stop ,
@@ -4157,13 +4171,12 @@ static struct cftype cgroup_base_files[] = {
41574171 },
41584172 {
41594173 .name = "notify_on_release" ,
4160- .flags = CFTYPE_INSANE ,
41614174 .read_u64 = cgroup_read_notify_on_release ,
41624175 .write_u64 = cgroup_write_notify_on_release ,
41634176 },
41644177 {
41654178 .name = "release_agent" ,
4166- .flags = CFTYPE_INSANE | CFTYPE_ONLY_ON_ROOT ,
4179+ .flags = CFTYPE_ONLY_ON_ROOT ,
41674180 .seq_show = cgroup_release_agent_show ,
41684181 .write = cgroup_release_agent_write ,
41694182 .max_write_len = PATH_MAX - 1 ,
@@ -4444,6 +4457,7 @@ static int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
44444457 struct cgroup_root * root ;
44454458 struct cgroup_subsys * ss ;
44464459 struct kernfs_node * kn ;
4460+ struct cftype * base_files ;
44474461 int ssid , ret ;
44484462
44494463 parent = cgroup_kn_lock_live (parent_kn );
@@ -4514,7 +4528,12 @@ static int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
45144528 if (ret )
45154529 goto out_destroy ;
45164530
4517- ret = cgroup_addrm_files (cgrp , cgroup_base_files , true);
4531+ if (cgroup_on_dfl (cgrp ))
4532+ base_files = cgroup_dfl_base_files ;
4533+ else
4534+ base_files = cgroup_legacy_base_files ;
4535+
4536+ ret = cgroup_addrm_files (cgrp , base_files , true);
45184537 if (ret )
45194538 goto out_destroy ;
45204539
@@ -4836,7 +4855,8 @@ int __init cgroup_init(void)
48364855 unsigned long key ;
48374856 int ssid , err ;
48384857
4839- BUG_ON (cgroup_init_cftypes (NULL , cgroup_base_files ));
4858+ BUG_ON (cgroup_init_cftypes (NULL , cgroup_dfl_base_files ));
4859+ BUG_ON (cgroup_init_cftypes (NULL , cgroup_legacy_base_files ));
48404860
48414861 mutex_lock (& cgroup_mutex );
48424862
0 commit comments