cgroup: make cgroup_taskset deal with cgroup_subsys_state instead of cgroup
authorTejun Heo <tj@kernel.org>
Fri, 9 Aug 2013 00:11:27 +0000 (20:11 -0400)
committerTejun Heo <tj@kernel.org>
Fri, 9 Aug 2013 00:11:27 +0000 (20:11 -0400)
cgroup is in the process of converting to css (cgroup_subsys_state)
from cgroup as the principal subsystem interface handle.  This is
mostly to prepare for the unified hierarchy support where css's will
be created and destroyed dynamically but also helps cleaning up
subsystem implementations as css is usually what they are interested
in anyway.

cgroup_taskset which is used by the subsystem attach methods is the
last cgroup subsystem API which isn't using css as the handle.  Update
cgroup_taskset_cur_cgroup() to cgroup_taskset_cur_css() and
cgroup_taskset_for_each() to take @skip_css instead of @skip_cgrp.

The conversions are pretty mechanical.  One exception is
cpuset::cgroup_cs(), which lost its last user and got removed.

This patch shouldn't introduce any functional changes.

Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Li Zefan <lizefan@huawei.com>
Acked-by: Daniel Wagner <daniel.wagner@bmw-carit.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Matt Helsley <matthltc@us.ibm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
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
net/core/netprio_cgroup.c
net/sched/cls_cgroup.c

