]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
erofs: simplify tail inline pcluster handling
authorGao Xiang <hsiangkao@linux.alibaba.com>
Wed, 23 Jul 2025 13:50:07 +0000 (09:50 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 1 Aug 2025 08:48:45 +0000 (09:48 +0100)
[ 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 <chao@kernel.org>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20250225114038.3259726-1-hsiangkao@linux.alibaba.com
Stable-dep-of: b44686c8391b ("erofs: fix large fragment handling")
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/erofs/internal.h
fs/erofs/zmap.c

index 3d06fda70f318b110bed2ed0b52a0cae7c12a223..06895e9fec38f186506b58ad06636996f0bfd994 100644 (file)
@@ -277,13 +277,8 @@ struct erofs_inode {
                        unsigned char  z_algorithmtype[2];
                        unsigned char  z_logical_clusterbits;
                        unsigned long  z_tailextent_headlcn;
-                       union {
-                               struct {
-                                       erofs_off_t    z_idataoff;
-                                       unsigned short z_idata_size;
-                               };
-                               erofs_off_t z_fragmentoff;
-                       };
+                       erofs_off_t    z_fragmentoff;
+                       unsigned short z_idata_size;
                };
 #endif /* CONFIG_EROFS_FS_ZIP */
        };
index d278ebd6028164b508cd128c97b151e7527e2bb7..f2ff0cba2bc8c33c3f36c3fff01cd4e6d871eed2 100644 (file)
@@ -395,8 +395,8 @@ static int z_erofs_do_map_blocks(struct inode *inode,
                                 struct erofs_map_blocks *map, int flags)
 {
        struct erofs_inode *const vi = EROFS_I(inode);
-       bool ztailpacking = vi->z_advise & Z_EROFS_ADVISE_INLINE_PCLUSTER;
        bool fragment = vi->z_advise & Z_EROFS_ADVISE_FRAGMENT_PCLUSTER;
+       bool ztailpacking = vi->z_idata_size;
        struct z_erofs_maprecorder m = {
                .inode = inode,
                .map = map,
@@ -415,9 +415,8 @@ static int z_erofs_do_map_blocks(struct inode *inode,
        if (err)
                goto unmap_out;
 
-       if (ztailpacking && (flags & EROFS_GET_BLOCKS_FINDTAIL))
-               vi->z_idataoff = m.nextpackoff;
-
+       if ((flags & EROFS_GET_BLOCKS_FINDTAIL) && ztailpacking)
+               vi->z_fragmentoff = m.nextpackoff;
        map->m_flags = EROFS_MAP_MAPPED | EROFS_MAP_ENCODED;
        end = (m.lcn + 1ULL) << lclusterbits;
 
@@ -472,7 +471,7 @@ static int z_erofs_do_map_blocks(struct inode *inode,
        }
        if (ztailpacking && m.lcn == vi->z_tailextent_headlcn) {
                map->m_flags |= EROFS_MAP_META;
-               map->m_pa = vi->z_idataoff;
+               map->m_pa = vi->z_fragmentoff;
                map->m_plen = vi->z_idata_size;
        } else if (fragment && m.lcn == vi->z_tailextent_headlcn) {
                map->m_flags |= EROFS_MAP_FRAGMENT;
@@ -565,6 +564,10 @@ static int z_erofs_fill_inode_lazy(struct inode *inode)
        vi->z_advise = le16_to_cpu(h->h_advise);
        vi->z_algorithmtype[0] = h->h_algorithmtype & 15;
        vi->z_algorithmtype[1] = h->h_algorithmtype >> 4;
+       if (vi->z_advise & Z_EROFS_ADVISE_FRAGMENT_PCLUSTER)
+               vi->z_fragmentoff = le32_to_cpu(h->h_fragmentoff);
+       else if (vi->z_advise & Z_EROFS_ADVISE_INLINE_PCLUSTER)
+               vi->z_idata_size = le16_to_cpu(h->h_idata_size);
 
        headnr = 0;
        if (vi->z_algorithmtype[0] >= Z_EROFS_COMPRESSION_MAX ||
@@ -593,18 +596,16 @@ static int z_erofs_fill_inode_lazy(struct inode *inode)
                goto out_put_metabuf;
        }
 
-       if (vi->z_advise & Z_EROFS_ADVISE_INLINE_PCLUSTER) {
+       if (vi->z_idata_size) {
                struct erofs_map_blocks map = {
                        .buf = __EROFS_BUF_INITIALIZER
                };
 
-               vi->z_idata_size = le16_to_cpu(h->h_idata_size);
                err = z_erofs_do_map_blocks(inode, &map,
                                            EROFS_GET_BLOCKS_FINDTAIL);
                erofs_put_metabuf(&map.buf);
 
-               if (!map.m_plen ||
-                   erofs_blkoff(sb, map.m_pa) + map.m_plen > sb->s_blocksize) {
+               if (erofs_blkoff(sb, map.m_pa) + map.m_plen > sb->s_blocksize) {
                        erofs_err(sb, "invalid tail-packing pclustersize %llu",
                                  map.m_plen);
                        err = -EFSCORRUPTED;
@@ -619,7 +620,6 @@ static int z_erofs_fill_inode_lazy(struct inode *inode)
                        .buf = __EROFS_BUF_INITIALIZER
                };
 
-               vi->z_fragmentoff = le32_to_cpu(h->h_fragmentoff);
                err = z_erofs_do_map_blocks(inode, &map,
                                            EROFS_GET_BLOCKS_FINDTAIL);
                erofs_put_metabuf(&map.buf);