aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/cgroup.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2014-05-13 12:16:21 -0400
committerTejun Heo <tj@kernel.org>2014-05-13 12:16:21 -0400
commit451af504df0c62f695a69b83c250486e77c66378 (patch)
treef89879cf3f88e9da346d8bd3fa1ae192a280d772 /kernel/cgroup.c
parentb41686401e501430ffe93b575ef7959d2ecc6f2e (diff)
cgroup: replace cftype->write_string() with cftype->write()
Convert all cftype->write_string() users to the new cftype->write() which maps directly to kernfs write operation and has full access to kernfs and cgroup contexts. The conversions are mostly mechanical. * @css and @cft are accessed using of_css() and of_cft() accessors respectively instead of being specified as arguments. * Should return @nbytes on success instead of 0. * @buf is not trimmed automatically. Trim if necessary. Note that blkcg and netprio don't need this as the parsers already handle whitespaces. cftype->write_string() has no user left after the conversions and removed. While at it, remove unnecessary local variable @p in cgroup_subtree_control_write() and stale comment about CGROUP_LOCAL_BUFFER_SIZE in cgroup_freezer.c. This patch doesn't introduce any visible behavior changes. v2: netprio was missing from conversion. Converted. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Aristeu Rozanski <arozansk@redhat.com> Acked-by: Vivek Goyal <vgoyal@redhat.com> Acked-by: Li Zefan <lizefan@huawei.com> Cc: Jens Axboe <axboe@kernel.dk> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Michal Hocko <mhocko@suse.cz> Cc: Neil Horman <nhorman@tuxdriver.com> Cc: "David S. Miller" <davem@davemloft.net>
Diffstat (limited to 'kernel/cgroup.c')
-rw-r--r--kernel/cgroup.c38
1 files changed, 19 insertions, 19 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index a16f91d12f4e..2a88ce7b24b6 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -1035,7 +1035,7 @@ static umode_t cgroup_file_mode(const struct cftype *cft)
1035 mode |= S_IRUGO; 1035 mode |= S_IRUGO;
1036 1036
1037 if (cft->write_u64 || cft->write_s64 || cft->write || 1037 if (cft->write_u64 || cft->write_s64 || cft->write ||
1038 cft->write_string || cft->trigger) 1038 cft->trigger)
1039 mode |= S_IWUSR; 1039 mode |= S_IWUSR;
1040 1040
1041 return mode; 1041 return mode;
@@ -2352,20 +2352,21 @@ static int cgroup_procs_write(struct cgroup_subsys_state *css,
2352 return attach_task_by_pid(css->cgroup, tgid, true); 2352 return attach_task_by_pid(css->cgroup, tgid, true);
2353} 2353}
2354 2354
2355static int cgroup_release_agent_write(struct cgroup_subsys_state *css, 2355static ssize_t cgroup_release_agent_write(struct kernfs_open_file *of,
2356 struct cftype *cft, char *buffer) 2356 char *buf, size_t nbytes, loff_t off)
2357{ 2357{
2358 struct cgroup_root *root = css->cgroup->root; 2358 struct cgroup *cgrp = of_css(of)->cgroup;
2359 struct cgroup_root *root = cgrp->root;
2359 2360
2360 BUILD_BUG_ON(sizeof(root->release_agent_path) < PATH_MAX); 2361 BUILD_BUG_ON(sizeof(root->release_agent_path) < PATH_MAX);
2361 if (!cgroup_lock_live_group(css->cgroup)) 2362 if (!cgroup_lock_live_group(cgrp))
2362 return -ENODEV; 2363 return -ENODEV;
2363 spin_lock(&release_agent_path_lock); 2364 spin_lock(&release_agent_path_lock);
2364 strlcpy(root->release_agent_path, buffer, 2365 strlcpy(root->release_agent_path, strstrip(buf),
2365 sizeof(root->release_agent_path)); 2366 sizeof(root->release_agent_path));
2366 spin_unlock(&release_agent_path_lock); 2367 spin_unlock(&release_agent_path_lock);
2367 mutex_unlock(&cgroup_mutex); 2368 mutex_unlock(&cgroup_mutex);
2368 return 0; 2369 return nbytes;
2369} 2370}
2370 2371
2371static int cgroup_release_agent_show(struct seq_file *seq, void *v) 2372static int cgroup_release_agent_show(struct seq_file *seq, void *v)
@@ -2530,21 +2531,22 @@ out_finish:
2530} 2531}
2531 2532
2532/* change the enabled child controllers for a cgroup in the default hierarchy */ 2533/* change the enabled child controllers for a cgroup in the default hierarchy */
2533static int cgroup_subtree_control_write(struct cgroup_subsys_state *dummy_css, 2534static ssize_t cgroup_subtree_control_write(struct kernfs_open_file *of,
2534 struct cftype *cft, char *buffer) 2535 char *buf, size_t nbytes,
2536 loff_t off)
2535{ 2537{
2536 unsigned int enable = 0, disable = 0; 2538 unsigned int enable = 0, disable = 0;
2537 struct cgroup *cgrp = dummy_css->cgroup, *child; 2539 struct cgroup *cgrp = of_css(of)->cgroup, *child;
2538 struct cgroup_subsys *ss; 2540 struct cgroup_subsys *ss;
2539 char *tok, *p; 2541 char *tok;
2540 int ssid, ret; 2542 int ssid, ret;
2541 2543
2542 /* 2544 /*
2543 * Parse input - space separated list of subsystem names prefixed 2545 * Parse input - space separated list of subsystem names prefixed
2544 * with either + or -. 2546 * with either + or -.
2545 */ 2547 */
2546 p = buffer; 2548 buf = strstrip(buf);
2547 while ((tok = strsep(&p, " "))) { 2549 while ((tok = strsep(&buf, " "))) {
2548 if (tok[0] == '\0') 2550 if (tok[0] == '\0')
2549 continue; 2551 continue;
2550 for_each_subsys(ss, ssid) { 2552 for_each_subsys(ss, ssid) {
@@ -2692,7 +2694,7 @@ out_unlock_tree:
2692out_unbreak: 2694out_unbreak:
2693 kernfs_unbreak_active_protection(cgrp->control_kn); 2695 kernfs_unbreak_active_protection(cgrp->control_kn);
2694 cgroup_put(cgrp); 2696 cgroup_put(cgrp);
2695 return ret; 2697 return ret ?: nbytes;
2696 2698
2697err_undo_css: 2699err_undo_css:
2698 cgrp->child_subsys_mask &= ~enable; 2700 cgrp->child_subsys_mask &= ~enable;
@@ -2738,9 +2740,7 @@ static ssize_t cgroup_file_write(struct kernfs_open_file *of, char *buf,
2738 css = cgroup_css(cgrp, cft->ss); 2740 css = cgroup_css(cgrp, cft->ss);
2739 rcu_read_unlock(); 2741 rcu_read_unlock();
2740 2742
2741 if (cft->write_string) { 2743 if (cft->write_u64) {
2742 ret = cft->write_string(css, cft, strstrip(buf));
2743 } else if (cft->write_u64) {
2744 unsigned long long v; 2744 unsigned long long v;
2745 ret = kstrtoull(buf, 0, &v); 2745 ret = kstrtoull(buf, 0, &v);
2746 if (!ret) 2746 if (!ret)
@@ -3984,7 +3984,7 @@ static struct cftype cgroup_base_files[] = {
3984 .name = "cgroup.subtree_control", 3984 .name = "cgroup.subtree_control",
3985 .flags = CFTYPE_ONLY_ON_DFL, 3985 .flags = CFTYPE_ONLY_ON_DFL,
3986 .seq_show = cgroup_subtree_control_show, 3986 .seq_show = cgroup_subtree_control_show,
3987 .write_string = cgroup_subtree_control_write, 3987 .write = cgroup_subtree_control_write,
3988 }, 3988 },
3989 { 3989 {
3990 .name = "cgroup.populated", 3990 .name = "cgroup.populated",
@@ -4018,7 +4018,7 @@ static struct cftype cgroup_base_files[] = {
4018 .name = "release_agent", 4018 .name = "release_agent",
4019 .flags = CFTYPE_INSANE | CFTYPE_ONLY_ON_ROOT, 4019 .flags = CFTYPE_INSANE | CFTYPE_ONLY_ON_ROOT,
4020 .seq_show = cgroup_release_agent_show, 4020 .seq_show = cgroup_release_agent_show,
4021 .write_string = cgroup_release_agent_write, 4021 .write = cgroup_release_agent_write,
4022 .max_write_len = PATH_MAX - 1, 4022 .max_write_len = PATH_MAX - 1,
4023 }, 4023 },
4024 { } /* terminate */ 4024 { } /* terminate */