From: Gao Xiang hsiangkao@linux.alibaba.com
anolis inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/IB5UKT
Reference: https://gitee.com/anolis/cloud-kernel/commit/2379fb87ba9e
--------------------------------
ANBZ: #1666
commit 1442b02b66ad2c568f9d5178b7c3c1287b37e438 upstream.
Implement the data plane of reading data from data blobs over fscache for non-inline layout.
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-19-jefflexu@linux.alibaba.com Acked-by: Chao Yu chao@kernel.org Signed-off-by: Gao Xiang hsiangkao@linux.alibaba.com Signed-off-by: Huang Jianan jnhuang@linux.alibaba.com Reviewed-by: Jeffle Xu jefflexu@linux.alibaba.com Signed-off-by: Baokun Li libaokun1@huawei.com --- fs/erofs/fscache.c | 59 +++++++++++++++++++++++++++++++++++++++++++++ fs/erofs/inode.c | 4 +++ fs/erofs/internal.h | 1 + 3 files changed, 64 insertions(+)
diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index c922dda36bda..5c48656550f7 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -89,12 +89,71 @@ static void erofs_fscache_invalidate_page(struct page *page, unsigned int offset ClearPageFsCache(page); }
+static int erofs_fscache_readpage(struct file *file, struct page *page) +{ + struct inode *inode = page->mapping->host; + struct super_block *sb = inode->i_sb; + struct erofs_map_blocks map; + struct erofs_map_dev mdev; + erofs_off_t pos = page_offset(page); + loff_t pstart; + int ret; + + map.m_la = pos; + ret = erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW); + if (ret) + goto out_unlock; + + if (!(map.m_flags & EROFS_MAP_MAPPED)) { + zero_user_segment(page, 0, PAGE_SIZE); + SetPageUptodate(page); + goto out_unlock; + } + + mdev = (struct erofs_map_dev) { + .m_deviceid = map.m_deviceid, + .m_pa = map.m_pa, + }; + + ret = erofs_map_dev(sb, &mdev); + if (ret) + goto out_unlock; + + pstart = mdev.m_pa + (pos - map.m_la); + ret = fscache_read_or_alloc_page2(mdev.m_fscache->cookie, page, + erofs_readpage_from_fscache_complete, + NULL, + GFP_KERNEL, pstart); + switch (ret) { + case 0: /* page found in fscache, read submitted */ + erofs_dbg("%s: submitted", __func__); + return ret; + case -ENOBUFS: /* page won't be cached */ + case -ENODATA: /* page not in cache */ + erofs_err(sb, "%s: %d", __func__, ret); + ret = -EIO; + goto out_unlock; + default: + erofs_err(sb, "unknown error ret = %d", ret); + } + +out_unlock: + unlock_page(page); + return ret; +} + static const struct address_space_operations erofs_fscache_meta_aops = { .readpage = erofs_fscache_meta_readpage, .releasepage = erofs_fscache_release_page, .invalidatepage = erofs_fscache_invalidate_page, };
+const struct address_space_operations erofs_fscache_access_aops = { + .readpage = erofs_fscache_readpage, + .releasepage = erofs_fscache_release_page, + .invalidatepage = erofs_fscache_invalidate_page, +}; + int erofs_fscache_register_cookie(struct super_block *sb, struct erofs_fscache **fscache, char *name, bool need_inode) diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c index b1aca34c47a6..bb6b41cd68b0 100644 --- a/fs/erofs/inode.c +++ b/fs/erofs/inode.c @@ -290,6 +290,10 @@ static int erofs_fill_inode(struct inode *inode, int isdir) goto out_unlock; } inode->i_mapping->a_ops = &erofs_raw_access_aops; +#ifdef CONFIG_EROFS_FS_ONDEMAND + if (erofs_is_fscache_mode(inode->i_sb)) + inode->i_mapping->a_ops = &erofs_fscache_access_aops; +#endif
out_unlock: erofs_put_metabuf(&buf); diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index e1d526ee5be4..b9ba4627fdf3 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -491,6 +491,7 @@ int erofs_fscache_register_cookie(struct super_block *sb, struct erofs_fscache **fscache, char *name, bool need_inode); void erofs_fscache_unregister_cookie(struct erofs_fscache **fscache); +extern const struct address_space_operations erofs_fscache_access_aops; #else static inline int erofs_fscache_register(void) {