[PATCH 1/2] erofs-utils: get rid of z_erofs_do_map_blocks() forward declaration
Gao Xiang
hsiangkao at linux.alibaba.com
Mon Mar 6 20:00:25 AEDT 2023
On 2023/3/6 16:54, Yue Hu wrote:
> From: Yue Hu <huyue2 at coolpad.com>
>
> Keep in sync with the kernel commit 999f2f9a63f4 ("erofs: get rid of
> z_erofs_do_map_blocks() forward declaration").
Does z_erofs_do_map_blocks() already keep in sync with the kernel
implementation? Anyway, it's just another question indepentently
to this patch.
>
> Signed-off-by: Yue Hu <huyue2 at coolpad.com>
> ---
> lib/zmap.c | 156 ++++++++++++++++++++++++++---------------------------
> 1 file changed, 76 insertions(+), 80 deletions(-)
>
> diff --git a/lib/zmap.c b/lib/zmap.c
> index 69b468d..3c665f8 100644
> --- a/lib/zmap.c
> +++ b/lib/zmap.c
> @@ -10,10 +10,6 @@
> #include "erofs/io.h"
> #include "erofs/print.h"
>
> -static int z_erofs_do_map_blocks(struct erofs_inode *vi,
> - struct erofs_map_blocks *map,
> - int flags);
> -
> int z_erofs_fill_inode(struct erofs_inode *vi)
> {
> if (!erofs_sb_has_big_pcluster() &&
> @@ -29,82 +25,6 @@ int z_erofs_fill_inode(struct erofs_inode *vi)
> return 0;
> }
>
> -static int z_erofs_fill_inode_lazy(struct erofs_inode *vi)
> -{
> - int ret;
> - erofs_off_t pos;
> - struct z_erofs_map_header *h;
> - char buf[sizeof(struct z_erofs_map_header)];
> -
> - if (vi->flags & EROFS_I_Z_INITED)
> - return 0;
> -
> - pos = round_up(iloc(vi->nid) + vi->inode_isize + vi->xattr_isize, 8);
> - ret = dev_read(0, buf, pos, sizeof(buf));
> - if (ret < 0)
> - return -EIO;
> -
> - h = (struct z_erofs_map_header *)buf;
> - /*
> - * if the highest bit of the 8-byte map header is set, the whole file
> - * is stored in the packed inode. The rest bits keeps z_fragmentoff.
> - */
> - if (h->h_clusterbits >> Z_EROFS_FRAGMENT_INODE_BIT) {
> - vi->z_advise = Z_EROFS_ADVISE_FRAGMENT_PCLUSTER;
> - vi->fragmentoff = le64_to_cpu(*(__le64 *)h) ^ (1ULL << 63);
> - vi->z_tailextent_headlcn = 0;
> - goto out;
> - }
> -
> - 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_algorithmtype[0] >= Z_EROFS_COMPRESSION_MAX) {
> - erofs_err("unknown compression format %u for nid %llu",
> - vi->z_algorithmtype[0], (unsigned long long)vi->nid);
> - return -EOPNOTSUPP;
> - }
> -
> - vi->z_logical_clusterbits = LOG_BLOCK_SIZE + (h->h_clusterbits & 7);
> - if (vi->datalayout == EROFS_INODE_FLAT_COMPRESSION &&
> - !(vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_1) ^
> - !(vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_2)) {
> - erofs_err("big pcluster head1/2 of compact indexes should be consistent for nid %llu",
> - vi->nid * 1ULL);
> - return -EFSCORRUPTED;
> - }
> -
> - if (vi->z_advise & Z_EROFS_ADVISE_INLINE_PCLUSTER) {
> - struct erofs_map_blocks map = { .index = UINT_MAX };
> -
> - vi->idata_size = le16_to_cpu(h->h_idata_size);
> - ret = z_erofs_do_map_blocks(vi, &map,
> - EROFS_GET_BLOCKS_FINDTAIL);
> - if (!map.m_plen ||
> - erofs_blkoff(map.m_pa) + map.m_plen > EROFS_BLKSIZ) {
> - erofs_err("invalid tail-packing pclustersize %llu",
> - map.m_plen | 0ULL);
> - return -EFSCORRUPTED;
> - }
> - if (ret < 0)
> - return ret;
> - }
> - if (vi->z_advise & Z_EROFS_ADVISE_FRAGMENT_PCLUSTER &&
> - !(h->h_clusterbits >> Z_EROFS_FRAGMENT_INODE_BIT)) {
> - struct erofs_map_blocks map = { .index = UINT_MAX };
> -
> - vi->fragmentoff = le32_to_cpu(h->h_fragmentoff);
> - ret = z_erofs_do_map_blocks(vi, &map,
> - EROFS_GET_BLOCKS_FINDTAIL);
> - if (ret < 0)
> - return ret;
> - }
> -out:
> - vi->flags |= EROFS_I_Z_INITED;
> - return 0;
> -}
> -
> struct z_erofs_maprecorder {
> struct erofs_inode *inode;
> struct erofs_map_blocks *map;
> @@ -675,6 +595,82 @@ out:
> return err;
> }
>
> +static int z_erofs_fill_inode_lazy(struct erofs_inode *vi)
> +{
> + int ret;
> + erofs_off_t pos;
> + struct z_erofs_map_header *h;
> + char buf[sizeof(struct z_erofs_map_header)];
> +
> + if (vi->flags & EROFS_I_Z_INITED)
> + return 0;
> +
> + pos = round_up(iloc(vi->nid) + vi->inode_isize + vi->xattr_isize, 8);
> + ret = dev_read(0, buf, pos, sizeof(buf));
> + if (ret < 0)
> + return -EIO;
> +
> + h = (struct z_erofs_map_header *)buf;
> + /*
> + * if the highest bit of the 8-byte map header is set, the whole file
> + * is stored in the packed inode. The rest bits keeps z_fragmentoff.
> + */
> + if (h->h_clusterbits >> Z_EROFS_FRAGMENT_INODE_BIT) {
> + vi->z_advise = Z_EROFS_ADVISE_FRAGMENT_PCLUSTER;
> + vi->fragmentoff = le64_to_cpu(*(__le64 *)h) ^ (1ULL << 63);
> + vi->z_tailextent_headlcn = 0;
> + goto out;
> + }
> +
> + 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_algorithmtype[0] >= Z_EROFS_COMPRESSION_MAX) {
> + erofs_err("unknown compression format %u for nid %llu",
> + vi->z_algorithmtype[0], (unsigned long long)vi->nid);
> + return -EOPNOTSUPP;
> + }
> +
> + vi->z_logical_clusterbits = LOG_BLOCK_SIZE + (h->h_clusterbits & 7);
> + if (vi->datalayout == EROFS_INODE_FLAT_COMPRESSION &&
> + !(vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_1) ^
> + !(vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_2)) {
> + erofs_err("big pcluster head1/2 of compact indexes should be consistent for nid %llu",
> + vi->nid * 1ULL);
> + return -EFSCORRUPTED;
> + }
> +
> + if (vi->z_advise & Z_EROFS_ADVISE_INLINE_PCLUSTER) {
> + struct erofs_map_blocks map = { .index = UINT_MAX };
> +
> + vi->idata_size = le16_to_cpu(h->h_idata_size);
> + ret = z_erofs_do_map_blocks(vi, &map,
> + EROFS_GET_BLOCKS_FINDTAIL);
> + if (!map.m_plen ||
> + erofs_blkoff(map.m_pa) + map.m_plen > EROFS_BLKSIZ) {
> + erofs_err("invalid tail-packing pclustersize %llu",
> + map.m_plen | 0ULL);
> + return -EFSCORRUPTED;
> + }
> + if (ret < 0)
> + return ret;
> + }
> + if (vi->z_advise & Z_EROFS_ADVISE_FRAGMENT_PCLUSTER &&
> + !(h->h_clusterbits >> Z_EROFS_FRAGMENT_INODE_BIT)) {
> + struct erofs_map_blocks map = { .index = UINT_MAX };
> +
> + vi->fragmentoff = le32_to_cpu(h->h_fragmentoff);
> + ret = z_erofs_do_map_blocks(vi, &map,
> + EROFS_GET_BLOCKS_FINDTAIL);
> + if (ret < 0)
> + return ret;
> + }
> +out:
> + vi->flags |= EROFS_I_Z_INITED;
> + return 0;
> +}
> +
> int z_erofs_map_blocks_iter(struct erofs_inode *vi,
> struct erofs_map_blocks *map,
> int flags)
More information about the Linux-erofs
mailing list