]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
cgroups: add previous cgroup in can_attach_task/attach_task callbacks
authorFrederic Weisbecker <fweisbec@gmail.com>
Mon, 24 Oct 2011 14:59:56 +0000 (01:59 +1100)
committerStephen Rothwell <sfr@canb.auug.org.au>
Tue, 25 Oct 2011 09:08:13 +0000 (20:08 +1100)
This is to prepare the integration of a new max number of proc cgroup
subsystem.  We'll need to release some resources from the previous cgroup.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Acked-by: Paul Menage <paul@paulmenage.org>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Aditya Kali <adityakali@google.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Kay Sievers <kay.sievers@vrfy.org>
Cc: Tim Hockin <thockin@hockin.org>
Cc: Tejun Heo <htejun@gmail.com>
Acked-by: Kirill A. Shutemov <kirill@shutemov.name>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Documentation/cgroups/cgroups.txt
block/blk-cgroup.c
include/linux/cgroup.h
kernel/cgroup.c
kernel/cgroup_freezer.c
kernel/cpuset.c
kernel/events/core.c
kernel/sched.c

index 9c452ef2328c73b606b40e01820624a3aa4c13a6..f5a0e9111d49c25505095d2f287f7bb57924bbca 100644 (file)
@@ -605,7 +605,8 @@ called on a fork. If this method returns 0 (success) then this should
 remain valid while the caller holds cgroup_mutex and it is ensured that either
 attach() or cancel_attach() will be called in future.
 
-int can_attach_task(struct cgroup *cgrp, struct task_struct *tsk);
+int can_attach_task(struct cgroup *cgrp, struct cgroup *old_cgrp,
+                   struct task_struct *tsk);
 (cgroup_mutex held by caller)
 
 As can_attach, but for operations that must be run once per task to be
@@ -635,7 +636,8 @@ void attach(struct cgroup_subsys *ss, struct cgroup *cgrp,
 Called after the task has been attached to the cgroup, to allow any
 post-attachment activity that requires memory allocations or blocking.
 
-void attach_task(struct cgroup *cgrp, struct task_struct *tsk);
+void attach_task(struct cgroup *cgrp, struct cgroup *old_cgrp,
+                struct task_struct *tsk);
 (cgroup_mutex held by caller)
 
 As attach, but for operations that must be run once per task to be attached,
index d61ec5636ce0ab2c62f269ea78b9f37a2251a166..d70f6583ed30ed623cbdba172e6e81ec571f5e66 100644 (file)
@@ -30,8 +30,10 @@ EXPORT_SYMBOL_GPL(blkio_root_cgroup);
 
 static struct cgroup_subsys_state *blkiocg_create(struct cgroup_subsys *,
                                                  struct cgroup *);
-static int blkiocg_can_attach_task(struct cgroup *, struct task_struct *);
-static void blkiocg_attach_task(struct cgroup *, struct task_struct *);
+static int blkiocg_can_attach_task(struct cgroup *, struct cgroup *,
+                                  struct task_struct *);
+static void blkiocg_attach_task(struct cgroup *, struct cgroup *,
+                               struct task_struct *);
 static void blkiocg_destroy(struct cgroup_subsys *, struct cgroup *);
 static int blkiocg_populate(struct cgroup_subsys *, struct cgroup *);
 
@@ -1599,7 +1601,8 @@ done:
  * of the main cic data structures.  For now we allow a task to change
  * its cgroup only if it's the only owner of its ioc.
  */
-static int blkiocg_can_attach_task(struct cgroup *cgrp, struct task_struct *tsk)
+static int blkiocg_can_attach_task(struct cgroup *cgrp, struct cgroup *old_cgrp,
+                                  struct task_struct *tsk)
 {
        struct io_context *ioc;
        int ret = 0;
@@ -1614,7 +1617,8 @@ static int blkiocg_can_attach_task(struct cgroup *cgrp, struct task_struct *tsk)
        return ret;
 }
 
-static void blkiocg_attach_task(struct cgroup *cgrp, struct task_struct *tsk)
+static void blkiocg_attach_task(struct cgroup *cgrp, struct cgroup *old_cgrp,
+                               struct task_struct *tsk)
 {
        struct io_context *ioc;
 
index da7e4bc34e8cfe1339af4de1c96f55e777867161..ed34eb8ca43c6f7197cdf3a77542900ee6345fda 100644 (file)
@@ -468,11 +468,13 @@ struct cgroup_subsys {
        void (*destroy)(struct cgroup_subsys *ss, struct cgroup *cgrp);
        int (*can_attach)(struct cgroup_subsys *ss, struct cgroup *cgrp,
                          struct task_struct *tsk);
-       int (*can_attach_task)(struct cgroup *cgrp, struct task_struct *tsk);
+       int (*can_attach_task)(struct cgroup *cgrp, struct cgroup *old_cgrp,
+                              struct task_struct *tsk);
        void (*cancel_attach)(struct cgroup_subsys *ss, struct cgroup *cgrp,
                              struct task_struct *tsk);
        void (*pre_attach)(struct cgroup *cgrp);
-       void (*attach_task)(struct cgroup *cgrp, struct task_struct *tsk);
+       void (*attach_task)(struct cgroup *cgrp, struct cgroup *old_cgrp,
+                           struct task_struct *tsk);
        void (*attach)(struct cgroup_subsys *ss, struct cgroup *cgrp,
                       struct cgroup *old_cgrp, struct task_struct *tsk);
        void (*fork)(struct cgroup_subsys *ss, struct task_struct *task);
index 8386b21224ef3e03ecc0ed850d949d6345888448..90b508d366741802cf28f5483dacaeff510d3271 100644 (file)
@@ -1844,7 +1844,7 @@ int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk)
                        }
                }
                if (ss->can_attach_task) {
-                       retval = ss->can_attach_task(cgrp, tsk);
+                       retval = ss->can_attach_task(cgrp, oldcgrp, tsk);
                        if (retval) {
                                failed_ss = ss;
                                goto out;
@@ -1860,7 +1860,7 @@ int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk)
                if (ss->pre_attach)
                        ss->pre_attach(cgrp);
                if (ss->attach_task)
-                       ss->attach_task(cgrp, tsk);
+                       ss->attach_task(cgrp, oldcgrp, tsk);
                if (ss->attach)
                        ss->attach(ss, cgrp, oldcgrp, tsk);
        }
