aboutsummaryrefslogtreecommitdiffstats
path: root/mm
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 /mm
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 'mm')
-rw-r--r--mm/hugetlb_cgroup.c17
-rw-r--r--mm/memcontrol.c46
2 files changed, 34 insertions, 29 deletions
diff --git a/mm/hugetlb_cgroup.c b/mm/hugetlb_cgroup.c
index 372f1adca491..191de26b0148 100644
--- a/mm/hugetlb_cgroup.c
+++ b/mm/hugetlb_cgroup.c
@@ -253,15 +253,16 @@ static u64 hugetlb_cgroup_read_u64(struct cgroup_subsys_state *css,
253 return res_counter_read_u64(&h_cg->hugepage[idx], name); 253 return res_counter_read_u64(&h_cg->hugepage[idx], name);
254} 254}
255 255
256static int hugetlb_cgroup_write(struct cgroup_subsys_state *css, 256static ssize_t hugetlb_cgroup_write(struct kernfs_open_file *of,
257 struct cftype *cft, char *buffer) 257 char *buf, size_t nbytes, loff_t off)
258{ 258{
259 int idx, name, ret; 259 int idx, name, ret;
260 unsigned long long val; 260 unsigned long long val;
261 struct hugetlb_cgroup *h_cg = hugetlb_cgroup_from_css(css); 261 struct hugetlb_cgroup *h_cg = hugetlb_cgroup_from_css(of_css(of));
262 262
263 idx = MEMFILE_IDX(cft->private); 263 buf = strstrip(buf);
264 name = MEMFILE_ATTR(cft->private); 264 idx = MEMFILE_IDX(of_cft(of)->private);
265 name = MEMFILE_ATTR(of_cft(of)->private);
265 266
266 switch (name) { 267 switch (name) {
267 case RES_LIMIT: 268 case RES_LIMIT:
@@ -271,7 +272,7 @@ static int hugetlb_cgroup_write(struct cgroup_subsys_state *css,
271 break; 272 break;
272 } 273 }
273 /* This function does all necessary parse...reuse it */ 274 /* This function does all necessary parse...reuse it */
274 ret = res_counter_memparse_write_strategy(buffer, &val); 275 ret = res_counter_memparse_write_strategy(buf, &val);
275 if (ret) 276 if (ret)
276 break; 277 break;
277 ret = res_counter_set_limit(&h_cg->hugepage[idx], val); 278 ret = res_counter_set_limit(&h_cg->hugepage[idx], val);
@@ -280,7 +281,7 @@ static int hugetlb_cgroup_write(struct cgroup_subsys_state *css,
280 ret = -EINVAL; 281 ret = -EINVAL;
281 break; 282 break;
282 } 283 }
283 return ret; 284 return ret ?: nbytes;
284} 285}
285 286
286static int hugetlb_cgroup_reset(struct cgroup_subsys_state *css, 287static int hugetlb_cgroup_reset(struct cgroup_subsys_state *css,
@@ -331,7 +332,7 @@ static void __init __hugetlb_cgroup_file_init(int idx)
331 snprintf(cft->name, MAX_CFTYPE_NAME, "%s.limit_in_bytes", buf); 332 snprintf(cft->name, MAX_CFTYPE_NAME, "%s.limit_in_bytes", buf);
332 cft->private = MEMFILE_PRIVATE(idx, RES_LIMIT); 333 cft->private = MEMFILE_PRIVATE(idx, RES_LIMIT);
333 cft->read_u64 = hugetlb_cgroup_read_u64; 334 cft->read_u64 = hugetlb_cgroup_read_u64;
334 cft->write_string = hugetlb_cgroup_write; 335 cft->write = hugetlb_cgroup_write;
335 336
336 /* Add the usage file */ 337 /* Add the usage file */
337 cft = &h->cgroup_files[1]; 338 cft = &h->cgroup_files[1];
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 5cf3246314a2..7098a43f7447 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -5143,17 +5143,18 @@ static int memcg_update_kmem_limit(struct mem_cgroup *memcg,
5143 * The user of this function is... 5143 * The user of this function is...
5144 * RES_LIMIT. 5144 * RES_LIMIT.
5145 */ 5145 */
5146static int mem_cgroup_write(struct cgroup_subsys_state *css, struct cftype *cft, 5146static ssize_t mem_cgroup_write(struct kernfs_open_file *of,
5147 char *buffer) 5147 char *buf, size_t nbytes, loff_t off)
5148{ 5148{
5149 struct mem_cgroup *memcg = mem_cgroup_from_css(css); 5149 struct mem_cgroup *memcg = mem_cgroup_from_css(of_css(of));
5150 enum res_type type; 5150 enum res_type type;
5151 int name; 5151 int name;
5152 unsigned long long val; 5152 unsigned long long val;
5153 int ret; 5153 int ret;
5154 5154
5155 type = MEMFILE_TYPE(cft->private); 5155 buf = strstrip(buf);
5156 name = MEMFILE_ATTR(cft->private); 5156 type = MEMFILE_TYPE(of_cft(of)->private);
5157 name = MEMFILE_ATTR(of_cft(of)->private);
5157 5158
5158 switch (name) { 5159 switch (name) {
5159 case RES_LIMIT: 5160 case RES_LIMIT:
@@ -5162,7 +5163,7 @@ static int mem_cgroup_write(struct cgroup_subsys_state *css, struct cftype *cft,
5162 break; 5163 break;
5163 } 5164 }
5164 /* This function does all necessary parse...reuse it */ 5165 /* This function does all necessary parse...reuse it */
5165 ret = res_counter_memparse_write_strategy(buffer, &val); 5166 ret = res_counter_memparse_write_strategy(buf, &val);
5166 if (ret) 5167 if (ret)
5167 break; 5168 break;
5168 if (type == _MEM) 5169 if (type == _MEM)
@@ -5175,7 +5176,7 @@ static int mem_cgroup_write(struct cgroup_subsys_state *css, struct cftype *cft,
5175 return -EINVAL; 5176 return -EINVAL;
5176 break; 5177 break;
5177 case RES_SOFT_LIMIT: 5178 case RES_SOFT_LIMIT:
5178 ret = res_counter_memparse_write_strategy(buffer, &val); 5179 ret = res_counter_memparse_write_strategy(buf, &val);
5179 if (ret) 5180 if (ret)
5180 break; 5181 break;
5181 /* 5182 /*
@@ -5192,7 +5193,7 @@ static int mem_cgroup_write(struct cgroup_subsys_state *css, struct cftype *cft,
5192 ret = -EINVAL; /* should be BUG() ? */ 5193 ret = -EINVAL; /* should be BUG() ? */
5193 break; 5194 break;
5194 } 5195 }
5195 return ret; 5196 return ret ?: nbytes;
5196} 5197}
5197 5198
5198static void memcg_get_hierarchical_limit(struct mem_cgroup *memcg, 5199static void memcg_get_hierarchical_limit(struct mem_cgroup *memcg,
@@ -5964,9 +5965,10 @@ static void memcg_event_ptable_queue_proc(struct file *file,
5964 * Input must be in format '<event_fd> <control_fd> <args>'. 5965 * Input must be in format '<event_fd> <control_fd> <args>'.
5965 * Interpretation of args is defined by control file implementation. 5966 * Interpretation of args is defined by control file implementation.
5966 */ 5967 */
5967static int memcg_write_event_control(struct cgroup_subsys_state *css, 5968static ssize_t memcg_write_event_control(struct kernfs_open_file *of,
5968 struct cftype *cft, char *buffer) 5969 char *buf, size_t nbytes, loff_t off)
5969{ 5970{
5971 struct cgroup_subsys_state *css = of_css(of);
5970 struct mem_cgroup *memcg = mem_cgroup_from_css(css); 5972 struct mem_cgroup *memcg = mem_cgroup_from_css(css);
5971 struct mem_cgroup_event *event; 5973 struct mem_cgroup_event *event;
5972 struct cgroup_subsys_state *cfile_css; 5974 struct cgroup_subsys_state *cfile_css;
@@ -5977,15 +5979,17 @@ static int memcg_write_event_control(struct cgroup_subsys_state *css,
5977 char *endp; 5979 char *endp;
5978 int ret; 5980 int ret;
5979 5981
5980 efd = simple_strtoul(buffer, &endp, 10); 5982 buf = strstrip(buf);
5983
5984 efd = simple_strtoul(buf, &endp, 10);
5981 if (*endp != ' ') 5985 if (*endp != ' ')
5982 return -EINVAL; 5986 return -EINVAL;
5983 buffer = endp + 1; 5987 buf = endp + 1;
5984 5988
5985 cfd = simple_strtoul(buffer, &endp, 10); 5989 cfd = simple_strtoul(buf, &endp, 10);
5986 if ((*endp != ' ') && (*endp != '\0')) 5990 if ((*endp != ' ') && (*endp != '\0'))
5987 return -EINVAL; 5991 return -EINVAL;
5988 buffer = endp + 1; 5992 buf = endp + 1;
5989 5993
5990 event = kzalloc(sizeof(*event), GFP_KERNEL); 5994 event = kzalloc(sizeof(*event), GFP_KERNEL);
5991 if (!event) 5995 if (!event)
@@ -6063,7 +6067,7 @@ static int memcg_write_event_control(struct cgroup_subsys_state *css,
6063 goto out_put_cfile; 6067 goto out_put_cfile;
6064 } 6068 }
6065 6069
6066 ret = event->register_event(memcg, event->eventfd, buffer); 6070 ret = event->register_event(memcg, event->eventfd, buf);
6067 if (ret) 6071 if (ret)
6068 goto out_put_css; 6072 goto out_put_css;
6069 6073
@@ -6076,7 +6080,7 @@ static int memcg_write_event_control(struct cgroup_subsys_state *css,
6076 fdput(cfile); 6080 fdput(cfile);
6077 fdput(efile); 6081 fdput(efile);
6078 6082
6079 return 0; 6083 return nbytes;
6080 6084
6081out_put_css: 6085out_put_css:
6082 css_put(css); 6086 css_put(css);
@@ -6107,13 +6111,13 @@ static struct cftype mem_cgroup_files[] = {
6107 { 6111 {
6108 .name = "limit_in_bytes", 6112 .name = "limit_in_bytes",
6109 .private = MEMFILE_PRIVATE(_MEM, RES_LIMIT), 6113 .private = MEMFILE_PRIVATE(_MEM, RES_LIMIT),
6110 .write_string = mem_cgroup_write, 6114 .write = mem_cgroup_write,
6111 .read_u64 = mem_cgroup_read_u64, 6115 .read_u64 = mem_cgroup_read_u64,
6112 }, 6116 },
6113 { 6117 {
6114 .name = "soft_limit_in_bytes", 6118 .name = "soft_limit_in_bytes",
6115 .private = MEMFILE_PRIVATE(_MEM, RES_SOFT_LIMIT), 6119 .private = MEMFILE_PRIVATE(_MEM, RES_SOFT_LIMIT),
6116 .write_string = mem_cgroup_write, 6120 .write = mem_cgroup_write,
6117 .read_u64 = mem_cgroup_read_u64, 6121 .read_u64 = mem_cgroup_read_u64,
6118 }, 6122 },
6119 { 6123 {
@@ -6138,7 +6142,7 @@ static struct cftype mem_cgroup_files[] = {
6138 }, 6142 },
6139 { 6143 {
6140 .name = "cgroup.event_control", /* XXX: for compat */ 6144 .name = "cgroup.event_control", /* XXX: for compat */
6141 .write_string = memcg_write_event_control, 6145 .write = memcg_write_event_control,
6142 .flags = CFTYPE_NO_PREFIX, 6146 .flags = CFTYPE_NO_PREFIX,
6143 .mode = S_IWUGO, 6147 .mode = S_IWUGO,
6144 }, 6148 },
@@ -6171,7 +6175,7 @@ static struct cftype mem_cgroup_files[] = {
6171 { 6175 {
6172 .name = "kmem.limit_in_bytes", 6176 .name = "kmem.limit_in_bytes",
6173 .private = MEMFILE_PRIVATE(_KMEM, RES_LIMIT), 6177 .private = MEMFILE_PRIVATE(_KMEM, RES_LIMIT),
6174 .write_string = mem_cgroup_write, 6178 .write = mem_cgroup_write,
6175 .read_u64 = mem_cgroup_read_u64, 6179 .read_u64 = mem_cgroup_read_u64,
6176 }, 6180 },
6177 { 6181 {
@@ -6217,7 +6221,7 @@ static struct cftype memsw_cgroup_files[] = {
6217 { 6221 {
6218 .name = "memsw.limit_in_bytes", 6222 .name = "memsw.limit_in_bytes",
6219 .private = MEMFILE_PRIVATE(_MEMSWAP, RES_LIMIT), 6223 .private = MEMFILE_PRIVATE(_MEMSWAP, RES_LIMIT),
6220 .write_string = mem_cgroup_write, 6224 .write = mem_cgroup_write,
6221 .read_u64 = mem_cgroup_read_u64, 6225 .read_u64 = mem_cgroup_read_u64,
6222 }, 6226 },
6223 { 6227 {