index 4b40640240a4a49b0ce7622930254e15c40fb77a..54ad00292edf1b0385b94bfde5e71cb84253ff22 100644 (file)
@@ -891,7 +891,7 @@ static int blkcg_can_attach(struct cgroup_subsys_state *css,
        int ret = 0;
 
        /* task_lock() is needed to avoid races with exit_io_context() */
-       cgroup_taskset_for_each(task, css->cgroup, tset) {
+       cgroup_taskset_for_each(task, css, tset) {
                task_lock(task);
                ioc = task->io_context;
                if (ioc && atomic_read(&ioc->nr_tasks) > 1)
index b065d24486e665561da55f95108f720bbc767850..d9a970568be966fbee33007f091d060c3a18bbdc 100644 (file)
@@ -562,20 +562,22 @@ int cgroup_task_count(const struct cgroup *cgrp);
 struct cgroup_taskset;
 struct task_struct *cgroup_taskset_first(struct cgroup_taskset *tset);
 struct task_struct *cgroup_taskset_next(struct cgroup_taskset *tset);
-struct cgroup *cgroup_taskset_cur_cgroup(struct cgroup_taskset *tset);
+struct cgroup_subsys_state *cgroup_taskset_cur_css(struct cgroup_taskset *tset,
+                                                  int subsys_id);
 int cgroup_taskset_size(struct cgroup_taskset *tset);
 
 /**
  * cgroup_taskset_for_each - iterate cgroup_taskset
  * @task: the loop cursor
- * @skip_cgrp: skip if task's cgroup matches this, %NULL to iterate through all
+ * @skip_css: skip if task's css matches this, %NULL to iterate through all
  * @tset: taskset to iterate
  */
-#define cgroup_taskset_for_each(task, skip_cgrp, tset)                 \
+#define cgroup_taskset_for_each(task, skip_css, tset)                  \
        for ((task) = cgroup_taskset_first((tset)); (task);             \
             (task) = cgroup_taskset_next((tset)))                      \
-               if (!(skip_cgrp) ||                                     \
-                   cgroup_taskset_cur_cgroup((tset)) != (skip_cgrp))
+               if (!(skip_css) ||                                      \
+                   cgroup_taskset_cur_css((tset),                      \
+                       (skip_css)->ss->subsys_id) != (skip_css))
 
 /*
  * Control Group subsystem type.
index a71f2e0f9711d7a0378b6f6bd2b1aab457c6c91a..e5bfb2a81dcb57b41ff1c4c2a3845fafe22c78d2 100644 (file)
@@ -1907,18 +1907,20 @@ struct task_struct *cgroup_taskset_next(struct cgroup_taskset *tset)
 EXPORT_SYMBOL_GPL(cgroup_taskset_next);
 
 /**
- * cgroup_taskset_cur_cgroup - return the matching cgroup for the current task
+ * cgroup_taskset_cur_css - return the matching css for the current task
  * @tset: taskset of interest
+ * @subsys_id: the ID of the target subsystem
  *
- * Return the cgroup for the current (last returned) task of @tset.  This
- * function must be preceded by either cgroup_taskset_first() or
- * cgroup_taskset_next().
+ * Return the css for the current (last returned) task of @tset for
+ * subsystem specified by @subsys_id.  This function must be preceded by
+ * either cgroup_taskset_first() or cgroup_taskset_next().
  */
-struct cgroup *cgroup_taskset_cur_cgroup(struct cgroup_taskset *tset)
+struct cgroup_subsys_state *cgroup_taskset_cur_css(struct cgroup_taskset *tset,
+                                                  int subsys_id)
 {
-       return tset->cur_cgrp;
+       return cgroup_css(tset->cur_cgrp, subsys_id);
 }
-EXPORT_SYMBOL_GPL(cgroup_taskset_cur_cgroup);
+EXPORT_SYMBOL_GPL(cgroup_taskset_cur_css);
 
 /**
  * cgroup_taskset_size - return the number of tasks in taskset
index 5cd2b6d55243633580772d8c613556f5bbc1b28f..224da9aa27f57a16beebd0e8cf5e85046ce97e78 100644 (file)
@@ -189,7 +189,7 @@ static void freezer_attach(struct cgroup_subsys_state *new_css,
         * current state before executing the following - !frozen tasks may
         * be visible in a FROZEN cgroup and frozen tasks in a THAWED one.
         */
-       cgroup_taskset_for_each(task, new_css->cgroup, tset) {
+       cgroup_taskset_for_each(task, new_css, tset) {
                if (!(freezer->state & CGROUP_FREEZING)) {
                        __thaw_task(task);
                } else {
index 39e52175f4af1bbdff30c51770c8ff7c35108560..bf69717325b45875be2bdd76e0129d7e918d5150 100644 (file)
@@ -119,12 +119,6 @@ static inline struct cpuset *css_cs(struct cgroup_subsys_state *css)
        return css ? container_of(css, struct cpuset, css) : NULL;
 }
 
-/* Retrieve the cpuset for a cgroup */
-static inline struct cpuset *cgroup_cs(struct cgroup *cgrp)
-{
-       return css_cs(cgroup_css(cgrp, cpuset_subsys_id));
-}
-
 /* Retrieve the cpuset for a task */
 static inline struct cpuset *task_cs(struct task_struct *task)
 {
@@ -1459,7 +1453,7 @@ static int cpuset_can_attach(struct cgroup_subsys_state *css,
            (cpumask_empty(cs->cpus_allowed) || nodes_empty(cs->mems_allowed)))
                goto out_unlock;
 
-       cgroup_taskset_for_each(task, css->cgroup, tset) {
+       cgroup_taskset_for_each(task, css, tset) {
                /*
                 * Kthreads which disallow setaffinity shouldn't be moved
                 * to a new cpuset; we don't want to change their cpu
@@ -1511,9 +1505,10 @@ static void cpuset_attach(struct cgroup_subsys_state *css,
        struct mm_struct *mm;
        struct task_struct *task;
        struct task_struct *leader = cgroup_taskset_first(tset);
-       struct cgroup *oldcgrp = cgroup_taskset_cur_cgroup(tset);
+       struct cgroup_subsys_state *oldcss = cgroup_taskset_cur_css(tset,
+                                                       cpuset_subsys_id);
        struct cpuset *cs = css_cs(css);
-       struct cpuset *oldcs = cgroup_cs(oldcgrp);
+       struct cpuset *oldcs = css_cs(oldcss);
        struct cpuset *cpus_cs = effective_cpumask_cpuset(cs);
        struct cpuset *mems_cs = effective_nodemask_cpuset(cs);
 
@@ -1527,7 +1522,7 @@ static void cpuset_attach(struct cgroup_subsys_state *css,
 
        guarantee_online_mems(mems_cs, &cpuset_attach_nodemask_to);
 
-       cgroup_taskset_for_each(task, css->cgroup, tset) {
+       cgroup_taskset_for_each(task, css, tset) {
                /*
                 * can_attach beforehand should guarantee that this doesn't
                 * fail.  TODO: have a better way to handle failure here
index 9705a0ed1dce03396e6407ee5b4c0378572ac093..c199c4f249109bc5130aeb0b451d2a8b22f35e48 100644 (file)
@@ -7816,7 +7816,7 @@ static void perf_cgroup_attach(struct cgroup_subsys_state *css,
 {
        struct task_struct *task;
 
-       cgroup_taskset_for_each(task, css->cgroup, tset)
+       cgroup_taskset_for_each(task, css, tset)
                task_function_call(task, __perf_cgroup_move, task);
 }
 
index cc9a49266382ad2d260092027c57dec421450edc..a7122d5b8310c900de171b13ff09d879d20992ff 100644 (file)
@@ -7135,7 +7135,7 @@ static int cpu_cgroup_can_attach(struct cgroup_subsys_state *css,
 {
        struct task_struct *task;
 
-       cgroup_taskset_for_each(task, css->cgroup, tset) {
+       cgroup_taskset_for_each(task, css, tset) {
 #ifdef CONFIG_RT_GROUP_SCHED
                if (!sched_rt_can_attach(css_tg(css), task))
                        return -EINVAL;
@@ -7153,7 +7153,7 @@ static void cpu_cgroup_attach(struct cgroup_subsys_state *css,
 {
        struct task_struct *task;
 
-       cgroup_taskset_for_each(task, css->cgroup, tset)
+       cgroup_taskset_for_each(task, css, tset)
                sched_move_task(task);
 }
 
index e00f60e5baeac90334651f28dfda0ae765385d3b..d9cd627e6a16a55bb9b6e8ec1619a0291e1621ab 100644 (file)
@@ -224,7 +224,7 @@ static void net_prio_attach(struct cgroup_subsys_state *css,
        struct task_struct *p;
        void *v;
 
-       cgroup_taskset_for_each(p, css->cgroup, tset) {
+       cgroup_taskset_for_each(p, css, tset) {
                task_lock(p);
                v = (void *)(unsigned long)task_netprioidx(p);
                iterate_fd(p->files, 0, update_netprio, v);
index 8ea1184cec9299027b013b7418b932a6479b6dc2..867b4a3e39800fb44819e3cfd68ad0fb30d6ea05 100644 (file)
@@ -74,7 +74,7 @@ static void cgrp_attach(struct cgroup_subsys_state *css,
        struct task_struct *p;
        void *v;
 
-       cgroup_taskset_for_each(p, css->cgroup, tset) {
+       cgroup_taskset_for_each(p, css, tset) {
                task_lock(p);
                v = (void *)(unsigned long)task_cls_classid(p);
                iterate_fd(p->files, 0, update_classid, v);