From patchwork Fri Oct 13 16:04:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13421172 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 37068CDB488 for ; Fri, 13 Oct 2023 16:06:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DC94580024; Fri, 13 Oct 2023 12:06:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D7CDB80022; Fri, 13 Oct 2023 12:06:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BF37980024; Fri, 13 Oct 2023 12:06:26 -0400 (EDT) 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 AA6F680022 for ; Fri, 13 Oct 2023 12:06:26 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 84A5FB4E83 for ; Fri, 13 Oct 2023 16:06:26 +0000 (UTC) X-FDA: 81340915572.13.2FE21B9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf07.hostedemail.com (Postfix) with ESMTP id CF9B440032 for ; Fri, 13 Oct 2023 16:06:24 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aOXeFzim; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf07.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.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=1697213184; 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=xgDLRrlPZ+fbYBYQqYIYXWKYaa9HMgYZfbqZFNilvm4=; b=nCbw+s+g9uyBKSJU5T/6kGBM+gpU8/4DQWZ70DDkCkR1pT6ZWW64EU6sDhlRTyYPJH7fBn PRYwJ5BD7BNTEYt+XzPE3IPMc1fEEGeJefMsipAJ+3oQrzoyD4wVJq0UBjt2Tho7jltmJQ AfNz52mAd0nlEuSOirnr4KYgFgYhyy8= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aOXeFzim; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf07.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697213184; a=rsa-sha256; cv=none; b=Zn4PnCZNd6lW6pHsVTjLRponQlmTluQstQkIkggVZW4MmBKQhXcmuXB1Uy/HJDgXdQUEdB 8knkPnLn7zaIKa599gUXqsOEoF1rYT1GleNVeI+Ef/wjvCRvFl3Evi/e5YuQOQvpeuwu5t IfP7nks7Exsa8bvPhdVOqftYMN90OYU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697213184; 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=xgDLRrlPZ+fbYBYQqYIYXWKYaa9HMgYZfbqZFNilvm4=; b=aOXeFzimSlzHPJLIwGF9D+tniD8dw4taE4M3RhlztwAz2+0TlM35ec5JZUmqJFGaENpwI7 TtyEGUdjIhBegkIM312eUYioFfm2y89IxWM4Y1Wzz00t3uZ8H1jf6pMjnGhNo9IOh7ZVJq eWdsCGWP9tCtKm4ulvRXqb+ICc2RMGU= 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-128-YyJ4fOlmM3q6kor9W6-rTQ-1; Fri, 13 Oct 2023 12:06:16 -0400 X-MC-Unique: YyJ4fOlmM3q6kor9W6-rTQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 28C4C185A795; Fri, 13 Oct 2023 16:06:15 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.226]) by smtp.corp.redhat.com (Postfix) with ESMTP id 950EF1C060DF; Fri, 13 Oct 2023 16:06:12 +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-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, linux-cachefs@redhat.com Subject: [RFC PATCH 31/53] netfs: Provide netfs_file_read_iter() Date: Fri, 13 Oct 2023 17:04:00 +0100 Message-ID: <20231013160423.2218093-32-dhowells@redhat.com> In-Reply-To: <20231013160423.2218093-1-dhowells@redhat.com> References: <20231013160423.2218093-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Rspam-User: X-Stat-Signature: 7pq6f534oqmamcw5qcgg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8G6HMXWdBf8NZww99VDcoxM2CRLHXJFBSx8dW8RY7XFtCTh2bZiA8v2TM7j/LkVQvn5c/XI3DenIJAV3i3dpfzvjX/qsXo3vd1Iyfu4vxW++SFm3tDPRUxH2rknZkfkAi/4PTECFi7AZ3xQZrUvSj6q+YhJrAfcuagk2AKzHwKfP3Ty8EDVzkEuYwo27nf9P5de7ttvyrh5eCbya3H8SIKfI4HCBdx3bmRn8d9zERHO1sIDQh/2TpOFl8NgLByexdYGpfQ5QTxPBYz1XtaIHMK6tQpwmseG/ilSUinytGyO5tWMYnQ+4jaRzhFqivAag6MgOsZGD6PlEpDg== 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 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 e2a5a441b7fc..6e02a68a51f7 100644 --- a/include/linux/netfs.h +++ b/include/linux/netfs.h @@ -384,6 +384,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,