From patchwork Fri May 19 07:40:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13247758 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 A8299C77B7F for ; Fri, 19 May 2023 07:41:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4CE12900009; Fri, 19 May 2023 03:41:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4567A900003; Fri, 19 May 2023 03:41:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D0D4900009; Fri, 19 May 2023 03:41:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 191A7900003 for ; Fri, 19 May 2023 03:41:23 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id DE048140952 for ; Fri, 19 May 2023 07:41:22 +0000 (UTC) X-FDA: 80806209204.18.0380792 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf01.hostedemail.com (Postfix) with ESMTP id 2311B4000D for ; Fri, 19 May 2023 07:41:20 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=XhlFMc0R; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf01.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=1684482081; 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=ajb+DQf4ARiWjgPxDf7oBmcuXX7xbhqUpLXrqXXlXzo=; b=zUxFwbB9wFBozoShpdbuV6uYIrB+8z48MCOGIf5HEvMjSXmbMjevdlAsveMbyBWLZwAhFZ 7yJ6CcFBkt3wYYgnXH+Kmi2IaUHU1YOPCfB4/zsSg41F85iF0ZFrSQXgAoUJ7tlsFfjR/I fcH1UATbOU4DzItnY7d6ZqEon+gtXxU= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=XhlFMc0R; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf01.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=1684482081; a=rsa-sha256; cv=none; b=s+ZIf1fjR2ndXTKJreDjpJekFK85fxFou2Do5zOapW+CB7oaFvFukliacVlX5ZEap79rDT YYACpcyVtrINSshK8YxtpuNOf6IAEn5PSSfpoDD/1fsjosmoLONAAWJQS52EINxJ06QESp RdJGRWokTU/vbc8LTwD1Lpob8HWfWfQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482080; 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=ajb+DQf4ARiWjgPxDf7oBmcuXX7xbhqUpLXrqXXlXzo=; b=XhlFMc0RFcHJIcCRU/SK8YyKjYUG95u+8/SICN1xjrB06mOikvFjnwfCYHV3yfsjMy29fN caaUPRecK33avpZot0RTcERGU9RONf51mbKEfcbX0rcrRBrk/+/dduTUziJ2qfajb+DG0S uUYIHsJewSfIFTDjRlBXP+VHN6/PGg8= 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-650-m-DjV4UkMcasoW9pDJqpqQ-1; Fri, 19 May 2023 03:41:17 -0400 X-MC-Unique: m-DjV4UkMcasoW9pDJqpqQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4A7D7185A791; Fri, 19 May 2023 07:41:16 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7EEE77C2A; Fri, 19 May 2023 07:41:13 +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 v20 04/32] splice: Make do_splice_to() generic and export it Date: Fri, 19 May 2023 08:40:19 +0100 Message-Id: <20230519074047.1739879-5-dhowells@redhat.com> In-Reply-To: <20230519074047.1739879-1-dhowells@redhat.com> References: <20230519074047.1739879-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 2311B4000D X-Stat-Signature: k4jtrtui7h5homfm5t5suzyt5r7opkh5 X-Rspam-User: X-HE-Tag: 1684482080-567712 X-HE-Meta: U2FsdGVkX18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waXM1WtZ3x31aoiA7vRnZNGb8HWtmoZCMKr+4ryjYbugVsLHHtGLtYu2vfNUYU5exTZ/E65mbgfsJf7s2UtBCZ/beEujH9pJqLTbvbF/g1K2Fz2bOohWCLxbHKCTtIjdK9CLMGDUAuF2MDw1hg+Aun7BlJSP+CreBfGtqNtbe4ph6VmGcwxWFqrP9SXd7Cz+6tl5beVtn4e3bjfFMohO4nWv2wY4meDwipbU9PuVGBOyyNH5eqFN2nLNYfFf077vFKynSiQfuomxyqR83bvJOIPObO2qxQyUqTfVZ3HF5Vx4Q0Ewg5u1mrBBu/f7PWFOkiQo8TtUS6muXzDHecJlXPVY4qFSkrviZx5jnVkXYJ4e5WBwGgeAzDEMA0uGq0uUFkkKWKihTsMW3UzDLQl0WHFWVjXnyPeNx 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] --- 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 89c8516554d1..1e0b7c7038b5 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -881,12 +881,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; @@ -909,6 +921,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 @@ -978,7 +991,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; @@ -1126,7 +1139,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,