diff options
Diffstat (limited to 'kernel/cgroup.c')
-rw-r--r-- | kernel/cgroup.c | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 3ac6f5b0a64b..192f88c5b0f9 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
@@ -1102,7 +1102,7 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts) | |||
1102 | if (opts->release_agent) | 1102 | if (opts->release_agent) |
1103 | return -EINVAL; | 1103 | return -EINVAL; |
1104 | opts->release_agent = | 1104 | opts->release_agent = |
1105 | kstrndup(token + 14, PATH_MAX, GFP_KERNEL); | 1105 | kstrndup(token + 14, PATH_MAX - 1, GFP_KERNEL); |
1106 | if (!opts->release_agent) | 1106 | if (!opts->release_agent) |
1107 | return -ENOMEM; | 1107 | return -ENOMEM; |
1108 | } else if (!strncmp(token, "name=", 5)) { | 1108 | } else if (!strncmp(token, "name=", 5)) { |
@@ -1123,7 +1123,7 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts) | |||
1123 | if (opts->name) | 1123 | if (opts->name) |
1124 | return -EINVAL; | 1124 | return -EINVAL; |
1125 | opts->name = kstrndup(name, | 1125 | opts->name = kstrndup(name, |
1126 | MAX_CGROUP_ROOT_NAMELEN, | 1126 | MAX_CGROUP_ROOT_NAMELEN - 1, |
1127 | GFP_KERNEL); | 1127 | GFP_KERNEL); |
1128 | if (!opts->name) | 1128 | if (!opts->name) |
1129 | return -ENOMEM; | 1129 | return -ENOMEM; |
@@ -1623,6 +1623,8 @@ static struct file_system_type cgroup_fs_type = { | |||
1623 | .kill_sb = cgroup_kill_sb, | 1623 | .kill_sb = cgroup_kill_sb, |
1624 | }; | 1624 | }; |
1625 | 1625 | ||
1626 | static struct kobject *cgroup_kobj; | ||
1627 | |||
1626 | static inline struct cgroup *__d_cgrp(struct dentry *dentry) | 1628 | static inline struct cgroup *__d_cgrp(struct dentry *dentry) |
1627 | { | 1629 | { |
1628 | return dentry->d_fsdata; | 1630 | return dentry->d_fsdata; |
@@ -1788,6 +1790,29 @@ out: | |||
1788 | return retval; | 1790 | return retval; |
1789 | } | 1791 | } |
1790 | 1792 | ||
1793 | /** | ||
1794 | * cgroup_attach_task_current_cg - attach task 'tsk' to current task's cgroup | ||
1795 | * @tsk: the task to be attached | ||
1796 | */ | ||
1797 | int cgroup_attach_task_current_cg(struct task_struct *tsk) | ||
1798 | { | ||
1799 | struct cgroupfs_root *root; | ||
1800 | struct cgroup *cur_cg; | ||
1801 | int retval = 0; | ||
1802 | |||
1803 | cgroup_lock(); | ||
1804 | for_each_active_root(root) { | ||
1805 | cur_cg = task_cgroup_from_root(current, root); | ||
1806 | retval = cgroup_attach_task(cur_cg, tsk); | ||
1807 | if (retval) | ||
1808 | break; | ||
1809 | } | ||
1810 | cgroup_unlock(); | ||
1811 | |||
1812 | return retval; | ||
1813 | } | ||
1814 | EXPORT_SYMBOL_GPL(cgroup_attach_task_current_cg); | ||
1815 | |||
1791 | /* | 1816 | /* |
1792 | * Attach task with pid 'pid' to cgroup 'cgrp'. Call with cgroup_mutex | 1817 | * Attach task with pid 'pid' to cgroup 'cgrp'. Call with cgroup_mutex |
1793 | * held. May take task_lock of task | 1818 | * held. May take task_lock of task |
@@ -3871,9 +3896,18 @@ int __init cgroup_init(void) | |||
3871 | hhead = css_set_hash(init_css_set.subsys); | 3896 | hhead = css_set_hash(init_css_set.subsys); |
3872 | hlist_add_head(&init_css_set.hlist, hhead); | 3897 | hlist_add_head(&init_css_set.hlist, hhead); |
3873 | BUG_ON(!init_root_id(&rootnode)); | 3898 | BUG_ON(!init_root_id(&rootnode)); |
3899 | |||
3900 | cgroup_kobj = kobject_create_and_add("cgroup", fs_kobj); | ||
3901 | if (!cgroup_kobj) { | ||
3902 | err = -ENOMEM; | ||
3903 | goto out; | ||
3904 | } | ||
3905 | |||
3874 | err = register_filesystem(&cgroup_fs_type); | 3906 | err = register_filesystem(&cgroup_fs_type); |
3875 | if (err < 0) | 3907 | if (err < 0) { |
3908 | kobject_put(cgroup_kobj); | ||
3876 | goto out; | 3909 | goto out; |
3910 | } | ||
3877 | 3911 | ||
3878 | proc_create("cgroups", 0, NULL, &proc_cgroupstats_operations); | 3912 | proc_create("cgroups", 0, NULL, &proc_cgroupstats_operations); |
3879 | 3913 | ||