From patchwork Fri May 19 07:40:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13247772 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 BFAE4C77B7F for ; Fri, 19 May 2023 07:42:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4D10B900019; Fri, 19 May 2023 03:42:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 456A7900003; Fri, 19 May 2023 03:42:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D208900019; Fri, 19 May 2023 03:42:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 1B946900003 for ; Fri, 19 May 2023 03:42:08 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id DFA07140957 for ; Fri, 19 May 2023 07:42:07 +0000 (UTC) X-FDA: 80806211094.08.D1C6A99 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf01.hostedemail.com (Postfix) with ESMTP id 30F9340002 for ; Fri, 19 May 2023 07:42:05 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=K+9wDHTi; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf01.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.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=1684482125; 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=NhBgu+YPWWuhiMuhxeBoG/WfhrSyIDZx4YN21OB8Xyg=; b=EpK0xpLM3SGkk5U3H5TIR++FcYMHsat/93Bm3Ts2cfulEl2DEX2hOx5AVFPPySshya7jpt EEl5YaxEJY6yGGUAMUq+hF4QFn7vMHA/QUF2d9fFeSj6BSLK3AyirtspWfK9CRo3iF8VAf xgzhv2fnOPE3jULfp5qaM0FL3sey1c8= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=K+9wDHTi; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf01.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684482125; a=rsa-sha256; cv=none; b=Qztbj3LwxOhr35+2SwThybYQLPZUXFsAC8BbcbDwl5LIUOhIXxiTLYAdvkU6iOiGRocFY+ rSKtAXE3nL1qbcz/fOELmgr1N84rJERK8FxMGzGJT9jiX6yO7TRBh6u52rLTx5iLdZxwvs KrQeArfDwD49MIa1Ek2U0CDzkYQtooY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684482124; 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=NhBgu+YPWWuhiMuhxeBoG/WfhrSyIDZx4YN21OB8Xyg=; b=K+9wDHTiJ0B88mO4oyOUKCWHCR8UY6/nx8lSDGQ18tvwaiUYyXSfQNyOloniLt0HN0zqk6 2KJcX8SO+FfCmLvJYrslZnF8VrNrIyZYka9dhpQEoLm8xWN06XKTpj2ehSi6aYwTiv1/1v 72n/AkdfwZRk1fZsiiB1nds2F9qYq0M= 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-675-eDOVwGWEMCmaAhO0IYU1iA-1; Fri, 19 May 2023 03:41:59 -0400 X-MC-Unique: eDOVwGWEMCmaAhO0IYU1iA-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 EABBE3C01D8C; Fri, 19 May 2023 07:41:58 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5AC6F2166B28; Fri, 19 May 2023 07:41:56 +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 v20 17/32] nfs: Provide a splice-read stub Date: Fri, 19 May 2023 08:40:32 +0100 Message-Id: <20230519074047.1739879-18-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.6 X-Rspamd-Queue-Id: 30F9340002 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: gqw146n6b4gguxx46xtxaoq8skn9tob4 X-HE-Tag: 1684482125-434751 X-HE-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Fd1I9Q3wHNqVZfaZ6Sr8kuForDYnIhehBa8BdYj0JKZZukkqyvU66N20Q3WtZRBLbpICMNeG9RvmSPKFnC/yOwz0aVo1dr+1nMpPsv41Vg9KSh/o83hLUJmlb9eMNAI5VPqddQRLYJ1kAtK7NFW2TDBgqD/tLPrUHqovelbwZ1W5MvQ4Nh5B00JXqdS6P2/ZrutF6AfrQbUQO4kyXYgL76zcpGec+RoKma4MxQlXirGphtTz7lF18wVVYoUGzNe6lSjQi6IDcOwtg4DqHvo3crOA9bVPZ6j7a5h6m4OYOnKpjhnnEb4qyZKKjaSO5z9oJDR1bk0vB5 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: Provide a splice_read stub for NFS. This locks the inode around filemap_splice_read() and revalidates the mapping. It cannot do this around direct_splice_read() as that calls ->read_iter(). 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 --- fs/nfs/file.c | 26 +++++++++++++++++++++++++- fs/nfs/internal.h | 2 ++ fs/nfs/nfs4file.c | 2 +- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/fs/nfs/file.c b/fs/nfs/file.c index f0edf5a36237..91fe48b47f3c 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c @@ -178,6 +178,30 @@ 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; + + if (in->f_flags & O_DIRECT) + return direct_splice_read(in, ppos, pipe, len, flags); + + dprintk("NFS: splice_read(%pD2, %zu@%lu)\n", in, len, *pos); + + 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 +903,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,