diff options
author | Jann Horn <jannh@google.com> | 2019-01-23 09:19:18 -0500 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2019-02-01 02:01:45 -0500 |
commit | 01e7187b41191376cee8bea8de9f907b001e87b4 (patch) | |
tree | 024b8f4afcf6bb85a5daafc475c47187b40435d3 /fs/pipe.c | |
parent | a0ce2f0aa6ad97c3d4927bf2ca54bcebdf062d55 (diff) |
pipe: stop using ->can_merge
Al Viro pointed out that since there is only one pipe buffer type to which
new data can be appended, it isn't necessary to have a ->can_merge field in
struct pipe_buf_operations, we can just check for a magic type.
Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Jann Horn <jannh@google.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/pipe.c')
-rw-r--r-- | fs/pipe.c | 20 |
1 files changed, 16 insertions, 4 deletions
@@ -226,8 +226,8 @@ void generic_pipe_buf_release(struct pipe_inode_info *pipe, | |||
226 | } | 226 | } |
227 | EXPORT_SYMBOL(generic_pipe_buf_release); | 227 | EXPORT_SYMBOL(generic_pipe_buf_release); |
228 | 228 | ||
229 | /* New data written to a pipe may be appended to a buffer with this type. */ | ||
229 | static const struct pipe_buf_operations anon_pipe_buf_ops = { | 230 | static const struct pipe_buf_operations anon_pipe_buf_ops = { |
230 | .can_merge = 1, | ||
231 | .confirm = generic_pipe_buf_confirm, | 231 | .confirm = generic_pipe_buf_confirm, |
232 | .release = anon_pipe_buf_release, | 232 | .release = anon_pipe_buf_release, |
233 | .steal = anon_pipe_buf_steal, | 233 | .steal = anon_pipe_buf_steal, |
@@ -235,7 +235,6 @@ static const struct pipe_buf_operations anon_pipe_buf_ops = { | |||
235 | }; | 235 | }; |
236 | 236 | ||
237 | static const struct pipe_buf_operations anon_pipe_buf_nomerge_ops = { | 237 | static const struct pipe_buf_operations anon_pipe_buf_nomerge_ops = { |
238 | .can_merge = 0, | ||
239 | .confirm = generic_pipe_buf_confirm, | 238 | .confirm = generic_pipe_buf_confirm, |
240 | .release = anon_pipe_buf_release, | 239 | .release = anon_pipe_buf_release, |
241 | .steal = anon_pipe_buf_steal, | 240 | .steal = anon_pipe_buf_steal, |
@@ -243,19 +242,32 @@ static const struct pipe_buf_operations anon_pipe_buf_nomerge_ops = { | |||
243 | }; | 242 | }; |
244 | 243 | ||
245 | static const struct pipe_buf_operations packet_pipe_buf_ops = { | 244 | static const struct pipe_buf_operations packet_pipe_buf_ops = { |
246 | .can_merge = 0, | ||
247 | .confirm = generic_pipe_buf_confirm, | 245 | .confirm = generic_pipe_buf_confirm, |
248 | .release = anon_pipe_buf_release, | 246 | .release = anon_pipe_buf_release, |
249 | .steal = anon_pipe_buf_steal, | 247 | .steal = anon_pipe_buf_steal, |
250 | .get = generic_pipe_buf_get, | 248 | .get = generic_pipe_buf_get, |
251 | }; | 249 | }; |
252 | 250 | ||
251 | /** | ||
252 | * pipe_buf_mark_unmergeable - mark a &struct pipe_buffer as unmergeable | ||
253 | * @buf: the buffer to mark | ||
254 | * | ||
255 | * Description: | ||
256 | * This function ensures that no future writes will be merged into the | ||
257 | * given &struct pipe_buffer. This is necessary when multiple pipe buffers | ||
258 | * share the same backing page. | ||
259 | */ | ||
253 | void pipe_buf_mark_unmergeable(struct pipe_buffer *buf) | 260 | void pipe_buf_mark_unmergeable(struct pipe_buffer *buf) |
254 | { | 261 | { |
255 | if (buf->ops == &anon_pipe_buf_ops) | 262 | if (buf->ops == &anon_pipe_buf_ops) |
256 | buf->ops = &anon_pipe_buf_nomerge_ops; | 263 | buf->ops = &anon_pipe_buf_nomerge_ops; |
257 | } | 264 | } |
258 | 265 | ||
266 | static bool pipe_buf_can_merge(struct pipe_buffer *buf) | ||
267 | { | ||
268 | return buf->ops == &anon_pipe_buf_ops; | ||
269 | } | ||
270 | |||
259 | static ssize_t | 271 | static ssize_t |
260 | pipe_read(struct kiocb *iocb, struct iov_iter *to) | 272 | pipe_read(struct kiocb *iocb, struct iov_iter *to) |
261 | { | 273 | { |
@@ -393,7 +405,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from) | |||
393 | struct pipe_buffer *buf = pipe->bufs + lastbuf; | 405 | struct pipe_buffer *buf = pipe->bufs + lastbuf; |
394 | int offset = buf->offset + buf->len; | 406 | int offset = buf->offset + buf->len; |
395 | 407 | ||
396 | if (buf->ops->can_merge && offset + chars <= PAGE_SIZE) { | 408 | if (pipe_buf_can_merge(buf) && offset + chars <= PAGE_SIZE) { |
397 | ret = pipe_buf_confirm(pipe, buf); | 409 | ret = pipe_buf_confirm(pipe, buf); |
398 | if (ret) | 410 | if (ret) |
399 | goto out; | 411 | goto out; |