fix ITER_PIPE interaction with direct_IO
[cascardo/linux.git] / fs / splice.c
index 188a386..153d4f3 100644 (file)
@@ -238,8 +238,7 @@ ssize_t add_to_pipe(struct pipe_inode_info *pipe, struct pipe_buffer *buf)
                pipe->nrbufs++;
                return buf->len;
        }
-       buf->ops->release(pipe, buf);
-       buf->ops = NULL;
+       pipe_buf_release(pipe, buf);
        return ret;
 }
 EXPORT_SYMBOL(add_to_pipe);
@@ -316,15 +315,9 @@ ssize_t generic_file_splice_read(struct file *in, loff_t *ppos,
                *ppos = kiocb.ki_pos;
                file_accessed(in);
        } else if (ret < 0) {
-               if (WARN_ON(to.idx != idx || to.iov_offset)) {
-                       /*
-                        * a bogus ->read_iter() has copied something and still
-                        * returned an error instead of a short read.
-                        */
-                       to.idx = idx;
-                       to.iov_offset = 0;
-                       iov_iter_advance(&to, 0); /* to free what was emitted */
-               }
+               to.idx = idx;
+               to.iov_offset = 0;
+               iov_iter_advance(&to, 0); /* to free what was emitted */
                /*
                 * callers of ->splice_read() expect -EAGAIN on
                 * "can't put anything in there", rather than -EFAULT.
@@ -516,13 +509,12 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
 
        while (pipe->nrbufs) {
                struct pipe_buffer *buf = pipe->bufs + pipe->curbuf;
-               const struct pipe_buf_operations *ops = buf->ops;
 
                sd->len = buf->len;
                if (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 (ret == -ENODATA)
                                ret = 0;
@@ -542,8 +534,7 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
                sd->total_len -= ret;
 
                if (!buf->len) {
-                       buf->ops = NULL;
-                       ops->release(pipe, buf);
+                       pipe_buf_release(pipe, buf);
                        pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
                        pipe->nrbufs--;
                        if (pipe->files)
@@ -762,7 +753,7 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
                        if (idx == pipe->buffers - 1)
                                idx = -1;
 
-                       ret = buf->ops->confirm(pipe, buf);
+                       ret = pipe_buf_confirm(pipe, buf);
                        if (unlikely(ret)) {
                                if (ret == -ENODATA)
                                        ret = 0;
@@ -789,11 +780,9 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
                while (ret) {
                        struct pipe_buffer *buf = pipe->bufs + pipe->curbuf;
                        if (ret >= buf->len) {
-                               const struct pipe_buf_operations *ops = buf->ops;
                                ret -= buf->len;
                                buf->len = 0;
-                               buf->ops = NULL;
-                               ops->release(pipe, buf);
+                               pipe_buf_release(pipe, buf);
                                pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
                                pipe->nrbufs--;
                                if (pipe->files)
@@ -1032,10 +1021,8 @@ out_release:
        for (i = 0; i < pipe->buffers; i++) {
                struct pipe_buffer *buf = pipe->bufs + i;
 
-               if (buf->ops) {
-                       buf->ops->release(pipe, buf);
-                       buf->ops = NULL;
-               }
+               if (buf->ops)
+                       pipe_buf_release(pipe, buf);
        }
 
        if (!bytes)