From: Al Viro <viro@zeniv.linux.org.uk>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Johannes Berg <johannes@sipsolutions.net>,
Christoph Hellwig <hch@lst.de>,
Oliver Giles <ohw.giles@gmail.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: [PATCH 1/3] do_splice_to(): move the logics for limiting the read length in
Date: Tue, 26 Jan 2021 06:08:15 +0000 [thread overview]
Message-ID: <20210126060815.GA1461355@zeniv-ca.linux.org.uk> (raw)
In-Reply-To: <20210126060720.GJ740243@zeniv-ca>
Both callers have the identical logics limiting the amount of
data we try to read into pipe - no more than would fit into
that pipe. Move that into do_splice_to() itself.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
fs/splice.c | 21 +++++++--------------
1 file changed, 7 insertions(+), 14 deletions(-)
diff --git a/fs/splice.c b/fs/splice.c
index 866d5c2367b2..c1ca2cc63b43 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -771,11 +771,16 @@ static long do_splice_to(struct file *in, loff_t *ppos,
struct pipe_inode_info *pipe, size_t len,
unsigned int flags)
{
+ unsigned int p_space;
int ret;
if (unlikely(!(in->f_mode & FMODE_READ)))
return -EBADF;
+ /* Don't try to read more the pipe has space for. */
+ p_space = pipe->max_usage - pipe_occupancy(pipe->head, pipe->tail);
+ len = min_t(size_t, len, p_space << PAGE_SHIFT);
+
ret = rw_verify_area(READ, in, ppos, len);
if (unlikely(ret < 0))
return ret;
@@ -856,15 +861,10 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
WARN_ON_ONCE(!pipe_empty(pipe->head, pipe->tail));
while (len) {
- unsigned int p_space;
size_t read_len;
loff_t pos = sd->pos, prev_pos = pos;
- /* Don't try to read more the pipe has space for. */
- p_space = pipe->max_usage -
- pipe_occupancy(pipe->head, pipe->tail);
- read_len = min_t(size_t, len, p_space << PAGE_SHIFT);
- ret = do_splice_to(in, &pos, pipe, read_len, flags);
+ ret = do_splice_to(in, &pos, pipe, len, flags);
if (unlikely(ret <= 0))
goto out_release;
@@ -1083,15 +1083,8 @@ long do_splice(struct file *in, loff_t *off_in, struct file *out,
pipe_lock(opipe);
ret = wait_for_space(opipe, flags);
- if (!ret) {
- unsigned int p_space;
-
- /* Don't try to read more the pipe has space for. */
- p_space = opipe->max_usage - pipe_occupancy(opipe->head, opipe->tail);
- len = min_t(size_t, len, p_space << PAGE_SHIFT);
-
+ if (!ret)
ret = do_splice_to(in, &offset, opipe, len, flags);
- }
pipe_unlock(opipe);
if (ret > 0)
wakeup_pipe_readers(opipe);
--
2.11.0
next prev parent reply other threads:[~2021-01-26 18:50 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-16 7:35 Splicing to/from a tty Oliver Giles
2021-01-16 16:46 ` Johannes Berg
2021-01-17 6:12 ` Oliver Giles
2021-01-18 8:53 ` Christoph Hellwig
2021-01-18 8:58 ` Johannes Berg
2021-01-18 19:26 ` Linus Torvalds
2021-01-18 19:45 ` Al Viro
2021-01-18 19:49 ` Linus Torvalds
2021-01-18 19:56 ` Al Viro
2021-01-24 19:11 ` Linus Torvalds
2021-01-25 9:16 ` [PATCH] fs/pipe: allow sendfile() to pipe again Johannes Berg
2021-01-25 10:16 ` Christoph Hellwig
2021-01-25 20:34 ` Linus Torvalds
2021-01-26 6:07 ` Splicing to/from a tty Al Viro
2021-01-26 6:08 ` Al Viro [this message]
2021-01-26 6:09 ` [PATCH 2/3] take the guts of file-to-pipe splice into a helper function Al Viro
2021-01-26 6:09 ` [PATCH 3/3] teach sendfile(2) to handle send-to-pipe directly Al Viro
2021-01-26 18:57 ` Linus Torvalds
2021-01-26 19:33 ` Al Viro
2021-01-26 18:49 ` Splicing to/from a tty Linus Torvalds
2021-01-26 19:42 ` Al Viro
2021-01-18 19:34 ` Al Viro
2021-01-18 19:46 ` Linus Torvalds
2021-01-18 19:54 ` Al Viro
2021-01-20 16:26 ` Al Viro
2021-01-20 19:11 ` Al Viro
2021-01-20 19:27 ` Linus Torvalds
2021-01-20 22:25 ` David Laight
2021-01-20 23:02 ` Al Viro
2021-01-20 23:14 ` Al Viro
2021-01-20 23:40 ` Linus Torvalds
2021-01-21 0:38 ` Al Viro
2021-01-21 1:04 ` Linus Torvalds
2021-01-21 1:45 ` Al Viro
2021-01-21 3:38 ` Linus Torvalds
2021-01-21 6:05 ` Willy Tarreau
2021-01-21 8:04 ` Johannes Berg
2021-01-21 10:08 ` David Laight
2021-01-18 8:16 ` Christoph Hellwig
2021-01-18 19:36 ` Linus Torvalds
2021-01-18 20:24 ` Linus Torvalds
2021-01-18 21:35 ` Linus Torvalds
2021-01-18 21:54 ` Linus Torvalds
2021-01-18 22:03 ` Linus Torvalds
2021-01-18 22:20 ` Linus Torvalds
2021-01-19 1:38 ` Linus Torvalds
2021-01-19 11:53 ` Greg Kroah-Hartman
2021-01-19 16:56 ` Robert Karszniewicz
2021-01-19 17:10 ` Robert Karszniewicz
2021-01-19 22:09 ` Oliver Giles
2021-01-19 17:25 ` Linus Torvalds
2021-01-19 20:24 ` Linus Torvalds
2021-01-19 20:38 ` Christoph Hellwig
2021-01-20 1:25 ` Oliver Giles
2021-01-20 4:44 ` Linus Torvalds
2021-01-20 8:15 ` Oliver Giles
2021-01-21 1:18 ` tty splice branch (was "Re: Splicing to/from a tty") Linus Torvalds
2021-01-21 8:44 ` Greg Kroah-Hartman
2021-01-21 8:50 ` Jiri Slaby
2021-01-21 8:58 ` Jiri Slaby
2021-01-21 17:52 ` Linus Torvalds
2021-01-21 8:58 ` Greg Kroah-Hartman
2021-01-21 17:03 ` Splicing to/from a tty Robert Karszniewicz
2021-01-21 18:43 ` Linus Torvalds
2021-01-19 11:52 ` Greg Kroah-Hartman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210126060815.GA1461355@zeniv-ca.linux.org.uk \
--to=viro@zeniv.linux.org.uk \
--cc=gregkh@linuxfoundation.org \
--cc=hch@lst.de \
--cc=johannes@sipsolutions.net \
--cc=linux-kernel@vger.kernel.org \
--cc=ohw.giles@gmail.com \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).