aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/cgroup.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2014-07-15 11:05:09 -0400
committerTejun Heo <tj@kernel.org>2014-07-15 11:05:09 -0400
commita14c6874be09a05a48093df8df87ca021f310332 (patch)
tree5ab9b25d30457737def61f0bd9fe68c857f9e46d /kernel/cgroup.c
parentafd1a8b3e0bc4d045d762dfdbc4d0cee189893a4 (diff)
cgroup: split cgroup_base_files[] into cgroup_{dfl|legacy}_base_files[]
Currently cgroup_base_files[] contains the cgroup core interface files for both legacy and default hierarchies with each file tagged with CFTYPE_INSANE and CFTYPE_ONLY_ON_DFL. This is difficult to read. Let's separate it out to two separate tables, cgroup_dfl_base_files[] and cgroup_legacy_base_files[], and use the appropriate one in cgroup_mkdir() depending on the hierarchy type. This makes tagging each file unnecessary. This patch doesn't introduce any behavior changes. v2: cgroup_dfl_base_files[] was missing the termination entry triggering WARN in cgroup_init_cftypes() for 0day kernel testing robot. Fixed. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Li Zefan <lizefan@huawei.com> Cc: Jet Chen <jet.chen@intel.com>
Diffstat (limited to 'kernel/cgroup.c')
-rw-r--r--kernel/cgroup.c76
1 files changed, 48 insertions, 28 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 28f7d47c1d4a..7e5fee5d6422 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -180,7 +180,8 @@ static u64 css_serial_nr_next = 1;
180 */ 180 */
181static int need_forkexit_callback __read_mostly; 181static int need_forkexit_callback __read_mostly;
182 182
183static struct cftype cgroup_base_files[]; 183static struct cftype cgroup_dfl_base_files[];
184static struct cftype cgroup_legacy_base_files[];
184 185
185static void cgroup_put(struct cgroup *cgrp); 186static void cgroup_put(struct cgroup *cgrp);
186static int rebind_subsystems(struct cgroup_root *dst_root, 187static 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)
1614{ 1615{
1615 LIST_HEAD(tmp_links); 1616 LIST_HEAD(tmp_links);
1616 struct cgroup *root_cgrp = &root->cgrp; 1617 struct cgroup *root_cgrp = &root->cgrp;
1618 struct cftype *base_files;
1617 struct css_set *cset; 1619 struct css_set *cset;
1618 int i, ret; 1620 int i, ret;
1619 1621
@@ -1651,7 +1653,12 @@ static int cgroup_setup_root(struct cgroup_root *root, unsigned int ss_mask)
1651 } 1653 }
1652 root_cgrp->kn = root->kf_root->kn; 1654 root_cgrp->kn = root->kf_root->kn;
1653 1655
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);
1655 if (ret) 1662 if (ret)
1656 goto destroy_root; 1663 goto destroy_root;
1657 1664
@@ -4095,7 +4102,8 @@ static int cgroup_clone_children_write(struct cgroup_subsys_state *css,
4095 return 0; 4102 return 0;
4096} 4103}
4097 4104
4098static struct cftype cgroup_base_files[] = { 4105/* cgroup core interface files for the default hierarchy */
4106static struct cftype cgroup_dfl_base_files[] = {
4099 { 4107 {
4100 .name = "cgroup.procs", 4108 .name = "cgroup.procs",
4101 .seq_start = cgroup_pidlist_start, 4109 .seq_start = cgroup_pidlist_start,
@@ -4107,46 +4115,52 @@ static struct cftype cgroup_base_files[] = {
4107 .mode = S_IRUGO | S_IWUSR, 4115 .mode = S_IRUGO | S_IWUSR,
4108 }, 4116 },
4109 { 4117 {
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 },
4120 {
4121 .name = "cgroup.controllers", 4118 .name = "cgroup.controllers",
4122 .flags = CFTYPE_ONLY_ON_DFL | CFTYPE_ONLY_ON_ROOT, 4119 .flags = CFTYPE_ONLY_ON_ROOT,
4123 .seq_show = cgroup_root_controllers_show, 4120 .seq_show = cgroup_root_controllers_show,
4124 }, 4121 },
4125 { 4122 {
4126 .name = "cgroup.controllers", 4123 .name = "cgroup.controllers",
4127 .flags = CFTYPE_ONLY_ON_DFL | CFTYPE_NOT_ON_ROOT, 4124 .flags = CFTYPE_NOT_ON_ROOT,
4128 .seq_show = cgroup_controllers_show, 4125 .seq_show = cgroup_controllers_show,
4129 }, 4126 },
4130 { 4127 {
4131 .name = "cgroup.subtree_control", 4128 .name = "cgroup.subtree_control",
4132 .flags = CFTYPE_ONLY_ON_DFL,
4133 .seq_show = cgroup_subtree_control_show, 4129 .seq_show = cgroup_subtree_control_show,
4134 .write = cgroup_subtree_control_write, 4130 .write = cgroup_subtree_control_write,
4135 }, 4131 },
4136 { 4132 {
4137 .name = "cgroup.populated", 4133 .name = "cgroup.populated",
4138 .flags = CFTYPE_ONLY_ON_DFL | CFTYPE_NOT_ON_ROOT, 4134 .flags = CFTYPE_NOT_ON_ROOT,
4139 .seq_show = cgroup_populated_show, 4135 .seq_show = cgroup_populated_show,
4140 }, 4136 },
4137 { } /* terminate */
4138};
4141 4139
4142 /* 4140/* cgroup core interface files for the legacy hierarchies */
4143 * Historical crazy stuff. These don't have "cgroup." prefix and 4141static struct cftype cgroup_legacy_base_files[] = {
4144 * don't exist if sane_behavior. If you're depending on these, be 4142 {
4145 * prepared to be burned. 4143 .name = "cgroup.procs",
4146 */ 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 },
4147 { 4162 {
4148 .name = "tasks", 4163 .name = "tasks",
4149 .flags = CFTYPE_INSANE, /* use "procs" instead */
4150 .seq_start = cgroup_pidlist_start, 4164 .seq_start = cgroup_pidlist_start,
4151 .seq_next = cgroup_pidlist_next, 4165 .seq_next = cgroup_pidlist_next,
4152 .seq_stop = cgroup_pidlist_stop, 4166 .seq_stop = cgroup_pidlist_stop,
@@ -4157,13 +4171,12 @@ static struct cftype cgroup_base_files[] = {
4157 }, 4171 },
4158 { 4172 {
4159 .name = "notify_on_release", 4173 .name = "notify_on_release",
4160 .flags = CFTYPE_INSANE,
4161 .read_u64 = cgroup_read_notify_on_release, 4174 .read_u64 = cgroup_read_notify_on_release,
4162 .write_u64 = cgroup_write_notify_on_release, 4175 .write_u64 = cgroup_write_notify_on_release,
4163 }, 4176 },
4164 { 4177 {
4165 .name = "release_agent", 4178 .name = "release_agent",
4166 .flags = CFTYPE_INSANE | CFTYPE_ONLY_ON_ROOT, 4179 .flags = CFTYPE_ONLY_ON_ROOT,
4167 .seq_show = cgroup_release_agent_show, 4180 .seq_show = cgroup_release_agent_show,
4168 .write = cgroup_release_agent_write, 4181 .write = cgroup_release_agent_write,
4169 .max_write_len = PATH_MAX - 1, 4182 .max_write_len = PATH_MAX - 1,
@@ -4444,6 +4457,7 @@ static int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
4444 struct cgroup_root *root; 4457 struct cgroup_root *root;
4445 struct cgroup_subsys *ss; 4458 struct cgroup_subsys *ss;
4446 struct kernfs_node *kn; 4459 struct kernfs_node *kn;
4460 struct cftype *base_files;
4447 int ssid, ret; 4461 int ssid, ret;
4448 4462
4449 parent = cgroup_kn_lock_live(parent_kn); 4463 parent = cgroup_kn_lock_live(parent_kn);
@@ -4514,7 +4528,12 @@ static int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
4514 if (ret) 4528 if (ret)
4515 goto out_destroy; 4529 goto out_destroy;
4516 4530
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);
4518 if (ret) 4537 if (ret)
4519 goto out_destroy; 4538 goto out_destroy;
4520 4539
@@ -4836,7 +4855,8 @@ int __init cgroup_init(void)
4836 unsigned long key; 4855 unsigned long key;
4837 int ssid, err; 4856 int ssid, err;
4838 4857
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));
4840 4860
4841 mutex_lock(&cgroup_mutex); 4861 mutex_lock(&cgroup_mutex);
4842 4862