Skip to content

Commit e406d1c

Browse files
committed
cgroup: reimplement cgroup_transfer_tasks() without using css_scan_tasks()
Reimplement cgroup_transfer_tasks() so that it repeatedly fetches the first task in the cgroup and then tranfers it. This achieves the same result without using css_scan_tasks() which is scheduled to be removed. Signed-off-by: Tejun Heo <[email protected]> Acked-by: Li Zefan <[email protected]>
1 parent 07bc356 commit e406d1c

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

kernel/cgroup.c

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2850,24 +2850,33 @@ int css_scan_tasks(struct cgroup_subsys_state *css,
28502850
return 0;
28512851
}
28522852

2853-
static void cgroup_transfer_one_task(struct task_struct *task, void *data)
2854-
{
2855-
struct cgroup *new_cgroup = data;
2856-
2857-
mutex_lock(&cgroup_mutex);
2858-
cgroup_attach_task(new_cgroup, task, false);
2859-
mutex_unlock(&cgroup_mutex);
2860-
}
2861-
28622853
/**
28632854
* cgroup_trasnsfer_tasks - move tasks from one cgroup to another
28642855
* @to: cgroup to which the tasks will be moved
28652856
* @from: cgroup in which the tasks currently reside
28662857
*/
28672858
int cgroup_transfer_tasks(struct cgroup *to, struct cgroup *from)
28682859
{
2869-
return css_scan_tasks(&from->dummy_css, NULL, cgroup_transfer_one_task,
2870-
to, NULL);
2860+
struct css_task_iter it;
2861+
struct task_struct *task;
2862+
int ret = 0;
2863+
2864+
do {
2865+
css_task_iter_start(&from->dummy_css, &it);
2866+
task = css_task_iter_next(&it);
2867+
if (task)
2868+
get_task_struct(task);
2869+
css_task_iter_end(&it);
2870+
2871+
if (task) {
2872+
mutex_lock(&cgroup_mutex);
2873+
ret = cgroup_attach_task(to, task, false);
2874+
mutex_unlock(&cgroup_mutex);
2875+
put_task_struct(task);
2876+
}
2877+
} while (task && !ret);
2878+
2879+
return ret;
28712880
}
28722881

28732882
/*

0 commit comments

Comments
 (0)