All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
To: lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org
Cc: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH 15/16] cgroup: cosmetic updates to cgroup_attach_task()
Date: Sun,  9 Feb 2014 08:52:43 -0500	[thread overview]
Message-ID: <1391953964-22088-16-git-send-email-tj__41668.9558922828$1391954105$gmane$org@kernel.org> (raw)
In-Reply-To: <1391953964-22088-1-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>

cgroup_attach_task() is planned to go through restructuring.  Let's
tidy it up a bit in preparation.

* Update cgroup_attach_task() to receive the target task argument in
  @leader instead of @tsk.

* Rename @tsk to @task.

* Rename @retval to @ret.

This is purely cosmetic.

Signed-off-by: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
---
 kernel/cgroup.c | 45 +++++++++++++++++++++++----------------------
 1 file changed, 23 insertions(+), 22 deletions(-)

diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 0108753..057ab96 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -1727,20 +1727,20 @@ static void cgroup_task_migrate(struct cgroup *old_cgrp,
 /**
  * cgroup_attach_task - attach a task or a whole threadgroup to a cgroup
  * @cgrp: the cgroup to attach to
- * @tsk: the task or the leader of the threadgroup to be attached
+ * @leader: the task or the leader of the threadgroup to be attached
  * @threadgroup: attach the whole threadgroup?
  *
  * Call holding cgroup_mutex and the group_rwsem of the leader. Will take
  * task_lock of @tsk or each thread in the threadgroup individually in turn.
  */
-static int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk,
+static int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *leader,
 			      bool threadgroup)
 {
-	int retval, i, group_size;
+	int ret, i, group_size;
 	struct cgroupfs_root *root = cgrp->root;
 	struct cgroup_subsys_state *css, *failed_css = NULL;
 	/* threadgroup list cursor and array */
-	struct task_struct *leader = tsk;
+	struct task_struct *task;
 	struct task_and_cgroup *tc;
 	struct flex_array *group;
 	struct cgroup_taskset tset = { };
@@ -1753,7 +1753,7 @@ static int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk,
 	 * threads exit, this will just be an over-estimate.
 	 */
 	if (threadgroup)
-		group_size = get_nr_threads(tsk);
+		group_size = get_nr_threads(task);
 	else
 		group_size = 1;
 	/* flex_array supports very large thread-groups better than kmalloc. */
@@ -1761,8 +1761,8 @@ static int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk,
 	if (!group)
 		return -ENOMEM;
 	/* pre-allocate to guarantee space while iterating in rcu read-side. */
-	retval = flex_array_prealloc(group, 0, group_size, GFP_KERNEL);
-	if (retval)
+	ret = flex_array_prealloc(group, 0, group_size, GFP_KERNEL);
+	if (ret)
 		goto out_free_group_list;
 
 	i = 0;
@@ -1773,17 +1773,18 @@ static int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk,
 	 */
 	down_read(&css_set_rwsem);
 	rcu_read_lock();
+	task = leader;
 	do {
 		struct task_and_cgroup ent;
 
-		/* @tsk either already exited or can't exit until the end */
-		if (tsk->flags & PF_EXITING)
+		/* @task either already exited or can't exit until the end */
+		if (task->flags & PF_EXITING)
 			goto next;
 
 		/* as per above, nr_threads may decrease, but not increase. */
 		BUG_ON(i >= group_size);
-		ent.task = tsk;
-		ent.cgrp = task_cgroup_from_root(tsk, root);
+		ent.task = task;
+		ent.cgrp = task_cgroup_from_root(task, root);
 		/* nothing to do if this task is already in the cgroup */
 		if (ent.cgrp == cgrp)
 			goto next;
@@ -1791,13 +1792,13 @@ static int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk,
 		 * saying GFP_ATOMIC has no effect here because we did prealloc
 		 * earlier, but it's good form to communicate our expectations.
 		 */
-		retval = flex_array_put(group, i, &ent, GFP_ATOMIC);
-		BUG_ON(retval != 0);
+		ret = flex_array_put(group, i, &ent, GFP_ATOMIC);
+		BUG_ON(ret != 0);
 		i++;
 	next:
 		if (!threadgroup)
 			break;
-	} while_each_thread(leader, tsk);
+	} while_each_thread(leader, task);
 	rcu_read_unlock();
 	up_read(&css_set_rwsem);
 	/* remember the number of threads in the array for later. */
@@ -1806,7 +1807,7 @@ static int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk,
 	tset.tc_array_len = group_size;
 
 	/* methods shouldn't be called if no task is actually migrating */
-	retval = 0;
+	ret = 0;
 	if (!group_size)
 		goto out_free_group_list;
 
