From patchwork Fri Nov 17 21:15:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13459586 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 150A2C072A2 for ; Fri, 17 Nov 2023 21:17:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 97D3E8D0054; Fri, 17 Nov 2023 16:17:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 92B5B8D001C; Fri, 17 Nov 2023 16:17:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7CB808D0054; Fri, 17 Nov 2023 16:17:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 6733A8D001C for ; Fri, 17 Nov 2023 16:17:56 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 4609640E0F for ; Fri, 17 Nov 2023 21:17:56 +0000 (UTC) X-FDA: 81468708552.20.EBBF64D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf24.hostedemail.com (Postfix) with ESMTP id 8F31018000E for ; Fri, 17 Nov 2023 21:17:54 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=G4plVrlN; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf24.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=1700255874; 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=F68X1wZZaRGmGzLVVWGsDmRPpkHPjy4MiUljuiD/iDI=; b=cVqGDn6F1QXmB/qVMMML4bBD7DggqX9rSqKr57cpn+kt1Erd5ZTgDfgBFsUKgMDLwFjjxb BTxKkvEMroD5PFdTb0rwrHOmLqBuATU2/o55UsRsgxiyzuPCZKORKL75+fhMAYgTPacnBo IeCLtUK7jhf8cThSwoG4ffWexBZpxtQ= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=G4plVrlN; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf24.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=1700255874; a=rsa-sha256; cv=none; b=ZiJYvBETFsU+XfYPzpMYwPislQ3qglbyYwYYlUXcGWuFaTL07NjUs6Rcxus/5DjcUqARVu bmdWqHAlgbjKlhcpwLBhD4C5ALEKg9UFbVXYmXkXl9GqMWNekOJ4DDASUV/rTDLKwE4kJT Z/nmpW1rh9omBGgR9g9WJ+jaAgomhU4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700255873; 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=F68X1wZZaRGmGzLVVWGsDmRPpkHPjy4MiUljuiD/iDI=; b=G4plVrlNnykJOO+JNk5sHeIe58snWywDvC7rASd9eclqTgv7qCok8CGHIZmDJPAMpjnf+y 3885m3wGbaWK7JbPWTxNnG2dMdEpqdXKbKV03hZbY2fExfjpu0MNLZniBiZTwjerHhGeRv oVKPBaT0C9pFK60ybu9B0WbB4jMWruo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-451-Ry7I_r6gOFS7zYizMfk53w-1; Fri, 17 Nov 2023 16:17:47 -0500 X-MC-Unique: Ry7I_r6gOFS7zYizMfk53w-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 976EA185A784; Fri, 17 Nov 2023 21:17:46 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id F020140C6EB9; Fri, 17 Nov 2023 21:17:43 +0000 (UTC) From: David Howells To: Jeff Layton , Steve French Cc: David Howells , Matthew Wilcox , Marc Dionne , Paulo Alcantara , Shyam Prasad N , Tom Talpey , Dominique Martinet , Ilya Dryomov , Christian Brauner , linux-cachefs@redhat.com, linux-afs@lists.infradead.org, linux-cifs@vger.kernel.org, linux-nfs@vger.kernel.org, ceph-devel@vger.kernel.org, v9fs@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 29/51] netfs: Provide netfs_file_read_iter() Date: Fri, 17 Nov 2023 21:15:21 +0000 Message-ID: <20231117211544.1740466-30-dhowells@redhat.com> In-Reply-To: <20231117211544.1740466-1-dhowells@redhat.com> References: <20231117211544.1740466-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Rspamd-Queue-Id: 8F31018000E X-Rspam-User: X-Rspamd-Server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Bh/U2cUV92Flq99Q/mJgWFhazz28sq5PG7aejBgRPTrg0OZ+zzUzhaAkQacHBcfVtauBqOESMvqGhvzuW2HlzRbv80kMhCjYWyxicWh9tkj/0VJvR/Zg5CkAw3c3xHef2pL2G3Qoo0fM9SuEwz2zLbdQGlIQ95byYuPOKVl6H/CF1O5G0MGTc1YzuNx2MU7usvV9rYx7UAh3qfzc8ljq+yJOy2IkFtBDtP3aYSeK6R/rzEVs6JxziCgGUs8I+ZCj+9s9ehxGKD+kG6rtkLE+hdNfUIx3xZX827eMZwozkz+fsAcqm/cGITB2D6S2Bxz2DZjZJCqhw3LYB0tm1/LNXmzo77g== 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: List-Subscribe: List-Unsubscribe: Provide a top-level-ish function that can be pointed to directly by ->read_iter file op. Signed-off-by: David Howells cc: Jeff Layton cc: linux-cachefs@redhat.com cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org --- fs/netfs/buffered_read.c | 33 +++++++++++++++++++++++++++++++++ include/linux/netfs.h | 1 + 2 files changed, 34 insertions(+) diff --git a/fs/netfs/buffered_read.c b/fs/netfs/buffered_read.c index 374707df6575..ab9f8e123245 100644 --- a/fs/netfs/buffered_read.c +++ b/fs/netfs/buffered_read.c @@ -564,3 +564,36 @@ int netfs_prefetch_for_write(struct file *file, struct folio *folio, _leave(" = %d", ret); return ret; } + +/** + * netfs_file_read_iter - Generic filesystem read routine + * @iocb: kernel I/O control block + * @iter: destination for the data read + * + * This is the ->read_iter() routine for all filesystems that can use the page + * cache directly. + * + * The IOCB_NOWAIT flag in iocb->ki_flags indicates that -EAGAIN shall be + * returned when no data can be read without waiting for I/O requests to + * complete; it doesn't prevent readahead. + * + * The IOCB_NOIO flag in iocb->ki_flags indicates that no new I/O requests + * shall be made for the read or for readahead. When no data can be read, + * -EAGAIN shall be returned. When readahead would be triggered, a partial, + * possibly empty read shall be returned. + * + * Return: + * * number of bytes copied, even for partial reads + * * negative error code (or 0 if IOCB_NOIO) if nothing was read + */ +ssize_t netfs_file_read_iter(struct kiocb *iocb, struct iov_iter *iter) +{ + struct netfs_inode *ictx = netfs_inode(iocb->ki_filp->f_mapping->host); + + if ((iocb->ki_flags & IOCB_DIRECT) || + test_bit(NETFS_ICTX_UNBUFFERED, &ictx->flags)) + return netfs_unbuffered_read_iter(iocb, iter); + + return filemap_read(iocb, iter, 0); +} +EXPORT_SYMBOL(netfs_file_read_iter); diff --git a/include/linux/netfs.h b/include/linux/netfs.h index 80e48af8b72f..2ab989407dcb 100644 --- a/include/linux/netfs.h +++ b/include/linux/netfs.h @@ -385,6 +385,7 @@ struct netfs_cache_ops { /* High-level read API. */ ssize_t netfs_unbuffered_read_iter(struct kiocb *iocb, struct iov_iter *iter); +ssize_t netfs_file_read_iter(struct kiocb *iocb, struct iov_iter *iter); /* High-level write API */ ssize_t netfs_perform_write(struct kiocb *iocb, struct iov_iter *iter,