diff options
author | Tejun Heo <tj@kernel.org> | 2014-03-19 10:23:54 -0400 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2014-03-19 10:23:54 -0400 |
commit | 3dd06ffa9df99aa88f4e01eaa0c9d3cb362430b0 (patch) | |
tree | e73905f27931fbfb1a5029b3712f74f77106e77e | |
parent | 944196278d3dea0cece1636de417b56897d9a108 (diff) |
cgroup: rename cgroup_dummy_root and related names
The dummy root will be repurposed to serve as the default unified
hierarchy. Let's rename things in preparation.
* s/cgroup_dummy_root/cgrp_dfl_root/
* s/cgroupfs_root/cgroup_root/ as we don't do fs part directly anymore
* s/cgroup_root->top_cgroup/cgroup_root->cgrp/ for brevity
This is pure rename.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Li Zefan <lizefan@huawei.com>
-rw-r--r-- | include/linux/cgroup.h | 14 | ||||
-rw-r--r-- | kernel/cgroup.c | 168 |
2 files changed, 88 insertions, 94 deletions
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index 3752a0182c94..77294fc66603 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h | |||
@@ -24,7 +24,7 @@ | |||
24 | 24 | ||
25 | #ifdef CONFIG_CGROUPS | 25 | #ifdef CONFIG_CGROUPS |
26 | 26 | ||
27 | struct cgroupfs_root; | 27 | struct cgroup_root; |
28 | struct cgroup_subsys; | 28 | struct cgroup_subsys; |
29 | struct inode; | 29 | struct inode; |
30 | struct cgroup; | 30 | struct cgroup; |
@@ -179,7 +179,7 @@ struct cgroup { | |||
179 | /* Private pointers for each registered subsystem */ | 179 | /* Private pointers for each registered subsystem */ |
180 | struct cgroup_subsys_state __rcu *subsys[CGROUP_SUBSYS_COUNT]; | 180 | struct cgroup_subsys_state __rcu *subsys[CGROUP_SUBSYS_COUNT]; |
181 | 181 | ||
182 | struct cgroupfs_root *root; | 182 | struct cgroup_root *root; |
183 | 183 | ||
184 | /* | 184 | /* |
185 | * List of cgrp_cset_links pointing at css_sets with tasks in this | 185 | * List of cgrp_cset_links pointing at css_sets with tasks in this |
@@ -211,7 +211,7 @@ struct cgroup { | |||
211 | 211 | ||
212 | #define MAX_CGROUP_ROOT_NAMELEN 64 | 212 | #define MAX_CGROUP_ROOT_NAMELEN 64 |
213 | 213 | ||
214 | /* cgroupfs_root->flags */ | 214 | /* cgroup_root->flags */ |
215 | enum { | 215 | enum { |
216 | /* | 216 | /* |
217 | * Unfortunately, cgroup core and various controllers are riddled | 217 | * Unfortunately, cgroup core and various controllers are riddled |
@@ -272,18 +272,18 @@ enum { | |||
272 | }; | 272 | }; |
273 | 273 | ||
274 | /* | 274 | /* |
275 | * A cgroupfs_root represents the root of a cgroup hierarchy, and may be | 275 | * A cgroup_root represents the root of a cgroup hierarchy, and may be |
276 | * associated with a kernfs_root to form an active hierarchy. This is | 276 | * associated with a kernfs_root to form an active hierarchy. This is |
277 | * internal to cgroup core. Don't access directly from controllers. | 277 | * internal to cgroup core. Don't access directly from controllers. |
278 | */ | 278 | */ |
279 | struct cgroupfs_root { | 279 | struct cgroup_root { |
280 | struct kernfs_root *kf_root; | 280 | struct kernfs_root *kf_root; |
281 | 281 | ||
282 | /* Unique id for this hierarchy. */ | 282 | /* Unique id for this hierarchy. */ |
283 | int hierarchy_id; | 283 | int hierarchy_id; |
284 | 284 | ||
285 | /* The root cgroup. Root is destroyed on its release. */ | 285 | /* The root cgroup. Root is destroyed on its release. */ |
286 | struct cgroup top_cgroup; | 286 | struct cgroup cgrp; |
287 | 287 | ||
288 | /* Number of cgroups in the hierarchy, used only for /proc/cgroups */ | 288 | /* Number of cgroups in the hierarchy, used only for /proc/cgroups */ |
289 | atomic_t nr_cgrps; | 289 | atomic_t nr_cgrps; |
@@ -598,7 +598,7 @@ struct cgroup_subsys { | |||
598 | const char *name; | 598 | const char *name; |
599 | 599 | ||
600 | /* link to parent, protected by cgroup_lock() */ | 600 | /* link to parent, protected by cgroup_lock() */ |
601 | struct cgroupfs_root *root; | 601 | struct cgroup_root *root; |
602 | 602 | ||
603 | /* | 603 | /* |
604 | * List of cftypes. Each entry is the first entry of an array | 604 | * List of cftypes. Each entry is the first entry of an array |
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 807f88dbda51..60ea16058c42 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
@@ -138,14 +138,11 @@ static const char *cgroup_subsys_name[] = { | |||
138 | #undef SUBSYS | 138 | #undef SUBSYS |
139 | 139 | ||
140 | /* | 140 | /* |
141 | * The dummy hierarchy, reserved for the subsystems that are otherwise | 141 | * The default hierarchy, reserved for the subsystems that are otherwise |
142 | * unattached - it never has more than a single cgroup, and all tasks are | 142 | * unattached - it never has more than a single cgroup, and all tasks are |
143 | * part of that cgroup. | 143 | * part of that cgroup. |
144 | */ | 144 | */ |
145 | static struct cgroupfs_root cgroup_dummy_root; | 145 | static struct cgroup_root cgrp_dfl_root; |
146 | |||
147 | /* dummy_top is a shorthand for the dummy hierarchy's top cgroup */ | ||
148 | static struct cgroup * const cgroup_dummy_top = &cgroup_dummy_root.top_cgroup; | ||
149 | 146 | ||
150 | /* The list of hierarchy roots */ | 147 | /* The list of hierarchy roots */ |
151 | 148 | ||
@@ -175,7 +172,7 @@ static int need_forkexit_callback __read_mostly; | |||
175 | static struct cftype cgroup_base_files[]; | 172 | static struct cftype cgroup_base_files[]; |
176 | 173 | ||
177 | static void cgroup_put(struct cgroup *cgrp); | 174 | static void cgroup_put(struct cgroup *cgrp); |
178 | static int rebind_subsystems(struct cgroupfs_root *dst_root, | 175 | static int rebind_subsystems(struct cgroup_root *dst_root, |
179 | unsigned long ss_mask); | 176 | unsigned long ss_mask); |
180 | static void cgroup_destroy_css_killed(struct cgroup *cgrp); | 177 | static void cgroup_destroy_css_killed(struct cgroup *cgrp); |
181 | static int cgroup_destroy_locked(struct cgroup *cgrp); | 178 | static int cgroup_destroy_locked(struct cgroup *cgrp); |
@@ -514,7 +511,7 @@ static struct css_set *find_existing_css_set(struct css_set *old_cset, | |||
514 | struct cgroup *cgrp, | 511 | struct cgroup *cgrp, |
515 | struct cgroup_subsys_state *template[]) | 512 | struct cgroup_subsys_state *template[]) |
516 | { | 513 | { |
517 | struct cgroupfs_root *root = cgrp->root; | 514 | struct cgroup_root *root = cgrp->root; |
518 | struct cgroup_subsys *ss; | 515 | struct cgroup_subsys *ss; |
519 | struct css_set *cset; | 516 | struct css_set *cset; |
520 | unsigned long key; | 517 | unsigned long key; |
@@ -526,7 +523,7 @@ static struct css_set *find_existing_css_set(struct css_set *old_cset, | |||
526 | * won't change, so no need for locking. | 523 | * won't change, so no need for locking. |
527 | */ | 524 | */ |
528 | for_each_subsys(ss, i) { | 525 | for_each_subsys(ss, i) { |
529 | if (root->top_cgroup.subsys_mask & (1UL << i)) { | 526 | if (root->cgrp.subsys_mask & (1UL << i)) { |
530 | /* Subsystem is in this hierarchy. So we want | 527 | /* Subsystem is in this hierarchy. So we want |
531 | * the subsystem state from the new | 528 | * the subsystem state from the new |
532 | * cgroup */ | 529 | * cgroup */ |
@@ -685,14 +682,14 @@ static struct css_set *find_css_set(struct css_set *old_cset, | |||
685 | return cset; | 682 | return cset; |
686 | } | 683 | } |
687 | 684 | ||
688 | static struct cgroupfs_root *cgroup_root_from_kf(struct kernfs_root *kf_root) | 685 | static struct cgroup_root *cgroup_root_from_kf(struct kernfs_root *kf_root) |
689 | { | 686 | { |
690 | struct cgroup *top_cgrp = kf_root->kn->priv; | 687 | struct cgroup *root_cgrp = kf_root->kn->priv; |
691 | 688 | ||
692 | return top_cgrp->root; | 689 | return root_cgrp->root; |
693 | } | 690 | } |
694 | 691 | ||
695 | static int cgroup_init_root_id(struct cgroupfs_root *root) | 692 | static int cgroup_init_root_id(struct cgroup_root *root) |
696 | { | 693 | { |
697 | int id; | 694 | int id; |
698 | 695 | ||
@@ -706,7 +703,7 @@ static int cgroup_init_root_id(struct cgroupfs_root *root) | |||
706 | return 0; | 703 | return 0; |
707 | } | 704 | } |
708 | 705 | ||
709 | static void cgroup_exit_root_id(struct cgroupfs_root *root) | 706 | static void cgroup_exit_root_id(struct cgroup_root *root) |
710 | { | 707 | { |
711 | lockdep_assert_held(&cgroup_mutex); | 708 | lockdep_assert_held(&cgroup_mutex); |
712 | 709 | ||
@@ -716,7 +713,7 @@ static void cgroup_exit_root_id(struct cgroupfs_root *root) | |||
716 | } | 713 | } |
717 | } | 714 | } |
718 | 715 | ||
719 | static void cgroup_free_root(struct cgroupfs_root *root) | 716 | static void cgroup_free_root(struct cgroup_root *root) |
720 | { | 717 | { |
721 | if (root) { | 718 | if (root) { |
722 | /* hierarhcy ID shoulid already have been released */ | 719 | /* hierarhcy ID shoulid already have been released */ |
@@ -727,9 +724,9 @@ static void cgroup_free_root(struct cgroupfs_root *root) | |||
727 | } | 724 | } |
728 | } | 725 | } |
729 | 726 | ||
730 | static void cgroup_destroy_root(struct cgroupfs_root *root) | 727 | static void cgroup_destroy_root(struct cgroup_root *root) |
731 | { | 728 | { |
732 | struct cgroup *cgrp = &root->top_cgroup; | 729 | struct cgroup *cgrp = &root->cgrp; |
733 | struct cgrp_cset_link *link, *tmp_link; | 730 | struct cgrp_cset_link *link, *tmp_link; |
734 | 731 | ||
735 | mutex_lock(&cgroup_tree_mutex); | 732 | mutex_lock(&cgroup_tree_mutex); |
@@ -739,7 +736,7 @@ static void cgroup_destroy_root(struct cgroupfs_root *root) | |||
739 | BUG_ON(!list_empty(&cgrp->children)); | 736 | BUG_ON(!list_empty(&cgrp->children)); |
740 | 737 | ||
741 | /* Rebind all subsystems back to the default hierarchy */ | 738 | /* Rebind all subsystems back to the default hierarchy */ |
742 | rebind_subsystems(&cgroup_dummy_root, cgrp->subsys_mask); | 739 | rebind_subsystems(&cgrp_dfl_root, cgrp->subsys_mask); |
743 | 740 | ||
744 | /* | 741 | /* |
745 | * Release all the links from cset_links to this hierarchy's | 742 | * Release all the links from cset_links to this hierarchy's |
@@ -770,7 +767,7 @@ static void cgroup_destroy_root(struct cgroupfs_root *root) | |||
770 | 767 | ||
771 | /* look up cgroup associated with given css_set on the specified hierarchy */ | 768 | /* look up cgroup associated with given css_set on the specified hierarchy */ |
772 | static struct cgroup *cset_cgroup_from_root(struct css_set *cset, | 769 | static struct cgroup *cset_cgroup_from_root(struct css_set *cset, |
773 | struct cgroupfs_root *root) | 770 | struct cgroup_root *root) |
774 | { | 771 | { |
775 | struct cgroup *res = NULL; | 772 | struct cgroup *res = NULL; |
776 | 773 | ||
@@ -778,7 +775,7 @@ static struct cgroup *cset_cgroup_from_root(struct css_set *cset, | |||
778 | lockdep_assert_held(&css_set_rwsem); | 775 | lockdep_assert_held(&css_set_rwsem); |
779 | 776 | ||
780 | if (cset == &init_css_set) { | 777 | if (cset == &init_css_set) { |
781 | res = &root->top_cgroup; | 778 | res = &root->cgrp; |
782 | } else { | 779 | } else { |
783 | struct cgrp_cset_link *link; | 780 | struct cgrp_cset_link *link; |
784 | 781 | ||
@@ -801,7 +798,7 @@ static struct cgroup *cset_cgroup_from_root(struct css_set *cset, | |||
801 | * called with cgroup_mutex and css_set_rwsem held. | 798 | * called with cgroup_mutex and css_set_rwsem held. |
802 | */ | 799 | */ |
803 | static struct cgroup *task_cgroup_from_root(struct task_struct *task, | 800 | static struct cgroup *task_cgroup_from_root(struct task_struct *task, |
804 | struct cgroupfs_root *root) | 801 | struct cgroup_root *root) |
805 | { | 802 | { |
806 | /* | 803 | /* |
807 | * No need to lock the task - since we hold cgroup_mutex the | 804 | * No need to lock the task - since we hold cgroup_mutex the |
@@ -837,9 +834,9 @@ static struct cgroup *task_cgroup_from_root(struct task_struct *task, | |||
837 | * A cgroup can only be deleted if both its 'count' of using tasks | 834 | * A cgroup can only be deleted if both its 'count' of using tasks |
838 | * is zero, and its list of 'children' cgroups is empty. Since all | 835 | * is zero, and its list of 'children' cgroups is empty. Since all |
839 | * tasks in the system use _some_ cgroup, and since there is always at | 836 | * tasks in the system use _some_ cgroup, and since there is always at |
840 | * least one task in the system (init, pid == 1), therefore, top_cgroup | 837 | * least one task in the system (init, pid == 1), therefore, root cgroup |
841 | * always has either children cgroups and/or using tasks. So we don't | 838 | * always has either children cgroups and/or using tasks. So we don't |
842 | * need a special hack to ensure that top_cgroup cannot be deleted. | 839 | * need a special hack to ensure that root cgroup cannot be deleted. |
843 | * | 840 | * |
844 | * P.S. One more locking exception. RCU is used to guard the | 841 | * P.S. One more locking exception. RCU is used to guard the |
845 | * update of a tasks cgroup pointer by cgroup_attach_task() | 842 | * update of a tasks cgroup pointer by cgroup_attach_task() |
@@ -905,7 +902,7 @@ static void cgroup_free_fn(struct work_struct *work) | |||
905 | kfree(cgrp); | 902 | kfree(cgrp); |
906 | } else { | 903 | } else { |
907 | /* | 904 | /* |
908 | * This is top cgroup's refcnt reaching zero, which | 905 | * This is root cgroup's refcnt reaching zero, which |
909 | * indicates that the root should be released. | 906 | * indicates that the root should be released. |
910 | */ | 907 | */ |
911 | cgroup_destroy_root(cgrp->root); | 908 | cgroup_destroy_root(cgrp->root); |
@@ -976,10 +973,9 @@ static void cgroup_clear_dir(struct cgroup *cgrp, unsigned long subsys_mask) | |||
976 | } | 973 | } |
977 | } | 974 | } |
978 | 975 | ||
979 | static int rebind_subsystems(struct cgroupfs_root *dst_root, | 976 | static int rebind_subsystems(struct cgroup_root *dst_root, |
980 | unsigned long ss_mask) | 977 | unsigned long ss_mask) |
981 | { | 978 | { |
982 | struct cgroup *dst_top = &dst_root->top_cgroup; | ||
983 | struct cgroup_subsys *ss; | 979 | struct cgroup_subsys *ss; |
984 | int ssid, ret; | 980 | int ssid, ret; |
985 | 981 | ||
@@ -991,20 +987,20 @@ static int rebind_subsystems(struct cgroupfs_root *dst_root, | |||
991 | continue; | 987 | continue; |
992 | 988 | ||
993 | /* if @ss is on the dummy_root, we can always move it */ | 989 | /* if @ss is on the dummy_root, we can always move it */ |
994 | if (ss->root == &cgroup_dummy_root) | 990 | if (ss->root == &cgrp_dfl_root) |
995 | continue; | 991 | continue; |
996 | 992 | ||
997 | /* if @ss has non-root cgroups attached to it, can't move */ | 993 | /* if @ss has non-root cgroups attached to it, can't move */ |
998 | if (!list_empty(&ss->root->top_cgroup.children)) | 994 | if (!list_empty(&ss->root->cgrp.children)) |
999 | return -EBUSY; | 995 | return -EBUSY; |
1000 | 996 | ||
1001 | /* can't move between two non-dummy roots either */ | 997 | /* can't move between two non-dummy roots either */ |
1002 | if (dst_root != &cgroup_dummy_root) | 998 | if (dst_root != &cgrp_dfl_root) |
1003 | return -EBUSY; | 999 | return -EBUSY; |
1004 | } | 1000 | } |
1005 | 1001 | ||
1006 | if (dst_root != &cgroup_dummy_root) { | 1002 | if (dst_root != &cgrp_dfl_root) { |
1007 | ret = cgroup_populate_dir(dst_top, ss_mask); | 1003 | ret = cgroup_populate_dir(&dst_root->cgrp, ss_mask); |
1008 | if (ret) | 1004 | if (ret) |
1009 | return ret; | 1005 | return ret; |
1010 | } | 1006 | } |
@@ -1015,50 +1011,48 @@ static int rebind_subsystems(struct cgroupfs_root *dst_root, | |||
1015 | */ | 1011 | */ |
1016 | mutex_unlock(&cgroup_mutex); | 1012 | mutex_unlock(&cgroup_mutex); |
1017 | for_each_subsys(ss, ssid) | 1013 | for_each_subsys(ss, ssid) |
1018 | if ((ss_mask & (1 << ssid)) && ss->root != &cgroup_dummy_root) | 1014 | if ((ss_mask & (1 << ssid)) && ss->root != &cgrp_dfl_root) |
1019 | cgroup_clear_dir(&ss->root->top_cgroup, 1 << ssid); | 1015 | cgroup_clear_dir(&ss->root->cgrp, 1 << ssid); |
1020 | mutex_lock(&cgroup_mutex); | 1016 | mutex_lock(&cgroup_mutex); |
1021 | 1017 | ||
1022 | for_each_subsys(ss, ssid) { | 1018 | for_each_subsys(ss, ssid) { |
1023 | struct cgroupfs_root *src_root; | 1019 | struct cgroup_root *src_root; |
1024 | struct cgroup *src_top; | ||
1025 | struct cgroup_subsys_state *css; | 1020 | struct cgroup_subsys_state *css; |
1026 | 1021 | ||
1027 | if (!(ss_mask & (1 << ssid))) | 1022 | if (!(ss_mask & (1 << ssid))) |
1028 | continue; | 1023 | continue; |
1029 | 1024 | ||
1030 | src_root = ss->root; | 1025 | src_root = ss->root; |
1031 | src_top = &src_root->top_cgroup; | 1026 | css = cgroup_css(&src_root->cgrp, ss); |
1032 | css = cgroup_css(src_top, ss); | ||
1033 | 1027 | ||
1034 | WARN_ON(!css || cgroup_css(dst_top, ss)); | 1028 | WARN_ON(!css || cgroup_css(&dst_root->cgrp, ss)); |
1035 | 1029 | ||
1036 | RCU_INIT_POINTER(src_top->subsys[ssid], NULL); | 1030 | RCU_INIT_POINTER(src_root->cgrp.subsys[ssid], NULL); |
1037 | rcu_assign_pointer(dst_top->subsys[ssid], css); | 1031 | rcu_assign_pointer(dst_root->cgrp.subsys[ssid], css); |
1038 | ss->root = dst_root; | 1032 | ss->root = dst_root; |
1039 | css->cgroup = dst_top; | 1033 | css->cgroup = &dst_root->cgrp; |
1040 | 1034 | ||
1041 | src_top->subsys_mask &= ~(1 << ssid); | 1035 | src_root->cgrp.subsys_mask &= ~(1 << ssid); |
1042 | dst_top->subsys_mask |= 1 << ssid; | 1036 | dst_root->cgrp.subsys_mask |= 1 << ssid; |
1043 | 1037 | ||
1044 | if (ss->bind) | 1038 | if (ss->bind) |
1045 | ss->bind(css); | 1039 | ss->bind(css); |
1046 | } | 1040 | } |
1047 | 1041 | ||
1048 | if (dst_root != &cgroup_dummy_root) | 1042 | if (dst_root != &cgrp_dfl_root) |
1049 | kernfs_activate(dst_top->kn); | 1043 | kernfs_activate(dst_root->cgrp.kn); |
1050 | return 0; | 1044 | return 0; |
1051 | } | 1045 | } |
1052 | 1046 | ||
1053 | static int cgroup_show_options(struct seq_file *seq, | 1047 | static int cgroup_show_options(struct seq_file *seq, |
1054 | struct kernfs_root *kf_root) | 1048 | struct kernfs_root *kf_root) |
1055 | { | 1049 | { |
1056 | struct cgroupfs_root *root = cgroup_root_from_kf(kf_root); | 1050 | struct cgroup_root *root = cgroup_root_from_kf(kf_root); |
1057 | struct cgroup_subsys *ss; | 1051 | struct cgroup_subsys *ss; |
1058 | int ssid; | 1052 | int ssid; |
1059 | 1053 | ||
1060 | for_each_subsys(ss, ssid) | 1054 | for_each_subsys(ss, ssid) |
1061 | if (root->top_cgroup.subsys_mask & (1 << ssid)) | 1055 | if (root->cgrp.subsys_mask & (1 << ssid)) |
1062 | seq_printf(seq, ",%s", ss->name); | 1056 | seq_printf(seq, ",%s", ss->name); |
1063 | if (root->flags & CGRP_ROOT_SANE_BEHAVIOR) | 1057 | if (root->flags & CGRP_ROOT_SANE_BEHAVIOR) |
1064 | seq_puts(seq, ",sane_behavior"); | 1058 | seq_puts(seq, ",sane_behavior"); |
@@ -1072,7 +1066,7 @@ static int cgroup_show_options(struct seq_file *seq, | |||
1072 | seq_printf(seq, ",release_agent=%s", root->release_agent_path); | 1066 | seq_printf(seq, ",release_agent=%s", root->release_agent_path); |
1073 | spin_unlock(&release_agent_path_lock); | 1067 | spin_unlock(&release_agent_path_lock); |
1074 | 1068 | ||
1075 | if (test_bit(CGRP_CPUSET_CLONE_CHILDREN, &root->top_cgroup.flags)) | 1069 | if (test_bit(CGRP_CPUSET_CLONE_CHILDREN, &root->cgrp.flags)) |
1076 | seq_puts(seq, ",clone_children"); | 1070 | seq_puts(seq, ",clone_children"); |
1077 | if (strlen(root->name)) | 1071 | if (strlen(root->name)) |
1078 | seq_printf(seq, ",name=%s", root->name); | 1072 | seq_printf(seq, ",name=%s", root->name); |
@@ -1245,7 +1239,7 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts) | |||
1245 | static int cgroup_remount(struct kernfs_root *kf_root, int *flags, char *data) | 1239 | static int cgroup_remount(struct kernfs_root *kf_root, int *flags, char *data) |
1246 | { | 1240 | { |
1247 | int ret = 0; | 1241 | int ret = 0; |
1248 | struct cgroupfs_root *root = cgroup_root_from_kf(kf_root); | 1242 | struct cgroup_root *root = cgroup_root_from_kf(kf_root); |
1249 | struct cgroup_sb_opts opts; | 1243 | struct cgroup_sb_opts opts; |
1250 | unsigned long added_mask, removed_mask; | 1244 | unsigned long added_mask, removed_mask; |
1251 | 1245 | ||
@@ -1262,12 +1256,12 @@ static int cgroup_remount(struct kernfs_root *kf_root, int *flags, char *data) | |||
1262 | if (ret) | 1256 | if (ret) |
1263 | goto out_unlock; | 1257 | goto out_unlock; |
1264 | 1258 | ||
1265 | if (opts.subsys_mask != root->top_cgroup.subsys_mask || opts.release_agent) | 1259 | if (opts.subsys_mask != root->cgrp.subsys_mask || opts.release_agent) |
1266 | pr_warning("cgroup: option changes via remount are deprecated (pid=%d comm=%s)\n", | 1260 | pr_warning("cgroup: option changes via remount are deprecated (pid=%d comm=%s)\n", |
1267 | task_tgid_nr(current), current->comm); | 1261 | task_tgid_nr(current), current->comm); |
1268 | 1262 | ||
1269 | added_mask = opts.subsys_mask & ~root->top_cgroup.subsys_mask; | 1263 | added_mask = opts.subsys_mask & ~root->cgrp.subsys_mask; |
1270 | removed_mask = root->top_cgroup.subsys_mask & ~opts.subsys_mask; | 1264 | removed_mask = root->cgrp.subsys_mask & ~opts.subsys_mask; |
1271 | 1265 | ||
1272 | /* Don't allow flags or name to change at remount */ | 1266 | /* Don't allow flags or name to change at remount */ |
1273 | if (((opts.flags ^ root->flags) & CGRP_ROOT_OPTION_MASK) || | 1267 | if (((opts.flags ^ root->flags) & CGRP_ROOT_OPTION_MASK) || |
@@ -1280,7 +1274,7 @@ static int cgroup_remount(struct kernfs_root *kf_root, int *flags, char *data) | |||
1280 | } | 1274 | } |
1281 | 1275 | ||
1282 | /* remounting is not allowed for populated hierarchies */ | 1276 | /* remounting is not allowed for populated hierarchies */ |
1283 | if (!list_empty(&root->top_cgroup.children)) { | 1277 | if (!list_empty(&root->cgrp.children)) { |
1284 | ret = -EBUSY; | 1278 | ret = -EBUSY; |
1285 | goto out_unlock; | 1279 | goto out_unlock; |
1286 | } | 1280 | } |
@@ -1289,7 +1283,7 @@ static int cgroup_remount(struct kernfs_root *kf_root, int *flags, char *data) | |||
1289 | if (ret) | 1283 | if (ret) |
1290 | goto out_unlock; | 1284 | goto out_unlock; |
1291 | 1285 | ||
1292 | rebind_subsystems(&cgroup_dummy_root, removed_mask); | 1286 | rebind_subsystems(&cgrp_dfl_root, removed_mask); |
1293 | 1287 | ||
1294 | if (opts.release_agent) { | 1288 | if (opts.release_agent) { |
1295 | spin_lock(&release_agent_path_lock); | 1289 | spin_lock(&release_agent_path_lock); |
@@ -1368,10 +1362,10 @@ static void init_cgroup_housekeeping(struct cgroup *cgrp) | |||
1368 | cgrp->dummy_css.cgroup = cgrp; | 1362 | cgrp->dummy_css.cgroup = cgrp; |
1369 | } | 1363 | } |
1370 | 1364 | ||
1371 | static void init_cgroup_root(struct cgroupfs_root *root, | 1365 | static void init_cgroup_root(struct cgroup_root *root, |
1372 | struct cgroup_sb_opts *opts) | 1366 | struct cgroup_sb_opts *opts) |
1373 | { | 1367 | { |
1374 | struct cgroup *cgrp = &root->top_cgroup; | 1368 | struct cgroup *cgrp = &root->cgrp; |
1375 | 1369 | ||
1376 | INIT_LIST_HEAD(&root->root_list); | 1370 | INIT_LIST_HEAD(&root->root_list); |
1377 | atomic_set(&root->nr_cgrps, 1); | 1371 | atomic_set(&root->nr_cgrps, 1); |
@@ -1385,13 +1379,13 @@ static void init_cgroup_root(struct cgroupfs_root *root, | |||
1385 | if (opts->name) | 1379 | if (opts->name) |
1386 | strcpy(root->name, opts->name); | 1380 | strcpy(root->name, opts->name); |
1387 | if (opts->cpuset_clone_children) | 1381 | if (opts->cpuset_clone_children) |
1388 | set_bit(CGRP_CPUSET_CLONE_CHILDREN, &root->top_cgroup.flags); | 1382 | set_bit(CGRP_CPUSET_CLONE_CHILDREN, &root->cgrp.flags); |
1389 | } | 1383 | } |
1390 | 1384 | ||
1391 | static int cgroup_setup_root(struct cgroupfs_root *root, unsigned long ss_mask) | 1385 | static int cgroup_setup_root(struct cgroup_root *root, unsigned long ss_mask) |
1392 | { | 1386 | { |
1393 | LIST_HEAD(tmp_links); | 1387 | LIST_HEAD(tmp_links); |
1394 | struct cgroup *root_cgrp = &root->top_cgroup; | 1388 | struct cgroup *root_cgrp = &root->cgrp; |
1395 | struct css_set *cset; | 1389 | struct css_set *cset; |
1396 | int i, ret; | 1390 | int i, ret; |
1397 | 1391 | ||
@@ -1443,7 +1437,7 @@ static int cgroup_setup_root(struct cgroupfs_root *root, unsigned long ss_mask) | |||
1443 | cgroup_root_count++; | 1437 | cgroup_root_count++; |
1444 | 1438 | ||
1445 | /* | 1439 | /* |
1446 | * Link the top cgroup in this hierarchy into all the css_set | 1440 | * Link the root cgroup in this hierarchy into all the css_set |
1447 | * objects. | 1441 | * objects. |
1448 | */ | 1442 | */ |
1449 | down_write(&css_set_rwsem); | 1443 | down_write(&css_set_rwsem); |
@@ -1472,7 +1466,7 @@ static struct dentry *cgroup_mount(struct file_system_type *fs_type, | |||
1472 | int flags, const char *unused_dev_name, | 1466 | int flags, const char *unused_dev_name, |
1473 | void *data) | 1467 | void *data) |
1474 | { | 1468 | { |
1475 | struct cgroupfs_root *root; | 1469 | struct cgroup_root *root; |
1476 | struct cgroup_sb_opts opts; | 1470 | struct cgroup_sb_opts opts; |
1477 | struct dentry *dentry; | 1471 | struct dentry *dentry; |
1478 | int ret; | 1472 | int ret; |
@@ -1496,7 +1490,7 @@ retry: | |||
1496 | for_each_root(root) { | 1490 | for_each_root(root) { |
1497 | bool name_match = false; | 1491 | bool name_match = false; |
1498 | 1492 | ||
1499 | if (root == &cgroup_dummy_root) | 1493 | if (root == &cgrp_dfl_root) |
1500 | continue; | 1494 | continue; |
1501 | 1495 | ||
1502 | /* | 1496 | /* |
@@ -1515,7 +1509,7 @@ retry: | |||
1515 | * subsystems) then they must match. | 1509 | * subsystems) then they must match. |
1516 | */ | 1510 | */ |
1517 | if ((opts.subsys_mask || opts.none) && | 1511 | if ((opts.subsys_mask || opts.none) && |
1518 | (opts.subsys_mask != root->top_cgroup.subsys_mask)) { | 1512 | (opts.subsys_mask != root->cgrp.subsys_mask)) { |
1519 | if (!name_match) | 1513 | if (!name_match) |
1520 | continue; | 1514 | continue; |
1521 | ret = -EBUSY; | 1515 | ret = -EBUSY; |
@@ -1533,13 +1527,13 @@ retry: | |||
1533 | } | 1527 | } |
1534 | 1528 | ||
1535 | /* | 1529 | /* |
1536 | * A root's lifetime is governed by its top cgroup. Zero | 1530 | * A root's lifetime is governed by its root cgroup. Zero |
1537 | * ref indicate that the root is being destroyed. Wait for | 1531 | * ref indicate that the root is being destroyed. Wait for |
1538 | * destruction to complete so that the subsystems are free. | 1532 | * destruction to complete so that the subsystems are free. |
1539 | * We can use wait_queue for the wait but this path is | 1533 | * We can use wait_queue for the wait but this path is |
1540 | * super cold. Let's just sleep for a bit and retry. | 1534 | * super cold. Let's just sleep for a bit and retry. |
1541 | */ | 1535 | */ |
1542 | if (!atomic_inc_not_zero(&root->top_cgroup.refcnt)) { | 1536 | if (!atomic_inc_not_zero(&root->cgrp.refcnt)) { |
1543 | mutex_unlock(&cgroup_mutex); | 1537 | mutex_unlock(&cgroup_mutex); |
1544 | mutex_unlock(&cgroup_tree_mutex); | 1538 | mutex_unlock(&cgroup_tree_mutex); |
1545 | kfree(opts.release_agent); | 1539 | kfree(opts.release_agent); |
@@ -1586,16 +1580,16 @@ out_unlock: | |||
1586 | 1580 | ||
1587 | dentry = kernfs_mount(fs_type, flags, root->kf_root); | 1581 | dentry = kernfs_mount(fs_type, flags, root->kf_root); |
1588 | if (IS_ERR(dentry)) | 1582 | if (IS_ERR(dentry)) |
1589 | cgroup_put(&root->top_cgroup); | 1583 | cgroup_put(&root->cgrp); |
1590 | return dentry; | 1584 | return dentry; |
1591 | } | 1585 | } |
1592 | 1586 | ||
1593 | static void cgroup_kill_sb(struct super_block *sb) | 1587 | static void cgroup_kill_sb(struct super_block *sb) |
1594 | { | 1588 | { |
1595 | struct kernfs_root *kf_root = kernfs_root_from_sb(sb); | 1589 | struct kernfs_root *kf_root = kernfs_root_from_sb(sb); |
1596 | struct cgroupfs_root *root = cgroup_root_from_kf(kf_root); | 1590 | struct cgroup_root *root = cgroup_root_from_kf(kf_root); |
1597 | 1591 | ||
1598 | cgroup_put(&root->top_cgroup); | 1592 | cgroup_put(&root->cgrp); |
1599 | kernfs_kill_sb(sb); | 1593 | kernfs_kill_sb(sb); |
1600 | } | 1594 | } |
1601 | 1595 | ||
@@ -1622,7 +1616,7 @@ static struct kobject *cgroup_kobj; | |||
1622 | */ | 1616 | */ |
1623 | char *task_cgroup_path(struct task_struct *task, char *buf, size_t buflen) | 1617 | char *task_cgroup_path(struct task_struct *task, char *buf, size_t buflen) |
1624 | { | 1618 | { |
1625 | struct cgroupfs_root *root; | 1619 | struct cgroup_root *root; |
1626 | struct cgroup *cgrp; | 1620 | struct cgroup *cgrp; |
1627 | int hierarchy_id = 1; | 1621 | int hierarchy_id = 1; |
1628 | char *path = NULL; | 1622 | char *path = NULL; |
@@ -2112,14 +2106,14 @@ out_unlock_cgroup: | |||
2112 | */ | 2106 | */ |
2113 | int cgroup_attach_task_all(struct task_struct *from, struct task_struct *tsk) | 2107 | int cgroup_attach_task_all(struct task_struct *from, struct task_struct *tsk) |
2114 | { | 2108 | { |
2115 | struct cgroupfs_root *root; | 2109 | struct cgroup_root *root; |
2116 | int retval = 0; | 2110 | int retval = 0; |
2117 | 2111 | ||
2118 | mutex_lock(&cgroup_mutex); | 2112 | mutex_lock(&cgroup_mutex); |
2119 | for_each_root(root) { | 2113 | for_each_root(root) { |
2120 | struct cgroup *from_cgrp; | 2114 | struct cgroup *from_cgrp; |
2121 | 2115 | ||
2122 | if (root == &cgroup_dummy_root) | 2116 | if (root == &cgrp_dfl_root) |
2123 | continue; | 2117 | continue; |
2124 | 2118 | ||
2125 | down_read(&css_set_rwsem); | 2119 | down_read(&css_set_rwsem); |
@@ -2151,7 +2145,7 @@ static int cgroup_procs_write(struct cgroup_subsys_state *css, | |||
2151 | static int cgroup_release_agent_write(struct cgroup_subsys_state *css, | 2145 | static int cgroup_release_agent_write(struct cgroup_subsys_state *css, |
2152 | struct cftype *cft, const char *buffer) | 2146 | struct cftype *cft, const char *buffer) |
2153 | { | 2147 | { |
2154 | struct cgroupfs_root *root = css->cgroup->root; | 2148 | struct cgroup_root *root = css->cgroup->root; |
2155 | 2149 | ||
2156 | BUILD_BUG_ON(sizeof(root->release_agent_path) < PATH_MAX); | 2150 | BUILD_BUG_ON(sizeof(root->release_agent_path) < PATH_MAX); |
2157 | if (!cgroup_lock_live_group(css->cgroup)) | 2151 | if (!cgroup_lock_live_group(css->cgroup)) |
@@ -2362,14 +2356,14 @@ static int cgroup_apply_cftypes(struct cftype *cfts, bool is_add) | |||
2362 | { | 2356 | { |
2363 | LIST_HEAD(pending); | 2357 | LIST_HEAD(pending); |
2364 | struct cgroup_subsys *ss = cfts[0].ss; | 2358 | struct cgroup_subsys *ss = cfts[0].ss; |
2365 | struct cgroup *root = &ss->root->top_cgroup; | 2359 | struct cgroup *root = &ss->root->cgrp; |
2366 | struct cgroup_subsys_state *css; | 2360 | struct cgroup_subsys_state *css; |
2367 | int ret = 0; | 2361 | int ret = 0; |
2368 | 2362 | ||
2369 | lockdep_assert_held(&cgroup_tree_mutex); | 2363 | lockdep_assert_held(&cgroup_tree_mutex); |
2370 | 2364 | ||
2371 | /* don't bother if @ss isn't attached */ | 2365 | /* don't bother if @ss isn't attached */ |
2372 | if (ss->root == &cgroup_dummy_root) | 2366 | if (ss->root == &cgrp_dfl_root) |
2373 | return 0; | 2367 | return 0; |
2374 | 2368 | ||
2375 | /* add/rm files for all cgroups created before */ | 2369 | /* add/rm files for all cgroups created before */ |
@@ -3623,7 +3617,7 @@ static long cgroup_create(struct cgroup *parent, const char *name, | |||
3623 | umode_t mode) | 3617 | umode_t mode) |
3624 | { | 3618 | { |
3625 | struct cgroup *cgrp; | 3619 | struct cgroup *cgrp; |
3626 | struct cgroupfs_root *root = parent->root; | 3620 | struct cgroup_root *root = parent->root; |
3627 | int ssid, err; | 3621 | int ssid, err; |
3628 | struct cgroup_subsys *ss; | 3622 | struct cgroup_subsys *ss; |
3629 | struct kernfs_node *kn; | 3623 | struct kernfs_node *kn; |
@@ -3702,7 +3696,7 @@ static long cgroup_create(struct cgroup *parent, const char *name, | |||
3702 | 3696 | ||
3703 | /* let's create and online css's */ | 3697 | /* let's create and online css's */ |
3704 | for_each_subsys(ss, ssid) { | 3698 | for_each_subsys(ss, ssid) { |
3705 | if (root->top_cgroup.subsys_mask & (1 << ssid)) { | 3699 | if (root->cgrp.subsys_mask & (1 << ssid)) { |
3706 | err = create_css(cgrp, ss); | 3700 | err = create_css(cgrp, ss); |
3707 | if (err) | 3701 | if (err) |
3708 | goto err_destroy; | 3702 | goto err_destroy; |
@@ -4031,17 +4025,17 @@ static void __init cgroup_init_subsys(struct cgroup_subsys *ss) | |||
4031 | 4025 | ||
4032 | INIT_LIST_HEAD(&ss->cfts); | 4026 | INIT_LIST_HEAD(&ss->cfts); |
4033 | 4027 | ||
4034 | /* Create the top cgroup state for this subsystem */ | 4028 | /* Create the root cgroup state for this subsystem */ |
4035 | ss->root = &cgroup_dummy_root; | 4029 | ss->root = &cgrp_dfl_root; |
4036 | css = ss->css_alloc(cgroup_css(cgroup_dummy_top, ss)); | 4030 | css = ss->css_alloc(cgroup_css(&cgrp_dfl_root.cgrp, ss)); |
4037 | /* We don't handle early failures gracefully */ | 4031 | /* We don't handle early failures gracefully */ |
4038 | BUG_ON(IS_ERR(css)); | 4032 | BUG_ON(IS_ERR(css)); |
4039 | init_css(css, ss, cgroup_dummy_top); | 4033 | init_css(css, ss, &cgrp_dfl_root.cgrp); |
4040 | 4034 | ||
4041 | /* Update the init_css_set to contain a subsys | 4035 | /* Update the init_css_set to contain a subsys |
4042 | * pointer to this state - since the subsystem is | 4036 | * pointer to this state - since the subsystem is |
4043 | * newly registered, all tasks and hence the | 4037 | * newly registered, all tasks and hence the |
4044 | * init_css_set is in the subsystem's top cgroup. */ | 4038 | * init_css_set is in the subsystem's root cgroup. */ |
4045 | init_css_set.subsys[ss->id] = css; | 4039 | init_css_set.subsys[ss->id] = css; |
4046 | 4040 | ||
4047 | need_forkexit_callback |= ss->fork || ss->exit; | 4041 | need_forkexit_callback |= ss->fork || ss->exit; |
@@ -4053,7 +4047,7 @@ static void __init cgroup_init_subsys(struct cgroup_subsys *ss) | |||
4053 | 4047 | ||
4054 | BUG_ON(online_css(css)); | 4048 | BUG_ON(online_css(css)); |
4055 | 4049 | ||
4056 | cgroup_dummy_root.top_cgroup.subsys_mask |= 1 << ss->id; | 4050 | cgrp_dfl_root.cgrp.subsys_mask |= 1 << ss->id; |
4057 | 4051 | ||
4058 | mutex_unlock(&cgroup_mutex); | 4052 | mutex_unlock(&cgroup_mutex); |
4059 | mutex_unlock(&cgroup_tree_mutex); | 4053 | mutex_unlock(&cgroup_tree_mutex); |
@@ -4071,7 +4065,7 @@ int __init cgroup_init_early(void) | |||
4071 | struct cgroup_subsys *ss; | 4065 | struct cgroup_subsys *ss; |
4072 | int i; | 4066 | int i; |
4073 | 4067 | ||
4074 | init_cgroup_root(&cgroup_dummy_root, &opts); | 4068 | init_cgroup_root(&cgrp_dfl_root, &opts); |
4075 | RCU_INIT_POINTER(init_task.cgroups, &init_css_set); | 4069 | RCU_INIT_POINTER(init_task.cgroups, &init_css_set); |
4076 | 4070 | ||
4077 | for_each_subsys(ss, i) { | 4071 | for_each_subsys(ss, i) { |
@@ -4112,7 +4106,7 @@ int __init cgroup_init(void) | |||
4112 | key = css_set_hash(init_css_set.subsys); | 4106 | key = css_set_hash(init_css_set.subsys); |
4113 | hash_add(css_set_table, &init_css_set.hlist, key); | 4107 | hash_add(css_set_table, &init_css_set.hlist, key); |
4114 | 4108 | ||
4115 | BUG_ON(cgroup_setup_root(&cgroup_dummy_root, 0)); | 4109 | BUG_ON(cgroup_setup_root(&cgrp_dfl_root, 0)); |
4116 | 4110 | ||
4117 | mutex_unlock(&cgroup_mutex); | 4111 | mutex_unlock(&cgroup_mutex); |
4118 | mutex_unlock(&cgroup_tree_mutex); | 4112 | mutex_unlock(&cgroup_tree_mutex); |
@@ -4181,7 +4175,7 @@ int proc_cgroup_show(struct seq_file *m, void *v) | |||
4181 | struct task_struct *tsk; | 4175 | struct task_struct *tsk; |
4182 | char *buf, *path; | 4176 | char *buf, *path; |
4183 | int retval; | 4177 | int retval; |
4184 | struct cgroupfs_root *root; | 4178 | struct cgroup_root *root; |
4185 | 4179 | ||
4186 | retval = -ENOMEM; | 4180 | retval = -ENOMEM; |
4187 | buf = kmalloc(PATH_MAX, GFP_KERNEL); | 4181 | buf = kmalloc(PATH_MAX, GFP_KERNEL); |
@@ -4204,12 +4198,12 @@ int proc_cgroup_show(struct seq_file *m, void *v) | |||
4204 | struct cgroup *cgrp; | 4198 | struct cgroup *cgrp; |
4205 | int ssid, count = 0; | 4199 | int ssid, count = 0; |
4206 | 4200 | ||
4207 | if (root == &cgroup_dummy_root) | 4201 | if (root == &cgrp_dfl_root) |
4208 | continue; | 4202 | continue; |
4209 | 4203 | ||
4210 | seq_printf(m, "%d:", root->hierarchy_id); | 4204 | seq_printf(m, "%d:", root->hierarchy_id); |
4211 | for_each_subsys(ss, ssid) | 4205 | for_each_subsys(ss, ssid) |
4212 | if (root->top_cgroup.subsys_mask & (1 << ssid)) | 4206 | if (root->cgrp.subsys_mask & (1 << ssid)) |
4213 | seq_printf(m, "%s%s", count++ ? "," : "", ss->name); | 4207 | seq_printf(m, "%s%s", count++ ? "," : "", ss->name); |
4214 | if (strlen(root->name)) | 4208 | if (strlen(root->name)) |
4215 | seq_printf(m, "%sname=%s", count ? "," : "", | 4209 | seq_printf(m, "%sname=%s", count ? "," : "", |
@@ -4639,7 +4633,7 @@ static int current_css_set_cg_links_read(struct seq_file *seq, void *v) | |||
4639 | struct cgroup *c = link->cgrp; | 4633 | struct cgroup *c = link->cgrp; |
4640 | const char *name = "?"; | 4634 | const char *name = "?"; |
4641 | 4635 | ||
4642 | if (c != cgroup_dummy_top) { | 4636 | if (c != &cgrp_dfl_root.cgrp) { |
4643 | cgroup_name(c, name_buf, NAME_MAX + 1); | 4637 | cgroup_name(c, name_buf, NAME_MAX + 1); |
4644 | name = name_buf; | 4638 | name = name_buf; |
4645 | } | 4639 | } |