summaryrefslogtreecommitdiff
path: root/fs/read_write.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2021-02-21 09:25:32 -0800
committerLinus Torvalds <torvalds@linux-foundation.org>2021-02-21 09:25:32 -0800
commit054560e961a0ee4067fccfcfa943335e1aa48928 (patch)
tree4b2c7f8eeb6f1631bb3c8ff352abf18a77ee28ef /fs/read_write.c
parent55f62bc873477dae2c45bbbc30b86cf3e0982f3b (diff)
parentb964bf53e540262f2d12672b3cca10842c0172e7 (diff)
Merge branch 'work.sendfile' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull sendfile updates from Al Viro: "Make sendfile() to pipe destination do the right thing, should make 'fs/pipe: allow sendfile() to pipe again' redundant" * 'work.sendfile' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: teach sendfile(2) to handle send-to-pipe directly take the guts of file-to-pipe splice into a helper function do_splice_to(): move the logics for limiting the read length in
Diffstat (limited to 'fs/read_write.c')
-rw-r--r--fs/read_write.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/fs/read_write.c b/fs/read_write.c
index 75f764b43418..9db7adf160d2 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -1188,6 +1188,7 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
{
struct fd in, out;
struct inode *in_inode, *out_inode;
+ struct pipe_inode_info *opipe;
loff_t pos;
loff_t out_pos;
ssize_t retval;
@@ -1228,9 +1229,6 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
in_inode = file_inode(in.file);
out_inode = file_inode(out.file);
out_pos = out.file->f_pos;
- retval = rw_verify_area(WRITE, out.file, &out_pos, count);
- if (retval < 0)
- goto fput_out;
if (!max)
max = min(in_inode->i_sb->s_maxbytes, out_inode->i_sb->s_maxbytes);
@@ -1253,9 +1251,18 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
if (in.file->f_flags & O_NONBLOCK)
fl = SPLICE_F_NONBLOCK;
#endif
- file_start_write(out.file);
- retval = do_splice_direct(in.file, &pos, out.file, &out_pos, count, fl);
- file_end_write(out.file);
+ opipe = get_pipe_info(out.file, true);
+ if (!opipe) {
+ retval = rw_verify_area(WRITE, out.file, &out_pos, count);
+ if (retval < 0)
+ goto fput_out;
+ file_start_write(out.file);
+ retval = do_splice_direct(in.file, &pos, out.file, &out_pos,
+ count, fl);
+ file_end_write(out.file);
+ } else {
+ retval = splice_file_to_pipe(in.file, opipe, &pos, count, fl);
+ }
if (retval > 0) {
add_rchar(current, retval);