Commit 88cb04b9 authored by Tejun Heo's avatar Tejun Heo

cgroup: explicitly track whether a cgroup_subsys_state is visible to userland

Currently, whether a css (cgroup_subsys_state) has its interface files
created is not tracked and assumed to change together with the owning
cgroup's lifecycle.  cgroup directory and interface creation is being
separated out from internal object creation to help refactoring and
eventually allow cgroups which are not visible through cgroupfs.

This patch adds CSS_VISIBLE to track whether a css has its interface
files created and perform management operations only when necessary
which helps decoupling interface file handling from internal object
lifecycle.  After this patch, all css interface file management
functions can be called regardless of the current state and will
achieve the expected result.
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Acked-by: default avatarZefan Li <lizefan@huawei.com>
parent 6cd0f5bb
...@@ -45,6 +45,7 @@ enum { ...@@ -45,6 +45,7 @@ enum {
CSS_NO_REF = (1 << 0), /* no reference counting for this css */ CSS_NO_REF = (1 << 0), /* no reference counting for this css */
CSS_ONLINE = (1 << 1), /* between ->css_online() and ->css_offline() */ CSS_ONLINE = (1 << 1), /* between ->css_online() and ->css_offline() */
CSS_RELEASED = (1 << 2), /* refcnt reached zero, released */ CSS_RELEASED = (1 << 2), /* refcnt reached zero, released */
CSS_VISIBLE = (1 << 3), /* css is visible to userland */
}; };
/* bits in struct cgroup flags field */ /* bits in struct cgroup flags field */
......
...@@ -1421,6 +1421,11 @@ static void css_clear_dir(struct cgroup_subsys_state *css, ...@@ -1421,6 +1421,11 @@ static void css_clear_dir(struct cgroup_subsys_state *css,
struct cgroup *cgrp = cgrp_override ?: css->cgroup; struct cgroup *cgrp = cgrp_override ?: css->cgroup;
struct cftype *cfts; struct cftype *cfts;
if (!(css->flags & CSS_VISIBLE))
return;
css->flags &= ~CSS_VISIBLE;
list_for_each_entry(cfts, &css->ss->cfts, node) list_for_each_entry(cfts, &css->ss->cfts, node)
cgroup_addrm_files(css, cgrp, cfts, false); cgroup_addrm_files(css, cgrp, cfts, false);
} }
...@@ -1439,6 +1444,9 @@ static int css_populate_dir(struct cgroup_subsys_state *css, ...@@ -1439,6 +1444,9 @@ static int css_populate_dir(struct cgroup_subsys_state *css,
struct cftype *cfts, *failed_cfts; struct cftype *cfts, *failed_cfts;
int ret; int ret;
if (css->flags & CSS_VISIBLE)
return 0;
if (!css->ss) { if (!css->ss) {
if (cgroup_on_dfl(cgrp)) if (cgroup_on_dfl(cgrp))
cfts = cgroup_dfl_base_files; cfts = cgroup_dfl_base_files;
...@@ -1455,6 +1463,9 @@ static int css_populate_dir(struct cgroup_subsys_state *css, ...@@ -1455,6 +1463,9 @@ static int css_populate_dir(struct cgroup_subsys_state *css,
goto err; goto err;
} }
} }
css->flags |= CSS_VISIBLE;
return 0; return 0;
err: err:
list_for_each_entry(cfts, &css->ss->cfts, node) { list_for_each_entry(cfts, &css->ss->cfts, node) {
...@@ -3403,7 +3414,7 @@ static int cgroup_apply_cftypes(struct cftype *cfts, bool is_add) ...@@ -3403,7 +3414,7 @@ static int cgroup_apply_cftypes(struct cftype *cfts, bool is_add)
css_for_each_descendant_pre(css, cgroup_css(root, ss)) { css_for_each_descendant_pre(css, cgroup_css(root, ss)) {
struct cgroup *cgrp = css->cgroup; struct cgroup *cgrp = css->cgroup;
if (cgroup_is_dead(cgrp)) if (!(css->flags & CSS_VISIBLE))
continue; continue;
ret = cgroup_addrm_files(css, cgrp, cfts, is_add); ret = cgroup_addrm_files(css, cgrp, cfts, is_add);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment