diff options
author | Tejun Heo <tj@kernel.org> | 2014-02-11 11:52:48 -0500 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2014-02-11 11:52:48 -0500 |
commit | 2da440a26ce4743bd3e71ba964ba3f983d09bba5 (patch) | |
tree | 3a8abc5740529ac5ba918fb464622f43beb6a533 /kernel/cgroup.c | |
parent | 5f46990787e2721b4db190ddc8af6fdbe8f010d7 (diff) |
cgroup: introduce cgroup_init/exit_cftypes()
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>
Diffstat (limited to 'kernel/cgroup.c')
-rw-r--r-- | kernel/cgroup.c | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index fde3633ef389..42e588ef62d1 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
@@ -2770,6 +2770,22 @@ static int cgroup_cfts_commit(struct cftype *cfts, bool is_add) | |||
2770 | return ret; | 2770 | return ret; |
2771 | } | 2771 | } |
2772 | 2772 | ||
2773 | static void cgroup_exit_cftypes(struct cftype *cfts) | ||
2774 | { | ||
2775 | struct cftype *cft; | ||
2776 | |||
2777 | for (cft = cfts; cft->name[0] != '\0'; cft++) | ||
2778 | cft->ss = NULL; | ||
2779 | } | ||
2780 | |||
2781 | static void cgroup_init_cftypes(struct cgroup_subsys *ss, struct cftype *cfts) | ||
2782 | { | ||
2783 | struct cftype *cft; | ||
2784 | |||
2785 | for (cft = cfts; cft->name[0] != '\0'; cft++) | ||
2786 | cft->ss = ss; | ||
2787 | } | ||
2788 | |||
2773 | /** | 2789 | /** |
2774 | * cgroup_add_cftypes - add an array of cftypes to a subsystem | 2790 | * cgroup_add_cftypes - add an array of cftypes to a subsystem |
2775 | * @ss: target cgroup subsystem | 2791 | * @ss: target cgroup subsystem |
@@ -2787,15 +2803,13 @@ static int cgroup_cfts_commit(struct cftype *cfts, bool is_add) | |||
2787 | int cgroup_add_cftypes(struct cgroup_subsys *ss, struct cftype *cfts) | 2803 | int cgroup_add_cftypes(struct cgroup_subsys *ss, struct cftype *cfts) |
2788 | { | 2804 | { |
2789 | struct cftype_set *set; | 2805 | struct cftype_set *set; |
2790 | struct cftype *cft; | ||
2791 | int ret; | 2806 | int ret; |
2792 | 2807 | ||
2793 | set = kzalloc(sizeof(*set), GFP_KERNEL); | 2808 | set = kzalloc(sizeof(*set), GFP_KERNEL); |
2794 | if (!set) | 2809 | if (!set) |
2795 | return -ENOMEM; | 2810 | return -ENOMEM; |
2796 | 2811 | ||
2797 | for (cft = cfts; cft->name[0] != '\0'; cft++) | 2812 | cgroup_init_cftypes(ss, cfts); |
2798 | cft->ss = ss; | ||
2799 | 2813 | ||
2800 | cgroup_cfts_prepare(); | 2814 | cgroup_cfts_prepare(); |
2801 | set->cfts = cfts; | 2815 | set->cfts = cfts; |
@@ -2820,6 +2834,7 @@ EXPORT_SYMBOL_GPL(cgroup_add_cftypes); | |||
2820 | */ | 2834 | */ |
2821 | int cgroup_rm_cftypes(struct cftype *cfts) | 2835 | int cgroup_rm_cftypes(struct cftype *cfts) |
2822 | { | 2836 | { |
2837 | struct cftype *found = NULL; | ||
2823 | struct cftype_set *set; | 2838 | struct cftype_set *set; |
2824 | 2839 | ||
2825 | if (!cfts || !cfts[0].ss) | 2840 | if (!cfts || !cfts[0].ss) |
@@ -2831,13 +2846,14 @@ int cgroup_rm_cftypes(struct cftype *cfts) | |||
2831 | if (set->cfts == cfts) { | 2846 | if (set->cfts == cfts) { |
2832 | list_del(&set->node); | 2847 | list_del(&set->node); |
2833 | kfree(set); | 2848 | kfree(set); |
2834 | cgroup_cfts_commit(cfts, false); | 2849 | found = cfts; |
2835 | return 0; | 2850 | break; |
2836 | } | 2851 | } |
2837 | } | 2852 | } |
2838 | 2853 | ||
2839 | cgroup_cfts_commit(NULL, false); | 2854 | cgroup_cfts_commit(found, false); |
2840 | return -ENOENT; | 2855 | cgroup_exit_cftypes(cfts); |
2856 | return found ? 0 : -ENOENT; | ||
2841 | } | 2857 | } |
2842 | 2858 | ||
2843 | /** | 2859 | /** |
@@ -4596,6 +4612,8 @@ int __init cgroup_init(void) | |||
4596 | if (err) | 4612 | if (err) |
4597 | return err; | 4613 | return err; |
4598 | 4614 | ||
4615 | cgroup_init_cftypes(NULL, cgroup_base_files); | ||
4616 | |||
4599 | for_each_subsys(ss, i) { | 4617 | for_each_subsys(ss, i) { |
4600 | if (!ss->early_init) | 4618 | if (!ss->early_init) |
4601 | cgroup_init_subsys(ss); | 4619 | cgroup_init_subsys(ss); |