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 reinitiate a 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]>
---
fs/erofs/fscache.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c
index 1c88614203d2..d38a6efc8e50 100644
--- a/fs/erofs/fscache.c
+++ b/fs/erofs/fscache.c
@@ -5,6 +5,35 @@
#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)
+{
+ struct netfs_cache_resources cres;
+ struct iov_iter iter;
+ int ret;
+
+ memset(&cres, 0, sizeof(cres));
+
+ ret = fscache_begin_read_operation(&cres, cookie);
+ if (ret)
+ return ret;
+
+ iov_iter_xarray(&iter, READ, &mapping->i_pages, start, len);
+
+ ret = fscache_read(&cres, pstart, &iter,
+ NETFS_READ_HOLE_ONDEMAND, NULL, NULL);
+
+ fscache_end_operation(&cres);
+ return ret;
+}
+
static const struct address_space_operations erofs_fscache_meta_aops = {
};
--
2.27.0
On Wed, Apr 06, 2022 at 03:56:05PM +0800, Jeffle Xu wrote:
> 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 reinitiate a 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]>
Thanks,
Gao Xiang
> ---
> fs/erofs/fscache.c | 29 +++++++++++++++++++++++++++++
> 1 file changed, 29 insertions(+)
>
> diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c
> index 1c88614203d2..d38a6efc8e50 100644
> --- a/fs/erofs/fscache.c
> +++ b/fs/erofs/fscache.c
> @@ -5,6 +5,35 @@
> #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)
> +{
> + struct netfs_cache_resources cres;
> + struct iov_iter iter;
> + int ret;
> +
> + memset(&cres, 0, sizeof(cres));
> +
> + ret = fscache_begin_read_operation(&cres, cookie);
> + if (ret)
> + return ret;
> +
> + iov_iter_xarray(&iter, READ, &mapping->i_pages, start, len);
> +
> + ret = fscache_read(&cres, pstart, &iter,
> + NETFS_READ_HOLE_ONDEMAND, NULL, NULL);
> +
> + fscache_end_operation(&cres);
> + return ret;
> +}
> +
> static const struct address_space_operations erofs_fscache_meta_aops = {
> };
>
> --
> 2.27.0
>