summaryrefslogtreecommitdiffstats
path: root/kernel/cgroup.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2014-05-13 12:19:22 -0400
committerTejun Heo <tj@kernel.org>2014-05-13 12:19:22 -0400
commitcfc79d5bec04cdf26cd207d3e73d8bd59fd780a8 (patch)
tree96a08e782596ce01a268a9309cf8d3fbc2f18ee9 /kernel/cgroup.c
parentddab2b6e0e516098efe6d3b69585bb25b1408d61 (diff)
downloadop-kernel-dev-cfc79d5bec04cdf26cd207d3e73d8bd59fd780a8.zip
op-kernel-dev-cfc79d5bec04cdf26cd207d3e73d8bd59fd780a8.tar.gz
cgroup: move cgroup->kn->priv clearing to cgroup_rmdir()
The ->priv field of a cgroup directory kernfs_node points back to the cgroup. This field is RCU cleared in cgroup_destroy_locked() for non-kernfs accesses from css_tryget_from_dir() and cgroupstats_build(). As these are only applicable to cgroups which finished creation successfully and fully initialized cgroups are always removed by cgroup_rmdir(), this can be safely moved to the end of cgroup_rmdir(). This will help simplifying cgroup locking and shouldn't introduce any behavior difference. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Li Zefan <lizefan@huawei.com>
Diffstat (limited to 'kernel/cgroup.c')
-rw-r--r--kernel/cgroup.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 8afddb1..b49e63d 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -4546,17 +4546,7 @@ static int cgroup_destroy_locked(struct cgroup *cgrp)
/* remove @cgrp directory along with the base files */
mutex_unlock(&cgroup_mutex);
-
- /*
- * There are two control paths which try to determine cgroup from
- * dentry without going through kernfs - cgroupstats_build() and
- * css_tryget_online_from_dir(). Those are supported by RCU
- * protecting clearing of cgrp->kn->priv backpointer, which should
- * happen after all files under it have been removed.
- */
kernfs_remove(cgrp->kn); /* @cgrp has an extra ref on its kn */
- RCU_INIT_POINTER(*(void __rcu __force **)&cgrp->kn->priv, NULL);
-
mutex_lock(&cgroup_mutex);
return 0;
@@ -4615,6 +4605,17 @@ static int cgroup_rmdir(struct kernfs_node *kn)
mutex_unlock(&cgroup_tree_mutex);
kernfs_unbreak_active_protection(kn);
+
+ /*
+ * There are two control paths which try to determine cgroup from
+ * dentry without going through kernfs - cgroupstats_build() and
+ * css_tryget_online_from_dir(). Those are supported by RCU
+ * protecting clearing of cgrp->kn->priv backpointer, which should
+ * happen after all files under it have been removed.
+ */
+ if (!ret)
+ RCU_INIT_POINTER(*(void __rcu __force **)&kn->priv, NULL);
+
cgroup_put(cgrp);
return ret;
}
@@ -5174,7 +5175,7 @@ struct cgroup_subsys_state *css_tryget_online_from_dir(struct dentry *dentry,
/*
* This path doesn't originate from kernfs and @kn could already
* have been or be removed at any point. @kn->priv is RCU
- * protected for this access. See destroy_locked() for details.
+ * protected for this access. See cgroup_rmdir() for details.
*/
cgrp = rcu_dereference(kn->priv);
if (cgrp)
OpenPOWER on IntegriCloud