]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
cgroups: add previous cgroup in can_attach_task/attach_task callbacks
authorFrederic Weisbecker <fweisbec@gmail.com>
Wed, 16 Nov 2011 23:41:37 +0000 (10:41 +1100)
committerStephen Rothwell <sfr@canb.auug.org.au>
Thu, 17 Nov 2011 02:57:16 +0000 (13:57 +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 8f630cec906e83f35b85df1a7437997dab9aae3d..fda00810a6d46987408931829b194795bb6533f0 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 *);
 
@@ -1626,7 +1628,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;
@@ -1641,7 +1644,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 1b7f9d5250131fe43acf75045142b544f6f1a396..0731c6bf96c7ee4eb869411e2d9a4f1573f5b371 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 d9d5648f3cdcc4bcde3a7a67afe845aa89dc2a1f..ba8f3ebeb0469a087096401a9f9b1d06afd69da2 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 9fe58c46a426de719da9636d8c74d8c9f6bb312d..00b3430db2940da55ce62831f8ca72c3e67c3ea4 100644 (file)
@@ -1393,7 +1393,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);
 }
@@ -1421,7 +1422,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 2e41c8ec5a76bd3239da37df689bb7a746d07f9f..cad4eab7d0cbdd0cc06d24b04996fb96b5b40939 100644 (file)
@@ -6844,7 +6844,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);
 }
@@ -6860,7 +6861,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 c0dcaa0d2f5ab9568d31a04800d9a871d398584d..b5efd6c88f5c843163398d3d0c953da3ac7095ef 100644 (file)
@@ -9165,7 +9165,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))
@@ -9179,7 +9180,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);
 }