summaryrefslogtreecommitdiff
path: root/fs/erofs
diff options
context:
space:
mode:
authorJeffle Xu <jefflexu@linux.alibaba.com>2022-04-25 15:21:36 +0300
committerGao Xiang <hsiangkao@linux.alibaba.com>2022-05-17 19:11:19 +0300
commitec00b5e29ce3a2493616a03b56593690574a8c86 (patch)
treeb69cfcc30f824b30cc21f65ddf51b027cead227a /fs/erofs
parent3c265d7dcefab21a58ca5454c0f778412bde0870 (diff)
downloadlinux-ec00b5e29ce3a2493616a03b56593690574a8c86.tar.xz
erofs: add erofs_fscache_read_folios() helper
Add erofs_fscache_read_folios() 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 read from the cache. This helper can then be used to implement .readpage()/.readahead() of on-demand read semantics. Signed-off-by: Jeffle Xu <jefflexu@linux.alibaba.com> Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com> Link: https://lore.kernel.org/r/20220425122143.56815-15-jefflexu@linux.alibaba.com Acked-by: Chao Yu <chao@kernel.org> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Diffstat (limited to 'fs/erofs')
-rw-r--r--fs/erofs/fscache.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c
index 26f038d9c4e1..ac02af8cce3e 100644
--- a/fs/erofs/fscache.c
+++ b/fs/erofs/fscache.c
@@ -5,6 +5,60 @@
#include <linux/fscache.h>
#include "internal.h"
+/*
+ * Read data from fscache and fill the read data into page cache described by
+ * @start/len, which shall be both aligned with PAGE_SIZE. @pstart describes
+ * the start physical address in the cache file.
+ */
+static int erofs_fscache_read_folios(struct fscache_cookie *cookie,
+ struct address_space *mapping,
+ loff_t start, size_t len,
+ loff_t pstart)
+{
+ enum netfs_io_source source;
+ struct netfs_io_request rreq = {};
+ struct netfs_io_subrequest subreq = { .rreq = &rreq, };
+ struct netfs_cache_resources *cres = &rreq.cache_resources;
+ struct super_block *sb = mapping->host->i_sb;
+ struct iov_iter iter;
+ size_t done = 0;
+ int ret;
+
+ ret = fscache_begin_read_operation(cres, cookie);
+ if (ret)
+ return ret;
+
+ while (done < len) {
+ subreq.start = pstart + done;
+ subreq.len = len - done;
+ subreq.flags = 1 << NETFS_SREQ_ONDEMAND;
+
+ source = cres->ops->prepare_read(&subreq, LLONG_MAX);
+ if (WARN_ON(subreq.len == 0))
+ source = NETFS_INVALID_READ;
+ if (source != NETFS_READ_FROM_CACHE) {
+ erofs_err(sb, "failed to fscache prepare_read (source %d)",
+ source);
+ ret = -EIO;
+ goto out;
+ }
+
+ iov_iter_xarray(&iter, READ, &mapping->i_pages,
+ start + done, subreq.len);
+ ret = fscache_read(cres, subreq.start, &iter,
+ NETFS_READ_HOLE_FAIL, NULL, NULL);
+ if (ret) {
+ erofs_err(sb, "failed to fscache_read (ret %d)", ret);
+ goto out;
+ }
+
+ done += subreq.len;
+ }
+out:
+ fscache_end_operation(cres);
+ return ret;
+}
+
static const struct address_space_operations erofs_fscache_meta_aops = {
};