From patchwork Mon May 22 13:50:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13250600 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 B018DC77B73 for ; Mon, 22 May 2023 13:51:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4A572900007; Mon, 22 May 2023 09:51:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 45501900006; Mon, 22 May 2023 09:51:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2F645900007; Mon, 22 May 2023 09:51:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 20CAD900006 for ; Mon, 22 May 2023 09:51:53 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id D936740175 for ; Mon, 22 May 2023 13:51:52 +0000 (UTC) X-FDA: 80818029264.01.13367D2 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf10.hostedemail.com (Postfix) with ESMTP id 28FA0C0012 for ; Mon, 22 May 2023 13:51:49 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=asLFi8lW; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf10.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=1684763510; 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=QCSWlIyDBY1jtat2vRjBrfL6m1m2dv8ce4hoKBezm4c=; b=q/dpFgqtTwT3F3mqBQ0HG5i9b2Knli+mn/Io3ZsmwsHolms9pgU1YsibKFmYdpFc2Zz+95 4yKAd8mfnZfgqYJZiOSRB3BvcuEl75Ls94RiK2BTNMHMTyFLqjGaOKGCNnxAwB7iWoI+LV cLIlEk6AYSulCwmAukS2qI7W7EYko0k= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=asLFi8lW; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf10.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=1684763510; a=rsa-sha256; cv=none; b=I+9SiNVm1j2PxNug8VkdPKnNRQK2S7w+QY168Rr1+0aKVx7fXDd0bJxGSkOjcb1nIpW5Xy 2Lr6Z8jWV7lRoQgpIB8WH6YbNCj+HqBYHZTQUq2627e3xQFFK/gfLFf4M/nrfwaNN/Ch4Z 67qLLDTYy7SIy2IZX+dhvIP+m60KUXg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684763509; 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=asLFi8lWqKYOpWnSkDzo7MztVI6HxMniWUDZrZnLfvAfOmv3bphgRxNzjjy6A2VvPxUD7Q yce1xiplLUC8gPd8EXfn8jzm7YqYj5K/35K8R7K2YgnL5K9AsFEBTNYK8UheNQBVR2g4ZH A97fLWls6xAh4uWzTx5IzVaCqieZoYw= 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 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Rspam-User: X-Stat-Signature: 5yopzaq1fc7yutnq1i4zkzta8mpskuxw X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 28FA0C0012 X-HE-Tag: 1684763509-292528 X-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GRsU5jRZxH2r+Gaf75u2+UN0ghpmSO/o0FCRuScptpC7T9aGI48Axb1gU8BBP12z+XZDkq7s8vqw42rHAfJhh5CFSZJS+m4ov/5Fi6UFegvbjQRgUolzEg59ROKJ0yxNOF9XU3Z+k3If0doVg3Mz7SECfO6MWpyZDSLcYygTsSoK5ZTmosL7axjNqLOVZ0o251yUXq406OJL7FruQyeVYUJMXQ8rvpdXPWVNrU9oaJMzgrJGELFmm+c+CMB9yxypHvDALA+LslXSnx0LeUnIghj/yFk2DAF4RlOwXJ9pNkh8On06ptHSMW+UZKO9MmsT/Gmy9g+S4v 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 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,