Skip to content

Commit ec00b5e

Browse files
lostjefflehsiangkao
authored andcommitted
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 <[email protected]> Reviewed-by: Gao Xiang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Acked-by: Chao Yu <[email protected]> Signed-off-by: Gao Xiang <[email protected]>
1 parent 3c265d7 commit ec00b5e

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

fs/erofs/fscache.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,60 @@
55
#include <linux/fscache.h>
66
#include "internal.h"
77

8+
/*
9+
* Read data from fscache and fill the read data into page cache described by
10+
* @start/len, which shall be both aligned with PAGE_SIZE. @pstart describes
11+
* the start physical address in the cache file.
12+
*/
13+
static int erofs_fscache_read_folios(struct fscache_cookie *cookie,
14+
struct address_space *mapping,
15+
loff_t start, size_t len,
16+
loff_t pstart)
17+
{
18+
enum netfs_io_source source;
19+
struct netfs_io_request rreq = {};
20+
struct netfs_io_subrequest subreq = { .rreq = &rreq, };
21+
struct netfs_cache_resources *cres = &rreq.cache_resources;
22+
struct super_block *sb = mapping->host->i_sb;
23+
struct iov_iter iter;
24+
size_t done = 0;
25+
int ret;
26+
27+
ret = fscache_begin_read_operation(cres, cookie);
28+
if (ret)
29+
return ret;
30+
31+
while (done < len) {
32+
subreq.start = pstart + done;
33+
subreq.len = len - done;
34+
subreq.flags = 1 << NETFS_SREQ_ONDEMAND;
35+
36+
source = cres->ops->prepare_read(&subreq, LLONG_MAX);
37+
if (WARN_ON(subreq.len == 0))
38+
source = NETFS_INVALID_READ;
39+
if (source != NETFS_READ_FROM_CACHE) {
40+
erofs_err(sb, "failed to fscache prepare_read (source %d)",
41+
source);
42+
ret = -EIO;
43+
goto out;
44+
}
45+
46+
iov_iter_xarray(&iter, READ, &mapping->i_pages,
47+
start + done, subreq.len);
48+
ret = fscache_read(cres, subreq.start, &iter,
49+
NETFS_READ_HOLE_FAIL, NULL, NULL);
50+
if (ret) {
51+
erofs_err(sb, "failed to fscache_read (ret %d)", ret);
52+
goto out;
53+
}
54+
55+
done += subreq.len;
56+
}
57+
out:
58+
fscache_end_operation(cres);
59+
return ret;
60+
}
61+
862
static const struct address_space_operations erofs_fscache_meta_aops = {
963
};
1064

0 commit comments

Comments
 (0)