From patchwork Sat May 20 00:00:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13248986 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 E6D0CC77B7F for ; Sat, 20 May 2023 00:01:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7C904280003; Fri, 19 May 2023 20:01:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 753EF280001; Fri, 19 May 2023 20:01:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5A627280003; Fri, 19 May 2023 20:01:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 41AB8280001 for ; Fri, 19 May 2023 20:01:17 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id CDA1A1C6BDE for ; Sat, 20 May 2023 00:01:16 +0000 (UTC) X-FDA: 80808678552.23.A788B74 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf27.hostedemail.com (Postfix) with ESMTP id 0979D40010 for ; Sat, 20 May 2023 00:01:14 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=T5Af40f4; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf27.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684540875; 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=nqg0PsCK+oTzlRLhXHvUNi3fY5C+vB/nfBPH52VrtTk=; b=B2GE13X53d18bbLtyDxjvKO7egl/qh5WHc9dpOH5tf38RAYcC7oAsX1mOUkN2XzMK9kx2Q 9PDauX5KGtA9PXmF2tz12X103mwSM3Tno00a+UWkmvbidszjHSTdOH6OZ1Hy+kocka4b4s qjJViAsbS3D6GD3fo5FuqBrW35ew6jw= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=T5Af40f4; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf27.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684540875; a=rsa-sha256; cv=none; b=J+Oo9xfpEF4E2IgFA11nGaygV8c/EteYdcd2F8KYb1YKfL9ZM06dkmYAX3Dmn9CG8YxAqg Tmdc2f4q3Fa6ri55GJRWOxDrvz6wXOHZiMCMsMl4iy01mncDobqGT4LiUgvUi3UKCK1+oy DgOGgdEHNqRBUmbvh3kk+nVUp04U+Uo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684540873; 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=nqg0PsCK+oTzlRLhXHvUNi3fY5C+vB/nfBPH52VrtTk=; b=T5Af40f4wjTgRiCjjBVoElqaVa0WgmU72E/luVCD4qz0LDtrvAVN+VXFGjWNIypND39dIc 4MyO0UShLF5WTR0u/q2BHLK4Kvj6l+fjK1uef68Ow3SKdykFhxi4M+TiOTTuNlzuZicQ9f MV75/ZwxOUNPEAwqyvc+4ucCdmqqil0= 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-28-PVv0fparO1Kemo38SEKFRw-1; Fri, 19 May 2023 20:01:10 -0400 X-MC-Unique: PVv0fparO1Kemo38SEKFRw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 08E53800141; Sat, 20 May 2023 00:01:09 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4BB9340CFD45; Sat, 20 May 2023 00:01:06 +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 , Christian Brauner , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig , Miklos Szeredi , John Hubbard , linux-unionfs@vger.kernel.org Subject: [PATCH v21 05/30] splice: Make do_splice_to() generic and export it Date: Sat, 20 May 2023 01:00:24 +0100 Message-Id: <20230520000049.2226926-6-dhowells@redhat.com> In-Reply-To: <20230520000049.2226926-1-dhowells@redhat.com> References: <20230520000049.2226926-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Rspamd-Queue-Id: 0979D40010 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: t7bqfnbb1146pzqua5zdnbf35nr3i6uz X-HE-Tag: 1684540874-120150 X-HE-Meta: U2Fsd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Gm8Z5ngYN2BFpGT3XCXUNk/cf2t7a/kWXmkBOJYtwrJFswb57zIXnQrODSetFHHXL5VxyMvdtHVC6uygQGURH/2T+PjsAI/tv/kHMZEmCS4BMpMV8uAQr+z9ehTXyioefgxEpkDQbCxF4C7IWIaFZWJ2vTGEfHxH4U1Cxh+KualsSRS6tcftBgs1CKzCyPKMn7q+khlOeNrJwO6FJa4Fyi3P7leloIq7SZFsMlYe7Ii/x+ttgQZdD3lo8zhiBgFHK339KD2cnjcAb+AbUITqrFl2JNRwIIKx4hGTUWPHHWeZQAgugUysA4tnj1NwFR6GhOnKfJpqrY+qX5apzfWDyT9iqUnpfvO2XO4a4EgLZRrtetHjfwShYcVRzVgCypxNFl4Yzo9/jNJGPXKipBJdJzTc6ObQCN6smhGlq+vCo 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 Reviewed-by: Christoph Hellwig cc: Miklos Szeredi 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: Christian Brauner --- 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 f9a9be797b0c..d815a69f6589 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -867,12 +867,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; @@ -895,6 +907,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 @@ -964,7 +977,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; @@ -1112,7 +1125,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,