From patchwork Thu Dec 7 21:21:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13484053 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 7BA5DC4167B for ; Thu, 7 Dec 2023 21:24:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BEC106B0085; Thu, 7 Dec 2023 16:24:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B9A7F6B00C0; Thu, 7 Dec 2023 16:24:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9C7696B00C1; Thu, 7 Dec 2023 16:24:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 8772E6B0085 for ; Thu, 7 Dec 2023 16:24:13 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 53F30A0272 for ; Thu, 7 Dec 2023 21:24:13 +0000 (UTC) X-FDA: 81541300386.28.7EBF744 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf11.hostedemail.com (Postfix) with ESMTP id 23C2740003 for ; Thu, 7 Dec 2023 21:24:09 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=i9wzEf4A; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.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=1701984251; 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=BBeV+gPa6exSN5f9Ij71agEQGyyesbGBrZnLGz9yhJU=; b=Agk9ypmxPgWlTRqOK/RQKED7B7uVX/LDt7QpQLUnZ2oXvYO2knUkiRaLehhEc6ST0Dqs/3 0Eas9Km3HcsAlHdub9of4yi7ltHtOId904xP50VvmSHsP0/yZvqm2YSOwDubBkIs5C9ZWm Jfo8XvGKv7bIC5dxyBUuPO3HnuqESLY= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=i9wzEf4A; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.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=1701984251; a=rsa-sha256; cv=none; b=wH3t1XD4Ivd7zhy9ZyjrufIY9u48rs8WndLmSGnmWW2O11tzL+QmMGcF+e/bBwthwa0EB/ /JEVmQyp3wPjmH9+yQ+GziO0FQDmnhZmD0IaTv+t4Bm35mluDqtiJAVTlImeRWb0oOSEQB kh0n+Dn+h750Kjd2sQ2HAdeAONbvBQI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701984249; 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=BBeV+gPa6exSN5f9Ij71agEQGyyesbGBrZnLGz9yhJU=; b=i9wzEf4ADMjah5xYyMhNXFwDBmCNkmc95Ub+spTJnW6hcfJnQAbOqMC6TIGbc/1G/jeLYJ /WAkOIyFoXWc3JdQGb1Rf1eJNMM4/z4Nm96RvN2+svPPPnZhWfffMNc2bmW91odQwzq69d TDxJ+HNHNJzHyGRG1Z1KL+xb0f1t5Ic= 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-467-xRXaFeGcNgOaRy7C7CAhjw-1; Thu, 07 Dec 2023 16:24:03 -0500 X-MC-Unique: xRXaFeGcNgOaRy7C7CAhjw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 17FBE870825; Thu, 7 Dec 2023 21:24:02 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.161]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E8473C35; Thu, 7 Dec 2023 21:23:59 +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 v3 32/59] netfs: Provide netfs_file_read_iter() Date: Thu, 7 Dec 2023 21:21:39 +0000 Message-ID: <20231207212206.1379128-33-dhowells@redhat.com> In-Reply-To: <20231207212206.1379128-1-dhowells@redhat.com> References: <20231207212206.1379128-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Rspamd-Queue-Id: 23C2740003 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: m6rq3xt6dz4xruracebi75qefgrnsf1h X-HE-Tag: 1701984249-543610 X-HE-Meta: U2FsdGVkX1/znwQ629L8J6NmZHWZurCHbD/E8ST5NoEhPijoRQ3h9At+jESF/N7lwaTGDekx2X6+qpUqDdEvGkszmA8OOrx4b4PpsJcJJPwc4KoxqfpmUptwrgoqYIcrvowvZtDEhT6v0aJ456ggj0Lvi7asYm/uOl4gLP9AjmnPjeYQQ7Fzj//2Xi6/Oha/5+PQWMywIfB3F5FAtGRg4oAmegCBbuzHwaYXsUnI9f6n93r41aVsbRs/Cz5//+8banQDPm/uEZ3b4RP3npB28Pcz29x1acAc6Va2QaysBBoMmRHWwvGfJ4OWaZwxXlVZujTMGdZApBPknC27s+RBaDsh2/PsdohPvlVlh8cKKprZAZXuvo1PR/mkErZJLjKJSi+80wfrwcQEAIg3AWqct7C6YKIbn/35ORTE+O5AGV2zpfU8EppXtgjz0TypZn9w1BNFeGIoZIo1ZHtvgBxegrTyoCaXoqgeQbJfaA/O+9OwnjnvyN+wR62l63B5s438MWqRn7GtWfFVk/LgOtQXdh5dEIYcIv8gu10ofOuUJRttohzvJtGCiyMKKRN4x8Lc3HykWwNsivYGlGApKemj5q/MX/vvhQbyaSXqbKCZmPdulXO2v2Bls8iAywh2he4Z+I05ryrJT+N7CnTVWHhe4EgJmFFYwwftadiBn7aiKAFZHYKzU/eJfKS0Xk7Qfkt9/Bc6bRU6JpNwXnS43k23Dt3PX7xEKEXU+IQwjPcszT0nOfepk5ola0vwon6Kk5zMwfdZM61xnOoAHbuzZ+duvQo7JszhEKU0sO2BQ03GVONYbrutZVM99hnghmVj3za33TFLCkKuy72Wc7srNL+zJTGzmFI/NOxqk2WmqPM9MtFmUsc3/ZvgCjrrV5VQW17EVtdha3FWakgaT3P+fyyf2LJ5njBjuxg7+BuK5qMyRZ9oiY9UxBc+rEGQ8/OF1+CDGsfGeKk+RCexErH2pMP 3H4WmG9c kQPqzxWVDRt1ASp4SWj7xBRdIm+hiCETr5jMRUtcwn4C5Rhw4LWx8kGAvGd9Nl+n1pN/yIgoPah+qyrkJs1U9OWGHjIS2MW9gDEC4O4xDBT//l5lLGayNGq1e/AFrjuoMSlMDiMA0fasD4HJv53FCkUzKnR3th650exrs8SXLM1nxw7wNiMMDyB/Xkmb3hvrTwt4vC19FSgyAZAJtaHnP6Rdqd7GR2J1jXaWBeG36pp5R/78ZyBa7zl2ZmR2IK1uOv0gV/KBPhT3pRNnycDjttsunLSBHkZO0kEocdq1BEJCpjbdp8x7wNAeVyMOn7g0S9s4YSkFmmGFmgZNoKx4ZZ2DA1Q== 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 | 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 46c0a6b45bb8..638f42fdaef5 100644 --- a/include/linux/netfs.h +++ b/include/linux/netfs.h @@ -381,6 +381,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,