Skip to content

Commit 41485d7

Browse files
hsiangkaogregkh
authored andcommitted
erofs: clean up header parsing for ztailpacking and fragments
[ Upstream commit 540787d38b10dbc16a7d2bc2845752ab1605403a ] Simplify the logic in z_erofs_fill_inode_lazy() by combining the handling of ztailpacking and fragments, as they are mutually exclusive. Note that `h->h_clusterbits >> Z_EROFS_FRAGMENT_INODE_BIT` is handled above, so no need to duplicate the check. Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Gao Xiang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Stable-dep-of: b44686c8391b ("erofs: fix large fragment handling") Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent f9b2cb6 commit 41485d7

File tree

1 file changed

+14
-25
lines changed

1 file changed

+14
-25
lines changed

fs/erofs/zmap.c

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,8 @@ static int z_erofs_get_extent_decompressedlen(struct z_erofs_maprecorder *m)
394394
static int z_erofs_do_map_blocks(struct inode *inode,
395395
struct erofs_map_blocks *map, int flags)
396396
{
397-
struct erofs_inode *const vi = EROFS_I(inode);
397+
struct erofs_inode *vi = EROFS_I(inode);
398+
struct super_block *sb = inode->i_sb;
398399
bool fragment = vi->z_advise & Z_EROFS_ADVISE_FRAGMENT_PCLUSTER;
399400
bool ztailpacking = vi->z_idata_size;
400401
struct z_erofs_maprecorder m = {
@@ -438,7 +439,7 @@ static int z_erofs_do_map_blocks(struct inode *inode,
438439
}
439440
/* m.lcn should be >= 1 if endoff < m.clusterofs */
440441
if (!m.lcn) {
441-
erofs_err(inode->i_sb, "invalid logical cluster 0 at nid %llu",
442+
erofs_err(sb, "invalid logical cluster 0 at nid %llu",
442443
vi->nid);
443444
err = -EFSCORRUPTED;
444445
goto unmap_out;
@@ -454,7 +455,7 @@ static int z_erofs_do_map_blocks(struct inode *inode,
454455
goto unmap_out;
455456
break;
456457
default:
457-
erofs_err(inode->i_sb, "unknown type %u @ offset %llu of nid %llu",
458+
erofs_err(sb, "unknown type %u @ offset %llu of nid %llu",
458459
m.type, ofs, vi->nid);
459460
err = -EOPNOTSUPP;
460461
goto unmap_out;
@@ -473,10 +474,16 @@ static int z_erofs_do_map_blocks(struct inode *inode,
473474
map->m_flags |= EROFS_MAP_META;
474475
map->m_pa = vi->z_fragmentoff;
475476
map->m_plen = vi->z_idata_size;
477+
if (erofs_blkoff(sb, map->m_pa) + map->m_plen > sb->s_blocksize) {
478+
erofs_err(sb, "invalid tail-packing pclustersize %llu",
479+
map->m_plen);
480+
err = -EFSCORRUPTED;
481+
goto unmap_out;
482+
}
476483
} else if (fragment && m.lcn == vi->z_tailextent_headlcn) {
477484
map->m_flags |= EROFS_MAP_FRAGMENT;
478485
} else {
479-
map->m_pa = erofs_pos(inode->i_sb, m.pblk);
486+
map->m_pa = erofs_pos(sb, m.pblk);
480487
err = z_erofs_get_extent_compressedlen(&m, initial_lcn);
481488
if (err)
482489
goto unmap_out;
@@ -495,7 +502,7 @@ static int z_erofs_do_map_blocks(struct inode *inode,
495502
afmt = m.headtype == Z_EROFS_LCLUSTER_TYPE_HEAD2 ?
496503
vi->z_algorithmtype[1] : vi->z_algorithmtype[0];
497504
if (!(EROFS_I_SB(inode)->available_compr_algs & (1 << afmt))) {
498-
erofs_err(inode->i_sb, "inconsistent algorithmtype %u for nid %llu",
505+
erofs_err(sb, "inconsistent algorithmtype %u for nid %llu",
499506
afmt, vi->nid);
500507
err = -EFSCORRUPTED;
501508
goto unmap_out;
@@ -596,26 +603,8 @@ static int z_erofs_fill_inode_lazy(struct inode *inode)
596603
goto out_put_metabuf;
597604
}
598605

599-
if (vi->z_idata_size) {
600-
struct erofs_map_blocks map = {
601-
.buf = __EROFS_BUF_INITIALIZER
602-
};
603-
604-
err = z_erofs_do_map_blocks(inode, &map,
605-
EROFS_GET_BLOCKS_FINDTAIL);
606-
erofs_put_metabuf(&map.buf);
607-
608-
if (erofs_blkoff(sb, map.m_pa) + map.m_plen > sb->s_blocksize) {
609-
erofs_err(sb, "invalid tail-packing pclustersize %llu",
610-
map.m_plen);
611-
err = -EFSCORRUPTED;
612-
}
613-
if (err < 0)
614-
goto out_put_metabuf;
615-
}
616-
617-
if (vi->z_advise & Z_EROFS_ADVISE_FRAGMENT_PCLUSTER &&
618-
!(h->h_clusterbits >> Z_EROFS_FRAGMENT_INODE_BIT)) {
606+
if (vi->z_idata_size ||
607+
(vi->z_advise & Z_EROFS_ADVISE_FRAGMENT_PCLUSTER)) {
619608
struct erofs_map_blocks map = {
620609
.buf = __EROFS_BUF_INITIALIZER
621610
};

0 commit comments

Comments
 (0)