Skip to content

Commit 37ff9f8

Browse files
committed
cgroup: make cgroup[_taskset]_migrate() take cgroup_root instead of cgroup
On the default hierarchy, a migration can be multi-source and/or multi-destination. cgroup_taskest_migrate() used to incorrectly assume single destination cgroup but the bug has been fixed by 1f7dd3e ("cgroup: fix handling of multi-destination migration from subtree_control enabling"). Since the commit, @dst_cgrp to cgroup[_taskset]_migrate() is only used to determine which subsystems are affected or which cgroup_root the migration is taking place in. As such, @dst_cgrp is misleading. This patch replaces @dst_cgrp with @root. Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent 6c694c8 commit 37ff9f8

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

kernel/cgroup.c

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2355,38 +2355,38 @@ struct task_struct *cgroup_taskset_next(struct cgroup_taskset *tset,
23552355
}
23562356

23572357
/**
2358-
* cgroup_taskset_migrate - migrate a taskset to a cgroup
2358+
* cgroup_taskset_migrate - migrate a taskset
23592359
* @tset: taget taskset
2360-
* @dst_cgrp: destination cgroup
2360+
* @root: cgroup root the migration is taking place on
23612361
*
2362-
* Migrate tasks in @tset to @dst_cgrp. This function fails iff one of the
2363-
* ->can_attach callbacks fails and guarantees that either all or none of
2364-
* the tasks in @tset are migrated. @tset is consumed regardless of
2365-
* success.
2362+
* Migrate tasks in @tset as setup by migration preparation functions.
2363+
* This function fails iff one of the ->can_attach callbacks fails and
2364+
* guarantees that either all or none of the tasks in @tset are migrated.
2365+
* @tset is consumed regardless of success.
23662366
*/
23672367
static int cgroup_taskset_migrate(struct cgroup_taskset *tset,
2368-
struct cgroup *dst_cgrp)
2368+
struct cgroup_root *root)
23692369
{
2370-
struct cgroup_subsys_state *css, *failed_css = NULL;
2370+
struct cgroup_subsys *ss;
23712371
struct task_struct *task, *tmp_task;
23722372
struct css_set *cset, *tmp_cset;
2373-
int i, ret;
2373+
int ssid, failed_ssid, ret;
23742374

23752375
/* methods shouldn't be called if no task is actually migrating */
23762376
if (list_empty(&tset->src_csets))
23772377
return 0;
23782378

23792379
/* check that we can legitimately attach to the cgroup */
2380-
for_each_e_css(css, i, dst_cgrp) {
2381-
if (css->ss->can_attach) {
2382-
tset->ssid = i;
2383-
ret = css->ss->can_attach(tset);
2380+
do_each_subsys_mask(ss, ssid, root->subsys_mask) {
2381+
if (ss->can_attach) {
2382+
tset->ssid = ssid;
2383+
ret = ss->can_attach(tset);
23842384
if (ret) {
2385-
failed_css = css;
2385+
failed_ssid = ssid;
23862386
goto out_cancel_attach;
23872387
}
23882388
}
2389-
}
2389+
} while_each_subsys_mask();
23902390

23912391
/*
23922392
* Now that we're guaranteed success, proceed to move all tasks to
@@ -2413,25 +2413,25 @@ static int cgroup_taskset_migrate(struct cgroup_taskset *tset,
24132413
*/
24142414
tset->csets = &tset->dst_csets;
24152415

2416-
for_each_e_css(css, i, dst_cgrp) {
2417-
if (css->ss->attach) {
2418-
tset->ssid = i;
2419-
css->ss->attach(tset);
2416+
do_each_subsys_mask(ss, ssid, root->subsys_mask) {
2417+
if (ss->attach) {
2418+
tset->ssid = ssid;
2419+
ss->attach(tset);
24202420
}
2421-
}
2421+
} while_each_subsys_mask();
24222422

24232423
ret = 0;
24242424
goto out_release_tset;
24252425

24262426
out_cancel_attach:
2427-
for_each_e_css(css, i, dst_cgrp) {
2428-
if (css == failed_css)
2427+
do_each_subsys_mask(ss, ssid, root->subsys_mask) {
2428+
if (ssid == failed_ssid)
24292429
break;
2430-
if (css->ss->cancel_attach) {
2431-
tset->ssid = i;
2432-
css->ss->cancel_attach(tset);
2430+
if (ss->cancel_attach) {
2431+
tset->ssid = ssid;
2432+
ss->cancel_attach(tset);
24332433
}
2434-
}
2434+
} while_each_subsys_mask();
24352435
out_release_tset:
24362436
spin_lock_bh(&css_set_lock);
24372437
list_splice_init(&tset->dst_csets, &tset->src_csets);
@@ -2586,11 +2586,11 @@ static int cgroup_migrate_prepare_dst(struct cgroup *dst_cgrp,
25862586
* cgroup_migrate - migrate a process or task to a cgroup
25872587
* @leader: the leader of the process or the task to migrate
25882588
* @threadgroup: whether @leader points to the whole process or a single task
2589-
* @cgrp: the destination cgroup
2589+
* @root: cgroup root migration is taking place on
25902590
*
2591-
* Migrate a process or task denoted by @leader to @cgrp. If migrating a
2592-
* process, the caller must be holding cgroup_threadgroup_rwsem. The
2593-
* caller is also responsible for invoking cgroup_migrate_add_src() and
2591+
* Migrate a process or task denoted by @leader. If migrating a process,
2592+
* the caller must be holding cgroup_threadgroup_rwsem. The caller is also
2593+
* responsible for invoking cgroup_migrate_add_src() and
25942594
* cgroup_migrate_prepare_dst() on the targets before invoking this
25952595
* function and following up with cgroup_migrate_finish().
25962596
*
@@ -2601,7 +2601,7 @@ static int cgroup_migrate_prepare_dst(struct cgroup *dst_cgrp,
26012601
* actually starting migrating.
26022602
*/
26032603
static int cgroup_migrate(struct task_struct *leader, bool threadgroup,
2604-
struct cgroup *cgrp)
2604+
struct cgroup_root *root)
26052605
{
26062606
struct cgroup_taskset tset = CGROUP_TASKSET_INIT(tset);
26072607
struct task_struct *task;
@@ -2622,7 +2622,7 @@ static int cgroup_migrate(struct task_struct *leader, bool threadgroup,
26222622
rcu_read_unlock();
26232623
spin_unlock_bh(&css_set_lock);
26242624

2625-
return cgroup_taskset_migrate(&tset, cgrp);
2625+
return cgroup_taskset_migrate(&tset, root);
26262626
}
26272627

26282628
/**
@@ -2659,7 +2659,7 @@ static int cgroup_attach_task(struct cgroup *dst_cgrp,
26592659
/* prepare dst csets and commit */
26602660
ret = cgroup_migrate_prepare_dst(dst_cgrp, &preloaded_csets);
26612661
if (!ret)
2662-
ret = cgroup_migrate(leader, threadgroup, dst_cgrp);
2662+
ret = cgroup_migrate(leader, threadgroup, dst_cgrp->root);
26632663

26642664
cgroup_migrate_finish(&preloaded_csets);
26652665
return ret;
@@ -2934,7 +2934,7 @@ static int cgroup_update_dfl_csses(struct cgroup *cgrp)
29342934
}
29352935
spin_unlock_bh(&css_set_lock);
29362936

2937-
ret = cgroup_taskset_migrate(&tset, cgrp);
2937+
ret = cgroup_taskset_migrate(&tset, cgrp->root);
29382938
out_finish:
29392939
cgroup_migrate_finish(&preloaded_csets);
29402940
percpu_up_write(&cgroup_threadgroup_rwsem);
@@ -4172,7 +4172,7 @@ int cgroup_transfer_tasks(struct cgroup *to, struct cgroup *from)
41724172
css_task_iter_end(&it);
41734173

41744174
if (task) {
4175-
ret = cgroup_migrate(task, false, to);
4175+
ret = cgroup_migrate(task, false, to->root);
41764176
put_task_struct(task);
41774177
}
41784178
} while (task && !ret);

0 commit comments

Comments
 (0)