]> git.karo-electronics.de Git - linux-beck.git/commitdiff
cgroup: introduce cgroup_init/exit_cftypes()
authorTejun Heo <tj@kernel.org>
Tue, 11 Feb 2014 16:52:48 +0000 (11:52 -0500)
committerTejun Heo <tj@kernel.org>
Tue, 11 Feb 2014 16:52:48 +0000 (11:52 -0500)
Factor out cft->ss initialization into cgroup_init_cftypes() from
cgroup_add_cftypes() and add cft->ss clearing to cgroup_rm_cftypes()
through cgroup_exit_cftypes().

This doesn't make any meaningful difference now but the two new
functions will be expanded during kernfs transition.

Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Li Zefan <lizefan@huawei.com>
kernel/cgroup.c

index fde3633ef38993f45652ecc1eaee8d17a7992882..42e588ef62d1ffb8d497952396cc8644065b8ca3 100644 (file)
@@ -2770,6 +2770,22 @@ static int cgroup_cfts_commit(struct cftype *cfts, bool is_add)
        return ret;
 }
 
+static void cgroup_exit_cftypes(struct cftype *cfts)
+{
+       struct cftype *cft;
+
+       for (cft = cfts; cft->name[0] != '\0'; cft++)
+               cft->ss = NULL;
+}
+
+static void cgroup_init_cftypes(struct cgroup_subsys *ss, struct cftype *cfts)
+{
+       struct cftype *cft;
+
+       for (cft = cfts; cft->name[0] != '\0'; cft++)
+               cft->ss = ss;
+}
+
 /**
  * cgroup_add_cftypes - add an array of cftypes to a subsystem
  * @ss: target cgroup subsystem
@@ -2787,15 +2803,13 @@ static int cgroup_cfts_commit(struct cftype *cfts, bool is_add)
 int cgroup_add_cftypes(struct cgroup_subsys *ss, struct cftype *cfts)
 {
        struct cftype_set *set;
-       struct cftype *cft;
        int ret;
 
        set = kzalloc(sizeof(*set), GFP_KERNEL);
        if (!set)
                return -ENOMEM;
 
-       for (cft = cfts; cft->name[0] != '\0'; cft++)
-               cft->ss = ss;
+       cgroup_init_cftypes(ss, cfts);
 
        cgroup_cfts_prepare();
        set->cfts = cfts;
@@ -2820,6 +2834,7 @@ EXPORT_SYMBOL_GPL(cgroup_add_cftypes);
  */
 int cgroup_rm_cftypes(struct cftype *cfts)
 {
+       struct cftype *found = NULL;
        struct cftype_set *set;
 
        if (!cfts || !cfts[0].ss)
@@ -2831,13 +2846,14 @@ int cgroup_rm_cftypes(struct cftype *cfts)
                if (set->cfts == cfts) {
                        list_del(&set->node);
                        kfree(set);
-                       cgroup_cfts_commit(cfts, false);
-                       return 0;
+                       found = cfts;
+                       break;
                }
        }
 
-       cgroup_cfts_commit(NULL, false);
-       return -ENOENT;
+       cgroup_cfts_commit(found, false);
+       cgroup_exit_cftypes(cfts);
+       return found ? 0 : -ENOENT;
 }
 
 /**
@@ -4596,6 +4612,8 @@ int __init cgroup_init(void)
        if (err)
                return err;
 
+       cgroup_init_cftypes(NULL, cgroup_base_files);
+
        for_each_subsys(ss, i) {
                if (!ss->early_init)
                        cgroup_init_subsys(ss);