Skip to content

Commit f9b2cb6

Browse files
hsiangkaogregkh
authored andcommitted
erofs: simplify tail inline pcluster handling
[ Upstream commit b7710262d743aca112877d12abed61ce8a5d0d98 ] Use `z_idata_size != 0` to indicate that ztailpacking is enabled. `Z_EROFS_ADVISE_INLINE_PCLUSTER` cannot be ignored, as `h_idata_size` could be non-zero prior to erofs-utils 1.6 [1]. Additionally, merge `z_idataoff` and `z_fragmentoff` since these two features are mutually exclusive for a given inode. [1] https://git.kernel.org/xiang/erofs-utils/c/547bea3cb71a 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 516fabf commit f9b2cb6

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

fs/erofs/internal.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,8 @@ struct erofs_inode {
277277
unsigned char z_algorithmtype[2];
278278
unsigned char z_logical_clusterbits;
279279
unsigned long z_tailextent_headlcn;
280-
union {
281-
struct {
282-
erofs_off_t z_idataoff;
283-
unsigned short z_idata_size;
284-
};
285-
erofs_off_t z_fragmentoff;
286-
};
280+
erofs_off_t z_fragmentoff;
281+
unsigned short z_idata_size;
287282
};
288283
#endif /* CONFIG_EROFS_FS_ZIP */
289284
};

fs/erofs/zmap.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,8 @@ static int z_erofs_do_map_blocks(struct inode *inode,
395395
struct erofs_map_blocks *map, int flags)
396396
{
397397
struct erofs_inode *const vi = EROFS_I(inode);
398-
bool ztailpacking = vi->z_advise & Z_EROFS_ADVISE_INLINE_PCLUSTER;
399398
bool fragment = vi->z_advise & Z_EROFS_ADVISE_FRAGMENT_PCLUSTER;
399+
bool ztailpacking = vi->z_idata_size;
400400
struct z_erofs_maprecorder m = {
401401
.inode = inode,
402402
.map = map,
@@ -415,9 +415,8 @@ static int z_erofs_do_map_blocks(struct inode *inode,
415415
if (err)
416416
goto unmap_out;
417417

418-
if (ztailpacking && (flags & EROFS_GET_BLOCKS_FINDTAIL))
419-
vi->z_idataoff = m.nextpackoff;
420-
418+
if ((flags & EROFS_GET_BLOCKS_FINDTAIL) && ztailpacking)
419+
vi->z_fragmentoff = m.nextpackoff;
421420
map->m_flags = EROFS_MAP_MAPPED | EROFS_MAP_ENCODED;
422421
end = (m.lcn + 1ULL) << lclusterbits;
423422

@@ -472,7 +471,7 @@ static int z_erofs_do_map_blocks(struct inode *inode,
472471
}
473472
if (ztailpacking && m.lcn == vi->z_tailextent_headlcn) {
474473
map->m_flags |= EROFS_MAP_META;
475-
map->m_pa = vi->z_idataoff;
474+
map->m_pa = vi->z_fragmentoff;
476475
map->m_plen = vi->z_idata_size;
477476
} else if (fragment && m.lcn == vi->z_tailextent_headlcn) {
478477
map->m_flags |= EROFS_MAP_FRAGMENT;
@@ -565,6 +564,10 @@ static int z_erofs_fill_inode_lazy(struct inode *inode)
565564
vi->z_advise = le16_to_cpu(h->h_advise);
566565
vi->z_algorithmtype[0] = h->h_algorithmtype & 15;
567566
vi->z_algorithmtype[1] = h->h_algorithmtype >> 4;
567+
if (vi->z_advise & Z_EROFS_ADVISE_FRAGMENT_PCLUSTER)
568+
vi->z_fragmentoff = le32_to_cpu(h->h_fragmentoff);
569+
else if (vi->z_advise & Z_EROFS_ADVISE_INLINE_PCLUSTER)
570+
vi->z_idata_size = le16_to_cpu(h->h_idata_size);
568571

569572
headnr = 0;
570573
if (vi->z_algorithmtype[0] >= Z_EROFS_COMPRESSION_MAX ||
@@ -593,18 +596,16 @@ static int z_erofs_fill_inode_lazy(struct inode *inode)
593596
goto out_put_metabuf;
594597
}
595598

596-
if (vi->z_advise & Z_EROFS_ADVISE_INLINE_PCLUSTER) {
599+
if (vi->z_idata_size) {
597600
struct erofs_map_blocks map = {
598601
.buf = __EROFS_BUF_INITIALIZER
599602
};
600603

601-
vi->z_idata_size = le16_to_cpu(h->h_idata_size);
602604
err = z_erofs_do_map_blocks(inode, &map,
603605
EROFS_GET_BLOCKS_FINDTAIL);
604606
erofs_put_metabuf(&map.buf);
605607

606-
if (!map.m_plen ||
607-
erofs_blkoff(sb, map.m_pa) + map.m_plen > sb->s_blocksize) {
608+
if (erofs_blkoff(sb, map.m_pa) + map.m_plen > sb->s_blocksize) {
608609
erofs_err(sb, "invalid tail-packing pclustersize %llu",
609610
map.m_plen);
610611
err = -EFSCORRUPTED;
@@ -619,7 +620,6 @@ static int z_erofs_fill_inode_lazy(struct inode *inode)
619620
.buf = __EROFS_BUF_INITIALIZER
620621
};
621622

622-
vi->z_fragmentoff = le32_to_cpu(h->h_fragmentoff);
623623
err = z_erofs_do_map_blocks(inode, &map,
624624
EROFS_GET_BLOCKS_FINDTAIL);
625625
erofs_put_metabuf(&map.buf);

0 commit comments

Comments
 (0)