diff mbox series

[v3,1/9] erofs: support readahead in meta routine

Message ID 20230203030143.73105-2-jefflexu@linux.alibaba.com (mailing list archive)
State New, archived
Headers show
Series erofs: support page cache sharing between EROFS images in fscache mode | expand

Commit Message

Jingbo Xu Feb. 3, 2023, 3:01 a.m. UTC
In prep for the following support for readahead for page cache sharing,
add support for readahead in meta routine.

Signed-off-by: Jingbo Xu <jefflexu@linux.alibaba.com>
---
 fs/erofs/fscache.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
diff mbox series

Patch

diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c
index 014e20962376..e2ebe8f7dbe9 100644
--- a/fs/erofs/fscache.c
+++ b/fs/erofs/fscache.c
@@ -193,6 +193,30 @@  static int erofs_fscache_meta_read_folio(struct file *data, struct folio *folio)
 	return ret;
 }
 
+static void erofs_fscache_meta_readahead(struct readahead_control *rac)
+{
+	int ret;
+	struct erofs_fscache *ctx = rac->mapping->host->i_private;
+	struct erofs_fscache_request *req;
+
+	if (!readahead_count(rac))
+		return;
+
+	req = erofs_fscache_req_alloc(rac->mapping,
+			readahead_pos(rac), readahead_length(rac));
+	if (IS_ERR(req))
+		return;
+
+	/* The request completion will drop refs on the folios. */
+	while (readahead_folio(rac))
+		;
+
+	ret = erofs_fscache_read_folios_async(ctx->cookie, req, req->start, req->len);
+	if (ret)
+		req->error = ret;
+	erofs_fscache_req_put(req);
+}
+
 static int erofs_fscache_data_read_slice(struct erofs_fscache_request *primary)
 {
 	struct address_space *mapping = primary->mapping;
@@ -319,6 +343,7 @@  static void erofs_fscache_readahead(struct readahead_control *rac)
 
 static const struct address_space_operations erofs_fscache_meta_aops = {
 	.read_folio = erofs_fscache_meta_read_folio,
+	.readahead  = erofs_fscache_meta_readahead,
 };
 
 const struct address_space_operations erofs_fscache_access_aops = {