Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp154441rdb; Thu, 21 Dec 2023 05:43:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IGaO714cT/InBlAdAysN67MtC0DP+dbis/lglQ9SSpEZ52X5SOu6cDuzxD50xzOfAacvvCB X-Received: by 2002:ac8:4e8e:0:b0:427:a316:a274 with SMTP id 14-20020ac84e8e000000b00427a316a274mr368702qtp.131.1703166216643; Thu, 21 Dec 2023 05:43:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703166216; cv=none; d=google.com; s=arc-20160816; b=eXi1oaEwwWfO9fufOLfcVvmRPxqVPAWBS1grd6ftUt6JildjfktzyihEZcgPY3eTm6 D7gtxgctU3Ou3Hl6/+ACRl5Ih6/u3YWOwao0P8oXqbtMO+R2KcPLEhkNK4D6jdvqJ9jg 6xHjl5lTfjqyxdSxfSla+BCDCzUUZEZhCLGqATRVt+vT8seIeljQxoNcWuDHLE3+/Y5n sH0CIl0nFmRXYBAoMQ15AC4le6tHIt5t8F5luiHJBpw3eOOq/UleYz7urxOK2ME85Z7G xXwLKSEYaK2Pd8sbzaZx7FJS6ymbk8gEPgD6v536B7BEsSAZ6V8WZrDdxUJ513fsskrx F50w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=MXyYddG/H4NtJwEG9O1cQV6BiNM35TAGFP5Wf/FnDYI=; fh=ib4gl95HfLmZdfX9QIMf3rTepWCH9JlNymcDKJTPhJg=; b=SEdDrA59L/vYzb/mKy8eAM02E9RFpjO+JruiK7ihJQkAoiDa1pLG++QU78w4pP0h05 lt+NMRC29MrHejD1YbEsQWgGlXn6l+rrvA1fAntoU3hzlFlxysNKHnZ8RgAVJtG+tsJL TvjWHuTJ8IOIPrl/BvR9OfVrl6Suool3psxVQSp5KfcfuzTh0cVgCR4Gl5IlC/irH46H EV6tMmHZAnEZuzBow+JRHz4nigdkc7wK5cWkPLU/8U4lz6E6D+eKhUnB90TrOCXA5aRj UJugEUHGjeq+0TInG4fwcwp02CSSj26MlQc6M2BoB1dlev9dAuF2C0NFXGlMDwY358qH m5QQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bNWekZTl; spf=pass (google.com: domain of linux-nfs+bounces-758-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-nfs+bounces-758-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id ay8-20020a05622a228800b00427581cae64si2142185qtb.764.2023.12.21.05.43.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 05:43:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs+bounces-758-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bNWekZTl; spf=pass (google.com: domain of linux-nfs+bounces-758-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-nfs+bounces-758-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 66B661C25567 for ; Thu, 21 Dec 2023 13:43:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6A9DF360BD; Thu, 21 Dec 2023 13:26:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="bNWekZTl" X-Original-To: linux-nfs@vger.kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC10D36080 for ; Thu, 21 Dec 2023 13:26:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703165172; 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=MXyYddG/H4NtJwEG9O1cQV6BiNM35TAGFP5Wf/FnDYI=; b=bNWekZTlw1r4QQFY7gRXh/hkCOgD2+SYHgUbqge/zyzRQdu2GuK24uEOfb1ROJyDHCiBnx Wtkqb9tXVndHS1ukY0VarTBG54Brf5shK4106GUHGGqBP7xGNWw32vnj76m6mvt6/1b2Th 3z8By8RFBPhPfM9M+RmMrIyu7JEAdJE= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-572-mtNdkgQBPHOdgb3MrMshMQ-1; Thu, 21 Dec 2023 08:26:08 -0500 X-MC-Unique: mtNdkgQBPHOdgb3MrMshMQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 7DB691C06532; Thu, 21 Dec 2023 13:26:07 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.39.195.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id 800F2C159B0; Thu, 21 Dec 2023 13:26:04 +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 , Eric Van Hensbergen , 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 v5 32/40] netfs: Provide netfs_file_read_iter() Date: Thu, 21 Dec 2023 13:23:27 +0000 Message-ID: <20231221132400.1601991-33-dhowells@redhat.com> In-Reply-To: <20231221132400.1601991-1-dhowells@redhat.com> References: <20231221132400.1601991-1-dhowells@redhat.com> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 Provide a top-level-ish function that can be pointed to directly by ->read_iter file op. Signed-off-by: David Howells Reviewed-by: Jeff Layton cc: linux-cachefs@redhat.com cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org --- fs/netfs/buffered_read.c | 73 ++++++++++++++++++++++++++++++++++++++++ include/linux/netfs.h | 2 ++ 2 files changed, 75 insertions(+) diff --git a/fs/netfs/buffered_read.c b/fs/netfs/buffered_read.c index 950f63fc156a..a59e7b2edaac 100644 --- a/fs/netfs/buffered_read.c +++ b/fs/netfs/buffered_read.c @@ -558,3 +558,76 @@ int netfs_prefetch_for_write(struct file *file, struct folio *folio, _leave(" = %d", ret); return ret; } + +/** + * netfs_buffered_read_iter - Filesystem buffered I/O 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_buffered_read_iter(struct kiocb *iocb, struct iov_iter *iter) +{ + struct inode *inode = file_inode(iocb->ki_filp); + struct netfs_inode *ictx = netfs_inode(inode); + ssize_t ret; + + if (WARN_ON_ONCE((iocb->ki_flags & IOCB_DIRECT) || + test_bit(NETFS_ICTX_UNBUFFERED, &ictx->flags))) + return -EINVAL; + + ret = netfs_start_io_read(inode); + if (ret == 0) { + ret = filemap_read(iocb, iter, 0); + netfs_end_io_read(inode); + } + return ret; +} +EXPORT_SYMBOL(netfs_buffered_read_iter); + +/** + * 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 netfs_buffered_read_iter(iocb, iter); +} +EXPORT_SYMBOL(netfs_file_read_iter); diff --git a/include/linux/netfs.h b/include/linux/netfs.h index e444f814dd56..a2e53ab06a1b 100644 --- a/include/linux/netfs.h +++ b/include/linux/netfs.h @@ -379,6 +379,8 @@ struct netfs_cache_ops { /* High-level read API. */ ssize_t netfs_unbuffered_read_iter(struct kiocb *iocb, struct iov_iter *iter); +ssize_t netfs_buffered_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,