aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-06-28 19:24:11 -0400
committerTejun Heo <tj@kernel.org>2013-07-12 15:34:01 -0400
commit628f7cd47ab758cae0353d1a6decf3d1459dca24 (patch)
tree6fd0b2d305ac70362af84f02636d2b79345de4d9
parent9ccece80ae19ed42439fc0ced76858f189cd41e8 (diff)
cgroup: separate out cgroup_base_files[] handling out of cgroup_populate/clear_dir()
cgroup_populate/clear_dir() currently take @base_files and adds and removes, respectively, cgroup_base_files[] to the directory. File additions and removals are being reorganized for proper error handling and more dynamic handling for the unified hierarchy, and mixing base and subsys file handling into the same functions gets a bit confusing. This patch moves base file handling out of cgroup_populate/clear_dir() into their users - cgroup_mount(), cgroup_create() and cgroup_destroy_locked(). Note that this changes the behavior of base file removal. If @base_files is %true, cgroup_clear_dir() used to delete files regardless of cftype until there's no files left. Now, only files with matching cfts are removed. As files can only be created by the base or registered cftypes, this shouldn't result in any behavior difference. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Li Zefan <lizefan@huawei.com>
-rw-r--r--kernel/cgroup.c46
1 files changed, 19 insertions, 27 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 36c0ccc921f4..9835a097f3c0 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -215,6 +215,8 @@ static u64 cgroup_serial_nr_next = 1;
215 */ 215 */
216static int need_forkexit_callback __read_mostly; 216static int need_forkexit_callback __read_mostly;
217 217
218static struct cftype cgroup_base_files[];
219
218static void cgroup_offline_fn(struct work_struct *work); 220static void cgroup_offline_fn(struct work_struct *work);
219static int cgroup_destroy_locked(struct cgroup *cgrp); 221static int cgroup_destroy_locked(struct cgroup *cgrp);
220static int cgroup_addrm_files(struct cgroup *cgrp, struct cgroup_subsys *subsys, 222static int cgroup_addrm_files(struct cgroup *cgrp, struct cgroup_subsys *subsys,
@@ -804,8 +806,7 @@ static struct cgroup *task_cgroup_from_root(struct task_struct *task,
804static int cgroup_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode); 806static int cgroup_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
805static struct dentry *cgroup_lookup(struct inode *, struct dentry *, unsigned int); 807static struct dentry *cgroup_lookup(struct inode *, struct dentry *, unsigned int);
806static int cgroup_rmdir(struct inode *unused_dir, struct dentry *dentry); 808static int cgroup_rmdir(struct inode *unused_dir, struct dentry *dentry);
807static int cgroup_populate_dir(struct cgroup *cgrp, bool base_files, 809static int cgroup_populate_dir(struct cgroup *cgrp, unsigned long subsys_mask);
808 unsigned long subsys_mask);
809static const struct inode_operations cgroup_dir_inode_operations; 810static const struct inode_operations cgroup_dir_inode_operations;
810static const struct file_operations proc_cgroupstats_operations; 811static const struct file_operations proc_cgroupstats_operations;
811 812
@@ -957,13 +958,11 @@ static void cgroup_rm_file(struct cgroup *cgrp, const struct cftype *cft)
957} 958}
958 959
959/** 960/**
960 * cgroup_clear_dir - selective removal of base and subsystem files 961 * cgroup_clear_dir - remove subsys files in a cgroup directory
961 * @cgrp: target cgroup 962 * @cgrp: target cgroup
962 * @base_files: true if the base files should be removed
963 * @subsys_mask: mask of the subsystem ids whose files should be removed 963 * @subsys_mask: mask of the subsystem ids whose files should be removed
964 */ 964 */
965static void cgroup_clear_dir(struct cgroup *cgrp, bool base_files, 965static void cgroup_clear_dir(struct cgroup *cgrp, unsigned long subsys_mask)
966 unsigned long subsys_mask)
967{ 966{
968 struct cgroup_subsys *ss; 967 struct cgroup_subsys *ss;
969 968
@@ -974,10 +973,6 @@ static void cgroup_clear_dir(struct cgroup *cgrp, bool base_files,
974 list_for_each_entry(set, &ss->cftsets, node) 973 list_for_each_entry(set, &ss->cftsets, node)
975 cgroup_addrm_files(cgrp, NULL, set->cfts, false); 974 cgroup_addrm_files(cgrp, NULL, set->cfts, false);
976 } 975 }
977 if (base_files) {
978 while (!list_empty(&cgrp->files))
979 cgroup_rm_file(cgrp, NULL);
980 }
981} 976}
982 977
983/* 978/*
@@ -1372,17 +1367,17 @@ static int cgroup_remount(struct super_block *sb, int *flags, char *data)
1372 * this before rebind_subsystems, since rebind_subsystems may 1367 * this before rebind_subsystems, since rebind_subsystems may
1373 * change this hierarchy's subsys_list. 1368 * change this hierarchy's subsys_list.
1374 */ 1369 */
1375 cgroup_clear_dir(cgrp, false, removed_mask); 1370 cgroup_clear_dir(cgrp, removed_mask);
1376 1371
1377 ret = rebind_subsystems(root, added_mask, removed_mask); 1372 ret = rebind_subsystems(root, added_mask, removed_mask);
1378 if (ret) { 1373 if (ret) {
1379 /* rebind_subsystems failed, re-populate the removed files */ 1374 /* rebind_subsystems failed, re-populate the removed files */
1380 cgroup_populate_dir(cgrp, false, removed_mask); 1375 cgroup_populate_dir(cgrp, removed_mask);
1381 goto out_unlock; 1376 goto out_unlock;
1382 } 1377 }
1383 1378
1384 /* re-populate subsystem files */ 1379 /* re-populate subsystem files */
1385 cgroup_populate_dir(cgrp, false, added_mask); 1380 cgroup_populate_dir(cgrp, added_mask);
1386 1381
1387 if (opts.release_agent) 1382 if (opts.release_agent)
1388 strcpy(root->release_agent_path, opts.release_agent); 1383 strcpy(root->release_agent_path, opts.release_agent);
@@ -1687,7 +1682,8 @@ static struct dentry *cgroup_mount(struct file_system_type *fs_type,
1687 BUG_ON(root->number_of_cgroups != 1); 1682 BUG_ON(root->number_of_cgroups != 1);
1688 1683
1689 cred = override_creds(&init_cred); 1684 cred = override_creds(&init_cred);
1690 cgroup_populate_dir(root_cgrp, true, root->subsys_mask); 1685 cgroup_addrm_files(root_cgrp, NULL, cgroup_base_files, true);
1686 cgroup_populate_dir(root_cgrp, root->subsys_mask);
1691 revert_creds(cred); 1687 revert_creds(cred);
1692 mutex_unlock(&cgroup_root_mutex); 1688 mutex_unlock(&cgroup_root_mutex);
1693 mutex_unlock(&cgroup_mutex); 1689 mutex_unlock(&cgroup_mutex);
@@ -4172,23 +4168,14 @@ static struct cftype cgroup_base_files[] = {
4172}; 4168};
4173 4169
4174/** 4170/**
4175 * cgroup_populate_dir - selectively creation of files in a directory 4171 * cgroup_populate_dir - create subsys files in a cgroup directory
4176 * @cgrp: target cgroup 4172 * @cgrp: target cgroup
4177 * @base_files: true if the base files should be added
4178 * @subsys_mask: mask of the subsystem ids whose files should be added 4173 * @subsys_mask: mask of the subsystem ids whose files should be added
4179 */ 4174 */
4180static int cgroup_populate_dir(struct cgroup *cgrp, bool base_files, 4175static int cgroup_populate_dir(struct cgroup *cgrp, unsigned long subsys_mask)
4181 unsigned long subsys_mask)
4182{ 4176{
4183 int err;
4184 struct cgroup_subsys *ss; 4177 struct cgroup_subsys *ss;
4185 4178
4186 if (base_files) {
4187 err = cgroup_addrm_files(cgrp, NULL, cgroup_base_files, true);
4188 if (err < 0)
4189 return err;
4190 }
4191
4192 /* process cftsets of each subsystem */ 4179 /* process cftsets of each subsystem */
4193 for_each_root_subsys(cgrp->root, ss) { 4180 for_each_root_subsys(cgrp->root, ss) {
4194 struct cftype_set *set; 4181 struct cftype_set *set;
@@ -4410,7 +4397,11 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
4410 } 4397 }
4411 } 4398 }
4412 4399
4413 err = cgroup_populate_dir(cgrp, true, root->subsys_mask); 4400 err = cgroup_addrm_files(cgrp, NULL, cgroup_base_files, true);
4401 if (err)
4402 goto err_destroy;
4403
4404 err = cgroup_populate_dir(cgrp, root->subsys_mask);
4414 if (err) 4405 if (err)
4415 goto err_destroy; 4406 goto err_destroy;
4416 4407
@@ -4566,7 +4557,8 @@ static int cgroup_destroy_locked(struct cgroup *cgrp)
4566 * Clear and remove @cgrp directory. The removal puts the base ref 4557 * Clear and remove @cgrp directory. The removal puts the base ref
4567 * but we aren't quite done with @cgrp yet, so hold onto it. 4558 * but we aren't quite done with @cgrp yet, so hold onto it.
4568 */ 4559 */
4569 cgroup_clear_dir(cgrp, true, cgrp->root->subsys_mask); 4560 cgroup_clear_dir(cgrp, cgrp->root->subsys_mask);
4561 cgroup_addrm_files(cgrp, NULL, cgroup_base_files, false);
4570 dget(d); 4562 dget(d);
4571 cgroup_d_remove_dir(d); 4563 cgroup_d_remove_dir(d);
4572 4564