Skip to content

Commit aeebae9

Browse files
committed
erofs: move preparation logic into z_erofs_pcluster_begin()
Some preparation logic should be part of z_erofs_pcluster_begin() instead of z_erofs_do_read_page(). Let's move now. Reviewed-by: Yue Hu <[email protected]> Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Gao Xiang <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent dcba1b2 commit aeebae9

File tree

1 file changed

+27
-33
lines changed

1 file changed

+27
-33
lines changed

fs/erofs/zdata.c

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,8 @@ static int z_erofs_register_pcluster(struct z_erofs_decompress_frontend *fe)
852852
static int z_erofs_pcluster_begin(struct z_erofs_decompress_frontend *fe)
853853
{
854854
struct erofs_map_blocks *map = &fe->map;
855+
struct super_block *sb = fe->inode->i_sb;
856+
erofs_blk_t blknr = erofs_blknr(sb, map->m_pa);
855857
struct erofs_workgroup *grp = NULL;
856858
int ret;
857859

@@ -861,8 +863,7 @@ static int z_erofs_pcluster_begin(struct z_erofs_decompress_frontend *fe)
861863
DBG_BUGON(fe->owned_head == Z_EROFS_PCLUSTER_NIL);
862864

863865
if (!(map->m_flags & EROFS_MAP_META)) {
864-
grp = erofs_find_workgroup(fe->inode->i_sb,
865-
map->m_pa >> PAGE_SHIFT);
866+
grp = erofs_find_workgroup(sb, blknr);
866867
} else if ((map->m_pa & ~PAGE_MASK) + map->m_plen > PAGE_SIZE) {
867868
DBG_BUGON(1);
868869
return -EFSCORRUPTED;
@@ -881,9 +882,26 @@ static int z_erofs_pcluster_begin(struct z_erofs_decompress_frontend *fe)
881882
} else if (ret) {
882883
return ret;
883884
}
885+
884886
z_erofs_bvec_iter_begin(&fe->biter, &fe->pcl->bvset,
885887
Z_EROFS_INLINE_BVECS, fe->pcl->vcnt);
886-
/* since file-backed online pages are traversed in reverse order */
888+
if (!z_erofs_is_inline_pcluster(fe->pcl)) {
889+
/* bind cache first when cached decompression is preferred */
890+
z_erofs_bind_cache(fe);
891+
} else {
892+
void *mptr;
893+
894+
mptr = erofs_read_metabuf(&map->buf, sb, blknr, EROFS_NO_KMAP);
895+
if (IS_ERR(mptr)) {
896+
ret = PTR_ERR(mptr);
897+
erofs_err(sb, "failed to get inline data %d", ret);
898+
return ret;
899+
}
900+
get_page(map->buf.page);
901+
WRITE_ONCE(fe->pcl->compressed_bvecs[0].page, map->buf.page);
902+
fe->mode = Z_EROFS_PCLUSTER_FOLLOWED_NOINPLACE;
903+
}
904+
/* file-backed inplace I/O pages are traversed in reverse order */
887905
fe->icur = z_erofs_pclusterpages(fe->pcl);
888906
return 0;
889907
}
@@ -982,39 +1000,15 @@ static int z_erofs_do_read_page(struct z_erofs_decompress_frontend *fe,
9821000
err = z_erofs_map_blocks_iter(inode, map, 0);
9831001
if (err)
9841002
goto out;
985-
} else {
986-
if (fe->pcl)
987-
goto hitted;
988-
/* didn't get a valid pcluster previously (very rare) */
989-
}
990-
991-
if (!(map->m_flags & EROFS_MAP_MAPPED) ||
992-
map->m_flags & EROFS_MAP_FRAGMENT)
1003+
} else if (fe->pcl) {
9931004
goto hitted;
1005+
}
9941006

995-
err = z_erofs_pcluster_begin(fe);
996-
if (err)
997-
goto out;
998-
999-
if (z_erofs_is_inline_pcluster(fe->pcl)) {
1000-
void *mp;
1001-
1002-
mp = erofs_read_metabuf(&fe->map.buf, inode->i_sb,
1003-
erofs_blknr(inode->i_sb, map->m_pa),
1004-
EROFS_NO_KMAP);
1005-
if (IS_ERR(mp)) {
1006-
err = PTR_ERR(mp);
1007-
erofs_err(inode->i_sb,
1008-
"failed to get inline page, err %d", err);
1007+
if ((map->m_flags & EROFS_MAP_MAPPED) &&
1008+
!(map->m_flags & EROFS_MAP_FRAGMENT)) {
1009+
err = z_erofs_pcluster_begin(fe);
1010+
if (err)
10091011
goto out;
1010-
}
1011-
get_page(fe->map.buf.page);
1012-
WRITE_ONCE(fe->pcl->compressed_bvecs[0].page,
1013-
fe->map.buf.page);
1014-
fe->mode = Z_EROFS_PCLUSTER_FOLLOWED_NOINPLACE;
1015-
} else {
1016-
/* bind cache first when cached decompression is preferred */
1017-
z_erofs_bind_cache(fe);
10181012
}
10191013
hitted:
10201014
/*

0 commit comments

Comments
 (0)