]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - fs/splice.c
net/dst: add new function skb_dst_update_pmtu_no_confirm
[mirror_ubuntu-bionic-kernel.git] / fs / splice.c
index 31a1d0d309140b3e505c61db8c76baa7ae253e9b..ffedf6ebb2341553afa74b83575488d2a7bc6d8c 100644 (file)
@@ -947,11 +947,17 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
        sd->flags &= ~SPLICE_F_NONBLOCK;
        more = sd->flags & SPLICE_F_MORE;
 
+       WARN_ON_ONCE(pipe->nrbufs != 0);
+
        while (len) {
+               unsigned int pipe_pages;
                size_t read_len;
                loff_t pos = sd->pos, prev_pos = pos;
 
-               ret = do_splice_to(in, &pos, pipe, len, flags);
+               /* Don't try to read more the pipe has space for. */
+               pipe_pages = pipe->buffers - pipe->nrbufs;
+               read_len = min(len, (size_t)pipe_pages << PAGE_SHIFT);
+               ret = do_splice_to(in, &pos, pipe, read_len, flags);
                if (unlikely(ret <= 0))
                        goto out_release;
 
@@ -1171,8 +1177,15 @@ static long do_splice(struct file *in, loff_t __user *off_in,
 
                pipe_lock(opipe);
                ret = wait_for_space(opipe, flags);
-               if (!ret)
+               if (!ret) {
+                       unsigned int pipe_pages;
+
+                       /* Don't try to read more the pipe has space for. */
+                       pipe_pages = opipe->buffers - opipe->nrbufs;
+                       len = min(len, (size_t)pipe_pages << PAGE_SHIFT);
+
                        ret = do_splice_to(in, &offset, opipe, len, flags);
+               }
                pipe_unlock(opipe);
                if (ret > 0)
                        wakeup_pipe_readers(opipe);