[PATCH 3/6] cgroup: make interface files visible iff enabled on cgroup->subtree_control

2014-06-27 Thread Tejun Heo
cgroup is implementing support for subsystem dependency which would
require a way to enable a subsystem even when it's not directly
configured through "cgroup.subtree_control".

The preceding patch distinguished cgroup->subtree_control and
->child_subsys_mask where the former is the subsystems explicitly
configured by the userland and the latter is all enabled subsystems
currently is equal to the former but will include subsystems
implicitly enabled through dependency.

Subsystems which are enabled due to dependency shouldn't be visible to
userland.  This patch updates cgroup_subtree_control_write() and
create_css() such that interface files are not created for implicitly
enabled subsytems.

* @visible paramter is added to create_css().  Interface files are
  created only when true.

* If an already implicitly enabled subsystem is turned on through
  "cgroup.subtree_control", the existing css should be used.  css
  draining is skipped.

* cgroup_subtree_control_write() computes the new target
  cgroup->child_subsys_mask and create/kill or show/hide csses
  accordingly.

As the two subsystem masks are still kept identical, this patch
doesn't introduce any behavior changes.

Signed-off-by: Tejun Heo 
---
 include/linux/cgroup.h |  2 ++
 kernel/cgroup.c| 78 +-
 2 files changed, 66 insertions(+), 14 deletions(-)

diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index 8d52c8e..5287f93 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -208,6 +208,8 @@ struct cgroup {
 * ->subtree_control is the one configured through
 * "cgroup.subtree_control" while ->child_subsys_mask is the
 * effective one which may have more subsystems enabled.
+* Controller knobs are made available iff it's enabled in
+* ->subtree_control.
 */
unsigned int subtree_control;
unsigned int child_subsys_mask;
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 14a9d88..331fa296 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -186,7 +186,8 @@ static void cgroup_put(struct cgroup *cgrp);
 static int rebind_subsystems(struct cgroup_root *dst_root,
 unsigned int ss_mask);
 static int cgroup_destroy_locked(struct cgroup *cgrp);
-static int create_css(struct cgroup *cgrp, struct cgroup_subsys *ss);
+static int create_css(struct cgroup *cgrp, struct cgroup_subsys *ss,
+ bool visible);
 static void css_release(struct percpu_ref *ref);
 static void kill_css(struct cgroup_subsys_state *css);
 static int cgroup_addrm_files(struct cgroup *cgrp, struct cftype cfts[],
@@ -2577,6 +2578,7 @@ static ssize_t cgroup_subtree_control_write(struct 
kernfs_open_file *of,
loff_t off)
 {
unsigned int enable = 0, disable = 0;
+   unsigned int css_enable, css_disable, old_ctrl, new_ctrl;
struct cgroup *cgrp, *child;
struct cgroup_subsys *ss;
char *tok;
@@ -2630,6 +2632,13 @@ static ssize_t cgroup_subtree_control_write(struct 
kernfs_open_file *of,
}
 
/*
+* @ss is already enabled through dependency and
+* we'll just make it visible.  Skip draining.
+*/
+   if (cgrp->child_subsys_mask & (1 << ssid))
+   continue;
+
+   /*
 * Because css offlining is asynchronous, userland
 * might try to re-enable the same controller while
 * the previous instance is still around.  In such
@@ -2681,17 +2690,39 @@ static ssize_t cgroup_subtree_control_write(struct 
kernfs_open_file *of,
goto out_unlock;
}
 
+   /*
+* Update subsys masks and calculate what needs to be done.  More
+* subsystems than specified may need to be enabled or disabled
+* depending on subsystem dependencies.
+*/
cgrp->subtree_control |= enable;
cgrp->subtree_control &= ~disable;
+
+   old_ctrl = cgrp->child_subsys_mask;
cgroup_refresh_child_subsys_mask(cgrp);
+   new_ctrl = cgrp->child_subsys_mask;
+
+   css_enable = ~old_ctrl & new_ctrl;
+   css_disable = old_ctrl & ~new_ctrl;
+   enable |= css_enable;
+   disable |= css_disable;
 
-   /* create new csses */
+   /*
+* Create new csses or make the existing ones visible.  A css is
+* created invisible if it's being implicitly enabled through
+* dependency.  An invisible css is made visible when the userland
+* explicitly enables it.
+*/
for_each_subsys(ss, ssid) {
if (!(enable & (1 << ssid)))
continue;
 
cgroup_for_each_live_child(child, cgrp) {
-   ret = create_css(child, ss);
+   

[PATCH 3/6] cgroup: make interface files visible iff enabled on cgroup-subtree_control

2014-06-27 Thread Tejun Heo
cgroup is implementing support for subsystem dependency which would
require a way to enable a subsystem even when it's not directly
configured through cgroup.subtree_control.

The preceding patch distinguished cgroup-subtree_control and
-child_subsys_mask where the former is the subsystems explicitly
configured by the userland and the latter is all enabled subsystems
currently is equal to the former but will include subsystems
implicitly enabled through dependency.

Subsystems which are enabled due to dependency shouldn't be visible to
userland.  This patch updates cgroup_subtree_control_write() and
create_css() such that interface files are not created for implicitly
enabled subsytems.

* @visible paramter is added to create_css().  Interface files are
  created only when true.

* If an already implicitly enabled subsystem is turned on through
  cgroup.subtree_control, the existing css should be used.  css
  draining is skipped.

* cgroup_subtree_control_write() computes the new target
  cgroup-child_subsys_mask and create/kill or show/hide csses
  accordingly.

As the two subsystem masks are still kept identical, this patch
doesn't introduce any behavior changes.

Signed-off-by: Tejun Heo t...@kernel.org
---
 include/linux/cgroup.h |  2 ++
 kernel/cgroup.c| 78 +-
 2 files changed, 66 insertions(+), 14 deletions(-)

diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index 8d52c8e..5287f93 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -208,6 +208,8 @@ struct cgroup {
 * -subtree_control is the one configured through
 * cgroup.subtree_control while -child_subsys_mask is the
 * effective one which may have more subsystems enabled.
+* Controller knobs are made available iff it's enabled in
+* -subtree_control.
 */
unsigned int subtree_control;
unsigned int child_subsys_mask;
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 14a9d88..331fa296 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -186,7 +186,8 @@ static void cgroup_put(struct cgroup *cgrp);
 static int rebind_subsystems(struct cgroup_root *dst_root,
 unsigned int ss_mask);
 static int cgroup_destroy_locked(struct cgroup *cgrp);
-static int create_css(struct cgroup *cgrp, struct cgroup_subsys *ss);
+static int create_css(struct cgroup *cgrp, struct cgroup_subsys *ss,
+ bool visible);
 static void css_release(struct percpu_ref *ref);
 static void kill_css(struct cgroup_subsys_state *css);
 static int cgroup_addrm_files(struct cgroup *cgrp, struct cftype cfts[],
@@ -2577,6 +2578,7 @@ static ssize_t cgroup_subtree_control_write(struct 
kernfs_open_file *of,
loff_t off)
 {
unsigned int enable = 0, disable = 0;
+   unsigned int css_enable, css_disable, old_ctrl, new_ctrl;
struct cgroup *cgrp, *child;
struct cgroup_subsys *ss;
char *tok;
@@ -2630,6 +2632,13 @@ static ssize_t cgroup_subtree_control_write(struct 
kernfs_open_file *of,
}
 
/*
+* @ss is already enabled through dependency and
+* we'll just make it visible.  Skip draining.
+*/
+   if (cgrp-child_subsys_mask  (1  ssid))
+   continue;
+
+   /*
 * Because css offlining is asynchronous, userland
 * might try to re-enable the same controller while
 * the previous instance is still around.  In such
@@ -2681,17 +2690,39 @@ static ssize_t cgroup_subtree_control_write(struct 
kernfs_open_file *of,
goto out_unlock;
}
 
+   /*
+* Update subsys masks and calculate what needs to be done.  More
+* subsystems than specified may need to be enabled or disabled
+* depending on subsystem dependencies.
+*/
cgrp-subtree_control |= enable;
cgrp-subtree_control = ~disable;
+
+   old_ctrl = cgrp-child_subsys_mask;
cgroup_refresh_child_subsys_mask(cgrp);
+   new_ctrl = cgrp-child_subsys_mask;
+
+   css_enable = ~old_ctrl  new_ctrl;
+   css_disable = old_ctrl  ~new_ctrl;
+   enable |= css_enable;
+   disable |= css_disable;
 
-   /* create new csses */
+   /*
+* Create new csses or make the existing ones visible.  A css is
+* created invisible if it's being implicitly enabled through
+* dependency.  An invisible css is made visible when the userland
+* explicitly enables it.
+*/
for_each_subsys(ss, ssid) {
if (!(enable  (1  ssid)))
continue;
 
cgroup_for_each_live_child(child, cgrp) {
-   ret = create_css(child, ss);
+   if