Commit 27f26753 authored by Tejun Heo's avatar Tejun Heo

cgroup: replace css_set walking populated test with testing cgrp->nr_populated_csets

Implement trivial cgroup_has_tasks() which tests whether
cgrp->nr_populated_csets is zero and replace the explicit local
populated test in cgroup_subtree_control().  This simplifies the code
and cgroup_has_tasks() will be used in more places later.
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
parent 788b950c
...@@ -325,6 +325,11 @@ static struct cgroup *cgroup_parent(struct cgroup *cgrp) ...@@ -325,6 +325,11 @@ static struct cgroup *cgroup_parent(struct cgroup *cgrp)
return NULL; return NULL;
} }
static bool cgroup_has_tasks(struct cgroup *cgrp)
{
return cgrp->nr_populated_csets;
}
/* subsystems visibly enabled on a cgroup */ /* subsystems visibly enabled on a cgroup */
static u16 cgroup_control(struct cgroup *cgrp) static u16 cgroup_control(struct cgroup *cgrp)
{ {
...@@ -2971,27 +2976,8 @@ static ssize_t cgroup_subtree_control_write(struct kernfs_open_file *of, ...@@ -2971,27 +2976,8 @@ static ssize_t cgroup_subtree_control_write(struct kernfs_open_file *of,
* Except for the root, subtree_control must be zero for a cgroup * Except for the root, subtree_control must be zero for a cgroup
* with tasks so that child cgroups don't compete against tasks. * with tasks so that child cgroups don't compete against tasks.
*/ */
if (enable && cgroup_parent(cgrp)) { if (enable && cgroup_parent(cgrp) && cgroup_has_tasks(cgrp)) {
struct cgrp_cset_link *link;
/*
* Because namespaces pin csets too, @cgrp->cset_links
* might not be empty even when @cgrp is empty. Walk and
* verify each cset.
*/
spin_lock_irq(&css_set_lock);
ret = 0;
list_for_each_entry(link, &cgrp->cset_links, cset_link) {
if (css_set_populated(link->cset)) {
ret = -EBUSY; ret = -EBUSY;
break;
}
}
spin_unlock_irq(&css_set_lock);
if (ret)
goto out_unlock; goto out_unlock;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment