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: 66367 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp447597wrd; Wed, 8 Mar 2023 08:58:36 -0800 (PST) X-Google-Smtp-Source: AK7set+fa+Io9w55zdB4TRo1iowXtcbm2BCbd+HGMXd+R3lCjC81OLN6hWAc62Ufgg07Bz4NIwQ2 X-Received: by 2002:a05:6a21:6da9:b0:d0:3eb7:4189 with SMTP id wl41-20020a056a216da900b000d03eb74189mr5900980pzb.3.1678294716584; Wed, 08 Mar 2023 08:58:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678294716; cv=none; d=google.com; s=arc-20160816; b=w9CBwJGCIipA1IWb2J3mUjCebXEnmW8q0I6gexlNXp2+Lx7CKWCnHmthPbH0CY/Tk4 TW8y3zDAjxexZMMaYupWLDHHWOm6D23ClW3yYZNBgxKGUs4SZm3wwA5NDE5VmUfs1e+g uYDQGen1K01kUpMVd4BQRvJGydo+wEfacpewpegnBz4eL3dP+26TS6lhILjUmsZEQqSB csZj4j2mq4qleTzbG3CRFhpDMu8SrjUFDpB82JmnkfjREJ3ElXH3qjQge2U7JX3SkbgU jYIIMUsIenI6+4k3+rpLfZCVzkwPe6N/4tJ/v9qOrRQjCJdMzaHxbyb6mR2X4g1rPIT7 cJ1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fokk7Crx10kBwBR9E3z6e4T6rL1k7XhHeFqewFVvsVE=; b=jSHdbVkFOAq8T7/VAMWIkVGF9FOeGGpV3xZmeQGRqDC5agzvLaYvkTcSAiPIwMWuIU kXSUMCejcFtJX4su4jbPr5BC/hXLL+nhrmNoR+0CduEAxo68UIonpfszMORoNGHJSeox rinAPHF6zo/I8UZ2o7uHvb/ricp9NPrvNjcgp5Vaqi2hb6UmVUyRvyQ/cNh/L4Qb6fq9 plNhq/QFJnH7LkNmPSsul1qvXCd2S1p+IIkHqSvWKcvGZHa9TQ7+7S/C84GOdNpJVMQD ds2CmAIfSI4Kq+8PMBSwDnk6oBztLfQaAB4Tj2wZC4Z7OQBV13ED58/o5zn6ugsRYUf8 lHUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YWf+OTmX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v11-20020a63464b000000b005033552517bsi13686175pgk.281.2023.03.08.08.58.21; Wed, 08 Mar 2023 08:58:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YWf+OTmX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229955AbjCHQyH (ORCPT + 99 others); Wed, 8 Mar 2023 11:54:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229634AbjCHQx7 (ORCPT ); Wed, 8 Mar 2023 11:53:59 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA3DE48E2F for ; Wed, 8 Mar 2023 08:53:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678294387; 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=YWf+OTmXf9pMPFDGIFLAiIomW4vbchxYA+UlksR7z7eksuP1xcb/gJnQCP7f3TfMGf0nPI vOi7bKQqx4KigQnNNkY1AsAZA2b2VitGlT6aDUeVJbOjMGo6hRNSz3GMPWJj8FlS8kdYCC icNmiizLoEmm3cb7JnibqMo2cfWUG34= 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759819561050996225?= X-GMAIL-MSGID: =?utf-8?q?1759819561050996225?= 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,