Skip to content

Commit 1442b02

Browse files
lostjefflehsiangkao
authored andcommitted
erofs: implement fscache-based data read for non-inline layout
Implement the data plane of reading data from data blobs over fscache for non-inline layout. 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 5375e7c commit 1442b02

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

fs/erofs/fscache.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,61 @@ static int erofs_fscache_meta_readpage(struct file *data, struct page *page)
8383
return ret;
8484
}
8585

86+
static int erofs_fscache_readpage(struct file *file, struct page *page)
87+
{
88+
struct folio *folio = page_folio(page);
89+
struct inode *inode = folio_mapping(folio)->host;
90+
struct super_block *sb = inode->i_sb;
91+
struct erofs_map_blocks map;
92+
struct erofs_map_dev mdev;
93+
erofs_off_t pos;
94+
loff_t pstart;
95+
int ret;
96+
97+
DBG_BUGON(folio_size(folio) != EROFS_BLKSIZ);
98+
99+
pos = folio_pos(folio);
100+
map.m_la = pos;
101+
102+
ret = erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW);
103+
if (ret)
104+
goto out_unlock;
105+
106+
if (!(map.m_flags & EROFS_MAP_MAPPED)) {
107+
folio_zero_range(folio, 0, folio_size(folio));
108+
goto out_uptodate;
109+
}
110+
111+
mdev = (struct erofs_map_dev) {
112+
.m_deviceid = map.m_deviceid,
113+
.m_pa = map.m_pa,
114+
};
115+
116+
ret = erofs_map_dev(sb, &mdev);
117+
if (ret)
118+
goto out_unlock;
119+
120+
pstart = mdev.m_pa + (pos - map.m_la);
121+
ret = erofs_fscache_read_folios(mdev.m_fscache->cookie,
122+
folio_mapping(folio), folio_pos(folio),
123+
folio_size(folio), pstart);
124+
125+
out_uptodate:
126+
if (!ret)
127+
folio_mark_uptodate(folio);
128+
out_unlock:
129+
folio_unlock(folio);
130+
return ret;
131+
}
132+
86133
static const struct address_space_operations erofs_fscache_meta_aops = {
87134
.readpage = erofs_fscache_meta_readpage,
88135
};
89136

137+
const struct address_space_operations erofs_fscache_access_aops = {
138+
.readpage = erofs_fscache_readpage,
139+
};
140+
90141
int erofs_fscache_register_cookie(struct super_block *sb,
91142
struct erofs_fscache **fscache,
92143
char *name, bool need_inode)

fs/erofs/inode.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,10 @@ static int erofs_fill_inode(struct inode *inode, int isdir)
292292
goto out_unlock;
293293
}
294294
inode->i_mapping->a_ops = &erofs_raw_access_aops;
295+
#ifdef CONFIG_EROFS_FS_ONDEMAND
296+
if (erofs_is_fscache_mode(inode->i_sb))
297+
inode->i_mapping->a_ops = &erofs_fscache_access_aops;
298+
#endif
295299

296300
out_unlock:
297301
erofs_put_metabuf(&buf);

fs/erofs/internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,8 @@ int erofs_fscache_register_cookie(struct super_block *sb,
614614
struct erofs_fscache **fscache,
615615
char *name, bool need_inode);
616616
void erofs_fscache_unregister_cookie(struct erofs_fscache **fscache);
617+
618+
extern const struct address_space_operations erofs_fscache_access_aops;
617619
#else
618620
static inline int erofs_fscache_register_fs(struct super_block *sb)
619621
{

0 commit comments

Comments
 (0)