|
5 | 5 | #include <linux/fscache.h>
|
6 | 6 | #include "internal.h"
|
7 | 7 |
|
| 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 | + |
8 | 62 | static const struct address_space_operations erofs_fscache_meta_aops = {
|
9 | 63 | };
|
10 | 64 |
|
|
0 commit comments