diff options
author | Miklos Szeredi <mszeredi@redhat.com> | 2016-09-27 04:45:12 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2016-10-05 18:23:59 -0400 |
commit | fba597db4218ac324eee34b64736ea94829c95bf (patch) | |
tree | 1f1a653fe362d94719d40c175e11e2aaa91d9c03 | |
parent | a779638cf622f069a484e8802134cca3c6c71415 (diff) |
pipe: add pipe_buf_confirm() helper
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r-- | fs/fuse/dev.c | 4 | ||||
-rw-r--r-- | fs/pipe.c | 8 | ||||
-rw-r--r-- | fs/splice.c | 4 | ||||
-rw-r--r-- | include/linux/pipe_fs_i.h | 12 |
4 files changed, 18 insertions, 10 deletions
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index d82414a1f936..e5d5cc922c70 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c | |||
@@ -728,7 +728,7 @@ static int fuse_copy_fill(struct fuse_copy_state *cs) | |||
728 | struct pipe_buffer *buf = cs->pipebufs; | 728 | struct pipe_buffer *buf = cs->pipebufs; |
729 | 729 | ||
730 | if (!cs->write) { | 730 | if (!cs->write) { |
731 | err = buf->ops->confirm(cs->pipe, buf); | 731 | err = pipe_buf_confirm(cs->pipe, buf); |
732 | if (err) | 732 | if (err) |
733 | return err; | 733 | return err; |
734 | 734 | ||
@@ -828,7 +828,7 @@ static int fuse_try_move_page(struct fuse_copy_state *cs, struct page **pagep) | |||
828 | 828 | ||
829 | fuse_copy_finish(cs); | 829 | fuse_copy_finish(cs); |
830 | 830 | ||
831 | err = buf->ops->confirm(cs->pipe, buf); | 831 | err = pipe_buf_confirm(cs->pipe, buf); |
832 | if (err) | 832 | if (err) |
833 | return err; | 833 | return err; |
834 | 834 | ||
@@ -267,7 +267,6 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to) | |||
267 | if (bufs) { | 267 | if (bufs) { |
268 | int curbuf = pipe->curbuf; | 268 | int curbuf = pipe->curbuf; |
269 | struct pipe_buffer *buf = pipe->bufs + curbuf; | 269 | struct pipe_buffer *buf = pipe->bufs + curbuf; |
270 | const struct pipe_buf_operations *ops = buf->ops; | ||
271 | size_t chars = buf->len; | 270 | size_t chars = buf->len; |
272 | size_t written; | 271 | size_t written; |
273 | int error; | 272 | int error; |
@@ -275,7 +274,7 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to) | |||
275 | if (chars > total_len) | 274 | if (chars > total_len) |
276 | chars = total_len; | 275 | chars = total_len; |
277 | 276 | ||
278 | error = ops->confirm(pipe, buf); | 277 | error = pipe_buf_confirm(pipe, buf); |
279 | if (error) { | 278 | if (error) { |
280 | if (!ret) | 279 | if (!ret) |
281 | ret = error; | 280 | ret = error; |
@@ -382,11 +381,10 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from) | |||
382 | int lastbuf = (pipe->curbuf + pipe->nrbufs - 1) & | 381 | int lastbuf = (pipe->curbuf + pipe->nrbufs - 1) & |
383 | (pipe->buffers - 1); | 382 | (pipe->buffers - 1); |
384 | struct pipe_buffer *buf = pipe->bufs + lastbuf; | 383 | struct pipe_buffer *buf = pipe->bufs + lastbuf; |
385 | const struct pipe_buf_operations *ops = buf->ops; | ||
386 | int offset = buf->offset + buf->len; | 384 | int offset = buf->offset + buf->len; |
387 | 385 | ||
388 | if (ops->can_merge && offset + chars <= PAGE_SIZE) { | 386 | if (buf->ops->can_merge && offset + chars <= PAGE_SIZE) { |
389 | ret = ops->confirm(pipe, buf); | 387 | ret = pipe_buf_confirm(pipe, buf); |
390 | if (ret) | 388 | if (ret) |
391 | goto out; | 389 | goto out; |
392 | 390 | ||
diff --git a/fs/splice.c b/fs/splice.c index ae90cd1d2999..aa38901a4f10 100644 --- a/fs/splice.c +++ b/fs/splice.c | |||
@@ -520,7 +520,7 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des | |||
520 | if (sd->len > sd->total_len) | 520 | if (sd->len > sd->total_len) |
521 | sd->len = sd->total_len; | 521 | sd->len = sd->total_len; |
522 | 522 | ||
523 | ret = buf->ops->confirm(pipe, buf); | 523 | ret = pipe_buf_confirm(pipe, buf); |
524 | if (unlikely(ret)) { | 524 | if (unlikely(ret)) { |
525 | if (ret == -ENODATA) | 525 | if (ret == -ENODATA) |
526 | ret = 0; | 526 | ret = 0; |
@@ -759,7 +759,7 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out, | |||
759 | if (idx == pipe->buffers - 1) | 759 | if (idx == pipe->buffers - 1) |
760 | idx = -1; | 760 | idx = -1; |
761 | 761 | ||
762 | ret = buf->ops->confirm(pipe, buf); | 762 | ret = pipe_buf_confirm(pipe, buf); |
763 | if (unlikely(ret)) { | 763 | if (unlikely(ret)) { |
764 | if (ret == -ENODATA) | 764 | if (ret == -ENODATA) |
765 | ret = 0; | 765 | ret = 0; |
diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h index d24fa6da6ae3..654413334537 100644 --- a/include/linux/pipe_fs_i.h +++ b/include/linux/pipe_fs_i.h | |||
@@ -140,6 +140,17 @@ static inline void pipe_buf_release(struct pipe_inode_info *pipe, | |||
140 | ops->release(pipe, buf); | 140 | ops->release(pipe, buf); |
141 | } | 141 | } |
142 | 142 | ||
143 | /** | ||
144 | * pipe_buf_confirm - verify contents of the pipe buffer | ||
145 | * @pipe: the pipe that the buffer belongs to | ||
146 | * @buf: the buffer to confirm | ||
147 | */ | ||
148 | static inline int pipe_buf_confirm(struct pipe_inode_info *pipe, | ||
149 | struct pipe_buffer *buf) | ||
150 | { | ||
151 | return buf->ops->confirm(pipe, buf); | ||
152 | } | ||
153 | |||
143 | /* Differs from PIPE_BUF in that PIPE_SIZE is the length of the actual | 154 | /* Differs from PIPE_BUF in that PIPE_SIZE is the length of the actual |
144 | memory allocation, whereas PIPE_BUF makes atomicity guarantees. */ | 155 | memory allocation, whereas PIPE_BUF makes atomicity guarantees. */ |
145 | #define PIPE_SIZE PAGE_SIZE | 156 | #define PIPE_SIZE PAGE_SIZE |
@@ -154,7 +165,6 @@ extern unsigned long pipe_user_pages_hard; | |||
154 | extern unsigned long pipe_user_pages_soft; | 165 | extern unsigned long pipe_user_pages_soft; |
155 | int pipe_proc_fn(struct ctl_table *, int, void __user *, size_t *, loff_t *); | 166 | int pipe_proc_fn(struct ctl_table *, int, void __user *, size_t *, loff_t *); |
156 | 167 | ||
157 | |||
158 | /* Drop the inode semaphore and wait for a pipe event, atomically */ | 168 | /* Drop the inode semaphore and wait for a pipe event, atomically */ |
159 | void pipe_wait(struct pipe_inode_info *pipe); | 169 | void pipe_wait(struct pipe_inode_info *pipe); |
160 | 170 | ||