diff options
Diffstat (limited to 'kernel/cgroup.c')
-rw-r--r-- | kernel/cgroup.c | 715 |
1 files changed, 661 insertions, 54 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 0249f4be9b5c..e2769e13980c 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
@@ -4,6 +4,10 @@ | |||
4 | * Based originally on the cpuset system, extracted by Paul Menage | 4 | * Based originally on the cpuset system, extracted by Paul Menage |
5 | * Copyright (C) 2006 Google, Inc | 5 | * Copyright (C) 2006 Google, Inc |
6 | * | 6 | * |
7 | * Notifications support | ||
8 | * Copyright (C) 2009 Nokia Corporation | ||
9 | * Author: Kirill A. Shutemov | ||
10 | * | ||
7 | * Copyright notices from the original cpuset code: | 11 | * Copyright notices from the original cpuset code: |
8 | * -------------------------------------------------- | 12 | * -------------------------------------------------- |
9 | * Copyright (C) 2003 BULL SA. | 13 | * Copyright (C) 2003 BULL SA. |
@@ -43,6 +47,7 @@ | |||
43 | #include <linux/string.h> | 47 | #include <linux/string.h> |
44 | #include <linux/sort.h> | 48 | #include <linux/sort.h> |
45 | #include <linux/kmod.h> | 49 | #include <linux/kmod.h> |
50 | #include <linux/module.h> | ||
46 | #include <linux/delayacct.h> | 51 | #include <linux/delayacct.h> |
47 | #include <linux/cgroupstats.h> | 52 | #include <linux/cgroupstats.h> |
48 | #include <linux/hash.h> | 53 | #include <linux/hash.h> |
@@ -51,15 +56,21 @@ | |||
51 | #include <linux/pid_namespace.h> | 56 | #include <linux/pid_namespace.h> |
52 | #include <linux/idr.h> | 57 | #include <linux/idr.h> |
53 | #include <linux/vmalloc.h> /* TODO: replace with more sophisticated array */ | 58 | #include <linux/vmalloc.h> /* TODO: replace with more sophisticated array */ |
59 | #include <linux/eventfd.h> | ||
60 | #include <linux/poll.h> | ||
54 | 61 | ||
55 | #include <asm/atomic.h> | 62 | #include <asm/atomic.h> |
56 | 63 | ||
57 | static DEFINE_MUTEX(cgroup_mutex); | 64 | static DEFINE_MUTEX(cgroup_mutex); |
58 | 65 | ||
59 | /* Generate an array of cgroup subsystem pointers */ | 66 | /* |
67 | * Generate an array of cgroup subsystem pointers. At boot time, this is | ||
68 | * populated up to CGROUP_BUILTIN_SUBSYS_COUNT, and modular subsystems are | ||
69 | * registered after that. The mutable section of this array is protected by | ||
70 | * cgroup_mutex. | ||
71 | */ | ||
60 | #define SUBSYS(_x) &_x ## _subsys, | 72 | #define SUBSYS(_x) &_x ## _subsys, |
61 | 73 | static struct cgroup_subsys *subsys[CGROUP_SUBSYS_COUNT] = { | |
62 | static struct cgroup_subsys *subsys[] = { | ||
63 | #include <linux/cgroup_subsys.h> | 74 | #include <linux/cgroup_subsys.h> |
64 | }; | 75 | }; |
65 | 76 | ||
@@ -146,6 +157,35 @@ struct css_id { | |||
146 | unsigned short stack[0]; /* Array of Length (depth+1) */ | 157 | unsigned short stack[0]; /* Array of Length (depth+1) */ |
147 | }; | 158 | }; |
148 | 159 | ||
160 | /* | ||
161 | * cgroup_event represents events which userspace want to recieve. | ||
162 | */ | ||
163 | struct cgroup_event { | ||
164 | /* | ||
165 | * Cgroup which the event belongs to. | ||
166 | */ | ||
167 | struct cgroup *cgrp; | ||
168 | /* | ||
169 | * Control file which the event associated. | ||
170 | */ | ||
171 | struct cftype *cft; | ||
172 | /* | ||
173 | * eventfd to signal userspace about the event. | ||
174 | */ | ||
175 | struct eventfd_ctx *eventfd; | ||
176 | /* | ||
177 | * Each of these stored in a list by the cgroup. | ||
178 | */ | ||
179 | struct list_head list; | ||
180 | /* | ||
181 | * All fields below needed to unregister event when | ||
182 | * userspace closes eventfd. | ||
183 | */ | ||
184 | poll_table pt; | ||
185 | wait_queue_head_t *wqh; | ||
186 | wait_queue_t wait; | ||
187 | struct work_struct remove; | ||
188 | }; | ||
149 | 189 | ||
150 | /* The list of hierarchy roots */ | 190 | /* The list of hierarchy roots */ |
151 | 191 | ||
@@ -166,6 +206,20 @@ static DEFINE_SPINLOCK(hierarchy_id_lock); | |||
166 | */ | 206 | */ |
167 | static int need_forkexit_callback __read_mostly; | 207 | static int need_forkexit_callback __read_mostly; |
168 | 208 | ||
209 | #ifdef CONFIG_PROVE_LOCKING | ||
210 | int cgroup_lock_is_held(void) | ||
211 | { | ||
212 | return lockdep_is_held(&cgroup_mutex); | ||
213 | } | ||
214 | #else /* #ifdef CONFIG_PROVE_LOCKING */ | ||
215 | int cgroup_lock_is_held(void) | ||
216 | { | ||
217 | return mutex_is_locked(&cgroup_mutex); | ||
218 | } | ||
219 | #endif /* #else #ifdef CONFIG_PROVE_LOCKING */ | ||
220 | |||
221 | EXPORT_SYMBOL_GPL(cgroup_lock_is_held); | ||
222 | |||
169 | /* convenient tests for these bits */ | 223 | /* convenient tests for these bits */ |
170 | inline int cgroup_is_removed(const struct cgroup *cgrp) | 224 | inline int cgroup_is_removed(const struct cgroup *cgrp) |
171 | { | 225 | { |
@@ -235,7 +289,8 @@ struct cg_cgroup_link { | |||
235 | static struct css_set init_css_set; | 289 | static struct css_set init_css_set; |
236 | static struct cg_cgroup_link init_css_set_link; | 290 | static struct cg_cgroup_link init_css_set_link; |
237 | 291 | ||
238 | static int cgroup_subsys_init_idr(struct cgroup_subsys *ss); | 292 | static int cgroup_init_idr(struct cgroup_subsys *ss, |
293 | struct cgroup_subsys_state *css); | ||
239 | 294 | ||
240 | /* css_set_lock protects the list of css_set objects, and the | 295 | /* css_set_lock protects the list of css_set objects, and the |
241 | * chain of tasks off each css_set. Nests outside task->alloc_lock | 296 | * chain of tasks off each css_set. Nests outside task->alloc_lock |
@@ -433,8 +488,11 @@ static struct css_set *find_existing_css_set( | |||
433 | struct hlist_node *node; | 488 | struct hlist_node *node; |
434 | struct css_set *cg; | 489 | struct css_set *cg; |
435 | 490 | ||
436 | /* Built the set of subsystem state objects that we want to | 491 | /* |
437 | * see in the new css_set */ | 492 | * Build the set of subsystem state objects that we want to see in the |
493 | * new css_set. while subsystems can change globally, the entries here | ||
494 | * won't change, so no need for locking. | ||
495 | */ | ||
438 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { | 496 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { |
439 | if (root->subsys_bits & (1UL << i)) { | 497 | if (root->subsys_bits & (1UL << i)) { |
440 | /* Subsystem is in this hierarchy. So we want | 498 | /* Subsystem is in this hierarchy. So we want |
@@ -681,6 +739,7 @@ void cgroup_lock(void) | |||
681 | { | 739 | { |
682 | mutex_lock(&cgroup_mutex); | 740 | mutex_lock(&cgroup_mutex); |
683 | } | 741 | } |
742 | EXPORT_SYMBOL_GPL(cgroup_lock); | ||
684 | 743 | ||
685 | /** | 744 | /** |
686 | * cgroup_unlock - release lock on cgroup changes | 745 | * cgroup_unlock - release lock on cgroup changes |
@@ -691,6 +750,7 @@ void cgroup_unlock(void) | |||
691 | { | 750 | { |
692 | mutex_unlock(&cgroup_mutex); | 751 | mutex_unlock(&cgroup_mutex); |
693 | } | 752 | } |
753 | EXPORT_SYMBOL_GPL(cgroup_unlock); | ||
694 | 754 | ||
695 | /* | 755 | /* |
696 | * A couple of forward declarations required, due to cyclic reference loop: | 756 | * A couple of forward declarations required, due to cyclic reference loop: |
@@ -742,6 +802,7 @@ static int cgroup_call_pre_destroy(struct cgroup *cgrp) | |||
742 | if (ret) | 802 | if (ret) |
743 | break; | 803 | break; |
744 | } | 804 | } |
805 | |||
745 | return ret; | 806 | return ret; |
746 | } | 807 | } |
747 | 808 | ||
@@ -869,7 +930,11 @@ void cgroup_release_and_wakeup_rmdir(struct cgroup_subsys_state *css) | |||
869 | css_put(css); | 930 | css_put(css); |
870 | } | 931 | } |
871 | 932 | ||
872 | 933 | /* | |
934 | * Call with cgroup_mutex held. Drops reference counts on modules, including | ||
935 | * any duplicate ones that parse_cgroupfs_options took. If this function | ||
936 | * returns an error, no reference counts are touched. | ||
937 | */ | ||
873 | static int rebind_subsystems(struct cgroupfs_root *root, | 938 | static int rebind_subsystems(struct cgroupfs_root *root, |
874 | unsigned long final_bits) | 939 | unsigned long final_bits) |
875 | { | 940 | { |
@@ -877,6 +942,8 @@ static int rebind_subsystems(struct cgroupfs_root *root, | |||
877 | struct cgroup *cgrp = &root->top_cgroup; | 942 | struct cgroup *cgrp = &root->top_cgroup; |
878 | int i; | 943 | int i; |
879 | 944 | ||
945 | BUG_ON(!mutex_is_locked(&cgroup_mutex)); | ||
946 | |||
880 | removed_bits = root->actual_subsys_bits & ~final_bits; | 947 | removed_bits = root->actual_subsys_bits & ~final_bits; |
881 | added_bits = final_bits & ~root->actual_subsys_bits; | 948 | added_bits = final_bits & ~root->actual_subsys_bits; |
882 | /* Check that any added subsystems are currently free */ | 949 | /* Check that any added subsystems are currently free */ |
@@ -885,6 +952,12 @@ static int rebind_subsystems(struct cgroupfs_root *root, | |||
885 | struct cgroup_subsys *ss = subsys[i]; | 952 | struct cgroup_subsys *ss = subsys[i]; |
886 | if (!(bit & added_bits)) | 953 | if (!(bit & added_bits)) |
887 | continue; | 954 | continue; |
955 | /* | ||
956 | * Nobody should tell us to do a subsys that doesn't exist: | ||
957 | * parse_cgroupfs_options should catch that case and refcounts | ||
958 | * ensure that subsystems won't disappear once selected. | ||
959 | */ | ||
960 | BUG_ON(ss == NULL); | ||
888 | if (ss->root != &rootnode) { | 961 | if (ss->root != &rootnode) { |
889 | /* Subsystem isn't free */ | 962 | /* Subsystem isn't free */ |
890 | return -EBUSY; | 963 | return -EBUSY; |
@@ -904,6 +977,7 @@ static int rebind_subsystems(struct cgroupfs_root *root, | |||
904 | unsigned long bit = 1UL << i; | 977 | unsigned long bit = 1UL << i; |
905 | if (bit & added_bits) { | 978 | if (bit & added_bits) { |
906 | /* We're binding this subsystem to this hierarchy */ | 979 | /* We're binding this subsystem to this hierarchy */ |
980 | BUG_ON(ss == NULL); | ||
907 | BUG_ON(cgrp->subsys[i]); | 981 | BUG_ON(cgrp->subsys[i]); |
908 | BUG_ON(!dummytop->subsys[i]); | 982 | BUG_ON(!dummytop->subsys[i]); |
909 | BUG_ON(dummytop->subsys[i]->cgroup != dummytop); | 983 | BUG_ON(dummytop->subsys[i]->cgroup != dummytop); |
@@ -915,8 +989,10 @@ static int rebind_subsystems(struct cgroupfs_root *root, | |||
915 | if (ss->bind) | 989 | if (ss->bind) |
916 | ss->bind(ss, cgrp); | 990 | ss->bind(ss, cgrp); |
917 | mutex_unlock(&ss->hierarchy_mutex); | 991 | mutex_unlock(&ss->hierarchy_mutex); |
992 | /* refcount was already taken, and we're keeping it */ | ||
918 | } else if (bit & removed_bits) { | 993 | } else if (bit & removed_bits) { |
919 | /* We're removing this subsystem */ | 994 | /* We're removing this subsystem */ |
995 | BUG_ON(ss == NULL); | ||
920 | BUG_ON(cgrp->subsys[i] != dummytop->subsys[i]); | 996 | BUG_ON(cgrp->subsys[i] != dummytop->subsys[i]); |
921 | BUG_ON(cgrp->subsys[i]->cgroup != cgrp); | 997 | BUG_ON(cgrp->subsys[i]->cgroup != cgrp); |
922 | mutex_lock(&ss->hierarchy_mutex); | 998 | mutex_lock(&ss->hierarchy_mutex); |
@@ -927,9 +1003,20 @@ static int rebind_subsystems(struct cgroupfs_root *root, | |||
927 | subsys[i]->root = &rootnode; | 1003 | subsys[i]->root = &rootnode; |
928 | list_move(&ss->sibling, &rootnode.subsys_list); | 1004 | list_move(&ss->sibling, &rootnode.subsys_list); |
929 | mutex_unlock(&ss->hierarchy_mutex); | 1005 | mutex_unlock(&ss->hierarchy_mutex); |
1006 | /* subsystem is now free - drop reference on module */ | ||
1007 | module_put(ss->module); | ||
930 | } else if (bit & final_bits) { | 1008 | } else if (bit & final_bits) { |
931 | /* Subsystem state should already exist */ | 1009 | /* Subsystem state should already exist */ |
1010 | BUG_ON(ss == NULL); | ||
932 | BUG_ON(!cgrp->subsys[i]); | 1011 | BUG_ON(!cgrp->subsys[i]); |
1012 | /* | ||
1013 | * a refcount was taken, but we already had one, so | ||
1014 | * drop the extra reference. | ||
1015 | */ | ||
1016 | module_put(ss->module); | ||
1017 | #ifdef CONFIG_MODULE_UNLOAD | ||
1018 | BUG_ON(ss->module && !module_refcount(ss->module)); | ||
1019 | #endif | ||
933 | } else { | 1020 | } else { |
934 | /* Subsystem state shouldn't exist */ | 1021 | /* Subsystem state shouldn't exist */ |
935 | BUG_ON(cgrp->subsys[i]); | 1022 | BUG_ON(cgrp->subsys[i]); |
@@ -971,13 +1058,20 @@ struct cgroup_sb_opts { | |||
971 | 1058 | ||
972 | }; | 1059 | }; |
973 | 1060 | ||
974 | /* Convert a hierarchy specifier into a bitmask of subsystems and | 1061 | /* |
975 | * flags. */ | 1062 | * Convert a hierarchy specifier into a bitmask of subsystems and flags. Call |
976 | static int parse_cgroupfs_options(char *data, | 1063 | * with cgroup_mutex held to protect the subsys[] array. This function takes |
977 | struct cgroup_sb_opts *opts) | 1064 | * refcounts on subsystems to be used, unless it returns error, in which case |
1065 | * no refcounts are taken. | ||
1066 | */ | ||
1067 | static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts) | ||
978 | { | 1068 | { |
979 | char *token, *o = data ?: "all"; | 1069 | char *token, *o = data ?: "all"; |
980 | unsigned long mask = (unsigned long)-1; | 1070 | unsigned long mask = (unsigned long)-1; |
1071 | int i; | ||
1072 | bool module_pin_failed = false; | ||
1073 | |||
1074 | BUG_ON(!mutex_is_locked(&cgroup_mutex)); | ||
981 | 1075 | ||
982 | #ifdef CONFIG_CPUSETS | 1076 | #ifdef CONFIG_CPUSETS |
983 | mask = ~(1UL << cpuset_subsys_id); | 1077 | mask = ~(1UL << cpuset_subsys_id); |
@@ -990,10 +1084,11 @@ static int parse_cgroupfs_options(char *data, | |||
990 | return -EINVAL; | 1084 | return -EINVAL; |
991 | if (!strcmp(token, "all")) { | 1085 | if (!strcmp(token, "all")) { |
992 | /* Add all non-disabled subsystems */ | 1086 | /* Add all non-disabled subsystems */ |
993 | int i; | ||
994 | opts->subsys_bits = 0; | 1087 | opts->subsys_bits = 0; |
995 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { | 1088 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { |
996 | struct cgroup_subsys *ss = subsys[i]; | 1089 | struct cgroup_subsys *ss = subsys[i]; |
1090 | if (ss == NULL) | ||
1091 | continue; | ||
997 | if (!ss->disabled) | 1092 | if (!ss->disabled) |
998 | opts->subsys_bits |= 1ul << i; | 1093 | opts->subsys_bits |= 1ul << i; |
999 | } | 1094 | } |
@@ -1011,7 +1106,6 @@ static int parse_cgroupfs_options(char *data, | |||
1011 | if (!opts->release_agent) | 1106 | if (!opts->release_agent) |
1012 | return -ENOMEM; | 1107 | return -ENOMEM; |
1013 | } else if (!strncmp(token, "name=", 5)) { | 1108 | } else if (!strncmp(token, "name=", 5)) { |
1014 | int i; | ||
1015 | const char *name = token + 5; | 1109 | const char *name = token + 5; |
1016 | /* Can't specify an empty name */ | 1110 | /* Can't specify an empty name */ |
1017 | if (!strlen(name)) | 1111 | if (!strlen(name)) |
@@ -1035,9 +1129,10 @@ static int parse_cgroupfs_options(char *data, | |||
1035 | return -ENOMEM; | 1129 | return -ENOMEM; |
1036 | } else { | 1130 | } else { |
1037 | struct cgroup_subsys *ss; | 1131 | struct cgroup_subsys *ss; |
1038 | int i; | ||
1039 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { | 1132 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { |
1040 | ss = subsys[i]; | 1133 | ss = subsys[i]; |
1134 | if (ss == NULL) | ||
1135 | continue; | ||
1041 | if (!strcmp(token, ss->name)) { | 1136 | if (!strcmp(token, ss->name)) { |
1042 | if (!ss->disabled) | 1137 | if (!ss->disabled) |
1043 | set_bit(i, &opts->subsys_bits); | 1138 | set_bit(i, &opts->subsys_bits); |
@@ -1072,9 +1167,54 @@ static int parse_cgroupfs_options(char *data, | |||
1072 | if (!opts->subsys_bits && !opts->name) | 1167 | if (!opts->subsys_bits && !opts->name) |
1073 | return -EINVAL; | 1168 | return -EINVAL; |
1074 | 1169 | ||
1170 | /* | ||
1171 | * Grab references on all the modules we'll need, so the subsystems | ||
1172 | * don't dance around before rebind_subsystems attaches them. This may | ||
1173 | * take duplicate reference counts on a subsystem that's already used, | ||
1174 | * but rebind_subsystems handles this case. | ||
1175 | */ | ||
1176 | for (i = CGROUP_BUILTIN_SUBSYS_COUNT; i < CGROUP_SUBSYS_COUNT; i++) { | ||
1177 | unsigned long bit = 1UL << i; | ||
1178 | |||
1179 | if (!(bit & opts->subsys_bits)) | ||
1180 | continue; | ||
1181 | if (!try_module_get(subsys[i]->module)) { | ||
1182 | module_pin_failed = true; | ||
1183 | break; | ||
1184 | } | ||
1185 | } | ||
1186 | if (module_pin_failed) { | ||
1187 | /* | ||
1188 | * oops, one of the modules was going away. this means that we | ||
1189 | * raced with a module_delete call, and to the user this is | ||
1190 | * essentially a "subsystem doesn't exist" case. | ||
1191 | */ | ||
1192 | for (i--; i >= CGROUP_BUILTIN_SUBSYS_COUNT; i--) { | ||
1193 | /* drop refcounts only on the ones we took */ | ||
1194 | unsigned long bit = 1UL << i; | ||
1195 | |||
1196 | if (!(bit & opts->subsys_bits)) | ||
1197 | continue; | ||
1198 | module_put(subsys[i]->module); | ||
1199 | } | ||
1200 | return -ENOENT; | ||
1201 | } | ||
1202 | |||
1075 | return 0; | 1203 | return 0; |
1076 | } | 1204 | } |
1077 | 1205 | ||
1206 | static void drop_parsed_module_refcounts(unsigned long subsys_bits) | ||
1207 | { | ||
1208 | int i; | ||
1209 | for (i = CGROUP_BUILTIN_SUBSYS_COUNT; i < CGROUP_SUBSYS_COUNT; i++) { | ||
1210 | unsigned long bit = 1UL << i; | ||
1211 | |||
1212 | if (!(bit & subsys_bits)) | ||
1213 | continue; | ||
1214 | module_put(subsys[i]->module); | ||
1215 | } | ||
1216 | } | ||
1217 | |||
1078 | static int cgroup_remount(struct super_block *sb, int *flags, char *data) | 1218 | static int cgroup_remount(struct super_block *sb, int *flags, char *data) |
1079 | { | 1219 | { |
1080 | int ret = 0; | 1220 | int ret = 0; |
@@ -1091,21 +1231,19 @@ static int cgroup_remount(struct super_block *sb, int *flags, char *data) | |||
1091 | if (ret) | 1231 | if (ret) |
1092 | goto out_unlock; | 1232 | goto out_unlock; |
1093 | 1233 | ||
1094 | /* Don't allow flags to change at remount */ | 1234 | /* Don't allow flags or name to change at remount */ |
1095 | if (opts.flags != root->flags) { | 1235 | if (opts.flags != root->flags || |
1096 | ret = -EINVAL; | 1236 | (opts.name && strcmp(opts.name, root->name))) { |
1097 | goto out_unlock; | ||
1098 | } | ||
1099 | |||
1100 | /* Don't allow name to change at remount */ | ||
1101 | if (opts.name && strcmp(opts.name, root->name)) { | ||
1102 | ret = -EINVAL; | 1237 | ret = -EINVAL; |
1238 | drop_parsed_module_refcounts(opts.subsys_bits); | ||
1103 | goto out_unlock; | 1239 | goto out_unlock; |
1104 | } | 1240 | } |
1105 | 1241 | ||
1106 | ret = rebind_subsystems(root, opts.subsys_bits); | 1242 | ret = rebind_subsystems(root, opts.subsys_bits); |
1107 | if (ret) | 1243 | if (ret) { |
1244 | drop_parsed_module_refcounts(opts.subsys_bits); | ||
1108 | goto out_unlock; | 1245 | goto out_unlock; |
1246 | } | ||
1109 | 1247 | ||
1110 | /* (re)populate subsystem files */ | 1248 | /* (re)populate subsystem files */ |
1111 | cgroup_populate_dir(cgrp); | 1249 | cgroup_populate_dir(cgrp); |
@@ -1136,6 +1274,8 @@ static void init_cgroup_housekeeping(struct cgroup *cgrp) | |||
1136 | INIT_LIST_HEAD(&cgrp->release_list); | 1274 | INIT_LIST_HEAD(&cgrp->release_list); |
1137 | INIT_LIST_HEAD(&cgrp->pidlists); | 1275 | INIT_LIST_HEAD(&cgrp->pidlists); |
1138 | mutex_init(&cgrp->pidlist_mutex); | 1276 | mutex_init(&cgrp->pidlist_mutex); |
1277 | INIT_LIST_HEAD(&cgrp->event_list); | ||
1278 | spin_lock_init(&cgrp->event_list_lock); | ||
1139 | } | 1279 | } |
1140 | 1280 | ||
1141 | static void init_cgroup_root(struct cgroupfs_root *root) | 1281 | static void init_cgroup_root(struct cgroupfs_root *root) |
@@ -1291,7 +1431,9 @@ static int cgroup_get_sb(struct file_system_type *fs_type, | |||
1291 | struct cgroupfs_root *new_root; | 1431 | struct cgroupfs_root *new_root; |
1292 | 1432 | ||
1293 | /* First find the desired set of subsystems */ | 1433 | /* First find the desired set of subsystems */ |
1434 | mutex_lock(&cgroup_mutex); | ||
1294 | ret = parse_cgroupfs_options(data, &opts); | 1435 | ret = parse_cgroupfs_options(data, &opts); |
1436 | mutex_unlock(&cgroup_mutex); | ||
1295 | if (ret) | 1437 | if (ret) |
1296 | goto out_err; | 1438 | goto out_err; |
1297 | 1439 | ||
@@ -1302,7 +1444,7 @@ static int cgroup_get_sb(struct file_system_type *fs_type, | |||
1302 | new_root = cgroup_root_from_opts(&opts); | 1444 | new_root = cgroup_root_from_opts(&opts); |
1303 | if (IS_ERR(new_root)) { | 1445 | if (IS_ERR(new_root)) { |
1304 | ret = PTR_ERR(new_root); | 1446 | ret = PTR_ERR(new_root); |
1305 | goto out_err; | 1447 | goto drop_modules; |
1306 | } | 1448 | } |
1307 | opts.new_root = new_root; | 1449 | opts.new_root = new_root; |
1308 | 1450 | ||
@@ -1311,7 +1453,7 @@ static int cgroup_get_sb(struct file_system_type *fs_type, | |||
1311 | if (IS_ERR(sb)) { | 1453 | if (IS_ERR(sb)) { |
1312 | ret = PTR_ERR(sb); | 1454 | ret = PTR_ERR(sb); |
1313 | cgroup_drop_root(opts.new_root); | 1455 | cgroup_drop_root(opts.new_root); |
1314 | goto out_err; | 1456 | goto drop_modules; |
1315 | } | 1457 | } |
1316 | 1458 | ||
1317 | root = sb->s_fs_info; | 1459 | root = sb->s_fs_info; |
@@ -1367,6 +1509,11 @@ static int cgroup_get_sb(struct file_system_type *fs_type, | |||
1367 | free_cg_links(&tmp_cg_links); | 1509 | free_cg_links(&tmp_cg_links); |
1368 | goto drop_new_super; | 1510 | goto drop_new_super; |
1369 | } | 1511 | } |
1512 | /* | ||
1513 | * There must be no failure case after here, since rebinding | ||
1514 | * takes care of subsystems' refcounts, which are explicitly | ||
1515 | * dropped in the failure exit path. | ||
1516 | */ | ||
1370 | 1517 | ||
1371 | /* EBUSY should be the only error here */ | 1518 | /* EBUSY should be the only error here */ |
1372 | BUG_ON(ret); | 1519 | BUG_ON(ret); |
@@ -1405,6 +1552,8 @@ static int cgroup_get_sb(struct file_system_type *fs_type, | |||
1405 | * any) is not needed | 1552 | * any) is not needed |
1406 | */ | 1553 | */ |
1407 | cgroup_drop_root(opts.new_root); | 1554 | cgroup_drop_root(opts.new_root); |
1555 | /* no subsys rebinding, so refcounts don't change */ | ||
1556 | drop_parsed_module_refcounts(opts.subsys_bits); | ||
1408 | } | 1557 | } |
1409 | 1558 | ||
1410 | simple_set_mnt(mnt, sb); | 1559 | simple_set_mnt(mnt, sb); |
@@ -1414,6 +1563,8 @@ static int cgroup_get_sb(struct file_system_type *fs_type, | |||
1414 | 1563 | ||
1415 | drop_new_super: | 1564 | drop_new_super: |
1416 | deactivate_locked_super(sb); | 1565 | deactivate_locked_super(sb); |
1566 | drop_modules: | ||
1567 | drop_parsed_module_refcounts(opts.subsys_bits); | ||
1417 | out_err: | 1568 | out_err: |
1418 | kfree(opts.release_agent); | 1569 | kfree(opts.release_agent); |
1419 | kfree(opts.name); | 1570 | kfree(opts.name); |
@@ -1527,6 +1678,7 @@ int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen) | |||
1527 | memmove(buf, start, buf + buflen - start); | 1678 | memmove(buf, start, buf + buflen - start); |
1528 | return 0; | 1679 | return 0; |
1529 | } | 1680 | } |
1681 | EXPORT_SYMBOL_GPL(cgroup_path); | ||
1530 | 1682 | ||
1531 | /** | 1683 | /** |
1532 | * cgroup_attach_task - attach task 'tsk' to cgroup 'cgrp' | 1684 | * cgroup_attach_task - attach task 'tsk' to cgroup 'cgrp' |
@@ -1539,7 +1691,7 @@ int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen) | |||
1539 | int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk) | 1691 | int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk) |
1540 | { | 1692 | { |
1541 | int retval = 0; | 1693 | int retval = 0; |
1542 | struct cgroup_subsys *ss; | 1694 | struct cgroup_subsys *ss, *failed_ss = NULL; |
1543 | struct cgroup *oldcgrp; | 1695 | struct cgroup *oldcgrp; |
1544 | struct css_set *cg; | 1696 | struct css_set *cg; |
1545 | struct css_set *newcg; | 1697 | struct css_set *newcg; |
@@ -1553,8 +1705,16 @@ int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk) | |||
1553 | for_each_subsys(root, ss) { | 1705 | for_each_subsys(root, ss) { |
1554 | if (ss->can_attach) { | 1706 | if (ss->can_attach) { |
1555 | retval = ss->can_attach(ss, cgrp, tsk, false); | 1707 | retval = ss->can_attach(ss, cgrp, tsk, false); |
1556 | if (retval) | 1708 | if (retval) { |
1557 | return retval; | 1709 | /* |
1710 | * Remember on which subsystem the can_attach() | ||
1711 | * failed, so that we only call cancel_attach() | ||
1712 | * against the subsystems whose can_attach() | ||
1713 | * succeeded. (See below) | ||
1714 | */ | ||
1715 | failed_ss = ss; | ||
1716 | goto out; | ||
1717 | } | ||
1558 | } | 1718 | } |
1559 | } | 1719 | } |
1560 | 1720 | ||
@@ -1568,14 +1728,17 @@ int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk) | |||
1568 | */ | 1728 | */ |
1569 | newcg = find_css_set(cg, cgrp); | 1729 | newcg = find_css_set(cg, cgrp); |
1570 | put_css_set(cg); | 1730 | put_css_set(cg); |
1571 | if (!newcg) | 1731 | if (!newcg) { |
1572 | return -ENOMEM; | 1732 | retval = -ENOMEM; |
1733 | goto out; | ||
1734 | } | ||
1573 | 1735 | ||
1574 | task_lock(tsk); | 1736 | task_lock(tsk); |
1575 | if (tsk->flags & PF_EXITING) { | 1737 | if (tsk->flags & PF_EXITING) { |
1576 | task_unlock(tsk); | 1738 | task_unlock(tsk); |
1577 | put_css_set(newcg); | 1739 | put_css_set(newcg); |
1578 | return -ESRCH; | 1740 | retval = -ESRCH; |
1741 | goto out; | ||
1579 | } | 1742 | } |
1580 | rcu_assign_pointer(tsk->cgroups, newcg); | 1743 | rcu_assign_pointer(tsk->cgroups, newcg); |
1581 | task_unlock(tsk); | 1744 | task_unlock(tsk); |
@@ -1601,7 +1764,22 @@ int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk) | |||
1601 | * is no longer empty. | 1764 | * is no longer empty. |
1602 | */ | 1765 | */ |
1603 | cgroup_wakeup_rmdir_waiter(cgrp); | 1766 | cgroup_wakeup_rmdir_waiter(cgrp); |
1604 | return 0; | 1767 | out: |
1768 | if (retval) { | ||
1769 | for_each_subsys(root, ss) { | ||
1770 | if (ss == failed_ss) | ||
1771 | /* | ||
1772 | * This subsystem was the one that failed the | ||
1773 | * can_attach() check earlier, so we don't need | ||
1774 | * to call cancel_attach() against it or any | ||
1775 | * remaining subsystems. | ||
1776 | */ | ||
1777 | break; | ||
1778 | if (ss->cancel_attach) | ||
1779 | ss->cancel_attach(ss, cgrp, tsk, false); | ||
1780 | } | ||
1781 | } | ||
1782 | return retval; | ||
1605 | } | 1783 | } |
1606 | 1784 | ||
1607 | /* | 1785 | /* |
@@ -1667,6 +1845,7 @@ bool cgroup_lock_live_group(struct cgroup *cgrp) | |||
1667 | } | 1845 | } |
1668 | return true; | 1846 | return true; |
1669 | } | 1847 | } |
1848 | EXPORT_SYMBOL_GPL(cgroup_lock_live_group); | ||
1670 | 1849 | ||
1671 | static int cgroup_release_agent_write(struct cgroup *cgrp, struct cftype *cft, | 1850 | static int cgroup_release_agent_write(struct cgroup *cgrp, struct cftype *cft, |
1672 | const char *buffer) | 1851 | const char *buffer) |
@@ -1935,6 +2114,16 @@ static const struct inode_operations cgroup_dir_inode_operations = { | |||
1935 | .rename = cgroup_rename, | 2114 | .rename = cgroup_rename, |
1936 | }; | 2115 | }; |
1937 | 2116 | ||
2117 | /* | ||
2118 | * Check if a file is a control file | ||
2119 | */ | ||
2120 | static inline struct cftype *__file_cft(struct file *file) | ||
2121 | { | ||
2122 | if (file->f_dentry->d_inode->i_fop != &cgroup_file_operations) | ||
2123 | return ERR_PTR(-EINVAL); | ||
2124 | return __d_cft(file->f_dentry); | ||
2125 | } | ||
2126 | |||
1938 | static int cgroup_create_file(struct dentry *dentry, mode_t mode, | 2127 | static int cgroup_create_file(struct dentry *dentry, mode_t mode, |
1939 | struct super_block *sb) | 2128 | struct super_block *sb) |
1940 | { | 2129 | { |
@@ -2054,6 +2243,7 @@ int cgroup_add_file(struct cgroup *cgrp, | |||
2054 | error = PTR_ERR(dentry); | 2243 | error = PTR_ERR(dentry); |
2055 | return error; | 2244 | return error; |
2056 | } | 2245 | } |
2246 | EXPORT_SYMBOL_GPL(cgroup_add_file); | ||
2057 | 2247 | ||
2058 | int cgroup_add_files(struct cgroup *cgrp, | 2248 | int cgroup_add_files(struct cgroup *cgrp, |
2059 | struct cgroup_subsys *subsys, | 2249 | struct cgroup_subsys *subsys, |
@@ -2068,6 +2258,7 @@ int cgroup_add_files(struct cgroup *cgrp, | |||
2068 | } | 2258 | } |
2069 | return 0; | 2259 | return 0; |
2070 | } | 2260 | } |
2261 | EXPORT_SYMBOL_GPL(cgroup_add_files); | ||
2071 | 2262 | ||
2072 | /** | 2263 | /** |
2073 | * cgroup_task_count - count the number of tasks in a cgroup. | 2264 | * cgroup_task_count - count the number of tasks in a cgroup. |
@@ -2453,7 +2644,8 @@ static struct cgroup_pidlist *cgroup_pidlist_find(struct cgroup *cgrp, | |||
2453 | { | 2644 | { |
2454 | struct cgroup_pidlist *l; | 2645 | struct cgroup_pidlist *l; |
2455 | /* don't need task_nsproxy() if we're looking at ourself */ | 2646 | /* don't need task_nsproxy() if we're looking at ourself */ |
2456 | struct pid_namespace *ns = get_pid_ns(current->nsproxy->pid_ns); | 2647 | struct pid_namespace *ns = current->nsproxy->pid_ns; |
2648 | |||
2457 | /* | 2649 | /* |
2458 | * We can't drop the pidlist_mutex before taking the l->mutex in case | 2650 | * We can't drop the pidlist_mutex before taking the l->mutex in case |
2459 | * the last ref-holder is trying to remove l from the list at the same | 2651 | * the last ref-holder is trying to remove l from the list at the same |
@@ -2463,12 +2655,9 @@ static struct cgroup_pidlist *cgroup_pidlist_find(struct cgroup *cgrp, | |||
2463 | mutex_lock(&cgrp->pidlist_mutex); | 2655 | mutex_lock(&cgrp->pidlist_mutex); |
2464 | list_for_each_entry(l, &cgrp->pidlists, links) { | 2656 | list_for_each_entry(l, &cgrp->pidlists, links) { |
2465 | if (l->key.type == type && l->key.ns == ns) { | 2657 | if (l->key.type == type && l->key.ns == ns) { |
2466 | /* found a matching list - drop the extra refcount */ | ||
2467 | put_pid_ns(ns); | ||
2468 | /* make sure l doesn't vanish out from under us */ | 2658 | /* make sure l doesn't vanish out from under us */ |
2469 | down_write(&l->mutex); | 2659 | down_write(&l->mutex); |
2470 | mutex_unlock(&cgrp->pidlist_mutex); | 2660 | mutex_unlock(&cgrp->pidlist_mutex); |
2471 | l->use_count++; | ||
2472 | return l; | 2661 | return l; |
2473 | } | 2662 | } |
2474 | } | 2663 | } |
@@ -2476,13 +2665,12 @@ static struct cgroup_pidlist *cgroup_pidlist_find(struct cgroup *cgrp, | |||
2476 | l = kmalloc(sizeof(struct cgroup_pidlist), GFP_KERNEL); | 2665 | l = kmalloc(sizeof(struct cgroup_pidlist), GFP_KERNEL); |
2477 | if (!l) { | 2666 | if (!l) { |
2478 | mutex_unlock(&cgrp->pidlist_mutex); | 2667 | mutex_unlock(&cgrp->pidlist_mutex); |
2479 | put_pid_ns(ns); | ||
2480 | return l; | 2668 | return l; |
2481 | } | 2669 | } |
2482 | init_rwsem(&l->mutex); | 2670 | init_rwsem(&l->mutex); |
2483 | down_write(&l->mutex); | 2671 | down_write(&l->mutex); |
2484 | l->key.type = type; | 2672 | l->key.type = type; |
2485 | l->key.ns = ns; | 2673 | l->key.ns = get_pid_ns(ns); |
2486 | l->use_count = 0; /* don't increment here */ | 2674 | l->use_count = 0; /* don't increment here */ |
2487 | l->list = NULL; | 2675 | l->list = NULL; |
2488 | l->owner = cgrp; | 2676 | l->owner = cgrp; |
@@ -2790,6 +2978,174 @@ static int cgroup_write_notify_on_release(struct cgroup *cgrp, | |||
2790 | } | 2978 | } |
2791 | 2979 | ||
2792 | /* | 2980 | /* |
2981 | * Unregister event and free resources. | ||
2982 | * | ||
2983 | * Gets called from workqueue. | ||
2984 | */ | ||
2985 | static void cgroup_event_remove(struct work_struct *work) | ||
2986 | { | ||
2987 | struct cgroup_event *event = container_of(work, struct cgroup_event, | ||
2988 | remove); | ||
2989 | struct cgroup *cgrp = event->cgrp; | ||
2990 | |||
2991 | /* TODO: check return code */ | ||
2992 | event->cft->unregister_event(cgrp, event->cft, event->eventfd); | ||
2993 | |||
2994 | eventfd_ctx_put(event->eventfd); | ||
2995 | kfree(event); | ||
2996 | dput(cgrp->dentry); | ||
2997 | } | ||
2998 | |||
2999 | /* | ||
3000 | * Gets called on POLLHUP on eventfd when user closes it. | ||
3001 | * | ||
3002 | * Called with wqh->lock held and interrupts disabled. | ||
3003 | */ | ||
3004 | static int cgroup_event_wake(wait_queue_t *wait, unsigned mode, | ||
3005 | int sync, void *key) | ||
3006 | { | ||
3007 | struct cgroup_event *event = container_of(wait, | ||
3008 | struct cgroup_event, wait); | ||
3009 | struct cgroup *cgrp = event->cgrp; | ||
3010 | unsigned long flags = (unsigned long)key; | ||
3011 | |||
3012 | if (flags & POLLHUP) { | ||
3013 | remove_wait_queue_locked(event->wqh, &event->wait); | ||
3014 | spin_lock(&cgrp->event_list_lock); | ||
3015 | list_del(&event->list); | ||
3016 | spin_unlock(&cgrp->event_list_lock); | ||
3017 | /* | ||
3018 | * We are in atomic context, but cgroup_event_remove() may | ||
3019 | * sleep, so we have to call it in workqueue. | ||
3020 | */ | ||
3021 | schedule_work(&event->remove); | ||
3022 | } | ||
3023 | |||
3024 | return 0; | ||
3025 | } | ||
3026 | |||
3027 | static void cgroup_event_ptable_queue_proc(struct file *file, | ||
3028 | wait_queue_head_t *wqh, poll_table *pt) | ||
3029 | { | ||
3030 | struct cgroup_event *event = container_of(pt, | ||
3031 | struct cgroup_event, pt); | ||
3032 | |||
3033 | event->wqh = wqh; | ||
3034 | add_wait_queue(wqh, &event->wait); | ||
3035 | } | ||
3036 | |||
3037 | /* | ||
3038 | * Parse input and register new cgroup event handler. | ||
3039 | * | ||
3040 | * Input must be in format '<event_fd> <control_fd> <args>'. | ||
3041 | * Interpretation of args is defined by control file implementation. | ||
3042 | */ | ||
3043 | static int cgroup_write_event_control(struct cgroup *cgrp, struct cftype *cft, | ||
3044 | const char *buffer) | ||
3045 | { | ||
3046 | struct cgroup_event *event = NULL; | ||
3047 | unsigned int efd, cfd; | ||
3048 | struct file *efile = NULL; | ||
3049 | struct file *cfile = NULL; | ||
3050 | char *endp; | ||
3051 | int ret; | ||
3052 | |||
3053 | efd = simple_strtoul(buffer, &endp, 10); | ||
3054 | if (*endp != ' ') | ||
3055 | return -EINVAL; | ||
3056 | buffer = endp + 1; | ||
3057 | |||
3058 | cfd = simple_strtoul(buffer, &endp, 10); | ||
3059 | if ((*endp != ' ') && (*endp != '\0')) | ||
3060 | return -EINVAL; | ||
3061 | buffer = endp + 1; | ||
3062 | |||
3063 | event = kzalloc(sizeof(*event), GFP_KERNEL); | ||
3064 | if (!event) | ||
3065 | return -ENOMEM; | ||
3066 | event->cgrp = cgrp; | ||
3067 | INIT_LIST_HEAD(&event->list); | ||
3068 | init_poll_funcptr(&event->pt, cgroup_event_ptable_queue_proc); | ||
3069 | init_waitqueue_func_entry(&event->wait, cgroup_event_wake); | ||
3070 | INIT_WORK(&event->remove, cgroup_event_remove); | ||
3071 | |||
3072 | efile = eventfd_fget(efd); | ||
3073 | if (IS_ERR(efile)) { | ||
3074 | ret = PTR_ERR(efile); | ||
3075 | goto fail; | ||
3076 | } | ||
3077 | |||
3078 | event->eventfd = eventfd_ctx_fileget(efile); | ||
3079 | if (IS_ERR(event->eventfd)) { | ||
3080 | ret = PTR_ERR(event->eventfd); | ||
3081 | goto fail; | ||
3082 | } | ||
3083 | |||
3084 | cfile = fget(cfd); | ||
3085 | if (!cfile) { | ||
3086 | ret = -EBADF; | ||
3087 | goto fail; | ||
3088 | } | ||
3089 | |||
3090 | /* the process need read permission on control file */ | ||
3091 | ret = file_permission(cfile, MAY_READ); | ||
3092 | if (ret < 0) | ||
3093 | goto fail; | ||
3094 | |||
3095 | event->cft = __file_cft(cfile); | ||
3096 | if (IS_ERR(event->cft)) { | ||
3097 | ret = PTR_ERR(event->cft); | ||
3098 | goto fail; | ||
3099 | } | ||
3100 | |||
3101 | if (!event->cft->register_event || !event->cft->unregister_event) { | ||
3102 | ret = -EINVAL; | ||
3103 | goto fail; | ||
3104 | } | ||
3105 | |||
3106 | ret = event->cft->register_event(cgrp, event->cft, | ||
3107 | event->eventfd, buffer); | ||
3108 | if (ret) | ||
3109 | goto fail; | ||
3110 | |||
3111 | if (efile->f_op->poll(efile, &event->pt) & POLLHUP) { | ||
3112 | event->cft->unregister_event(cgrp, event->cft, event->eventfd); | ||
3113 | ret = 0; | ||
3114 | goto fail; | ||
3115 | } | ||
3116 | |||
3117 | /* | ||
3118 | * Events should be removed after rmdir of cgroup directory, but before | ||
3119 | * destroying subsystem state objects. Let's take reference to cgroup | ||
3120 | * directory dentry to do that. | ||
3121 | */ | ||
3122 | dget(cgrp->dentry); | ||
3123 | |||
3124 | spin_lock(&cgrp->event_list_lock); | ||
3125 | list_add(&event->list, &cgrp->event_list); | ||
3126 | spin_unlock(&cgrp->event_list_lock); | ||
3127 | |||
3128 | fput(cfile); | ||
3129 | fput(efile); | ||
3130 | |||
3131 | return 0; | ||
3132 | |||
3133 | fail: | ||
3134 | if (cfile) | ||
3135 | fput(cfile); | ||
3136 | |||
3137 | if (event && event->eventfd && !IS_ERR(event->eventfd)) | ||
3138 | eventfd_ctx_put(event->eventfd); | ||
3139 | |||
3140 | if (!IS_ERR_OR_NULL(efile)) | ||
3141 | fput(efile); | ||
3142 | |||
3143 | kfree(event); | ||
3144 | |||
3145 | return ret; | ||
3146 | } | ||
3147 | |||
3148 | /* | ||
2793 | * for the common functions, 'private' gives the type of file | 3149 | * for the common functions, 'private' gives the type of file |
2794 | */ | 3150 | */ |
2795 | /* for hysterical raisins, we can't put this on the older files */ | 3151 | /* for hysterical raisins, we can't put this on the older files */ |
@@ -2814,6 +3170,11 @@ static struct cftype files[] = { | |||
2814 | .read_u64 = cgroup_read_notify_on_release, | 3170 | .read_u64 = cgroup_read_notify_on_release, |
2815 | .write_u64 = cgroup_write_notify_on_release, | 3171 | .write_u64 = cgroup_write_notify_on_release, |
2816 | }, | 3172 | }, |
3173 | { | ||
3174 | .name = CGROUP_FILE_GENERIC_PREFIX "event_control", | ||
3175 | .write_string = cgroup_write_event_control, | ||
3176 | .mode = S_IWUGO, | ||
3177 | }, | ||
2817 | }; | 3178 | }; |
2818 | 3179 | ||
2819 | static struct cftype cft_release_agent = { | 3180 | static struct cftype cft_release_agent = { |
@@ -2878,8 +3239,14 @@ static void cgroup_lock_hierarchy(struct cgroupfs_root *root) | |||
2878 | /* We need to take each hierarchy_mutex in a consistent order */ | 3239 | /* We need to take each hierarchy_mutex in a consistent order */ |
2879 | int i; | 3240 | int i; |
2880 | 3241 | ||
3242 | /* | ||
3243 | * No worry about a race with rebind_subsystems that might mess up the | ||
3244 | * locking order, since both parties are under cgroup_mutex. | ||
3245 | */ | ||
2881 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { | 3246 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { |
2882 | struct cgroup_subsys *ss = subsys[i]; | 3247 | struct cgroup_subsys *ss = subsys[i]; |
3248 | if (ss == NULL) | ||
3249 | continue; | ||
2883 | if (ss->root == root) | 3250 | if (ss->root == root) |
2884 | mutex_lock(&ss->hierarchy_mutex); | 3251 | mutex_lock(&ss->hierarchy_mutex); |
2885 | } | 3252 | } |
@@ -2891,6 +3258,8 @@ static void cgroup_unlock_hierarchy(struct cgroupfs_root *root) | |||
2891 | 3258 | ||
2892 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { | 3259 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { |
2893 | struct cgroup_subsys *ss = subsys[i]; | 3260 | struct cgroup_subsys *ss = subsys[i]; |
3261 | if (ss == NULL) | ||
3262 | continue; | ||
2894 | if (ss->root == root) | 3263 | if (ss->root == root) |
2895 | mutex_unlock(&ss->hierarchy_mutex); | 3264 | mutex_unlock(&ss->hierarchy_mutex); |
2896 | } | 3265 | } |
@@ -2937,14 +3306,17 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry, | |||
2937 | 3306 | ||
2938 | for_each_subsys(root, ss) { | 3307 | for_each_subsys(root, ss) { |
2939 | struct cgroup_subsys_state *css = ss->create(ss, cgrp); | 3308 | struct cgroup_subsys_state *css = ss->create(ss, cgrp); |
3309 | |||
2940 | if (IS_ERR(css)) { | 3310 | if (IS_ERR(css)) { |
2941 | err = PTR_ERR(css); | 3311 | err = PTR_ERR(css); |
2942 | goto err_destroy; | 3312 | goto err_destroy; |
2943 | } | 3313 | } |
2944 | init_cgroup_css(css, ss, cgrp); | 3314 | init_cgroup_css(css, ss, cgrp); |
2945 | if (ss->use_id) | 3315 | if (ss->use_id) { |
2946 | if (alloc_css_id(ss, parent, cgrp)) | 3316 | err = alloc_css_id(ss, parent, cgrp); |
3317 | if (err) | ||
2947 | goto err_destroy; | 3318 | goto err_destroy; |
3319 | } | ||
2948 | /* At error, ->destroy() callback has to free assigned ID. */ | 3320 | /* At error, ->destroy() callback has to free assigned ID. */ |
2949 | } | 3321 | } |
2950 | 3322 | ||
@@ -3011,11 +3383,16 @@ static int cgroup_has_css_refs(struct cgroup *cgrp) | |||
3011 | * synchronization other than RCU, and the subsystem linked | 3383 | * synchronization other than RCU, and the subsystem linked |
3012 | * list isn't RCU-safe */ | 3384 | * list isn't RCU-safe */ |
3013 | int i; | 3385 | int i; |
3386 | /* | ||
3387 | * We won't need to lock the subsys array, because the subsystems | ||
3388 | * we're concerned about aren't going anywhere since our cgroup root | ||
3389 | * has a reference on them. | ||
3390 | */ | ||
3014 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { | 3391 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { |
3015 | struct cgroup_subsys *ss = subsys[i]; | 3392 | struct cgroup_subsys *ss = subsys[i]; |
3016 | struct cgroup_subsys_state *css; | 3393 | struct cgroup_subsys_state *css; |
3017 | /* Skip subsystems not in this hierarchy */ | 3394 | /* Skip subsystems not present or not in this hierarchy */ |
3018 | if (ss->root != cgrp->root) | 3395 | if (ss == NULL || ss->root != cgrp->root) |
3019 | continue; | 3396 | continue; |
3020 | css = cgrp->subsys[ss->subsys_id]; | 3397 | css = cgrp->subsys[ss->subsys_id]; |
3021 | /* When called from check_for_release() it's possible | 3398 | /* When called from check_for_release() it's possible |
@@ -3089,6 +3466,7 @@ static int cgroup_rmdir(struct inode *unused_dir, struct dentry *dentry) | |||
3089 | struct dentry *d; | 3466 | struct dentry *d; |
3090 | struct cgroup *parent; | 3467 | struct cgroup *parent; |
3091 | DEFINE_WAIT(wait); | 3468 | DEFINE_WAIT(wait); |
3469 | struct cgroup_event *event, *tmp; | ||
3092 | int ret; | 3470 | int ret; |
3093 | 3471 | ||
3094 | /* the vfs holds both inode->i_mutex already */ | 3472 | /* the vfs holds both inode->i_mutex already */ |
@@ -3172,6 +3550,20 @@ again: | |||
3172 | set_bit(CGRP_RELEASABLE, &parent->flags); | 3550 | set_bit(CGRP_RELEASABLE, &parent->flags); |
3173 | check_for_release(parent); | 3551 | check_for_release(parent); |
3174 | 3552 | ||
3553 | /* | ||
3554 | * Unregister events and notify userspace. | ||
3555 | * Notify userspace about cgroup removing only after rmdir of cgroup | ||
3556 | * directory to avoid race between userspace and kernelspace | ||
3557 | */ | ||
3558 | spin_lock(&cgrp->event_list_lock); | ||
3559 | list_for_each_entry_safe(event, tmp, &cgrp->event_list, list) { | ||
3560 | list_del(&event->list); | ||
3561 | remove_wait_queue(event->wqh, &event->wait); | ||
3562 | eventfd_signal(event->eventfd, 1); | ||
3563 | schedule_work(&event->remove); | ||
3564 | } | ||
3565 | spin_unlock(&cgrp->event_list_lock); | ||
3566 | |||
3175 | mutex_unlock(&cgroup_mutex); | 3567 | mutex_unlock(&cgroup_mutex); |
3176 | return 0; | 3568 | return 0; |
3177 | } | 3569 | } |
@@ -3206,7 +3598,196 @@ static void __init cgroup_init_subsys(struct cgroup_subsys *ss) | |||
3206 | mutex_init(&ss->hierarchy_mutex); | 3598 | mutex_init(&ss->hierarchy_mutex); |
3207 | lockdep_set_class(&ss->hierarchy_mutex, &ss->subsys_key); | 3599 | lockdep_set_class(&ss->hierarchy_mutex, &ss->subsys_key); |
3208 | ss->active = 1; | 3600 | ss->active = 1; |
3601 | |||
3602 | /* this function shouldn't be used with modular subsystems, since they | ||
3603 | * need to register a subsys_id, among other things */ | ||
3604 | BUG_ON(ss->module); | ||
3605 | } | ||
3606 | |||
3607 | /** | ||
3608 | * cgroup_load_subsys: load and register a modular subsystem at runtime | ||
3609 | * @ss: the subsystem to load | ||
3610 | * | ||
3611 | * This function should be called in a modular subsystem's initcall. If the | ||
3612 | * subsytem is built as a module, it will be assigned a new subsys_id and set | ||
3613 | * up for use. If the subsystem is built-in anyway, work is delegated to the | ||
3614 | * simpler cgroup_init_subsys. | ||
3615 | */ | ||
3616 | int __init_or_module cgroup_load_subsys(struct cgroup_subsys *ss) | ||
3617 | { | ||
3618 | int i; | ||
3619 | struct cgroup_subsys_state *css; | ||
3620 | |||
3621 | /* check name and function validity */ | ||
3622 | if (ss->name == NULL || strlen(ss->name) > MAX_CGROUP_TYPE_NAMELEN || | ||
3623 | ss->create == NULL || ss->destroy == NULL) | ||
3624 | return -EINVAL; | ||
3625 | |||
3626 | /* | ||
3627 | * we don't support callbacks in modular subsystems. this check is | ||
3628 | * before the ss->module check for consistency; a subsystem that could | ||
3629 | * be a module should still have no callbacks even if the user isn't | ||
3630 | * compiling it as one. | ||
3631 | */ | ||
3632 | if (ss->fork || ss->exit) | ||
3633 | return -EINVAL; | ||
3634 | |||
3635 | /* | ||
3636 | * an optionally modular subsystem is built-in: we want to do nothing, | ||
3637 | * since cgroup_init_subsys will have already taken care of it. | ||
3638 | */ | ||
3639 | if (ss->module == NULL) { | ||
3640 | /* a few sanity checks */ | ||
3641 | BUG_ON(ss->subsys_id >= CGROUP_BUILTIN_SUBSYS_COUNT); | ||
3642 | BUG_ON(subsys[ss->subsys_id] != ss); | ||
3643 | return 0; | ||
3644 | } | ||
3645 | |||
3646 | /* | ||
3647 | * need to register a subsys id before anything else - for example, | ||
3648 | * init_cgroup_css needs it. | ||
3649 | */ | ||
3650 | mutex_lock(&cgroup_mutex); | ||
3651 | /* find the first empty slot in the array */ | ||
3652 | for (i = CGROUP_BUILTIN_SUBSYS_COUNT; i < CGROUP_SUBSYS_COUNT; i++) { | ||
3653 | if (subsys[i] == NULL) | ||
3654 | break; | ||
3655 | } | ||
3656 | if (i == CGROUP_SUBSYS_COUNT) { | ||
3657 | /* maximum number of subsystems already registered! */ | ||
3658 | mutex_unlock(&cgroup_mutex); | ||
3659 | return -EBUSY; | ||
3660 | } | ||
3661 | /* assign ourselves the subsys_id */ | ||
3662 | ss->subsys_id = i; | ||
3663 | subsys[i] = ss; | ||
3664 | |||
3665 | /* | ||
3666 | * no ss->create seems to need anything important in the ss struct, so | ||
3667 | * this can happen first (i.e. before the rootnode attachment). | ||
3668 | */ | ||
3669 | css = ss->create(ss, dummytop); | ||
3670 | if (IS_ERR(css)) { | ||
3671 | /* failure case - need to deassign the subsys[] slot. */ | ||
3672 | subsys[i] = NULL; | ||
3673 | mutex_unlock(&cgroup_mutex); | ||
3674 | return PTR_ERR(css); | ||
3675 | } | ||
3676 | |||
3677 | list_add(&ss->sibling, &rootnode.subsys_list); | ||
3678 | ss->root = &rootnode; | ||
3679 | |||
3680 | /* our new subsystem will be attached to the dummy hierarchy. */ | ||
3681 | init_cgroup_css(css, ss, dummytop); | ||
3682 | /* init_idr must be after init_cgroup_css because it sets css->id. */ | ||
3683 | if (ss->use_id) { | ||
3684 | int ret = cgroup_init_idr(ss, css); | ||
3685 | if (ret) { | ||
3686 | dummytop->subsys[ss->subsys_id] = NULL; | ||
3687 | ss->destroy(ss, dummytop); | ||
3688 | subsys[i] = NULL; | ||
3689 | mutex_unlock(&cgroup_mutex); | ||
3690 | return ret; | ||
3691 | } | ||
3692 | } | ||
3693 | |||
3694 | /* | ||
3695 | * Now we need to entangle the css into the existing css_sets. unlike | ||
3696 | * in cgroup_init_subsys, there are now multiple css_sets, so each one | ||
3697 | * will need a new pointer to it; done by iterating the css_set_table. | ||
3698 | * furthermore, modifying the existing css_sets will corrupt the hash | ||
3699 | * table state, so each changed css_set will need its hash recomputed. | ||
3700 | * this is all done under the css_set_lock. | ||
3701 | */ | ||
3702 | write_lock(&css_set_lock); | ||
3703 | for (i = 0; i < CSS_SET_TABLE_SIZE; i++) { | ||
3704 | struct css_set *cg; | ||
3705 | struct hlist_node *node, *tmp; | ||
3706 | struct hlist_head *bucket = &css_set_table[i], *new_bucket; | ||
3707 | |||
3708 | hlist_for_each_entry_safe(cg, node, tmp, bucket, hlist) { | ||
3709 | /* skip entries that we already rehashed */ | ||
3710 | if (cg->subsys[ss->subsys_id]) | ||
3711 | continue; | ||
3712 | /* remove existing entry */ | ||
3713 | hlist_del(&cg->hlist); | ||
3714 | /* set new value */ | ||
3715 | cg->subsys[ss->subsys_id] = css; | ||
3716 | /* recompute hash and restore entry */ | ||
3717 | new_bucket = css_set_hash(cg->subsys); | ||
3718 | hlist_add_head(&cg->hlist, new_bucket); | ||
3719 | } | ||
3720 | } | ||
3721 | write_unlock(&css_set_lock); | ||
3722 | |||
3723 | mutex_init(&ss->hierarchy_mutex); | ||
3724 | lockdep_set_class(&ss->hierarchy_mutex, &ss->subsys_key); | ||
3725 | ss->active = 1; | ||
3726 | |||
3727 | /* success! */ | ||
3728 | mutex_unlock(&cgroup_mutex); | ||
3729 | return 0; | ||
3209 | } | 3730 | } |
3731 | EXPORT_SYMBOL_GPL(cgroup_load_subsys); | ||
3732 | |||
3733 | /** | ||
3734 | * cgroup_unload_subsys: unload a modular subsystem | ||
3735 | * @ss: the subsystem to unload | ||
3736 | * | ||
3737 | * This function should be called in a modular subsystem's exitcall. When this | ||
3738 | * function is invoked, the refcount on the subsystem's module will be 0, so | ||
3739 | * the subsystem will not be attached to any hierarchy. | ||
3740 | */ | ||
3741 | void cgroup_unload_subsys(struct cgroup_subsys *ss) | ||
3742 | { | ||
3743 | struct cg_cgroup_link *link; | ||
3744 | struct hlist_head *hhead; | ||
3745 | |||
3746 | BUG_ON(ss->module == NULL); | ||
3747 | |||
3748 | /* | ||
3749 | * we shouldn't be called if the subsystem is in use, and the use of | ||
3750 | * try_module_get in parse_cgroupfs_options should ensure that it | ||
3751 | * doesn't start being used while we're killing it off. | ||
3752 | */ | ||
3753 | BUG_ON(ss->root != &rootnode); | ||
3754 | |||
3755 | mutex_lock(&cgroup_mutex); | ||
3756 | /* deassign the subsys_id */ | ||
3757 | BUG_ON(ss->subsys_id < CGROUP_BUILTIN_SUBSYS_COUNT); | ||
3758 | subsys[ss->subsys_id] = NULL; | ||
3759 | |||
3760 | /* remove subsystem from rootnode's list of subsystems */ | ||
3761 | list_del(&ss->sibling); | ||
3762 | |||
3763 | /* | ||
3764 | * disentangle the css from all css_sets attached to the dummytop. as | ||
3765 | * in loading, we need to pay our respects to the hashtable gods. | ||
3766 | */ | ||
3767 | write_lock(&css_set_lock); | ||
3768 | list_for_each_entry(link, &dummytop->css_sets, cgrp_link_list) { | ||
3769 | struct css_set *cg = link->cg; | ||
3770 | |||
3771 | hlist_del(&cg->hlist); | ||
3772 | BUG_ON(!cg->subsys[ss->subsys_id]); | ||
3773 | cg->subsys[ss->subsys_id] = NULL; | ||
3774 | hhead = css_set_hash(cg->subsys); | ||
3775 | hlist_add_head(&cg->hlist, hhead); | ||
3776 | } | ||
3777 | write_unlock(&css_set_lock); | ||
3778 | |||
3779 | /* | ||
3780 | * remove subsystem's css from the dummytop and free it - need to free | ||
3781 | * before marking as null because ss->destroy needs the cgrp->subsys | ||
3782 | * pointer to find their state. note that this also takes care of | ||
3783 | * freeing the css_id. | ||
3784 | */ | ||
3785 | ss->destroy(ss, dummytop); | ||
3786 | dummytop->subsys[ss->subsys_id] = NULL; | ||
3787 | |||
3788 | mutex_unlock(&cgroup_mutex); | ||
3789 | } | ||
3790 | EXPORT_SYMBOL_GPL(cgroup_unload_subsys); | ||
3210 | 3791 | ||
3211 | /** | 3792 | /** |
3212 | * cgroup_init_early - cgroup initialization at system boot | 3793 | * cgroup_init_early - cgroup initialization at system boot |
@@ -3236,7 +3817,8 @@ int __init cgroup_init_early(void) | |||
3236 | for (i = 0; i < CSS_SET_TABLE_SIZE; i++) | 3817 | for (i = 0; i < CSS_SET_TABLE_SIZE; i++) |
3237 | INIT_HLIST_HEAD(&css_set_table[i]); | 3818 | INIT_HLIST_HEAD(&css_set_table[i]); |
3238 | 3819 | ||
3239 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { | 3820 | /* at bootup time, we don't worry about modular subsystems */ |
3821 | for (i = 0; i < CGROUP_BUILTIN_SUBSYS_COUNT; i++) { | ||
3240 | struct cgroup_subsys *ss = subsys[i]; | 3822 | struct cgroup_subsys *ss = subsys[i]; |
3241 | 3823 | ||
3242 | BUG_ON(!ss->name); | 3824 | BUG_ON(!ss->name); |
@@ -3271,12 +3853,13 @@ int __init cgroup_init(void) | |||
3271 | if (err) | 3853 | if (err) |
3272 | return err; | 3854 | return err; |
3273 | 3855 | ||
3274 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { | 3856 | /* at bootup time, we don't worry about modular subsystems */ |
3857 | for (i = 0; i < CGROUP_BUILTIN_SUBSYS_COUNT; i++) { | ||
3275 | struct cgroup_subsys *ss = subsys[i]; | 3858 | struct cgroup_subsys *ss = subsys[i]; |
3276 | if (!ss->early_init) | 3859 | if (!ss->early_init) |
3277 | cgroup_init_subsys(ss); | 3860 | cgroup_init_subsys(ss); |
3278 | if (ss->use_id) | 3861 | if (ss->use_id) |
3279 | cgroup_subsys_init_idr(ss); | 3862 | cgroup_init_idr(ss, init_css_set.subsys[ss->subsys_id]); |
3280 | } | 3863 | } |
3281 | 3864 | ||
3282 | /* Add init_css_set to the hash table */ | 3865 | /* Add init_css_set to the hash table */ |
@@ -3380,9 +3963,16 @@ static int proc_cgroupstats_show(struct seq_file *m, void *v) | |||
3380 | int i; | 3963 | int i; |
3381 | 3964 | ||
3382 | seq_puts(m, "#subsys_name\thierarchy\tnum_cgroups\tenabled\n"); | 3965 | seq_puts(m, "#subsys_name\thierarchy\tnum_cgroups\tenabled\n"); |
3966 | /* | ||
3967 | * ideally we don't want subsystems moving around while we do this. | ||
3968 | * cgroup_mutex is also necessary to guarantee an atomic snapshot of | ||
3969 | * subsys/hierarchy state. | ||
3970 | */ | ||
3383 | mutex_lock(&cgroup_mutex); | 3971 | mutex_lock(&cgroup_mutex); |
3384 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { | 3972 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { |
3385 | struct cgroup_subsys *ss = subsys[i]; | 3973 | struct cgroup_subsys *ss = subsys[i]; |
3974 | if (ss == NULL) | ||
3975 | continue; | ||
3386 | seq_printf(m, "%s\t%d\t%d\t%d\n", | 3976 | seq_printf(m, "%s\t%d\t%d\t%d\n", |
3387 | ss->name, ss->root->hierarchy_id, | 3977 | ss->name, ss->root->hierarchy_id, |
3388 | ss->root->number_of_cgroups, !ss->disabled); | 3978 | ss->root->number_of_cgroups, !ss->disabled); |
@@ -3440,7 +4030,12 @@ void cgroup_fork_callbacks(struct task_struct *child) | |||
3440 | { | 4030 | { |
3441 | if (need_forkexit_callback) { | 4031 | if (need_forkexit_callback) { |
3442 | int i; | 4032 | int i; |
3443 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { | 4033 | /* |
4034 | * forkexit callbacks are only supported for builtin | ||
4035 | * subsystems, and the builtin section of the subsys array is | ||
4036 | * immutable, so we don't need to lock the subsys array here. | ||
4037 | */ | ||
4038 | for (i = 0; i < CGROUP_BUILTIN_SUBSYS_COUNT; i++) { | ||
3444 | struct cgroup_subsys *ss = subsys[i]; | 4039 | struct cgroup_subsys *ss = subsys[i]; |
3445 | if (ss->fork) | 4040 | if (ss->fork) |
3446 | ss->fork(ss, child); | 4041 | ss->fork(ss, child); |
@@ -3509,7 +4104,11 @@ void cgroup_exit(struct task_struct *tsk, int run_callbacks) | |||
3509 | struct css_set *cg; | 4104 | struct css_set *cg; |
3510 | 4105 | ||
3511 | if (run_callbacks && need_forkexit_callback) { | 4106 | if (run_callbacks && need_forkexit_callback) { |
3512 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { | 4107 | /* |
4108 | * modular subsystems can't use callbacks, so no need to lock | ||
4109 | * the subsys array | ||
4110 | */ | ||
4111 | for (i = 0; i < CGROUP_BUILTIN_SUBSYS_COUNT; i++) { | ||
3513 | struct cgroup_subsys *ss = subsys[i]; | 4112 | struct cgroup_subsys *ss = subsys[i]; |
3514 | if (ss->exit) | 4113 | if (ss->exit) |
3515 | ss->exit(ss, tsk); | 4114 | ss->exit(ss, tsk); |
@@ -3703,12 +4302,13 @@ static void check_for_release(struct cgroup *cgrp) | |||
3703 | } | 4302 | } |
3704 | } | 4303 | } |
3705 | 4304 | ||
3706 | void __css_put(struct cgroup_subsys_state *css) | 4305 | /* Caller must verify that the css is not for root cgroup */ |
4306 | void __css_put(struct cgroup_subsys_state *css, int count) | ||
3707 | { | 4307 | { |
3708 | struct cgroup *cgrp = css->cgroup; | 4308 | struct cgroup *cgrp = css->cgroup; |
3709 | int val; | 4309 | int val; |
3710 | rcu_read_lock(); | 4310 | rcu_read_lock(); |
3711 | val = atomic_dec_return(&css->refcnt); | 4311 | val = atomic_sub_return(count, &css->refcnt); |
3712 | if (val == 1) { | 4312 | if (val == 1) { |
3713 | if (notify_on_release(cgrp)) { | 4313 | if (notify_on_release(cgrp)) { |
3714 | set_bit(CGRP_RELEASABLE, &cgrp->flags); | 4314 | set_bit(CGRP_RELEASABLE, &cgrp->flags); |
@@ -3719,6 +4319,7 @@ void __css_put(struct cgroup_subsys_state *css) | |||
3719 | rcu_read_unlock(); | 4319 | rcu_read_unlock(); |
3720 | WARN_ON_ONCE(val < 1); | 4320 | WARN_ON_ONCE(val < 1); |
3721 | } | 4321 | } |
4322 | EXPORT_SYMBOL_GPL(__css_put); | ||
3722 | 4323 | ||
3723 | /* | 4324 | /* |
3724 | * Notify userspace when a cgroup is released, by running the | 4325 | * Notify userspace when a cgroup is released, by running the |
@@ -3800,8 +4401,11 @@ static int __init cgroup_disable(char *str) | |||
3800 | while ((token = strsep(&str, ",")) != NULL) { | 4401 | while ((token = strsep(&str, ",")) != NULL) { |
3801 | if (!*token) | 4402 | if (!*token) |
3802 | continue; | 4403 | continue; |
3803 | 4404 | /* | |
3804 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { | 4405 | * cgroup_disable, being at boot time, can't know about module |
4406 | * subsystems, so we don't worry about them. | ||
4407 | */ | ||
4408 | for (i = 0; i < CGROUP_BUILTIN_SUBSYS_COUNT; i++) { | ||
3805 | struct cgroup_subsys *ss = subsys[i]; | 4409 | struct cgroup_subsys *ss = subsys[i]; |
3806 | 4410 | ||
3807 | if (!strcmp(token, ss->name)) { | 4411 | if (!strcmp(token, ss->name)) { |
@@ -3831,6 +4435,7 @@ unsigned short css_id(struct cgroup_subsys_state *css) | |||
3831 | return cssid->id; | 4435 | return cssid->id; |
3832 | return 0; | 4436 | return 0; |
3833 | } | 4437 | } |
4438 | EXPORT_SYMBOL_GPL(css_id); | ||
3834 | 4439 | ||
3835 | unsigned short css_depth(struct cgroup_subsys_state *css) | 4440 | unsigned short css_depth(struct cgroup_subsys_state *css) |
3836 | { | 4441 | { |
@@ -3840,6 +4445,7 @@ unsigned short css_depth(struct cgroup_subsys_state *css) | |||
3840 | return cssid->depth; | 4445 | return cssid->depth; |
3841 | return 0; | 4446 | return 0; |
3842 | } | 4447 | } |
4448 | EXPORT_SYMBOL_GPL(css_depth); | ||
3843 | 4449 | ||
3844 | bool css_is_ancestor(struct cgroup_subsys_state *child, | 4450 | bool css_is_ancestor(struct cgroup_subsys_state *child, |
3845 | const struct cgroup_subsys_state *root) | 4451 | const struct cgroup_subsys_state *root) |
@@ -3876,6 +4482,7 @@ void free_css_id(struct cgroup_subsys *ss, struct cgroup_subsys_state *css) | |||
3876 | spin_unlock(&ss->id_lock); | 4482 | spin_unlock(&ss->id_lock); |
3877 | call_rcu(&id->rcu_head, __free_css_id_cb); | 4483 | call_rcu(&id->rcu_head, __free_css_id_cb); |
3878 | } | 4484 | } |
4485 | EXPORT_SYMBOL_GPL(free_css_id); | ||
3879 | 4486 | ||
3880 | /* | 4487 | /* |
3881 | * This is called by init or create(). Then, calls to this function are | 4488 | * This is called by init or create(). Then, calls to this function are |
@@ -3925,15 +4532,14 @@ err_out: | |||
3925 | 4532 | ||
3926 | } | 4533 | } |
3927 | 4534 | ||
3928 | static int __init cgroup_subsys_init_idr(struct cgroup_subsys *ss) | 4535 | static int __init_or_module cgroup_init_idr(struct cgroup_subsys *ss, |
4536 | struct cgroup_subsys_state *rootcss) | ||
3929 | { | 4537 | { |
3930 | struct css_id *newid; | 4538 | struct css_id *newid; |
3931 | struct cgroup_subsys_state *rootcss; | ||
3932 | 4539 | ||
3933 | spin_lock_init(&ss->id_lock); | 4540 | spin_lock_init(&ss->id_lock); |
3934 | idr_init(&ss->idr); | 4541 | idr_init(&ss->idr); |
3935 | 4542 | ||
3936 | rootcss = init_css_set.subsys[ss->subsys_id]; | ||
3937 | newid = get_new_cssid(ss, 0); | 4543 | newid = get_new_cssid(ss, 0); |
3938 | if (IS_ERR(newid)) | 4544 | if (IS_ERR(newid)) |
3939 | return PTR_ERR(newid); | 4545 | return PTR_ERR(newid); |
@@ -3993,6 +4599,7 @@ struct cgroup_subsys_state *css_lookup(struct cgroup_subsys *ss, int id) | |||
3993 | 4599 | ||
3994 | return rcu_dereference(cssid->css); | 4600 | return rcu_dereference(cssid->css); |
3995 | } | 4601 | } |
4602 | EXPORT_SYMBOL_GPL(css_lookup); | ||
3996 | 4603 | ||
3997 | /** | 4604 | /** |
3998 | * css_get_next - lookup next cgroup under specified hierarchy. | 4605 | * css_get_next - lookup next cgroup under specified hierarchy. |