Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2963551rwd; Mon, 22 May 2023 06:55:53 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6O2VA5hFv+PcsGqDWki8cSyuAkFeUEi8H9tplap9Z+U+nh4bcNH6bpy6NM6xYk3Rt+FK+J X-Received: by 2002:a05:6a20:9389:b0:103:b585:b594 with SMTP id x9-20020a056a20938900b00103b585b594mr12152501pzh.35.1684763752953; Mon, 22 May 2023 06:55:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684763752; cv=none; d=google.com; s=arc-20160816; b=xjxf0C4LS2Ka6mgbVlPbiiG9Zt7ql0yglHPOBTAm18CgkegSx8XVNVFqyt1d8ARd6G agdd+12PjW8Mu0hyHmBocWV98bhc8RBc58tSMHCRQLeAbVU4lvsmPkMTON7UgNY2XbsQ ixNbzUUeU1DepWiGgVgZrQ2EL9OwZT9T08Rtgpb2sq7dMgsp78STUFfanT9mj6FjdNXi BtA1DkIuwYsqoIZdtdN7vVZ3wsQ/v/LFKAau27Y1e/KfTNHeFx98GbVRCtZNYoCK3R4b SAVN5l6MJIhBW0DjBBr9uDISu5QviVaHhNg7H7G1Za1yl5gemEbMDDCJMykxInyUNDgP 9ZHA== 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=QCSWlIyDBY1jtat2vRjBrfL6m1m2dv8ce4hoKBezm4c=; b=OdbZxg7vZKJ85iPEDlTwj2eTtPoZQyZj7Gd696U8a4yWgbLEOw0YT+saV94mIUu1zr h8aertgwvVwwUs7ZI0wjzcjhdx6EwUy+lpNrNYC3Ii/hUdmlhLRWoQqz2qJju4WII5xB o1+Gt/WprgX24J5PsQYxzHHRnmxqA5xNdS0NH3NgVgvV0F2iiYwmhBURHg5iw2Js01H8 NYWJIZSTAuzSqamAlyu/jMTOSt8BlmwDkCTUgR92s3SrGj/pk9CqSdDpFYOXi2upCzN1 KS9w7KUCrdSEHuBwMssUIWPB+aa32kpJvNE59pidMBtVwOwkfyzWNBYUfiV3jvotYB41 J2wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="X5lB7KA/"; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s129-20020a632c87000000b0053488ce246esi4649382pgs.609.2023.05.22.06.55.37; Mon, 22 May 2023 06:55:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-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="X5lB7KA/"; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-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 S234305AbjEVNyt (ORCPT + 99 others); Mon, 22 May 2023 09:54:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233959AbjEVNxa (ORCPT ); Mon, 22 May 2023 09:53:30 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6207C10FA for ; Mon, 22 May 2023 06:51:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684763508; 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=QCSWlIyDBY1jtat2vRjBrfL6m1m2dv8ce4hoKBezm4c=; b=X5lB7KA/gq4OTOSJANF9YpRYXKZIqdGTaFzKkH7IjIWg/iCmigZp5JHNrbm+DZp/NbpUTt AZ/nUm06Tf8YwM59CxkdozKZEXC2hHBlGf/TQsywn7hU3W80h23qGsSkFpzSCeczkP8Fxb 377d/Qpb9TI238p1bKxjBXC9kIWFapg= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-543-ktvQdbIxMHSGBGqUdvd_JA-1; Mon, 22 May 2023 09:51:45 -0400 X-MC-Unique: ktvQdbIxMHSGBGqUdvd_JA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2F0793C025AD; Mon, 22 May 2023 13:51:44 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.39.192.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id D7EBC2166B29; Mon, 22 May 2023 13:51:40 +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 , Trond Myklebust , Anna Schumaker , linux-nfs@vger.kernel.org Subject: [PATCH v22 20/31] nfs: Provide a splice-read wrapper Date: Mon, 22 May 2023 14:50:07 +0100 Message-Id: <20230522135018.2742245-21-dhowells@redhat.com> In-Reply-To: <20230522135018.2742245-1-dhowells@redhat.com> References: <20230522135018.2742245-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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,T_SCC_BODY_TEXT_LINE 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-nfs@vger.kernel.org Provide a splice_read wrapper for NFS. This locks the inode around filemap_splice_read() and revalidates the mapping. Splicing from direct I/O is handled by the caller. Signed-off-by: David Howells cc: Christoph Hellwig cc: Al Viro cc: Jens Axboe cc: Trond Myklebust cc: Anna Schumaker cc: linux-nfs@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-block@vger.kernel.org cc: linux-mm@kvack.org --- Notes: ver #22) - Fix format spec in dprintk() for *ppos. ver #21) - Fix pos -> ppos in dprintk(). fs/nfs/file.c | 23 ++++++++++++++++++++++- fs/nfs/internal.h | 2 ++ fs/nfs/nfs4file.c | 2 +- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/fs/nfs/file.c b/fs/nfs/file.c index f0edf5a36237..3855f3ce8d2d 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c @@ -178,6 +178,27 @@ nfs_file_read(struct kiocb *iocb, struct iov_iter *to) } EXPORT_SYMBOL_GPL(nfs_file_read); +ssize_t +nfs_file_splice_read(struct file *in, loff_t *ppos, struct pipe_inode_info *pipe, + size_t len, unsigned int flags) +{ + struct inode *inode = file_inode(in); + ssize_t result; + + dprintk("NFS: splice_read(%pD2, %zu@%llu)\n", in, len, *ppos); + + nfs_start_io_read(inode); + result = nfs_revalidate_mapping(inode, in->f_mapping); + if (!result) { + result = filemap_splice_read(in, ppos, pipe, len, flags); + if (result > 0) + nfs_add_stats(inode, NFSIOS_NORMALREADBYTES, result); + } + nfs_end_io_read(inode); + return result; +} +EXPORT_SYMBOL_GPL(nfs_file_splice_read); + int nfs_file_mmap(struct file * file, struct vm_area_struct * vma) { @@ -879,7 +900,7 @@ const struct file_operations nfs_file_operations = { .fsync = nfs_file_fsync, .lock = nfs_lock, .flock = nfs_flock, - .splice_read = generic_file_splice_read, + .splice_read = nfs_file_splice_read, .splice_write = iter_file_splice_write, .check_flags = nfs_check_flags, .setlease = simple_nosetlease, diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h index 3cc027d3bd58..b5f21d35d30e 100644 --- a/fs/nfs/internal.h +++ b/fs/nfs/internal.h @@ -416,6 +416,8 @@ static inline __u32 nfs_access_xattr_mask(const struct nfs_server *server) int nfs_file_fsync(struct file *file, loff_t start, loff_t end, int datasync); loff_t nfs_file_llseek(struct file *, loff_t, int); ssize_t nfs_file_read(struct kiocb *, struct iov_iter *); +ssize_t nfs_file_splice_read(struct file *in, loff_t *ppos, struct pipe_inode_info *pipe, + size_t len, unsigned int flags); int nfs_file_mmap(struct file *, struct vm_area_struct *); ssize_t nfs_file_write(struct kiocb *, struct iov_iter *); int nfs_file_release(struct inode *, struct file *); diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c index 2563ed8580f3..4aeadd6e1a6d 100644 --- a/fs/nfs/nfs4file.c +++ b/fs/nfs/nfs4file.c @@ -454,7 +454,7 @@ const struct file_operations nfs4_file_operations = { .fsync = nfs_file_fsync, .lock = nfs_lock, .flock = nfs_flock, - .splice_read = generic_file_splice_read, + .splice_read = nfs_file_splice_read, .splice_write = iter_file_splice_write, .check_flags = nfs_check_flags, .setlease = nfs4_setlease,