@@ -2075,7 +2075,10 @@ int cgroup_attach_proc(struct cgroup *cgrp, struct task_struct *leader)
                        /* run on each task in the threadgroup. */
                        for (i = 0; i < group_size; i++) {
                                tsk = flex_array_get_ptr(group, i);
-                               retval = ss->can_attach_task(cgrp, tsk);
+                               oldcgrp = task_cgroup_from_root(tsk, root);
+
+                               retval = ss->can_attach_task(cgrp,
+                                                            oldcgrp, tsk);
                                if (retval) {
                                        failed_ss = ss;
                                        cancel_failed_ss = true;
@@ -2141,7 +2144,7 @@ int cgroup_attach_proc(struct cgroup *cgrp, struct task_struct *leader)
                        /* attach each task to each subsystem */
                        for_each_subsys(root, ss) {
                                if (ss->attach_task)
-                                       ss->attach_task(cgrp, tsk);
+                                       ss->attach_task(cgrp, oldcgrp, tsk);
                        }
                } else {
                        BUG_ON(retval != -ESRCH);
index 5e828a2ca8e64641749da837fe093cefcfc958dc..ee34627c440892e1123316f440cca1e6e3963514 100644 (file)
@@ -175,7 +175,8 @@ static int freezer_can_attach(struct cgroup_subsys *ss,
        return 0;
 }
 
-static int freezer_can_attach_task(struct cgroup *cgrp, struct task_struct *tsk)
+static int freezer_can_attach_task(struct cgroup *cgrp, struct cgroup *old_cgrp,
+                                  struct task_struct *tsk)
 {
        rcu_read_lock();
        if (__cgroup_freezing_or_frozen(tsk)) {
index d970fb508e341ee4f2f7334d6994efd8dcdd2607..9ec7cc79e6e8f97c2e313706a38b2b4cad720318 100644 (file)
@@ -1390,7 +1390,8 @@ static int cpuset_can_attach(struct cgroup_subsys *ss, struct cgroup *cont,
        return 0;
 }
 
-static int cpuset_can_attach_task(struct cgroup *cgrp, struct task_struct *task)
+static int cpuset_can_attach_task(struct cgroup *cgrp, struct cgroup *old_cgrp,
+                                 struct task_struct *task)
 {
        return security_task_setscheduler(task);
 }
@@ -1418,7 +1419,8 @@ static void cpuset_pre_attach(struct cgroup *cont)
 }
 
 /* Per-thread attachment work. */
-static void cpuset_attach_task(struct cgroup *cont, struct task_struct *tsk)
+static void cpuset_attach_task(struct cgroup *cont, struct cgroup *old,
+                              struct task_struct *tsk)
 {
        int err;
        struct cpuset *cs = cgroup_cs(cont);
index 69e5b4064b9702171659d44f37c47d516fb1358c..3e8b1c9710b07b0d3210648420050ef5b1e951e5 100644 (file)
@@ -7138,7 +7138,8 @@ static int __perf_cgroup_move(void *info)
 }
 
 static void
-perf_cgroup_attach_task(struct cgroup *cgrp, struct task_struct *task)
+perf_cgroup_attach_task(struct cgroup *cgrp, struct cgroup *old_cgrp,
+                       struct task_struct *task)
 {
        task_function_call(task, __perf_cgroup_move, task);
 }
@@ -7154,7 +7155,7 @@ static void perf_cgroup_exit(struct cgroup_subsys *ss, struct cgroup *cgrp,
        if (!(task->flags & PF_EXITING))
                return;
 
-       perf_cgroup_attach_task(cgrp, task);
+       perf_cgroup_attach_task(cgrp, old_cgrp, task);
 }
 
 struct cgroup_subsys perf_subsys = {
index 48dfd92c8378dc4e2b98c87fe02b3590af17cb61..fdaea91af046b7b7e19ec618c016f9888bfb603a 100644 (file)
@@ -9117,7 +9117,8 @@ cpu_cgroup_destroy(struct cgroup_subsys *ss, struct cgroup *cgrp)
 }
 
 static int
-cpu_cgroup_can_attach_task(struct cgroup *cgrp, struct task_struct *tsk)
+cpu_cgroup_can_attach_task(struct cgroup *cgrp, struct cgroup *old_cgrp,
+                          struct task_struct *tsk)
 {
 #ifdef CONFIG_RT_GROUP_SCHED
        if (!sched_rt_can_attach(cgroup_tg(cgrp), tsk))
@@ -9131,7 +9132,8 @@ cpu_cgroup_can_attach_task(struct cgroup *cgrp, struct task_struct *tsk)
 }
 
 static void
-cpu_cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk)
+cpu_cgroup_attach_task(struct cgroup *cgrp, struct cgroup *old_cgrp,
+                      struct task_struct *tsk)
 {
        sched_move_task(tsk);
 }