[PATCH 03/10] cgroup: introduce CGRP_MIGRATE_* flags
From: Tejun Heo
Date: Fri Mar 11 2016 - 10:41:58 EST
Currently, the only migration modifier is boolean @threadgroup. Make
the functions pass around unsigned flag mask instead and replace
@threadgroup with CGRP_MIGRATE_PROCESS. This will allow addition of
other modifiers.
This patch doesn't introduce any behavior changes.
Signed-off-by: Tejun Heo <tj@xxxxxxxxxx>
---
kernel/cgroup.c | 32 ++++++++++++++++++--------------
1 file changed, 18 insertions(+), 14 deletions(-)
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 4c3c43e..8ecb8d6 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -2403,6 +2403,10 @@ struct task_struct *cgroup_taskset_next(struct cgroup_taskset *tset,
return NULL;
}
+enum {
+ CGRP_MIGRATE_PROCESS = (1 << 0), /* migrate the whole process */
+};
+
/**
* cgroup_taskset_migrate - migrate a taskset
* @tset: taget taskset
@@ -2634,7 +2638,7 @@ static int cgroup_migrate_prepare_dst(struct list_head *preloaded_csets)
/**
* cgroup_migrate - migrate a process or task to a cgroup
* @leader: the leader of the process or the task to migrate
- * @threadgroup: whether @leader points to the whole process or a single task
+ * @mflags: CGRP_MIGRATE_* flags
* @root: cgroup root migration is taking place on
*
* Migrate a process or task denoted by @leader. If migrating a process,
@@ -2649,7 +2653,7 @@ static int cgroup_migrate_prepare_dst(struct list_head *preloaded_csets)
* decided for all targets by invoking group_migrate_prepare_dst() before
* actually starting migrating.
*/
-static int cgroup_migrate(struct task_struct *leader, bool threadgroup,
+static int cgroup_migrate(struct task_struct *leader, unsigned mflags,
struct cgroup_root *root)
{
struct cgroup_taskset tset = CGROUP_TASKSET_INIT(tset);
@@ -2665,7 +2669,7 @@ static int cgroup_migrate(struct task_struct *leader, bool threadgroup,
task = leader;
do {
cgroup_taskset_add(task, &tset);
- if (!threadgroup)
+ if (!(mflags & CGRP_MIGRATE_PROCESS))
break;
} while_each_thread(leader, task);
rcu_read_unlock();
@@ -2678,12 +2682,12 @@ static int cgroup_migrate(struct task_struct *leader, bool threadgroup,
* cgroup_attach_task - attach a task or a whole threadgroup to a cgroup
* @dst_cgrp: the cgroup to attach to
* @leader: the task or the leader of the threadgroup to be attached
- * @threadgroup: attach the whole threadgroup?
+ * @mflags: CGRP_MIGRATE_* flags
*
* Call holding cgroup_mutex and cgroup_threadgroup_rwsem.
*/
static int cgroup_attach_task(struct cgroup *dst_cgrp,
- struct task_struct *leader, bool threadgroup)
+ struct task_struct *leader, unsigned mflags)
{
LIST_HEAD(preloaded_csets);
struct task_struct *task;
@@ -2699,7 +2703,7 @@ static int cgroup_attach_task(struct cgroup *dst_cgrp,
do {
cgroup_migrate_add_src(task_css_set(task), dst_cgrp,
&preloaded_csets);
- if (!threadgroup)
+ if (!(mflags & CGRP_MIGRATE_PROCESS))
break;
} while_each_thread(leader, task);
rcu_read_unlock();
@@ -2708,7 +2712,7 @@ static int cgroup_attach_task(struct cgroup *dst_cgrp,
/* prepare dst csets and commit */
ret = cgroup_migrate_prepare_dst(&preloaded_csets);
if (!ret)
- ret = cgroup_migrate(leader, threadgroup, dst_cgrp->root);
+ ret = cgroup_migrate(leader, mflags, dst_cgrp->root);
cgroup_migrate_finish(&preloaded_csets);
return ret;
@@ -2761,7 +2765,7 @@ static int cgroup_procs_write_permission(struct task_struct *task,
* cgroup_mutex and threadgroup.
*/
static ssize_t __cgroup_procs_write(struct kernfs_open_file *of, char *buf,
- size_t nbytes, loff_t off, bool threadgroup)
+ size_t nbytes, loff_t off, unsigned mflags)
{
struct task_struct *tsk;
struct cgroup *cgrp;
@@ -2787,7 +2791,7 @@ static ssize_t __cgroup_procs_write(struct kernfs_open_file *of, char *buf,
tsk = current;
}
- if (threadgroup)
+ if (mflags & CGRP_MIGRATE_PROCESS)
tsk = tsk->group_leader;
/*
@@ -2805,7 +2809,7 @@ static ssize_t __cgroup_procs_write(struct kernfs_open_file *of, char *buf,
ret = cgroup_procs_write_permission(tsk, cgrp, of);
if (!ret)
- ret = cgroup_attach_task(cgrp, tsk, threadgroup);
+ ret = cgroup_attach_task(cgrp, tsk, mflags);
put_task_struct(tsk);
goto out_unlock_threadgroup;
@@ -2840,7 +2844,7 @@ int cgroup_attach_task_all(struct task_struct *from, struct task_struct *tsk)
from_cgrp = task_cgroup_from_root(from, root);
spin_unlock_bh(&css_set_lock);
- retval = cgroup_attach_task(from_cgrp, tsk, false);
+ retval = cgroup_attach_task(from_cgrp, tsk, 0);
if (retval)
break;
}
@@ -2853,13 +2857,13 @@ EXPORT_SYMBOL_GPL(cgroup_attach_task_all);
static ssize_t cgroup_tasks_write(struct kernfs_open_file *of,
char *buf, size_t nbytes, loff_t off)
{
- return __cgroup_procs_write(of, buf, nbytes, off, false);
+ return __cgroup_procs_write(of, buf, nbytes, off, 0);
}
static ssize_t cgroup_procs_write(struct kernfs_open_file *of,
char *buf, size_t nbytes, loff_t off)
{
- return __cgroup_procs_write(of, buf, nbytes, off, true);
+ return __cgroup_procs_write(of, buf, nbytes, off, CGRP_MIGRATE_PROCESS);
}
static ssize_t cgroup_release_agent_write(struct kernfs_open_file *of,
@@ -4233,7 +4237,7 @@ int cgroup_transfer_tasks(struct cgroup *to, struct cgroup *from)
css_task_iter_end(&it);
if (task) {
- ret = cgroup_migrate(task, false, to->root);
+ ret = cgroup_migrate(task, 0, to->root);
put_task_struct(task);
}
} while (task && !ret);
--
2.5.0