]> 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>
Thu, 8 Dec 2011 04:42:35 +0000 (15:42 +1100)
committerStephen Rothwell <sfr@canb.auug.org.au>
Tue, 13 Dec 2011 06:43:26 +0000 (17:43 +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/core.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 fcb93fca782d482ec57b0163db6b04420d70b639..43e76144b01c860aa4416ba24a6204188f00419d 100644 (file)
@@ -181,7 +181,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)
 {
        return cgroup_freezing(tsk) ? -EBUSY : 0;
 }
index 793eca605d5c65df5fbd50709b8af81ad6f307c0..163b16ed81e373102c845995822a48cc8bd178f2 100644 (file)
@@ -1404,7 +1404,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);
 }
@@ -1432,7 +1433,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 2f8f3f103cb444e333b31c600bf09425a1af3e60..4eafb1b9f9f8e62245a418690cea8dbf040a6f60 100644 (file)
@@ -6938,7 +6938,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);
 }
@@ -6954,7 +6955,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 e1aa1f994bdff2faf073925549f11730f04261e0..cdd11484d94f60d499dec747da964efd751914b8 100644 (file)
@@ -7531,7 +7531,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)
 {
        /*
         * kthreadd can fork workers for an RT workqueue in a cgroup
@@ -7554,7 +7555,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);
 }