@@ -1815,8 +1816,8 @@ static int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk,
 	 */
 	for_each_css(css, i, cgrp) {
 		if (css->ss->can_attach) {
-			retval = css->ss->can_attach(css, &tset);
-			if (retval) {
+			ret = css->ss->can_attach(css, &tset);
+			if (ret) {
 				failed_css = css;
 				goto out_cancel_attach;
 			}
@@ -1834,7 +1835,7 @@ static int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk,
 		old_cset = task_css_set(tc->task);
 		tc->cset = find_css_set(old_cset, cgrp);
 		if (!tc->cset) {
-			retval = -ENOMEM;
+			ret = -ENOMEM;
 			goto out_put_css_set_refs;
 		}
 	}
@@ -1862,9 +1863,9 @@ static int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk,
 	/*
 	 * step 5: success! and cleanup
 	 */
-	retval = 0;
+	ret = 0;
 out_put_css_set_refs:
-	if (retval) {
+	if (ret) {
 		for (i = 0; i < group_size; i++) {
 			tc = flex_array_get(group, i);
 			if (!tc->cset)
@@ -1873,7 +1874,7 @@ out_put_css_set_refs:
 		}
 	}
 out_cancel_attach:
-	if (retval) {
+	if (ret) {
 		for_each_css(css, i, cgrp) {
 			if (css == failed_css)
 				break;
@@ -1883,7 +1884,7 @@ out_cancel_attach:
 	}
 out_free_group_list:
 	flex_array_free(group);
-	return retval;
+	return ret;
 }
 
 /*
-- 
1.8.5.3

  parent reply	other threads:[~2014-02-09 13:52 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-09 13:52 [PATCHSET cgroup/for-3.15] cgroup: more cleanups Tejun Heo
2014-02-09 13:52 ` Tejun Heo
2014-02-09 13:52 ` [PATCH 05/16] cgroup: implement cgroup_has_tasks() and unexport cgroup_task_count() Tejun Heo
     [not found]   ` <1391953964-22088-6-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2014-02-10 12:36     ` Michal Hocko
2014-02-10 12:36   ` Michal Hocko
2014-02-10 12:36     ` Michal Hocko
     [not found] ` <1391953964-22088-1-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2014-02-09 13:52   ` [PATCH 01/16] cgroup: disallow xattr, release_agent and name if sane_behavior Tejun Heo
2014-02-09 13:52     ` Tejun Heo
2014-02-09 13:52   ` [PATCH 02/16] cgroup: drop CGRP_ROOT_SUBSYS_BOUND Tejun Heo
2014-02-09 13:52     ` Tejun Heo
2014-02-09 13:52   ` [PATCH 03/16] cgroup: enable task_cg_lists on the first cgroup mount Tejun Heo
2014-02-09 13:52     ` Tejun Heo
2014-02-09 13:52   ` [PATCH 04/16] cgroup: relocate cgroup_enable_task_cg_lists() Tejun Heo
2014-02-09 13:52     ` Tejun Heo
2014-02-09 13:52   ` [PATCH 05/16] cgroup: implement cgroup_has_tasks() and unexport cgroup_task_count() Tejun Heo
2014-02-09 13:52   ` [PATCH 06/16] cgroup: reimplement cgroup_transfer_tasks() without using css_scan_tasks() Tejun Heo
2014-02-09 13:52     ` Tejun Heo
2014-02-09 13:52   ` [PATCH 07/16] cgroup: make css_set_lock a rwsem and rename it to css_set_rwsem Tejun Heo
2014-02-09 13:52     ` Tejun Heo
2014-02-09 13:52   ` [PATCH 08/16] cpuset: use css_task_iter_start/next/end() instead of css_scan_tasks() Tejun Heo
2014-02-09 13:52     ` Tejun Heo
2014-02-09 13:52   ` [PATCH 09/16] cgroup: remove css_scan_tasks() Tejun Heo
2014-02-09 13:52     ` Tejun Heo
     [not found]     ` <1391953964-22088-10-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2014-02-13  2:01       ` Li Zefan
2014-02-13  2:01         ` Li Zefan
2014-02-09 13:52   ` [PATCH 10/16] cgroup: separate out put_css_set_locked() and remove put_css_set_taskexit() Tejun Heo
2014-02-09 13:52     ` Tejun Heo
2014-02-09 13:52   ` [PATCH 11/16] cgroup: move css_set_rwsem locking outside of cgroup_task_migrate() Tejun Heo
2014-02-09 13:52   ` [PATCH 12/16] cgroup: drop @skip_css from cgroup_taskset_for_each() Tejun Heo
2014-02-09 13:52     ` Tejun Heo
2014-02-09 13:52   ` [PATCH 13/16] cpuset: don't use cgroup_taskset_cur_css() Tejun Heo
2014-02-09 13:52   ` [PATCH 14/16] cgroup: remove cgroup_taskset_cur_css() and cgroup_taskset_size() Tejun Heo
2014-02-09 13:52   ` Tejun Heo [this message]
2014-02-09 13:52   ` [PATCH 16/16] cgroup: unexport functions Tejun Heo
2014-02-13  2:01   ` [PATCHSET cgroup/for-3.15] cgroup: more cleanups Li Zefan
2014-02-13  2:01     ` Li Zefan
2014-02-13 11:59   ` Tejun Heo
2014-02-13 11:59     ` Tejun Heo
2014-02-09 13:52 ` [PATCH 11/16] cgroup: move css_set_rwsem locking outside of cgroup_task_migrate() Tejun Heo
2014-02-09 13:52 ` [PATCH 13/16] cpuset: don't use cgroup_taskset_cur_css() Tejun Heo
2014-02-09 13:52 ` [PATCH 14/16] cgroup: remove cgroup_taskset_cur_css() and cgroup_taskset_size() Tejun Heo
2014-02-09 13:52 ` [PATCH 15/16] cgroup: cosmetic updates to cgroup_attach_task() Tejun Heo
2014-02-10 23:06   ` [PATCH v2 " Tejun Heo
2014-02-10 23:06     ` Tejun Heo
     [not found]   ` <1391953964-22088-16-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2014-02-10 23:06     ` Tejun Heo
2014-02-09 13:52 ` [PATCH 16/16] cgroup: unexport functions Tejun Heo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='1391953964-22088-16-git-send-email-tj__41668.9558922828$1391954105$gmane$org@kernel.org' \
    --to=tj-dgejt+ai2ygdnm+yrofe0a@public.gmane.org \
    --cc=cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.