From patchwork Wed Mar 8 16:52:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13166144 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A212DC678D5 for ; Wed, 8 Mar 2023 16:53:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 21FE16B007D; Wed, 8 Mar 2023 11:53:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1A9CE6B007E; Wed, 8 Mar 2023 11:53:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EEFD56B0080; Wed, 8 Mar 2023 11:53:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id DB2066B007D for ; Wed, 8 Mar 2023 11:53:11 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 9EB51140FC1 for ; Wed, 8 Mar 2023 16:53:11 +0000 (UTC) X-FDA: 80546326182.01.C550736 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf07.hostedemail.com (Postfix) with ESMTP id F1BE240019 for ; Wed, 8 Mar 2023 16:53:08 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HqjkFi4Y; spf=pass (imf07.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678294389; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=fokk7Crx10kBwBR9E3z6e4T6rL1k7XhHeFqewFVvsVE=; b=0ujrFeOOe1DdWSX04AkbHWKgOJPcREuCs5LZlLshY3UAI16oOFwBd2+oFqFmt+Fyk+tsks G3zaVKjEYyqMQuLhGYVmnvzfH35R03EfbyAo1n/Vl2SfoTCwNR5TPOfV7QSzIo3rWz214i fza84FJU2ifV3RUmg6u633Ie/a+ChfQ= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HqjkFi4Y; spf=pass (imf07.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678294389; a=rsa-sha256; cv=none; b=k5nVpvq9ZBODiim38DDpE4VMtGRtOnwgNgJLqE6bMYFrS+5jQc5A46NgWpRD8A+szfkaGW Yba3Dyf6enb+QA7lZKbA7RMpt1wpyFELgVRx9KGAL+y4SSuvCotsXEwqoa0fmzo2zDvkx+ zbGMk60Un4+9ikx+tN1PQZ0Q2hdXhBU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678294388; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fokk7Crx10kBwBR9E3z6e4T6rL1k7XhHeFqewFVvsVE=; b=HqjkFi4YrYJiWI1oUe0ohpgDr9KDjRiL/DUNHD6yAplE2slqHAzGH7DXzP9YhvrQjggHV/ iNfuMaCwB3S37v6+lNQ/VZF6fpLrGN4f/24DsiLqm2yA9erL4JVlxzUxoJGcMqDP0iNqeT I0w87ejOWwwReySJXLXMpUQSaCGrLeg= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-194-7CVrQpdMObaxQx7KSWspRQ-1; Wed, 08 Mar 2023 11:53:04 -0500 X-MC-Unique: 7CVrQpdMObaxQx7KSWspRQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EB104100F90A; Wed, 8 Mar 2023 16:53:03 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA1FE492C3E; Wed, 8 Mar 2023 16:53:01 +0000 (UTC) From: David Howells To: Jens Axboe , Al Viro , Christoph Hellwig Cc: David Howells , Matthew Wilcox , Jan Kara , Jeff Layton , David Hildenbrand , Jason Gunthorpe , Logan Gunthorpe , Hillf Danton , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Miklos Szeredi , Christoph Hellwig , John Hubbard , linux-unionfs@vger.kernel.org Subject: [PATCH v17 02/14] splice: Make do_splice_to() generic and export it Date: Wed, 8 Mar 2023 16:52:39 +0000 Message-Id: <20230308165251.2078898-3-dhowells@redhat.com> In-Reply-To: <20230308165251.2078898-1-dhowells@redhat.com> References: <20230308165251.2078898-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Stat-Signature: i3enkemopup1ffc91k1u73ezosc513mp X-Rspam-User: X-Rspamd-Queue-Id: F1BE240019 X-Rspamd-Server: rspam06 X-HE-Tag: 1678294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5H/0+omTWwDjU2M1/FLVvKeFGYzRqlnb6tlSWR2H73IRKoVfXz/w+TVnocvC57h81iVQoC4VEE9N6zOCk19d3z7z7xxKPoyxcljjIPeFGSqPi6V/E56ayDfmB5Pz19ip2MkRrGFjgfMSgJNLvmeWRFgAQr23ZAvH7wLhCiVNynSmSoOdF4l81B3H0JK9P7fUhROMba7A4oy15CevTlkUMt3TdqwdpyRPyVnQA474j4QGsr0iN8YWylnWQ/+auzOuIir3tvj8xo8aU+1rwxzi/ymM2DmJDBvgoRszPY+EcxQbuLqi9kXhg9ghkS6nUEuGii+akb/GVsd5UjmBOf0DboFNJrvn+flQnkRlJS+snqrjU+Wc7HN+3x1w4BfIktLSz8BZSL9Lni5sOsBc2SANt7JJi5nXDKJUjojKyUeX8FrON8VXoTFGFezx8CpIyzbagtnSpfA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Rename do_splice_to() to vfs_splice_read() and export it so that it can be used as a helper when calling down to a lower layer filesystem as it performs all the necessary checks[1]. Signed-off-by: David Howells cc: Miklos Szeredi cc: Christoph Hellwig cc: Jens Axboe cc: Al Viro cc: John Hubbard cc: David Hildenbrand cc: Matthew Wilcox cc: linux-unionfs@vger.kernel.org cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org Link: https://lore.kernel.org/r/CAJfpeguGksS3sCigmRi9hJdUec8qtM9f+_9jC1rJhsXT+dV01w@mail.gmail.com/ [1] Reviewed-by: Christoph Hellwig --- fs/splice.c | 27 ++++++++++++++++++++------- include/linux/splice.h | 3 +++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/fs/splice.c b/fs/splice.c index abd21a455a2b..90ccd3666dca 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -851,12 +851,24 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out, return out->f_op->splice_write(pipe, out, ppos, len, flags); } -/* - * Attempt to initiate a splice from a file to a pipe. +/** + * vfs_splice_read - Read data from a file and splice it into a pipe + * @in: File to splice from + * @ppos: Input file offset + * @pipe: Pipe to splice to + * @len: Number of bytes to splice + * @flags: Splice modifier flags (SPLICE_F_*) + * + * Splice the requested amount of data from the input file to the pipe. This + * is synchronous as the caller must hold the pipe lock across the entire + * operation. + * + * If successful, it returns the amount of data spliced, 0 if it hit the EOF or + * a hole and a negative error code otherwise. */ -static long do_splice_to(struct file *in, loff_t *ppos, - struct pipe_inode_info *pipe, size_t len, - unsigned int flags) +long vfs_splice_read(struct file *in, loff_t *ppos, + struct pipe_inode_info *pipe, size_t len, + unsigned int flags) { unsigned int p_space; int ret; @@ -879,6 +891,7 @@ static long do_splice_to(struct file *in, loff_t *ppos, return warn_unsupported(in, "read"); return in->f_op->splice_read(in, ppos, pipe, len, flags); } +EXPORT_SYMBOL_GPL(vfs_splice_read); /** * splice_direct_to_actor - splices data directly between two non-pipes @@ -949,7 +962,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd, size_t read_len; loff_t pos = sd->pos, prev_pos = pos; - ret = do_splice_to(in, &pos, pipe, len, flags); + ret = vfs_splice_read(in, &pos, pipe, len, flags); if (unlikely(ret <= 0)) goto out_release; @@ -1097,7 +1110,7 @@ long splice_file_to_pipe(struct file *in, pipe_lock(opipe); ret = wait_for_space(opipe, flags); if (!ret) - ret = do_splice_to(in, offset, opipe, len, flags); + ret = vfs_splice_read(in, offset, opipe, len, flags); pipe_unlock(opipe); if (ret > 0) wakeup_pipe_readers(opipe); diff --git a/include/linux/splice.h b/include/linux/splice.h index a55179fd60fc..8f052c3dae95 100644 --- a/include/linux/splice.h +++ b/include/linux/splice.h @@ -76,6 +76,9 @@ extern ssize_t splice_to_pipe(struct pipe_inode_info *, struct splice_pipe_desc *); extern ssize_t add_to_pipe(struct pipe_inode_info *, struct pipe_buffer *); +long vfs_splice_read(struct file *in, loff_t *ppos, + struct pipe_inode_info *pipe, size_t len, + unsigned int flags); extern ssize_t splice_direct_to_actor(struct file *, struct splice_desc *, splice_direct_actor *); extern long do_splice(struct file *in, loff_t *off_in,