[PATCH 01/10] cgroup: separate out cgroup_has_tasks()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Separate out cgroup_has_tasks() test from
cgroup_subtree_control_write().  This will be used by the following
changes.

This patch doesn't cause any behavior changes.

Signed-off-by: Tejun Heo <tj@xxxxxxxxxx>
---
 kernel/cgroup/cgroup.c | 49 +++++++++++++++++++++++++++----------------------
 1 file changed, 27 insertions(+), 22 deletions(-)

diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index 8d4e85eae42c..dcd120af4084 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -581,6 +581,30 @@ static bool css_set_populated(struct css_set *cset)
 	return !list_empty(&cset->tasks) || !list_empty(&cset->mg_tasks);
 }
 
+static bool cgroup_has_tasks(struct cgroup *cgrp)
+{
+	struct cgrp_cset_link *link;
+	bool has_tasks = false;
+
+	/*
+	 * 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);
+
+	list_for_each_entry(link, &cgrp->cset_links, cset_link) {
+		if (css_set_populated(link->cset)) {
+			has_tasks = true;
+			break;
+		}
+	}
+
+	spin_unlock_irq(&css_set_lock);
+
+	return has_tasks;
+}
+
 /**
  * cgroup_update_populated - updated populated count of a cgroup
  * @cgrp: the target cgroup
@@ -2886,28 +2910,9 @@ static ssize_t cgroup_subtree_control_write(struct kernfs_open_file *of,
 	 * Except for the root, subtree_control must be zero for a cgroup
 	 * with tasks so that child cgroups don't compete against tasks.
 	 */
-	if (enable && cgroup_parent(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;
-				break;
-			}
-		}
-
-		spin_unlock_irq(&css_set_lock);
-
-		if (ret)
-			goto out_unlock;
+	if (enable && cgroup_parent(cgrp) && cgroup_has_tasks(cgrp)) {
+		ret = -EBUSY;
+		goto out_unlock;
 	}
 
 	/* save and update control masks and prepare csses */
-- 
2.13.0

--
To unsubscribe from this list: send the line "unsubscribe cgroups" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]     [Monitors]

  Powered by Linux