[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220209060108.43051-13-jefflexu@linux.alibaba.com>
Date: Wed, 9 Feb 2022 14:00:58 +0800
From: Jeffle Xu <jefflexu@...ux.alibaba.com>
To: dhowells@...hat.com, linux-cachefs@...hat.com, xiang@...nel.org,
chao@...nel.org, linux-erofs@...ts.ozlabs.org
Cc: torvalds@...ux-foundation.org, gregkh@...uxfoundation.org,
willy@...radead.org, linux-fsdevel@...r.kernel.org,
joseph.qi@...ux.alibaba.com, bo.liu@...ux.alibaba.com,
tao.peng@...ux.alibaba.com, gerry@...ux.alibaba.com,
eguan@...ux.alibaba.com, linux-kernel@...r.kernel.org
Subject: [PATCH v3 12/22] erofs: add erofs_fscache_read_page() helper
Add erofs_fscache_read_page() helper reading from fscache. It supports
on-demand read semantics. That is, it will make the backend prepare for
the data when cache miss. Once data ready, it will reinitiate a read
from the cache.
This helper can then be used to implement .readpage() of on-demand
reading semantics.
Signed-off-by: Jeffle Xu <jefflexu@...ux.alibaba.com>
---
fs/erofs/fscache.c | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c
index 3addd9aa549c..f4aade711664 100644
--- a/fs/erofs/fscache.c
+++ b/fs/erofs/fscache.c
@@ -6,6 +6,42 @@
static struct fscache_volume *volume;
+static int erofs_fscache_read_page(struct fscache_cookie *cookie,
+ struct page *page, loff_t start_pos)
+{
+ struct netfs_cache_resources cres;
+ struct bio_vec bvec[1];
+ struct iov_iter iter;
+ int ret;
+
+ memset(&cres, 0, sizeof(cres));
+
+ ret = fscache_begin_read_operation(&cres, cookie);
+ if (ret)
+ return ret;
+
+ bvec[0].bv_page = page;
+ bvec[0].bv_offset = 0;
+ bvec[0].bv_len = PAGE_SIZE;
+ iov_iter_bvec(&iter, READ, bvec, ARRAY_SIZE(bvec), PAGE_SIZE);
+
+ ret = fscache_read(&cres, start_pos, &iter,
+ NETFS_READ_HOLE_FAIL, NULL, NULL);
+ /*
+ * -ENODATA will be returned when cache miss. In this case, make the
+ * backend prepare for the data and then reinitiate a read from cache.
+ */
+ if (ret == -ENODATA) {
+ ret = fscache_ondemand_read(&cres, start_pos, PAGE_SIZE);
+ if (ret == 0)
+ ret = fscache_read(&cres, start_pos, &iter,
+ NETFS_READ_HOLE_FAIL, NULL, NULL);
+ }
+
+ fscache_end_operation(&cres);
+ return ret;
+}
+
static const struct address_space_operations erofs_fscache_blob_aops = {
};
--
2.27.0
Powered by blists - more mailing lists