pipe: add pipe_buf_confirm() helper

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
Miklos Szeredi 2016-09-27 10:45:12 +02:00 committed by Al Viro
parent a779638cf6
commit fba597db42
4 changed files with 18 additions and 10 deletions

View File

@ -728,7 +728,7 @@ static int fuse_copy_fill(struct fuse_copy_state *cs)
struct pipe_buffer *buf = cs->pipebufs; struct pipe_buffer *buf = cs->pipebufs;
if (!cs->write) { if (!cs->write) {
err = buf->ops->confirm(cs->pipe, buf); err = pipe_buf_confirm(cs->pipe, buf);
if (err) if (err)
return err; return err;
@ -828,7 +828,7 @@ static int fuse_try_move_page(struct fuse_copy_state *cs, struct page **pagep)
fuse_copy_finish(cs); fuse_copy_finish(cs);
err = buf->ops->confirm(cs->pipe, buf); err = pipe_buf_confirm(cs->pipe, buf);
if (err) if (err)
return err; return err;

View File

@ -267,7 +267,6 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)
if (bufs) { if (bufs) {
int curbuf = pipe->curbuf; int curbuf = pipe->curbuf;
struct pipe_buffer *buf = pipe->bufs + curbuf; struct pipe_buffer *buf = pipe->bufs + curbuf;
const struct pipe_buf_operations *ops = buf->ops;
size_t chars = buf->len; size_t chars = buf->len;
size_t written; size_t written;
int error; int error;
@ -275,7 +274,7 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)
if (chars > total_len) if (chars > total_len)
chars = total_len; chars = total_len;
error = ops->confirm(pipe, buf); error = pipe_buf_confirm(pipe, buf);
if (error) { if (error) {
if (!ret) if (!ret)
ret = error; ret = error;
@ -382,11 +381,10 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
int lastbuf = (pipe->curbuf + pipe->nrbufs - 1) & int lastbuf = (pipe->curbuf + pipe->nrbufs - 1) &
(pipe->buffers - 1); (pipe->buffers - 1);
struct pipe_buffer *buf = pipe->bufs + lastbuf; struct pipe_buffer *buf = pipe->bufs + lastbuf;
const struct pipe_buf_operations *ops = buf->ops;
int offset = buf->offset + buf->len; int offset = buf->offset + buf->len;
if (ops->can_merge && offset + chars <= PAGE_SIZE) { if (buf->ops->can_merge && offset + chars <= PAGE_SIZE) {
ret = ops->confirm(pipe, buf); ret = pipe_buf_confirm(pipe, buf);
if (ret) if (ret)
goto out; goto out;

View File

@ -520,7 +520,7 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
if (sd->len > sd->total_len) if (sd->len > sd->total_len)
sd->len = sd->total_len; sd->len = sd->total_len;
ret = buf->ops->confirm(pipe, buf); ret = pipe_buf_confirm(pipe, buf);
if (unlikely(ret)) { if (unlikely(ret)) {
if (ret == -ENODATA) if (ret == -ENODATA)
ret = 0; ret = 0;
@ -759,7 +759,7 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
if (idx == pipe->buffers - 1) if (idx == pipe->buffers - 1)
idx = -1; idx = -1;
ret = buf->ops->confirm(pipe, buf); ret = pipe_buf_confirm(pipe, buf);
if (unlikely(ret)) { if (unlikely(ret)) {
if (ret == -ENODATA) if (ret == -ENODATA)
ret = 0; ret = 0;

View File

@ -140,6 +140,17 @@ static inline void pipe_buf_release(struct pipe_inode_info *pipe,
ops->release(pipe, buf); ops->release(pipe, buf);
} }
/**
* pipe_buf_confirm - verify contents of the pipe buffer
* @pipe: the pipe that the buffer belongs to
* @buf: the buffer to confirm
*/
static inline int pipe_buf_confirm(struct pipe_inode_info *pipe,
struct pipe_buffer *buf)
{
return buf->ops->confirm(pipe, buf);
}
/* Differs from PIPE_BUF in that PIPE_SIZE is the length of the actual /* Differs from PIPE_BUF in that PIPE_SIZE is the length of the actual
memory allocation, whereas PIPE_BUF makes atomicity guarantees. */ memory allocation, whereas PIPE_BUF makes atomicity guarantees. */
#define PIPE_SIZE PAGE_SIZE #define PIPE_SIZE PAGE_SIZE
@ -154,7 +165,6 @@ extern unsigned long pipe_user_pages_hard;
extern unsigned long pipe_user_pages_soft; extern unsigned long pipe_user_pages_soft;
int pipe_proc_fn(struct ctl_table *, int, void __user *, size_t *, loff_t *); int pipe_proc_fn(struct ctl_table *, int, void __user *, size_t *, loff_t *);
/* Drop the inode semaphore and wait for a pipe event, atomically */ /* Drop the inode semaphore and wait for a pipe event, atomically */
void pipe_wait(struct pipe_inode_info *pipe); void pipe_wait(struct pipe_inode_info *pipe);