diff options
author | Tejun Heo <tj@kernel.org> | 2014-05-13 12:16:21 -0400 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2014-05-13 12:16:21 -0400 |
commit | 6770c64e5c8da4705d1f0973bdeb5c2bf4f3a404 (patch) | |
tree | 29e16383df94d4a31f6fec2f49f5ae84c369f911 | |
parent | 451af504df0c62f695a69b83c250486e77c66378 (diff) |
cgroup: replace cftype->trigger() with cftype->write()
cftype->trigger() is pointless. It's trivial to ignore the input
buffer from a regular ->write() operation. Convert all ->trigger()
users to ->write() and remove ->trigger().
This patch doesn't introduce any visible behavior changes.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Li Zefan <lizefan@huawei.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@suse.cz>
-rw-r--r-- | include/linux/cgroup.h | 8 | ||||
-rw-r--r-- | kernel/cgroup.c | 5 | ||||
-rw-r--r-- | mm/hugetlb_cgroup.c | 16 | ||||
-rw-r--r-- | mm/memcontrol.c | 34 | ||||
-rw-r--r-- | net/ipv4/tcp_memcontrol.c | 15 |
5 files changed, 35 insertions, 43 deletions
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index aecdc84fe128..08eb71ee600b 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h | |||
@@ -500,14 +500,6 @@ struct cftype { | |||
500 | s64 val); | 500 | s64 val); |
501 | 501 | ||
502 | /* | 502 | /* |
503 | * trigger() callback can be used to get some kick from the | ||
504 | * userspace, when the actual string written is not important | ||
505 | * at all. The private field can be used to determine the | ||
506 | * kick type for multiplexing. | ||
507 | */ | ||
508 | int (*trigger)(struct cgroup_subsys_state *css, unsigned int event); | ||
509 | |||
510 | /* | ||
511 | * write() is the generic write callback which maps directly to | 503 | * write() is the generic write callback which maps directly to |
512 | * kernfs write operation and overrides all other operations. | 504 | * kernfs write operation and overrides all other operations. |
513 | * Maximum write size is determined by ->max_write_len. Use | 505 | * Maximum write size is determined by ->max_write_len. Use |
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 2a88ce7b24b6..2f16aab03493 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
@@ -1034,8 +1034,7 @@ static umode_t cgroup_file_mode(const struct cftype *cft) | |||
1034 | if (cft->read_u64 || cft->read_s64 || cft->seq_show) | 1034 | if (cft->read_u64 || cft->read_s64 || cft->seq_show) |
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->trigger) | ||
1039 | mode |= S_IWUSR; | 1038 | mode |= S_IWUSR; |
1040 | 1039 | ||
1041 | return mode; | 1040 | return mode; |
@@ -2750,8 +2749,6 @@ static ssize_t cgroup_file_write(struct kernfs_open_file *of, char *buf, | |||
2750 | ret = kstrtoll(buf, 0, &v); | 2749 | ret = kstrtoll(buf, 0, &v); |
2751 | if (!ret) | 2750 | if (!ret) |
2752 | ret = cft->write_s64(css, cft, v); | 2751 | ret = cft->write_s64(css, cft, v); |
2753 | } else if (cft->trigger) { | ||
2754 | ret = cft->trigger(css, (unsigned int)cft->private); | ||
2755 | } else { | 2752 | } else { |
2756 | ret = -EINVAL; | 2753 | ret = -EINVAL; |
2757 | } | 2754 | } |
diff --git a/mm/hugetlb_cgroup.c b/mm/hugetlb_cgroup.c index 191de26b0148..a380681ab3cf 100644 --- a/mm/hugetlb_cgroup.c +++ b/mm/hugetlb_cgroup.c | |||
@@ -284,14 +284,14 @@ static ssize_t hugetlb_cgroup_write(struct kernfs_open_file *of, | |||
284 | return ret ?: nbytes; | 284 | return ret ?: nbytes; |
285 | } | 285 | } |
286 | 286 | ||
287 | static int hugetlb_cgroup_reset(struct cgroup_subsys_state *css, | 287 | static ssize_t hugetlb_cgroup_reset(struct kernfs_open_file *of, |
288 | unsigned int event) | 288 | char *buf, size_t nbytes, loff_t off) |
289 | { | 289 | { |
290 | int idx, name, ret = 0; | 290 | int idx, name, ret = 0; |
291 | struct hugetlb_cgroup *h_cg = hugetlb_cgroup_from_css(css); | 291 | struct hugetlb_cgroup *h_cg = hugetlb_cgroup_from_css(of_css(of)); |
292 | 292 | ||
293 | idx = MEMFILE_IDX(event); | 293 | idx = MEMFILE_IDX(of_cft(of)->private); |
294 | name = MEMFILE_ATTR(event); | 294 | name = MEMFILE_ATTR(of_cft(of)->private); |
295 | 295 | ||
296 | switch (name) { | 296 | switch (name) { |
297 | case RES_MAX_USAGE: | 297 | case RES_MAX_USAGE: |
@@ -304,7 +304,7 @@ static int hugetlb_cgroup_reset(struct cgroup_subsys_state *css, | |||
304 | ret = -EINVAL; | 304 | ret = -EINVAL; |
305 | break; | 305 | break; |
306 | } | 306 | } |
307 | return ret; | 307 | return ret ?: nbytes; |
308 | } | 308 | } |
309 | 309 | ||
310 | static char *mem_fmt(char *buf, int size, unsigned long hsize) | 310 | static char *mem_fmt(char *buf, int size, unsigned long hsize) |
@@ -344,14 +344,14 @@ static void __init __hugetlb_cgroup_file_init(int idx) | |||
344 | cft = &h->cgroup_files[2]; | 344 | cft = &h->cgroup_files[2]; |
345 | snprintf(cft->name, MAX_CFTYPE_NAME, "%s.max_usage_in_bytes", buf); | 345 | snprintf(cft->name, MAX_CFTYPE_NAME, "%s.max_usage_in_bytes", buf); |
346 | cft->private = MEMFILE_PRIVATE(idx, RES_MAX_USAGE); | 346 | cft->private = MEMFILE_PRIVATE(idx, RES_MAX_USAGE); |
347 | cft->trigger = hugetlb_cgroup_reset; | 347 | cft->write = hugetlb_cgroup_reset; |
348 | cft->read_u64 = hugetlb_cgroup_read_u64; | 348 | cft->read_u64 = hugetlb_cgroup_read_u64; |
349 | 349 | ||
350 | /* Add the failcntfile */ | 350 | /* Add the failcntfile */ |
351 | cft = &h->cgroup_files[3]; | 351 | cft = &h->cgroup_files[3]; |
352 | snprintf(cft->name, MAX_CFTYPE_NAME, "%s.failcnt", buf); | 352 | snprintf(cft->name, MAX_CFTYPE_NAME, "%s.failcnt", buf); |
353 | cft->private = MEMFILE_PRIVATE(idx, RES_FAILCNT); | 353 | cft->private = MEMFILE_PRIVATE(idx, RES_FAILCNT); |
354 | cft->trigger = hugetlb_cgroup_reset; | 354 | cft->write = hugetlb_cgroup_reset; |
355 | cft->read_u64 = hugetlb_cgroup_read_u64; | 355 | cft->read_u64 = hugetlb_cgroup_read_u64; |
356 | 356 | ||
357 | /* NULL terminate the last cft */ | 357 | /* NULL terminate the last cft */ |
diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 7098a43f7447..b638a79209ee 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c | |||
@@ -4887,14 +4887,15 @@ static int mem_cgroup_force_empty(struct mem_cgroup *memcg) | |||
4887 | return 0; | 4887 | return 0; |
4888 | } | 4888 | } |
4889 | 4889 | ||
4890 | static int mem_cgroup_force_empty_write(struct cgroup_subsys_state *css, | 4890 | static ssize_t mem_cgroup_force_empty_write(struct kernfs_open_file *of, |
4891 | unsigned int event) | 4891 | char *buf, size_t nbytes, |
4892 | loff_t off) | ||
4892 | { | 4893 | { |
4893 | struct mem_cgroup *memcg = mem_cgroup_from_css(css); | 4894 | struct mem_cgroup *memcg = mem_cgroup_from_css(of_css(of)); |
4894 | 4895 | ||
4895 | if (mem_cgroup_is_root(memcg)) | 4896 | if (mem_cgroup_is_root(memcg)) |
4896 | return -EINVAL; | 4897 | return -EINVAL; |
4897 | return mem_cgroup_force_empty(memcg); | 4898 | return mem_cgroup_force_empty(memcg) ?: nbytes; |
4898 | } | 4899 | } |
4899 | 4900 | ||
4900 | static u64 mem_cgroup_hierarchy_read(struct cgroup_subsys_state *css, | 4901 | static u64 mem_cgroup_hierarchy_read(struct cgroup_subsys_state *css, |
@@ -5220,14 +5221,15 @@ out: | |||
5220 | *memsw_limit = min_memsw_limit; | 5221 | *memsw_limit = min_memsw_limit; |
5221 | } | 5222 | } |
5222 | 5223 | ||
5223 | static int mem_cgroup_reset(struct cgroup_subsys_state *css, unsigned int event) | 5224 | static ssize_t mem_cgroup_reset(struct kernfs_open_file *of, char *buf, |
5225 | size_t nbytes, loff_t off) | ||
5224 | { | 5226 | { |
5225 | struct mem_cgroup *memcg = mem_cgroup_from_css(css); | 5227 | struct mem_cgroup *memcg = mem_cgroup_from_css(of_css(of)); |
5226 | int name; | 5228 | int name; |
5227 | enum res_type type; | 5229 | enum res_type type; |
5228 | 5230 | ||
5229 | type = MEMFILE_TYPE(event); | 5231 | type = MEMFILE_TYPE(of_cft(of)->private); |
5230 | name = MEMFILE_ATTR(event); | 5232 | name = MEMFILE_ATTR(of_cft(of)->private); |
5231 | 5233 | ||
5232 | switch (name) { | 5234 | switch (name) { |
5233 | case RES_MAX_USAGE: | 5235 | case RES_MAX_USAGE: |
@@ -5252,7 +5254,7 @@ static int mem_cgroup_reset(struct cgroup_subsys_state *css, unsigned int event) | |||
5252 | break; | 5254 | break; |
5253 | } | 5255 | } |
5254 | 5256 | ||
5255 | return 0; | 5257 | return nbytes; |
5256 | } | 5258 | } |
5257 | 5259 | ||
5258 | static u64 mem_cgroup_move_charge_read(struct cgroup_subsys_state *css, | 5260 | static u64 mem_cgroup_move_charge_read(struct cgroup_subsys_state *css, |
@@ -6105,7 +6107,7 @@ static struct cftype mem_cgroup_files[] = { | |||
6105 | { | 6107 | { |
6106 | .name = "max_usage_in_bytes", | 6108 | .name = "max_usage_in_bytes", |
6107 | .private = MEMFILE_PRIVATE(_MEM, RES_MAX_USAGE), | 6109 | .private = MEMFILE_PRIVATE(_MEM, RES_MAX_USAGE), |
6108 | .trigger = mem_cgroup_reset, | 6110 | .write = mem_cgroup_reset, |
6109 | .read_u64 = mem_cgroup_read_u64, | 6111 | .read_u64 = mem_cgroup_read_u64, |
6110 | }, | 6112 | }, |
6111 | { | 6113 | { |
@@ -6123,7 +6125,7 @@ static struct cftype mem_cgroup_files[] = { | |||
6123 | { | 6125 | { |
6124 | .name = "failcnt", | 6126 | .name = "failcnt", |
6125 | .private = MEMFILE_PRIVATE(_MEM, RES_FAILCNT), | 6127 | .private = MEMFILE_PRIVATE(_MEM, RES_FAILCNT), |
6126 | .trigger = mem_cgroup_reset, | 6128 | .write = mem_cgroup_reset, |
6127 | .read_u64 = mem_cgroup_read_u64, | 6129 | .read_u64 = mem_cgroup_read_u64, |
6128 | }, | 6130 | }, |
6129 | { | 6131 | { |
@@ -6132,7 +6134,7 @@ static struct cftype mem_cgroup_files[] = { | |||
6132 | }, | 6134 | }, |
6133 | { | 6135 | { |
6134 | .name = "force_empty", | 6136 | .name = "force_empty", |
6135 | .trigger = mem_cgroup_force_empty_write, | 6137 | .write = mem_cgroup_force_empty_write, |
6136 | }, | 6138 | }, |
6137 | { | 6139 | { |
6138 | .name = "use_hierarchy", | 6140 | .name = "use_hierarchy", |
@@ -6186,13 +6188,13 @@ static struct cftype mem_cgroup_files[] = { | |||
6186 | { | 6188 | { |
6187 | .name = "kmem.failcnt", | 6189 | .name = "kmem.failcnt", |
6188 | .private = MEMFILE_PRIVATE(_KMEM, RES_FAILCNT), | 6190 | .private = MEMFILE_PRIVATE(_KMEM, RES_FAILCNT), |
6189 | .trigger = mem_cgroup_reset, | 6191 | .write = mem_cgroup_reset, |
6190 | .read_u64 = mem_cgroup_read_u64, | 6192 | .read_u64 = mem_cgroup_read_u64, |
6191 | }, | 6193 | }, |
6192 | { | 6194 | { |
6193 | .name = "kmem.max_usage_in_bytes", | 6195 | .name = "kmem.max_usage_in_bytes", |
6194 | .private = MEMFILE_PRIVATE(_KMEM, RES_MAX_USAGE), | 6196 | .private = MEMFILE_PRIVATE(_KMEM, RES_MAX_USAGE), |
6195 | .trigger = mem_cgroup_reset, | 6197 | .write = mem_cgroup_reset, |
6196 | .read_u64 = mem_cgroup_read_u64, | 6198 | .read_u64 = mem_cgroup_read_u64, |
6197 | }, | 6199 | }, |
6198 | #ifdef CONFIG_SLABINFO | 6200 | #ifdef CONFIG_SLABINFO |
@@ -6215,7 +6217,7 @@ static struct cftype memsw_cgroup_files[] = { | |||
6215 | { | 6217 | { |
6216 | .name = "memsw.max_usage_in_bytes", | 6218 | .name = "memsw.max_usage_in_bytes", |
6217 | .private = MEMFILE_PRIVATE(_MEMSWAP, RES_MAX_USAGE), | 6219 | .private = MEMFILE_PRIVATE(_MEMSWAP, RES_MAX_USAGE), |
6218 | .trigger = mem_cgroup_reset, | 6220 | .write = mem_cgroup_reset, |
6219 | .read_u64 = mem_cgroup_read_u64, | 6221 | .read_u64 = mem_cgroup_read_u64, |
6220 | }, | 6222 | }, |
6221 | { | 6223 | { |
@@ -6227,7 +6229,7 @@ static struct cftype memsw_cgroup_files[] = { | |||
6227 | { | 6229 | { |
6228 | .name = "memsw.failcnt", | 6230 | .name = "memsw.failcnt", |
6229 | .private = MEMFILE_PRIVATE(_MEMSWAP, RES_FAILCNT), | 6231 | .private = MEMFILE_PRIVATE(_MEMSWAP, RES_FAILCNT), |
6230 | .trigger = mem_cgroup_reset, | 6232 | .write = mem_cgroup_reset, |
6231 | .read_u64 = mem_cgroup_read_u64, | 6233 | .read_u64 = mem_cgroup_read_u64, |
6232 | }, | 6234 | }, |
6233 | { }, /* terminate */ | 6235 | { }, /* terminate */ |
diff --git a/net/ipv4/tcp_memcontrol.c b/net/ipv4/tcp_memcontrol.c index 841fd3fa937a..f7a2ec3ac584 100644 --- a/net/ipv4/tcp_memcontrol.c +++ b/net/ipv4/tcp_memcontrol.c | |||
@@ -170,17 +170,18 @@ static u64 tcp_cgroup_read(struct cgroup_subsys_state *css, struct cftype *cft) | |||
170 | return val; | 170 | return val; |
171 | } | 171 | } |
172 | 172 | ||
173 | static int tcp_cgroup_reset(struct cgroup_subsys_state *css, unsigned int event) | 173 | static ssize_t tcp_cgroup_reset(struct kernfs_open_file *of, |
174 | char *buf, size_t nbytes, loff_t off) | ||
174 | { | 175 | { |
175 | struct mem_cgroup *memcg; | 176 | struct mem_cgroup *memcg; |
176 | struct cg_proto *cg_proto; | 177 | struct cg_proto *cg_proto; |
177 | 178 | ||
178 | memcg = mem_cgroup_from_css(css); | 179 | memcg = mem_cgroup_from_css(of_css(of)); |
179 | cg_proto = tcp_prot.proto_cgroup(memcg); | 180 | cg_proto = tcp_prot.proto_cgroup(memcg); |
180 | if (!cg_proto) | 181 | if (!cg_proto) |
181 | return 0; | 182 | return nbytes; |
182 | 183 | ||
183 | switch (event) { | 184 | switch (of_cft(of)->private) { |
184 | case RES_MAX_USAGE: | 185 | case RES_MAX_USAGE: |
185 | res_counter_reset_max(&cg_proto->memory_allocated); | 186 | res_counter_reset_max(&cg_proto->memory_allocated); |
186 | break; | 187 | break; |
@@ -189,7 +190,7 @@ static int tcp_cgroup_reset(struct cgroup_subsys_state *css, unsigned int event) | |||
189 | break; | 190 | break; |
190 | } | 191 | } |
191 | 192 | ||
192 | return 0; | 193 | return nbytes; |
193 | } | 194 | } |
194 | 195 | ||
195 | static struct cftype tcp_files[] = { | 196 | static struct cftype tcp_files[] = { |
@@ -207,13 +208,13 @@ static struct cftype tcp_files[] = { | |||
207 | { | 208 | { |
208 | .name = "kmem.tcp.failcnt", | 209 | .name = "kmem.tcp.failcnt", |
209 | .private = RES_FAILCNT, | 210 | .private = RES_FAILCNT, |
210 | .trigger = tcp_cgroup_reset, | 211 | .write = tcp_cgroup_reset, |
211 | .read_u64 = tcp_cgroup_read, | 212 | .read_u64 = tcp_cgroup_read, |
212 | }, | 213 | }, |
213 | { | 214 | { |
214 | .name = "kmem.tcp.max_usage_in_bytes", | 215 | .name = "kmem.tcp.max_usage_in_bytes", |
215 | .private = RES_MAX_USAGE, | 216 | .private = RES_MAX_USAGE, |
216 | .trigger = tcp_cgroup_reset, | 217 | .write = tcp_cgroup_reset, |
217 | .read_u64 = tcp_cgroup_read, | 218 | .read_u64 = tcp_cgroup_read, |
218 | }, | 219 | }, |
219 | { } /* terminate */ | 220 | { } /* terminate */ |