aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2012-11-19 11:13:36 -0500
committerTejun Heo <tj@kernel.org>2012-11-19 11:13:36 -0500
commit28fd6f30ac3efd9170ae1ac89f3521d53b5eb83a (patch)
tree8f9742385f1e8447c3b66e8f87d7c2fc5ae4441c /kernel
parent2243076ad128d0cc196cf6597e6ddcf6bc907676 (diff)
cgroup: open-code cgroup_create_dir()
The operation order of cgroup creation is about to change and cgroup_create_dir() is more of a hindrance than a proper abstraction. Open-code it by moving the parent nlink adjustment next to self nlink adjustment in cgroup_create_file() and the rest to cgroup_create(). This patch doesn't introduce any behavior change. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Li Zefan <lizefan@huawei.com>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/cgroup.c30
1 files changed, 5 insertions, 25 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index ed0e177c4650..b042673171e9 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -2652,6 +2652,7 @@ static int cgroup_create_file(struct dentry *dentry, umode_t mode,
2652 2652
2653 /* start off with i_nlink == 2 (for "." entry) */ 2653 /* start off with i_nlink == 2 (for "." entry) */
2654 inc_nlink(inode); 2654 inc_nlink(inode);
2655 inc_nlink(dentry->d_parent->d_inode);
2655 2656
2656 /* start with the directory inode held, so that we can 2657 /* start with the directory inode held, so that we can
2657 * populate it without racing with another mkdir */ 2658 * populate it without racing with another mkdir */
@@ -2666,30 +2667,6 @@ static int cgroup_create_file(struct dentry *dentry, umode_t mode,
2666 return 0; 2667 return 0;
2667} 2668}
2668 2669
2669/*
2670 * cgroup_create_dir - create a directory for an object.
2671 * @cgrp: the cgroup we create the directory for. It must have a valid
2672 * ->parent field. And we are going to fill its ->dentry field.
2673 * @dentry: dentry of the new cgroup
2674 * @mode: mode to set on new directory.
2675 */
2676static int cgroup_create_dir(struct cgroup *cgrp, struct dentry *dentry,
2677 umode_t mode)
2678{
2679 struct dentry *parent;
2680 int error = 0;
2681
2682 parent = cgrp->parent->dentry;
2683 error = cgroup_create_file(dentry, S_IFDIR | mode, cgrp->root->sb);
2684 if (!error) {
2685 dentry->d_fsdata = cgrp;
2686 inc_nlink(parent->d_inode);
2687 rcu_assign_pointer(cgrp->dentry, dentry);
2688 }
2689
2690 return error;
2691}
2692
2693/** 2670/**
2694 * cgroup_file_mode - deduce file mode of a control file 2671 * cgroup_file_mode - deduce file mode of a control file
2695 * @cft: the control file in question 2672 * @cft: the control file in question
@@ -4138,10 +4115,13 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
4138 list_add_tail_rcu(&cgrp->sibling, &cgrp->parent->children); 4115 list_add_tail_rcu(&cgrp->sibling, &cgrp->parent->children);
4139 root->number_of_cgroups++; 4116 root->number_of_cgroups++;
4140 4117
4141 err = cgroup_create_dir(cgrp, dentry, mode); 4118 err = cgroup_create_file(dentry, S_IFDIR | mode, sb);
4142 if (err < 0) 4119 if (err < 0)
4143 goto err_remove; 4120 goto err_remove;
4144 4121
4122 dentry->d_fsdata = cgrp;
4123 rcu_assign_pointer(cgrp->dentry, dentry);
4124
4145 for_each_subsys(root, ss) { 4125 for_each_subsys(root, ss) {
4146 /* each css holds a ref to the cgroup's dentry */ 4126 /* each css holds a ref to the cgroup's dentry */
4147 dget(dentry); 4127 dget(dentry);