From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752177AbdFJOEM (ORCPT ); Sat, 10 Jun 2017 10:04:12 -0400 Received: from mail-qt0-f193.google.com ([209.85.216.193]:35540 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752110AbdFJOEI (ORCPT ); Sat, 10 Jun 2017 10:04:08 -0400 From: Tejun Heo To: Li Zefan , hannes@cmpxchg.org, peterz@infradead.org, mingo@redhat.com, longman@redhat.com Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, pjt@google.com, luto@amacapital.net, efault@gmx.de, torvalds@linux-foundation.org, Tejun Heo Subject: [PATCH 01/10] cgroup: separate out cgroup_has_tasks() Date: Sat, 10 Jun 2017 10:03:42 -0400 Message-Id: <20170610140351.10703-2-tj@kernel.org> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170610140351.10703-1-tj@kernel.org> References: <20170610140351.10703-1-tj@kernel.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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