diff options
Diffstat (limited to 'kernel/cgroup.c')
| -rw-r--r-- | kernel/cgroup.c | 130 |
1 files changed, 101 insertions, 29 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 7b69b8d0313d..5cf366965d0c 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
| @@ -243,6 +243,11 @@ static int notify_on_release(const struct cgroup *cgrp) | |||
| 243 | return test_bit(CGRP_NOTIFY_ON_RELEASE, &cgrp->flags); | 243 | return test_bit(CGRP_NOTIFY_ON_RELEASE, &cgrp->flags); |
| 244 | } | 244 | } |
| 245 | 245 | ||
| 246 | static int clone_children(const struct cgroup *cgrp) | ||
| 247 | { | ||
| 248 | return test_bit(CGRP_CLONE_CHILDREN, &cgrp->flags); | ||
| 249 | } | ||
| 250 | |||
| 246 | /* | 251 | /* |
| 247 | * for_each_subsys() allows you to iterate on each subsystem attached to | 252 | * for_each_subsys() allows you to iterate on each subsystem attached to |
| 248 | * an active hierarchy | 253 | * an active hierarchy |
| @@ -777,6 +782,7 @@ static struct inode *cgroup_new_inode(mode_t mode, struct super_block *sb) | |||
| 777 | struct inode *inode = new_inode(sb); | 782 | struct inode *inode = new_inode(sb); |
| 778 | 783 | ||
| 779 | if (inode) { | 784 | if (inode) { |
| 785 | inode->i_ino = get_next_ino(); | ||
| 780 | inode->i_mode = mode; | 786 | inode->i_mode = mode; |
| 781 | inode->i_uid = current_fsuid(); | 787 | inode->i_uid = current_fsuid(); |
| 782 | inode->i_gid = current_fsgid(); | 788 | inode->i_gid = current_fsgid(); |
| @@ -1039,6 +1045,8 @@ static int cgroup_show_options(struct seq_file *seq, struct vfsmount *vfs) | |||
| 1039 | seq_puts(seq, ",noprefix"); | 1045 | seq_puts(seq, ",noprefix"); |
| 1040 | if (strlen(root->release_agent_path)) | 1046 | if (strlen(root->release_agent_path)) |
| 1041 | seq_printf(seq, ",release_agent=%s", root->release_agent_path); | 1047 | seq_printf(seq, ",release_agent=%s", root->release_agent_path); |
| 1048 | if (clone_children(&root->top_cgroup)) | ||
| 1049 | seq_puts(seq, ",clone_children"); | ||
| 1042 | if (strlen(root->name)) | 1050 | if (strlen(root->name)) |
| 1043 | seq_printf(seq, ",name=%s", root->name); | 1051 | seq_printf(seq, ",name=%s", root->name); |
| 1044 | mutex_unlock(&cgroup_mutex); | 1052 | mutex_unlock(&cgroup_mutex); |
| @@ -1049,6 +1057,7 @@ struct cgroup_sb_opts { | |||
| 1049 | unsigned long subsys_bits; | 1057 | unsigned long subsys_bits; |
| 1050 | unsigned long flags; | 1058 | unsigned long flags; |
| 1051 | char *release_agent; | 1059 | char *release_agent; |
| 1060 | bool clone_children; | ||
| 1052 | char *name; | 1061 | char *name; |
| 1053 | /* User explicitly requested empty subsystem */ | 1062 | /* User explicitly requested empty subsystem */ |
| 1054 | bool none; | 1063 | bool none; |
| @@ -1065,7 +1074,8 @@ struct cgroup_sb_opts { | |||
| 1065 | */ | 1074 | */ |
| 1066 | static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts) | 1075 | static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts) |
| 1067 | { | 1076 | { |
| 1068 | char *token, *o = data ?: "all"; | 1077 | char *token, *o = data; |
| 1078 | bool all_ss = false, one_ss = false; | ||
| 1069 | unsigned long mask = (unsigned long)-1; | 1079 | unsigned long mask = (unsigned long)-1; |
| 1070 | int i; | 1080 | int i; |
| 1071 | bool module_pin_failed = false; | 1081 | bool module_pin_failed = false; |
| @@ -1081,22 +1091,27 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts) | |||
| 1081 | while ((token = strsep(&o, ",")) != NULL) { | 1091 | while ((token = strsep(&o, ",")) != NULL) { |
| 1082 | if (!*token) | 1092 | if (!*token) |
| 1083 | return -EINVAL; | 1093 | return -EINVAL; |
| 1084 | if (!strcmp(token, "all")) { | 1094 | if (!strcmp(token, "none")) { |
| 1085 | /* Add all non-disabled subsystems */ | ||
| 1086 | opts->subsys_bits = 0; | ||
| 1087 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { | ||
| 1088 | struct cgroup_subsys *ss = subsys[i]; | ||
| 1089 | if (ss == NULL) | ||
| 1090 | continue; | ||
| 1091 | if (!ss->disabled) | ||
| 1092 | opts->subsys_bits |= 1ul << i; | ||
| 1093 | } | ||
| 1094 | } else if (!strcmp(token, "none")) { | ||
| 1095 | /* Explicitly have no subsystems */ | 1095 | /* Explicitly have no subsystems */ |
| 1096 | opts->none = true; | 1096 | opts->none = true; |
| 1097 | } else if (!strcmp(token, "noprefix")) { | 1097 | continue; |
| 1098 | } | ||
| 1099 | if (!strcmp(token, "all")) { | ||
| 1100 | /* Mutually exclusive option 'all' + subsystem name */ | ||
| 1101 | if (one_ss) | ||
| 1102 | return -EINVAL; | ||
| 1103 | all_ss = true; | ||
| 1104 | continue; | ||
| 1105 | } | ||
| 1106 | if (!strcmp(token, "noprefix")) { | ||
| 1098 | set_bit(ROOT_NOPREFIX, &opts->flags); | 1107 | set_bit(ROOT_NOPREFIX, &opts->flags); |
| 1099 | } else if (!strncmp(token, "release_agent=", 14)) { | 1108 | continue; |
| 1109 | } | ||
| 1110 | if (!strcmp(token, "clone_children")) { | ||
| 1111 | opts->clone_children = true; | ||
| 1112 | continue; | ||
| 1113 | } | ||
| 1114 | if (!strncmp(token, "release_agent=", 14)) { | ||
| 1100 | /* Specifying two release agents is forbidden */ | 1115 | /* Specifying two release agents is forbidden */ |
| 1101 | if (opts->release_agent) | 1116 | if (opts->release_agent) |
| 1102 | return -EINVAL; | 1117 | return -EINVAL; |
| @@ -1104,7 +1119,9 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts) | |||
| 1104 | kstrndup(token + 14, PATH_MAX - 1, GFP_KERNEL); | 1119 | kstrndup(token + 14, PATH_MAX - 1, GFP_KERNEL); |
| 1105 | if (!opts->release_agent) | 1120 | if (!opts->release_agent) |
| 1106 | return -ENOMEM; | 1121 | return -ENOMEM; |
| 1107 | } else if (!strncmp(token, "name=", 5)) { | 1122 | continue; |
| 1123 | } | ||
| 1124 | if (!strncmp(token, "name=", 5)) { | ||
| 1108 | const char *name = token + 5; | 1125 | const char *name = token + 5; |
| 1109 | /* Can't specify an empty name */ | 1126 | /* Can't specify an empty name */ |
| 1110 | if (!strlen(name)) | 1127 | if (!strlen(name)) |
| @@ -1126,20 +1143,44 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts) | |||
| 1126 | GFP_KERNEL); | 1143 | GFP_KERNEL); |
| 1127 | if (!opts->name) | 1144 | if (!opts->name) |
| 1128 | return -ENOMEM; | 1145 | return -ENOMEM; |
| 1129 | } else { | 1146 | |
| 1130 | struct cgroup_subsys *ss; | 1147 | continue; |
| 1131 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { | 1148 | } |
| 1132 | ss = subsys[i]; | 1149 | |
| 1133 | if (ss == NULL) | 1150 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { |
| 1134 | continue; | 1151 | struct cgroup_subsys *ss = subsys[i]; |
| 1135 | if (!strcmp(token, ss->name)) { | 1152 | if (ss == NULL) |
| 1136 | if (!ss->disabled) | 1153 | continue; |
| 1137 | set_bit(i, &opts->subsys_bits); | 1154 | if (strcmp(token, ss->name)) |
| 1138 | break; | 1155 | continue; |
| 1139 | } | 1156 | if (ss->disabled) |
| 1140 | } | 1157 | continue; |
| 1141 | if (i == CGROUP_SUBSYS_COUNT) | 1158 | |
| 1142 | return -ENOENT; | 1159 | /* Mutually exclusive option 'all' + subsystem name */ |
| 1160 | if (all_ss) | ||
| 1161 | return -EINVAL; | ||
| 1162 | set_bit(i, &opts->subsys_bits); | ||
| 1163 | one_ss = true; | ||
| 1164 | |||
| 1165 | break; | ||
| 1166 | } | ||
| 1167 | if (i == CGROUP_SUBSYS_COUNT) | ||
| 1168 | return -ENOENT; | ||
| 1169 | } | ||
| 1170 | |||
| 1171 | /* | ||
| 1172 | * If the 'all' option was specified select all the subsystems, | ||
| 1173 | * otherwise 'all, 'none' and a subsystem name options were not | ||
| 1174 | * specified, let's default to 'all' | ||
| 1175 | */ | ||
| 1176 | if (all_ss || (!all_ss && !one_ss && !opts->none)) { | ||
| 1177 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { | ||
| 1178 | struct cgroup_subsys *ss = subsys[i]; | ||
| 1179 | if (ss == NULL) | ||
| 1180 | continue; | ||
| 1181 | if (ss->disabled) | ||
| 1182 | continue; | ||
| 1183 | set_bit(i, &opts->subsys_bits); | ||
| 1143 | } | 1184 | } |
| 1144 | } | 1185 | } |
| 1145 | 1186 | ||
| @@ -1354,6 +1395,8 @@ static struct cgroupfs_root *cgroup_root_from_opts(struct cgroup_sb_opts *opts) | |||
| 1354 | strcpy(root->release_agent_path, opts->release_agent); | 1395 | strcpy(root->release_agent_path, opts->release_agent); |
| 1355 | if (opts->name) | 1396 | if (opts->name) |
| 1356 | strcpy(root->name, opts->name); | 1397 | strcpy(root->name, opts->name); |
| 1398 | if (opts->clone_children) | ||
| 1399 | set_bit(CGRP_CLONE_CHILDREN, &root->top_cgroup.flags); | ||
| 1357 | return root; | 1400 | return root; |
| 1358 | } | 1401 | } |
| 1359 | 1402 | ||
| @@ -1879,6 +1922,8 @@ static int cgroup_release_agent_write(struct cgroup *cgrp, struct cftype *cft, | |||
| 1879 | const char *buffer) | 1922 | const char *buffer) |
| 1880 | { | 1923 | { |
| 1881 | BUILD_BUG_ON(sizeof(cgrp->root->release_agent_path) < PATH_MAX); | 1924 | BUILD_BUG_ON(sizeof(cgrp->root->release_agent_path) < PATH_MAX); |
| 1925 | if (strlen(buffer) >= PATH_MAX) | ||
| 1926 | return -EINVAL; | ||
| 1882 | if (!cgroup_lock_live_group(cgrp)) | 1927 | if (!cgroup_lock_live_group(cgrp)) |
| 1883 | return -ENODEV; | 1928 | return -ENODEV; |
| 1884 | strcpy(cgrp->root->release_agent_path, buffer); | 1929 | strcpy(cgrp->root->release_agent_path, buffer); |
| @@ -3172,6 +3217,23 @@ fail: | |||
| 3172 | return ret; | 3217 | return ret; |
| 3173 | } | 3218 | } |
| 3174 | 3219 | ||
| 3220 | static u64 cgroup_clone_children_read(struct cgroup *cgrp, | ||
| 3221 | struct cftype *cft) | ||
| 3222 | { | ||
| 3223 | return clone_children(cgrp); | ||
| 3224 | } | ||
| 3225 | |||
| 3226 | static int cgroup_clone_children_write(struct cgroup *cgrp, | ||
| 3227 | struct cftype *cft, | ||
| 3228 | u64 val) | ||
| 3229 | { | ||
| 3230 | if (val) | ||
| 3231 | set_bit(CGRP_CLONE_CHILDREN, &cgrp->flags); | ||
| 3232 | else | ||
| 3233 | clear_bit(CGRP_CLONE_CHILDREN, &cgrp->flags); | ||
| 3234 | return 0; | ||
| 3235 | } | ||
| 3236 | |||
| 3175 | /* | 3237 | /* |
| 3176 | * for the common functions, 'private' gives the type of file | 3238 | * for the common functions, 'private' gives the type of file |
| 3177 | */ | 3239 | */ |
| @@ -3202,6 +3264,11 @@ static struct cftype files[] = { | |||
| 3202 | .write_string = cgroup_write_event_control, | 3264 | .write_string = cgroup_write_event_control, |
| 3203 | .mode = S_IWUGO, | 3265 | .mode = S_IWUGO, |
| 3204 | }, | 3266 | }, |
| 3267 | { | ||
| 3268 | .name = "cgroup.clone_children", | ||
| 3269 | .read_u64 = cgroup_clone_children_read, | ||
| 3270 | .write_u64 = cgroup_clone_children_write, | ||
| 3271 | }, | ||
| 3205 | }; | 3272 | }; |
| 3206 | 3273 | ||
| 3207 | static struct cftype cft_release_agent = { | 3274 | static struct cftype cft_release_agent = { |
| @@ -3331,6 +3398,9 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry, | |||
| 3331 | if (notify_on_release(parent)) | 3398 | if (notify_on_release(parent)) |
| 3332 | set_bit(CGRP_NOTIFY_ON_RELEASE, &cgrp->flags); | 3399 | set_bit(CGRP_NOTIFY_ON_RELEASE, &cgrp->flags); |
| 3333 | 3400 | ||
| 3401 | if (clone_children(parent)) | ||
| 3402 | set_bit(CGRP_CLONE_CHILDREN, &cgrp->flags); | ||
| 3403 | |||
| 3334 | for_each_subsys(root, ss) { | 3404 | for_each_subsys(root, ss) { |
| 3335 | struct cgroup_subsys_state *css = ss->create(ss, cgrp); | 3405 | struct cgroup_subsys_state *css = ss->create(ss, cgrp); |
| 3336 | 3406 | ||
| @@ -3345,6 +3415,8 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry, | |||
| 3345 | goto err_destroy; | 3415 | goto err_destroy; |
| 3346 | } | 3416 | } |
| 3347 | /* At error, ->destroy() callback has to free assigned ID. */ | 3417 | /* At error, ->destroy() callback has to free assigned ID. */ |
| 3418 | if (clone_children(parent) && ss->post_clone) | ||
| 3419 | ss->post_clone(ss, cgrp); | ||
| 3348 | } | 3420 | } |
| 3349 | 3421 | ||
| 3350 | cgroup_lock_hierarchy(root); | 3422 | cgroup_lock_hierarchy(root); |
