@@ -1,5 +1,78 @@
#include "internal.h"
+/*
+ * erofs_fscache_readpage
+ *
+ * Copy data from backpage (bootstrap) to page of files among erofs.
+ */
+static int erofs_fscache_readpage(struct file *file, struct page *page)
+{
+ struct inode *inode = page->mapping->host;
+ struct super_block *sb = inode->i_sb;
+ erofs_off_t pos = page->index << PAGE_SHIFT;
+ struct erofs_map_blocks map = { .m_la = pos };
+ erofs_blk_t blkaddr;
+ struct page *backpage;
+ u64 total, batch, copied = 0;
+ char *vsrc, *vdst; /* virtual address of mapped src/dst page */
+ char *psrc, *pdst; /* cursor inside src/dst page */
+ u64 osrc; /* offset inside src page */
+ int err;
+
+ err = erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW);
+ if (err)
+ goto out;
+
+ total = min_t(u64, PAGE_SIZE, map.m_plen - (pos - map.m_la));
+ blkaddr = map.m_pa >> PAGE_SHIFT;
+ osrc = map.m_pa & (PAGE_SIZE - 1);
+
+ while (total) {
+ backpage = erofs_get_meta_page(sb, blkaddr);
+ if (IS_ERR(backpage)) {
+ err = PTR_ERR(backpage);
+ goto out;
+ }
+
+ vsrc = psrc = kmap_atomic(backpage);
+ vdst = pdst = kmap_atomic(page);
+
+ psrc += osrc;
+ pdst += copied;
+ batch = min_t(u64, PAGE_SIZE - osrc, total);
+
+ memcpy(pdst, psrc, batch);
+
+ copied += batch;
+ total -= batch;
+ blkaddr++;
+ osrc = 0; /* copy from the beginning of the next backpage */
+
+ /*
+ * Avoid 'scheduling while atomic' error. Unmap before going
+ * into the next turn, since we may schedule inside
+ * erofs_get_meta_page().
+ * */
+ kunmap_atomic(vsrc);
+ kunmap_atomic(vdst);
+
+ unlock_page(backpage);
+ put_page(backpage);
+ }
+
+out:
+ if (err)
+ SetPageError(page);
+ else
+ SetPageUptodate(page);
+ unlock_page(page);
+ return err;
+}
+
+const struct address_space_operations erofs_fscache_access_aops = {
+ .readpage = erofs_fscache_readpage,
+};
+
static int erofs_begin_cache_operation(struct netfs_read_request *rreq)
{
return fscache_begin_read_operation(&rreq->cache_resources,
@@ -299,7 +299,11 @@ static int erofs_fill_inode(struct inode *inode, int isdir)
err = z_erofs_fill_inode(inode);
goto out_unlock;
}
- inode->i_mapping->a_ops = &erofs_raw_access_aops;
+
+ if (inode->i_sb->s_bdev)
+ inode->i_mapping->a_ops = &erofs_raw_access_aops;
+ else
+ inode->i_mapping->a_ops = &erofs_fscache_access_aops;
out_unlock:
unlock_page(page);
@@ -353,6 +353,7 @@ struct page *erofs_grab_cache_page_nowait(struct address_space *mapping,
extern const struct super_operations erofs_sops;
extern const struct address_space_operations erofs_raw_access_aops;
+extern const struct address_space_operations erofs_fscache_access_aops;
extern const struct address_space_operations z_erofs_aops;
/*
Signed-off-by: Jeffle Xu <jefflexu@linux.alibaba.com> --- fs/erofs/fscache.c | 73 +++++++++++++++++++++++++++++++++++++++++++++ fs/erofs/inode.c | 6 +++- fs/erofs/internal.h | 1 + 3 files changed, 79 insertions(+), 1 deletion(-)