All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH -v2] freezer_cg: disable writing freezer.state of root cgroup
@ 2008-11-06  1:18 Li Zefan
       [not found] ` <491245F1.5070707-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
  2008-11-06  1:24 ` Paul Menage
  0 siblings, 2 replies; 12+ messages in thread
From: Li Zefan @ 2008-11-06  1:18 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Matt Helsley, Cedric Le Goater, Serge E. Hallyn, Paul Menage,
	LKML, Linux Containers

With this change, control file 'freezer.state' doesn't exist in root
cgroup, making root cgroup unfreezable.

I think it's reasonable to disallow freeze tasks in the root cgroup.
And then we can avoid fork overhead when freezer subsystem is
compiled but not used.

Also make writing invalid value to freezer.state returns EINVAL
rather than EIO. This is more consistent with other cgroup subsystem.

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
---

patch is based on freezer_cg-remove-task_lock-from-freezer_fork.patch

---
 Documentation/cgroups/freezer-subsystem.txt |    3 +++
 kernel/cgroup_freezer.c                     |   11 ++++++++++-
 2 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/Documentation/cgroups/freezer-subsystem.txt b/Documentation/cgroups/freezer-subsystem.txt
index c50ab58..91572b9 100644
--- a/Documentation/cgroups/freezer-subsystem.txt
+++ b/Documentation/cgroups/freezer-subsystem.txt
@@ -54,6 +54,9 @@ freezer.state. Writing "FROZEN" to the state file will freeze all tasks in the
 cgroup. Subsequently writing "THAWED" will unfreeze the tasks in the cgroup.
 Reading will return the current state.
 
+Note freezer.state doesn't exist in root cgroup, which means root cgroup
+is unfreezable.
+
 * Examples of usage :
 
    # mkdir /containers/freezer
diff --git a/kernel/cgroup_freezer.c b/kernel/cgroup_freezer.c
index 6605907..cf3fce9 100644
--- a/kernel/cgroup_freezer.c
+++ b/kernel/cgroup_freezer.c
@@ -192,6 +192,13 @@ static void freezer_fork(struct cgroup_subsys *ss, struct task_struct *task)
 	 */
 	freezer = task_freezer(task);
 
+	/*
+	 * The root cgroup is unfreezable, so we can skip the
+	 * following check.
+	 */
+	if (!freezer->css.cgroup->parent)
+		return;
+
 	spin_lock_irq(&freezer->lock);
 	BUG_ON(freezer->state == CGROUP_FROZEN);
 
@@ -335,7 +342,7 @@ static int freezer_write(struct cgroup *cgroup,
 	else if (strcmp(buffer, freezer_state_strs[CGROUP_FROZEN]) == 0)
 		goal_state = CGROUP_FROZEN;
 	else
-		return -EIO;
+		return -EINVAL;
 
 	if (!cgroup_lock_live_group(cgroup))
 		return -ENODEV;
@@ -354,6 +361,8 @@ static struct cftype files[] = {
 
 static int freezer_populate(struct cgroup_subsys *ss, struct cgroup *cgroup)
 {
+	if (!cgroup->parent)
+		return 0;
 	return cgroup_add_files(cgroup, ss, files, ARRAY_SIZE(files));
 }
 
-- 
1.5.4.rc3


^ permalink raw reply related	[flat|nested] 12+ messages in thread
* [PATCH -v2] freezer_cg: disable writing freezer.state of root cgroup
@ 2008-11-06  1:18 Li Zefan
  0 siblings, 0 replies; 12+ messages in thread
From: Li Zefan @ 2008-11-06  1:18 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Linux Containers, LKML, Cedric Le Goater, Paul Menage

With this change, control file 'freezer.state' doesn't exist in root
cgroup, making root cgroup unfreezable.

I think it's reasonable to disallow freeze tasks in the root cgroup.
And then we can avoid fork overhead when freezer subsystem is
compiled but not used.

Also make writing invalid value to freezer.state returns EINVAL
rather than EIO. This is more consistent with other cgroup subsystem.

Signed-off-by: Li Zefan <lizf-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
---

patch is based on freezer_cg-remove-task_lock-from-freezer_fork.patch

---
 Documentation/cgroups/freezer-subsystem.txt |    3 +++
 kernel/cgroup_freezer.c                     |   11 ++++++++++-
 2 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/Documentation/cgroups/freezer-subsystem.txt b/Documentation/cgroups/freezer-subsystem.txt
index c50ab58..91572b9 100644
--- a/Documentation/cgroups/freezer-subsystem.txt
+++ b/Documentation/cgroups/freezer-subsystem.txt
@@ -54,6 +54,9 @@ freezer.state. Writing "FROZEN" to the state file will freeze all tasks in the
 cgroup. Subsequently writing "THAWED" will unfreeze the tasks in the cgroup.
 Reading will return the current state.
 
+Note freezer.state doesn't exist in root cgroup, which means root cgroup
+is unfreezable.
+
 * Examples of usage :
 
    # mkdir /containers/freezer
diff --git a/kernel/cgroup_freezer.c b/kernel/cgroup_freezer.c
index 6605907..cf3fce9 100644
--- a/kernel/cgroup_freezer.c
+++ b/kernel/cgroup_freezer.c
@@ -192,6 +192,13 @@ static void freezer_fork(struct cgroup_subsys *ss, struct task_struct *task)
 	 */
 	freezer = task_freezer(task);
 
+	/*
+	 * The root cgroup is unfreezable, so we can skip the
+	 * following check.
+	 */
+	if (!freezer->css.cgroup->parent)
+		return;
+
 	spin_lock_irq(&freezer->lock);
 	BUG_ON(freezer->state == CGROUP_FROZEN);
 
@@ -335,7 +342,7 @@ static int freezer_write(struct cgroup *cgroup,
 	else if (strcmp(buffer, freezer_state_strs[CGROUP_FROZEN]) == 0)
 		goal_state = CGROUP_FROZEN;
 	else
-		return -EIO;
+		return -EINVAL;
 
 	if (!cgroup_lock_live_group(cgroup))
 		return -ENODEV;
@@ -354,6 +361,8 @@ static struct cftype files[] = {
 
 static int freezer_populate(struct cgroup_subsys *ss, struct cgroup *cgroup)
 {
+	if (!cgroup->parent)
+		return 0;
 	return cgroup_add_files(cgroup, ss, files, ARRAY_SIZE(files));
 }
 
-- 
1.5.4.rc3

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2008-11-07  7:01 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-06  1:18 [PATCH -v2] freezer_cg: disable writing freezer.state of root cgroup Li Zefan
     [not found] ` <491245F1.5070707-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2008-11-06  1:24   ` Paul Menage
2008-11-06  1:24 ` Paul Menage
     [not found]   ` <6599ad830811051724p1f97026fl96be5efe38b33152-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-11-06  1:53     ` Li Zefan
2008-11-06  1:53   ` Li Zefan
2008-11-06  2:01     ` [PATCH -last version] " Li Zefan
2008-11-06  8:13       ` Cedric Le Goater
2008-11-07  6:58         ` Li Zefan
     [not found]         ` <4912A73C.4080308-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
2008-11-07  6:58           ` Li Zefan
     [not found]       ` <49125006.4050206-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2008-11-06  8:13         ` Cedric Le Goater
     [not found]     ` <49124DFF.1090702-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2008-11-06  2:01       ` Li Zefan
  -- strict thread matches above, loose matches on Subject: below --
2008-11-06  1:18 [PATCH -v2] " Li Zefan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.