Skip to content

Commit 5faaf05

Browse files
committed
cgroup: Explicitly remove core interface files
The "cgroup." core interface files bypass the usual interface removal path and get removed recursively along with the cgroup itself. While this works now, the subtle discrepancy gets in the way of implementing common mechanisms. This patch updates cgroup core interface file handling so that it's consistent with controller interface files. When added, the css is marked CSS_VISIBLE and they're explicitly removed before the cgroup is destroyed. This doesn't cause user-visible behavior changes. Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent fe03a75 commit 5faaf05

1 file changed

Lines changed: 22 additions & 13 deletions

File tree

‎kernel/cgroup/cgroup.c‎

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,8 +1573,17 @@ static void css_clear_dir(struct cgroup_subsys_state *css)
15731573

15741574
css->flags &= ~CSS_VISIBLE;
15751575

1576-
list_for_each_entry(cfts, &css->ss->cfts, node)
1576+
if (!css->ss) {
1577+
if (cgroup_on_dfl(cgrp))
1578+
cfts = cgroup_base_files;
1579+
else
1580+
cfts = cgroup1_base_files;
1581+
15771582
cgroup_addrm_files(css, cgrp, cfts, false);
1583+
} else {
1584+
list_for_each_entry(cfts, &css->ss->cfts, node)
1585+
cgroup_addrm_files(css, cgrp, cfts, false);
1586+
}
15781587
}
15791588

15801589
/**
@@ -1598,14 +1607,16 @@ static int css_populate_dir(struct cgroup_subsys_state *css)
15981607
else
15991608
cfts = cgroup1_base_files;
16001609

1601-
return cgroup_addrm_files(&cgrp->self, cgrp, cfts, true);
1602-
}
1603-
1604-
list_for_each_entry(cfts, &css->ss->cfts, node) {
1605-
ret = cgroup_addrm_files(css, cgrp, cfts, true);
1606-
if (ret < 0) {
1607-
failed_cfts = cfts;
1608-
goto err;
1610+
ret = cgroup_addrm_files(&cgrp->self, cgrp, cfts, true);
1611+
if (ret < 0)
1612+
return ret;
1613+
} else {
1614+
list_for_each_entry(cfts, &css->ss->cfts, node) {
1615+
ret = cgroup_addrm_files(css, cgrp, cfts, true);
1616+
if (ret < 0) {
1617+
failed_cfts = cfts;
1618+
goto err;
1619+
}
16091620
}
16101621
}
16111622

@@ -5090,10 +5101,8 @@ static int cgroup_destroy_locked(struct cgroup *cgrp)
50905101
for_each_css(css, ssid, cgrp)
50915102
kill_css(css);
50925103

5093-
/*
5094-
* Remove @cgrp directory along with the base files. @cgrp has an
5095-
* extra ref on its kn.
5096-
*/
5104+
/* clear and remove @cgrp dir, @cgrp has an extra ref on its kn */
5105+
css_clear_dir(&cgrp->self);
50975106
kernfs_remove(cgrp->kn);
50985107

50995108
if (parent && cgroup_is_threaded(cgrp))

0 commit comments

Comments
 (0)