Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp1075472rdg; Fri, 13 Oct 2023 09:27:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHvXlIHX7QmwZnxc1dL/XbCGB2QfZfECg5RNrZ9ApOIRluBt2K37pnVmEwXtXm4Def4DKrv X-Received: by 2002:a05:6358:618c:b0:145:6e16:fa86 with SMTP id w12-20020a056358618c00b001456e16fa86mr35359055rww.22.1697214461080; Fri, 13 Oct 2023 09:27:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697214461; cv=none; d=google.com; s=arc-20160816; b=j20t5WVQ53DmmAUPl4d4NKCvf0Ejpubl52fo1QocvQ19rEh/UiS5xxLb+HJREJ0kzn N+/MIbQ/sDPl7BUrtbR3uPrOyToY6ibkhO3+TGnefQLGGQhMP4hVqbYZLpvEFiM4Uhh/ ypBL1++jh837hob+1iw4Lc6cjsoFxpevhE89U5OAghiE0fTKDFoUjOra5QbmGdpYU7bV RJhdJxX4pMlRbTccWZGGf4FsChOtkTq2417RBQISHr/vo+GWdSqTHI8GAbZhV98Zruy8 ilHuHsXJkj/xSKEmdQboYKwckQNeqJ9biLDF5DUmVsZq9VGw1erGx5B+FgDaQKbthOGR 85rg== 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=xgDLRrlPZ+fbYBYQqYIYXWKYaa9HMgYZfbqZFNilvm4=; fh=QCasRecNkSMoqSQLnZiX89u33dCID3L05AOtURpI2pA=; b=AF6DdFGvzvBb80tBv+iFqNN5CQfw2OkoVU40xhnid05MsOWfBHXGE3TBCZyA/HiOn6 eLZtSSkrlJflN3NCxxlgiCBqJ9aB8I0+1PP12/d6qmy45c4rp0C8scHHyfZciEeLem0R sVJzedpHW42hykAbXrHTk1VrVg/pbwPQqXAItwWj0fMIp8/NqljVfPbaeCR/CAgf0jic 55S/Q+LyW8F43dSutJlIMsSDecNDt7KbxzZHRdqVPwzX/fp+veRBCg8dhvMUpzxO1Hkn 6+qCDEvoHQO4S8BNoZj7nR3Cssabyqt6pC5hINPbeAJm/WJFvgA5BoziYMK9ZJ5GNu0u z+Sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=b1r18hUR; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id bz41-20020a056a02062900b00588fa0def2asi991896pgb.778.2023.10.13.09.27.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 09:27:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=b1r18hUR; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id A17928338144; Fri, 13 Oct 2023 09:27:39 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230223AbjJMQ1Z (ORCPT + 99 others); Fri, 13 Oct 2023 12:27:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232308AbjJMQ0u (ORCPT ); Fri, 13 Oct 2023 12:26:50 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 900C21708 for ; Fri, 13 Oct 2023 09:06:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697213179; 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=b1r18hURAVVRq0SjU+6AtLrjQcqGTn3X/YgcZmB2BcP0toAJnuMwhxIdtYLTgUQzanFaq+ Y8L9WHrso4HMdga6KoauLf8FblqSAx2tHk8YTH3oy6liDg0zd9ST09MjNXMYAprmRcWthq Da727tK1EVa2lahESLoYqY//Dh8P1cs= 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 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 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_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 13 Oct 2023 09:27:39 -0700 (PDT) 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,