Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4387077pxb; Tue, 26 Jan 2021 21:55:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJyfcdjMslRSeq9f5+6TIYmEzU4oHH8E9vcN2z1D7QgCC54k8gmvOh75ldHU/rf0dxqpdv/j X-Received: by 2002:a17:906:4694:: with SMTP id a20mr5193075ejr.201.1611726929006; Tue, 26 Jan 2021 21:55:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611726929; cv=none; d=google.com; s=arc-20160816; b=V0+5yksG9NzZu8TwB0YLI89YbSsnpt61zuBAKebUQGV+UqaNweEHyxovfX0vyy0SZ2 cTFPhsgeVfxx8LscWEJN6XZMCJx2S86DoA1ijyBro0zFf0tLzbBBYHA4lbfbxaveRkaH TXve+u5wyYM0TuzASbwVaGcQjUC2FaTMz7J/xt9AuAUlf03ZtMDfwU/YACVUOFfl2Woe 9aADFipAjHFbcj0dpCQl4zrvjgr82GhcDq1XjkrTrma1PcyVEQIY77pOYrmRfteQpG8m Pfvx+Kw4hH/xlxq48JTp89SxXDBeCfuhShpq/1xcUEHARupAWjcrqCrbRbx69qirITrm 3jRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=CiHp1l8VVyHB46D0YHpiTYeEkqK7u7MaNHtiKDtvp9Q=; b=HoILRnFgJDil2iRMdrJIBvxvuQk+KtZTo25cSvZIglPnexL5ljX734Kak5yDEdX9Fh 5HUQyNaHv3RIaqttakDMSZFr5lELbFDFXPiLbFr6L/AqgvFSb3HiaoN6AXSnvAOi2pXo ba8rVkGeIhfDBu5brWGBID6pso8Phl2EzWT6wqP5+AbtvVXrtcLIQmkVbYrsB5wdfyD0 G1zxCSDgbCUlewzHc4Bw0wYAY8PaE2ln6mELZU/2z2a0mDTrhZdBs7CnLOocVt30SRoL m8QK+Dben6Iy/z53Y4fb6ZIKKYh23UMph5ewl9+8AbL5xxfv9PqMYmTstNwM31joZQXe +3kw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z12si476141edc.117.2021.01.26.21.54.54; Tue, 26 Jan 2021 21:55:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389615AbhAZRPo (ORCPT + 99 others); Tue, 26 Jan 2021 12:15:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730230AbhAZGK2 (ORCPT ); Tue, 26 Jan 2021 01:10:28 -0500 Received: from zeniv-ca.linux.org.uk (zeniv-ca.linux.org.uk [IPv6:2607:5300:60:148a::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9C98C061574 for ; Mon, 25 Jan 2021 22:09:37 -0800 (PST) Received: from viro by zeniv-ca.linux.org.uk with local (Exim 4.94 #2 (Red Hat Linux)) id 1l4HXg-0068Dh-FC; Tue, 26 Jan 2021 06:09:32 +0000 Date: Tue, 26 Jan 2021 06:09:32 +0000 From: Al Viro To: Linus Torvalds Cc: Johannes Berg , Christoph Hellwig , Oliver Giles , Linux Kernel Mailing List , Greg Kroah-Hartman Subject: [PATCH 3/3] teach sendfile(2) to handle send-to-pipe directly Message-ID: <20210126060932.GC1461355@zeniv-ca.linux.org.uk> References: <20210118085311.GA2735@lst.de> <20210118194545.GB736435@zeniv-ca> <20210126060720.GJ740243@zeniv-ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210126060720.GJ740243@zeniv-ca> Sender: Al Viro Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org no point going through the intermediate pipe Signed-off-by: Al Viro --- fs/internal.h | 9 +++++++++ fs/read_write.c | 19 +++++++++++++------ fs/splice.c | 2 +- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/fs/internal.h b/fs/internal.h index 77c50befbfbe..cff1f30cfefb 100644 --- a/fs/internal.h +++ b/fs/internal.h @@ -15,6 +15,7 @@ struct mount; struct shrink_control; struct fs_context; struct user_namespace; +struct pipe_inode_info; /* * block_dev.c @@ -193,3 +194,11 @@ int sb_init_dio_done_wq(struct super_block *sb); */ int do_statx(int dfd, const char __user *filename, unsigned flags, unsigned int mask, struct statx __user *buffer); + +/* + * fs/splice.c: + */ +long splice_file_to_pipe(struct file *in, + struct pipe_inode_info *opipe, + loff_t *offset, + size_t len, unsigned int flags); 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); diff --git a/fs/splice.c b/fs/splice.c index 74f968c65a93..b06846f1e6ee 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -1002,7 +1002,7 @@ static int splice_pipe_to_pipe(struct pipe_inode_info *ipipe, struct pipe_inode_info *opipe, size_t len, unsigned int flags); -static long splice_file_to_pipe(struct file *in, +long splice_file_to_pipe(struct file *in, struct pipe_inode_info *opipe, loff_t *offset, size_t len, unsigned int flags) -- 2.11.0