aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/cgroup.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/cgroup.c')
-rw-r--r--kernel/cgroup.c162
1 files changed, 83 insertions, 79 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index c049992f1ffa..6ee469837fda 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -2235,34 +2235,38 @@ int cgroup_attach_task_all(struct task_struct *from, struct task_struct *tsk)
2235} 2235}
2236EXPORT_SYMBOL_GPL(cgroup_attach_task_all); 2236EXPORT_SYMBOL_GPL(cgroup_attach_task_all);
2237 2237
2238static int cgroup_tasks_write(struct cgroup *cgrp, struct cftype *cft, u64 pid) 2238static int cgroup_tasks_write(struct cgroup_subsys_state *css,
2239 struct cftype *cft, u64 pid)
2239{ 2240{
2240 return attach_task_by_pid(cgrp, pid, false); 2241 return attach_task_by_pid(css->cgroup, pid, false);
2241} 2242}
2242 2243
2243static int cgroup_procs_write(struct cgroup *cgrp, struct cftype *cft, u64 tgid) 2244static int cgroup_procs_write(struct cgroup_subsys_state *css,
2245 struct cftype *cft, u64 tgid)
2244{ 2246{
2245 return attach_task_by_pid(cgrp, tgid, true); 2247 return attach_task_by_pid(css->cgroup, tgid, true);
2246} 2248}
2247 2249
2248static int cgroup_release_agent_write(struct cgroup *cgrp, struct cftype *cft, 2250static int cgroup_release_agent_write(struct cgroup_subsys_state *css,
2249 const char *buffer) 2251 struct cftype *cft, const char *buffer)
2250{ 2252{
2251 BUILD_BUG_ON(sizeof(cgrp->root->release_agent_path) < PATH_MAX); 2253 BUILD_BUG_ON(sizeof(css->cgroup->root->release_agent_path) < PATH_MAX);
2252 if (strlen(buffer) >= PATH_MAX) 2254 if (strlen(buffer) >= PATH_MAX)
2253 return -EINVAL; 2255 return -EINVAL;
2254 if (!cgroup_lock_live_group(cgrp)) 2256 if (!cgroup_lock_live_group(css->cgroup))
2255 return -ENODEV; 2257 return -ENODEV;
2256 mutex_lock(&cgroup_root_mutex); 2258 mutex_lock(&cgroup_root_mutex);
2257 strcpy(cgrp->root->release_agent_path, buffer); 2259 strcpy(css->cgroup->root->release_agent_path, buffer);
2258 mutex_unlock(&cgroup_root_mutex); 2260 mutex_unlock(&cgroup_root_mutex);
2259 mutex_unlock(&cgroup_mutex); 2261 mutex_unlock(&cgroup_mutex);
2260 return 0; 2262 return 0;
2261} 2263}
2262 2264
2263static int cgroup_release_agent_show(struct cgroup *cgrp, struct cftype *cft, 2265static int cgroup_release_agent_show(struct cgroup_subsys_state *css,
2264 struct seq_file *seq) 2266 struct cftype *cft, struct seq_file *seq)
2265{ 2267{
2268 struct cgroup *cgrp = css->cgroup;
2269
2266 if (!cgroup_lock_live_group(cgrp)) 2270 if (!cgroup_lock_live_group(cgrp))
2267 return -ENODEV; 2271 return -ENODEV;
2268 seq_puts(seq, cgrp->root->release_agent_path); 2272 seq_puts(seq, cgrp->root->release_agent_path);
@@ -2271,10 +2275,10 @@ static int cgroup_release_agent_show(struct cgroup *cgrp, struct cftype *cft,
2271 return 0; 2275 return 0;
2272} 2276}
2273 2277
2274static int cgroup_sane_behavior_show(struct cgroup *cgrp, struct cftype *cft, 2278static int cgroup_sane_behavior_show(struct cgroup_subsys_state *css,
2275 struct seq_file *seq) 2279 struct cftype *cft, struct seq_file *seq)
2276{ 2280{
2277 seq_printf(seq, "%d\n", cgroup_sane_behavior(cgrp)); 2281 seq_printf(seq, "%d\n", cgroup_sane_behavior(css->cgroup));
2278 return 0; 2282 return 0;
2279} 2283}
2280 2284
@@ -2292,10 +2296,10 @@ static struct cgroup_subsys_state *cgroup_file_css(struct cfent *cfe)
2292/* A buffer size big enough for numbers or short strings */ 2296/* A buffer size big enough for numbers or short strings */
2293#define CGROUP_LOCAL_BUFFER_SIZE 64 2297#define CGROUP_LOCAL_BUFFER_SIZE 64
2294 2298
2295static ssize_t cgroup_write_X64(struct cgroup *cgrp, struct cftype *cft, 2299static ssize_t cgroup_write_X64(struct cgroup_subsys_state *css,
2296 struct file *file, 2300 struct cftype *cft, struct file *file,
2297 const char __user *userbuf, 2301 const char __user *userbuf, size_t nbytes,
2298 size_t nbytes, loff_t *unused_ppos) 2302 loff_t *unused_ppos)
2299{ 2303{
2300 char buffer[CGROUP_LOCAL_BUFFER_SIZE]; 2304 char buffer[CGROUP_LOCAL_BUFFER_SIZE];
2301 int retval = 0; 2305 int retval = 0;
@@ -2313,22 +2317,22 @@ static ssize_t cgroup_write_X64(struct cgroup *cgrp, struct cftype *cft,
2313 u64 val = simple_strtoull(strstrip(buffer), &end, 0); 2317 u64 val = simple_strtoull(strstrip(buffer), &end, 0);
2314 if (*end) 2318 if (*end)
2315 return -EINVAL; 2319 return -EINVAL;
2316 retval = cft->write_u64(cgrp, cft, val); 2320 retval = cft->write_u64(css, cft, val);
2317 } else { 2321 } else {
2318 s64 val = simple_strtoll(strstrip(buffer), &end, 0); 2322 s64 val = simple_strtoll(strstrip(buffer), &end, 0);
2319 if (*end) 2323 if (*end)
2320 return -EINVAL; 2324 return -EINVAL;
2321 retval = cft->write_s64(cgrp, cft, val); 2325 retval = cft->write_s64(css, cft, val);
2322 } 2326 }
2323 if (!retval) 2327 if (!retval)
2324 retval = nbytes; 2328 retval = nbytes;
2325 return retval; 2329 return retval;
2326} 2330}
2327 2331
2328static ssize_t cgroup_write_string(struct cgroup *cgrp, struct cftype *cft, 2332static ssize_t cgroup_write_string(struct cgroup_subsys_state *css,
2329 struct file *file, 2333 struct cftype *cft, struct file *file,
2330 const char __user *userbuf, 2334 const char __user *userbuf, size_t nbytes,
2331 size_t nbytes, loff_t *unused_ppos) 2335 loff_t *unused_ppos)
2332{ 2336{
2333 char local_buffer[CGROUP_LOCAL_BUFFER_SIZE]; 2337 char local_buffer[CGROUP_LOCAL_BUFFER_SIZE];
2334 int retval = 0; 2338 int retval = 0;
@@ -2351,7 +2355,7 @@ static ssize_t cgroup_write_string(struct cgroup *cgrp, struct cftype *cft,
2351 } 2355 }
2352 2356
2353 buffer[nbytes] = 0; /* nul-terminate */ 2357 buffer[nbytes] = 0; /* nul-terminate */
2354 retval = cft->write_string(cgrp, cft, strstrip(buffer)); 2358 retval = cft->write_string(css, cft, strstrip(buffer));
2355 if (!retval) 2359 if (!retval)
2356 retval = nbytes; 2360 retval = nbytes;
2357out: 2361out:
@@ -2361,60 +2365,60 @@ out:
2361} 2365}
2362 2366
2363static ssize_t cgroup_file_write(struct file *file, const char __user *buf, 2367static ssize_t cgroup_file_write(struct file *file, const char __user *buf,
2364 size_t nbytes, loff_t *ppos) 2368 size_t nbytes, loff_t *ppos)
2365{ 2369{
2370 struct cfent *cfe = __d_cfe(file->f_dentry);
2366 struct cftype *cft = __d_cft(file->f_dentry); 2371 struct cftype *cft = __d_cft(file->f_dentry);
2367 struct cgroup *cgrp = __d_cgrp(file->f_dentry->d_parent); 2372 struct cgroup_subsys_state *css = cgroup_file_css(cfe);
2368 2373
2369 if (cft->write) 2374 if (cft->write)
2370 return cft->write(cgrp, cft, file, buf, nbytes, ppos); 2375 return cft->write(css, cft, file, buf, nbytes, ppos);
2371 if (cft->write_u64 || cft->write_s64) 2376 if (cft->write_u64 || cft->write_s64)
2372 return cgroup_write_X64(cgrp, cft, file, buf, nbytes, ppos); 2377 return cgroup_write_X64(css, cft, file, buf, nbytes, ppos);
2373 if (cft->write_string) 2378 if (cft->write_string)
2374 return cgroup_write_string(cgrp, cft, file, buf, nbytes, ppos); 2379 return cgroup_write_string(css, cft, file, buf, nbytes, ppos);
2375 if (cft->trigger) { 2380 if (cft->trigger) {
2376 int ret = cft->trigger(cgrp, (unsigned int)cft->private); 2381 int ret = cft->trigger(css, (unsigned int)cft->private);
2377 return ret ? ret : nbytes; 2382 return ret ? ret : nbytes;
2378 } 2383 }
2379 return -EINVAL; 2384 return -EINVAL;
2380} 2385}
2381 2386
2382static ssize_t cgroup_read_u64(struct cgroup *cgrp, struct cftype *cft, 2387static ssize_t cgroup_read_u64(struct cgroup_subsys_state *css,
2383 struct file *file, 2388 struct cftype *cft, struct file *file,
2384 char __user *buf, size_t nbytes, 2389 char __user *buf, size_t nbytes, loff_t *ppos)
2385 loff_t *ppos)
2386{ 2390{
2387 char tmp[CGROUP_LOCAL_BUFFER_SIZE]; 2391 char tmp[CGROUP_LOCAL_BUFFER_SIZE];
2388 u64 val = cft->read_u64(cgrp, cft); 2392 u64 val = cft->read_u64(css, cft);
2389 int len = sprintf(tmp, "%llu\n", (unsigned long long) val); 2393 int len = sprintf(tmp, "%llu\n", (unsigned long long) val);
2390 2394
2391 return simple_read_from_buffer(buf, nbytes, ppos, tmp, len); 2395 return simple_read_from_buffer(buf, nbytes, ppos, tmp, len);
2392} 2396}
2393 2397
2394static ssize_t cgroup_read_s64(struct cgroup *cgrp, struct cftype *cft, 2398static ssize_t cgroup_read_s64(struct cgroup_subsys_state *css,
2395 struct file *file, 2399 struct cftype *cft, struct file *file,
2396 char __user *buf, size_t nbytes, 2400 char __user *buf, size_t nbytes, loff_t *ppos)
2397 loff_t *ppos)
2398{ 2401{
2399 char tmp[CGROUP_LOCAL_BUFFER_SIZE]; 2402 char tmp[CGROUP_LOCAL_BUFFER_SIZE];
2400 s64 val = cft->read_s64(cgrp, cft); 2403 s64 val = cft->read_s64(css, cft);
2401 int len = sprintf(tmp, "%lld\n", (long long) val); 2404 int len = sprintf(tmp, "%lld\n", (long long) val);
2402 2405
2403 return simple_read_from_buffer(buf, nbytes, ppos, tmp, len); 2406 return simple_read_from_buffer(buf, nbytes, ppos, tmp, len);
2404} 2407}
2405 2408
2406static ssize_t cgroup_file_read(struct file *file, char __user *buf, 2409static ssize_t cgroup_file_read(struct file *file, char __user *buf,
2407 size_t nbytes, loff_t *ppos) 2410 size_t nbytes, loff_t *ppos)
2408{ 2411{
2412 struct cfent *cfe = __d_cfe(file->f_dentry);
2409 struct cftype *cft = __d_cft(file->f_dentry); 2413 struct cftype *cft = __d_cft(file->f_dentry);
2410 struct cgroup *cgrp = __d_cgrp(file->f_dentry->d_parent); 2414 struct cgroup_subsys_state *css = cgroup_file_css(cfe);
2411 2415
2412 if (cft->read) 2416 if (cft->read)
2413 return cft->read(cgrp, cft, file, buf, nbytes, ppos); 2417 return cft->read(css, cft, file, buf, nbytes, ppos);
2414 if (cft->read_u64) 2418 if (cft->read_u64)
2415 return cgroup_read_u64(cgrp, cft, file, buf, nbytes, ppos); 2419 return cgroup_read_u64(css, cft, file, buf, nbytes, ppos);
2416 if (cft->read_s64) 2420 if (cft->read_s64)
2417 return cgroup_read_s64(cgrp, cft, file, buf, nbytes, ppos); 2421 return cgroup_read_s64(css, cft, file, buf, nbytes, ppos);
2418 return -EINVAL; 2422 return -EINVAL;
2419} 2423}
2420 2424
@@ -2433,16 +2437,16 @@ static int cgroup_seqfile_show(struct seq_file *m, void *arg)
2433{ 2437{
2434 struct cfent *cfe = m->private; 2438 struct cfent *cfe = m->private;
2435 struct cftype *cft = cfe->type; 2439 struct cftype *cft = cfe->type;
2436 struct cgroup *cgrp = __d_cgrp(cfe->dentry->d_parent); 2440 struct cgroup_subsys_state *css = cgroup_file_css(cfe);
2437 2441
2438 if (cft->read_map) { 2442 if (cft->read_map) {
2439 struct cgroup_map_cb cb = { 2443 struct cgroup_map_cb cb = {
2440 .fill = cgroup_map_add, 2444 .fill = cgroup_map_add,
2441 .state = m, 2445 .state = m,
2442 }; 2446 };
2443 return cft->read_map(cgrp, cft, &cb); 2447 return cft->read_map(css, cft, &cb);
2444 } 2448 }
2445 return cft->read_seq_string(cgrp, cft, m); 2449 return cft->read_seq_string(css, cft, m);
2446} 2450}
2447 2451
2448static const struct file_operations cgroup_seqfile_operations = { 2452static const struct file_operations cgroup_seqfile_operations = {
@@ -3860,21 +3864,20 @@ static int cgroup_procs_open(struct inode *unused, struct file *file)
3860 return cgroup_pidlist_open(file, CGROUP_FILE_PROCS); 3864 return cgroup_pidlist_open(file, CGROUP_FILE_PROCS);
3861} 3865}
3862 3866
3863static u64 cgroup_read_notify_on_release(struct cgroup *cgrp, 3867static u64 cgroup_read_notify_on_release(struct cgroup_subsys_state *css,
3864 struct cftype *cft) 3868 struct cftype *cft)
3865{ 3869{
3866 return notify_on_release(cgrp); 3870 return notify_on_release(css->cgroup);
3867} 3871}
3868 3872
3869static int cgroup_write_notify_on_release(struct cgroup *cgrp, 3873static int cgroup_write_notify_on_release(struct cgroup_subsys_state *css,
3870 struct cftype *cft, 3874 struct cftype *cft, u64 val)
3871 u64 val)
3872{ 3875{
3873 clear_bit(CGRP_RELEASABLE, &cgrp->flags); 3876 clear_bit(CGRP_RELEASABLE, &css->cgroup->flags);
3874 if (val) 3877 if (val)
3875 set_bit(CGRP_NOTIFY_ON_RELEASE, &cgrp->flags); 3878 set_bit(CGRP_NOTIFY_ON_RELEASE, &css->cgroup->flags);
3876 else 3879 else
3877 clear_bit(CGRP_NOTIFY_ON_RELEASE, &cgrp->flags); 3880 clear_bit(CGRP_NOTIFY_ON_RELEASE, &css->cgroup->flags);
3878 return 0; 3881 return 0;
3879} 3882}
3880 3883
@@ -3972,9 +3975,10 @@ static void cgroup_event_ptable_queue_proc(struct file *file,
3972 * Input must be in format '<event_fd> <control_fd> <args>'. 3975 * Input must be in format '<event_fd> <control_fd> <args>'.
3973 * Interpretation of args is defined by control file implementation. 3976 * Interpretation of args is defined by control file implementation.
3974 */ 3977 */
3975static int cgroup_write_event_control(struct cgroup *cgrp, struct cftype *cft, 3978static int cgroup_write_event_control(struct cgroup_subsys_state *css,
3976 const char *buffer) 3979 struct cftype *cft, const char *buffer)
3977{ 3980{
3981 struct cgroup *cgrp = css->cgroup;
3978 struct cgroup_event *event; 3982 struct cgroup_event *event;
3979 struct cgroup *cgrp_cfile; 3983 struct cgroup *cgrp_cfile;
3980 unsigned int efd, cfd; 3984 unsigned int efd, cfd;
@@ -4082,20 +4086,19 @@ out_kfree:
4082 return ret; 4086 return ret;
4083} 4087}
4084 4088
4085static u64 cgroup_clone_children_read(struct cgroup *cgrp, 4089static u64 cgroup_clone_children_read(struct cgroup_subsys_state *css,
4086 struct cftype *cft) 4090 struct cftype *cft)
4087{ 4091{
4088 return test_bit(CGRP_CPUSET_CLONE_CHILDREN, &cgrp->flags); 4092 return test_bit(CGRP_CPUSET_CLONE_CHILDREN, &css->cgroup->flags);
4089} 4093}
4090 4094
4091static int cgroup_clone_children_write(struct cgroup *cgrp, 4095static int cgroup_clone_children_write(struct cgroup_subsys_state *css,
4092 struct cftype *cft, 4096 struct cftype *cft, u64 val)
4093 u64 val)
4094{ 4097{
4095 if (val) 4098 if (val)
4096 set_bit(CGRP_CPUSET_CLONE_CHILDREN, &cgrp->flags); 4099 set_bit(CGRP_CPUSET_CLONE_CHILDREN, &css->cgroup->flags);
4097 else 4100 else
4098 clear_bit(CGRP_CPUSET_CLONE_CHILDREN, &cgrp->flags); 4101 clear_bit(CGRP_CPUSET_CLONE_CHILDREN, &css->cgroup->flags);
4099 return 0; 4102 return 0;
4100} 4103}
4101 4104
@@ -5585,17 +5588,19 @@ static void debug_css_free(struct cgroup_subsys_state *css)
5585 kfree(css); 5588 kfree(css);
5586} 5589}
5587 5590
5588static u64 debug_taskcount_read(struct cgroup *cgrp, struct cftype *cft) 5591static u64 debug_taskcount_read(struct cgroup_subsys_state *css,
5592 struct cftype *cft)
5589{ 5593{
5590 return cgroup_task_count(cgrp); 5594 return cgroup_task_count(css->cgroup);
5591} 5595}
5592 5596
5593static u64 current_css_set_read(struct cgroup *cgrp, struct cftype *cft) 5597static u64 current_css_set_read(struct cgroup_subsys_state *css,
5598 struct cftype *cft)
5594{ 5599{
5595 return (u64)(unsigned long)current->cgroups; 5600 return (u64)(unsigned long)current->cgroups;
5596} 5601}
5597 5602
5598static u64 current_css_set_refcount_read(struct cgroup *cgrp, 5603static u64 current_css_set_refcount_read(struct cgroup_subsys_state *css,
5599 struct cftype *cft) 5604 struct cftype *cft)
5600{ 5605{
5601 u64 count; 5606 u64 count;
@@ -5606,7 +5611,7 @@ static u64 current_css_set_refcount_read(struct cgroup *cgrp,
5606 return count; 5611 return count;
5607} 5612}
5608 5613
5609static int current_css_set_cg_links_read(struct cgroup *cgrp, 5614static int current_css_set_cg_links_read(struct cgroup_subsys_state *css,
5610 struct cftype *cft, 5615 struct cftype *cft,
5611 struct seq_file *seq) 5616 struct seq_file *seq)
5612{ 5617{
@@ -5633,14 +5638,13 @@ static int current_css_set_cg_links_read(struct cgroup *cgrp,
5633} 5638}
5634 5639
5635#define MAX_TASKS_SHOWN_PER_CSS 25 5640#define MAX_TASKS_SHOWN_PER_CSS 25
5636static int cgroup_css_links_read(struct cgroup *cgrp, 5641static int cgroup_css_links_read(struct cgroup_subsys_state *css,
5637 struct cftype *cft, 5642 struct cftype *cft, struct seq_file *seq)
5638 struct seq_file *seq)
5639{ 5643{
5640 struct cgrp_cset_link *link; 5644 struct cgrp_cset_link *link;
5641 5645
5642 read_lock(&css_set_lock); 5646 read_lock(&css_set_lock);
5643 list_for_each_entry(link, &cgrp->cset_links, cset_link) { 5647 list_for_each_entry(link, &css->cgroup->cset_links, cset_link) {
5644 struct css_set *cset = link->cset; 5648 struct css_set *cset = link->cset;
5645 struct task_struct *task; 5649 struct task_struct *task;
5646 int count = 0; 5650 int count = 0;
@@ -5659,9 +5663,9 @@ static int cgroup_css_links_read(struct cgroup *cgrp,
5659 return 0; 5663 return 0;
5660} 5664}
5661 5665
5662static u64 releasable_read(struct cgroup *cgrp, struct cftype *cft) 5666static u64 releasable_read(struct cgroup_subsys_state *css, struct cftype *cft)
5663{ 5667{
5664 return test_bit(CGRP_RELEASABLE, &cgrp->flags); 5668 return test_bit(CGRP_RELEASABLE, &css->cgroup->flags);
5665} 5669}
5666 5670
5667static struct cftype debug_files[] = { 5671static struct cftype debug_files[] = {