staging: erofs: cleanup z_erofs_vle_work_{lookup, register}
PATCH RESEND 1/10 staging: erofs: cleanup z_erofs_vle_work_{lookup, register}
This patch introduces 'struct z_erofs_vle_work_finder' to clean up arguments of z_erofs_vle_work_lookup and z_erofs_vle_work_register.
---
RESEND:
- add `Reviewed-by: Chao Yu <yuchao0 at huawei.com>'
- no logic change
drivers/staging/erofs/unzip_vle.c | 89 +++++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 42 deletions(-)
drivers/staging/erofs/unzip_vle.c +47 -42
@@ -271,36 +271,42 @@ static inline bool try_to_claim_workgroup(return true;/* lucky, I am the followee :) */ } +struct z_erofs_vle_work_finder { +struct super_block *sb; +pgoff_t idx; +unsigned pageofs; + +struct z_erofs_vle_workgroup **grp_ret; +enum z_erofs_vle_work_role *role; +z_erofs_vle_owned_workgrp_t *owned_head; +bool *hosted; +}; +static struct z_erofs_vle_work * -z_erofs_vle_work_lookup (struct super_block *sb, -pgoff_t idx,unsigned pageofs, -struct z_erofs_vle_workgroup **grp_ret, -enum z_erofs_vle_work_role *role, -z_erofs_vle_owned_workgrp_t *owned_head, -bool *hosted) +z_erofs_vle_work_lookup (const struct z_erofs_vle_work_finder *f) {bool tag, primary;struct erofs_workgroup *egrp;struct z_erofs_vle_workgroup *grp;struct z_erofs_vle_work *work; - egrp =erofs_find_workgroup (sb, idx, &tag); + egrp =erofs_find_workgroup (f->sb, f->idx, &tag);if (egrp ==NULL ) { - *grp_ret =NULL ; + *f->grp_ret =NULL ;return NULL ; } - *grp_ret = grp =container_of (egrp, - struct z_erofs_vle_workgroup, obj); + grp = container_of(egrp, struct z_erofs_vle_workgroup, obj); + *f->grp_ret = grp;#ifndef CONFIG_EROFS_FS_ZIP_MULTIREF - work =z_erofs_vle_grab_work (grp, pageofs); + work =z_erofs_vle_grab_work (grp, f->pageofs); primary = true;#else BUG ();#endif -DBG_BUGON (work->pageofs != pageofs); +DBG_BUGON (work->pageofs != f->pageofs);/* * lock must be taken first to avoid grp->next == NIL between
@@ -340,29 +346,24 @@ static inline bool try_to_claim_workgroup(*/ mutex_lock (&work->lock); - *hosted = false; + *f->hosted = false;if (!primary) - *role =Z_EROFS_VLE_WORK_SECONDARY ; + *f->role =Z_EROFS_VLE_WORK_SECONDARY ;/* claim the workgroup if possible */ -else if (try_to_claim_workgroup (grp, owned_head, hosted)) - *role =Z_EROFS_VLE_WORK_PRIMARY_FOLLOWED ; +else if (try_to_claim_workgroup (grp, f->owned_head, f->hosted)) + *f->role =Z_EROFS_VLE_WORK_PRIMARY_FOLLOWED ;else - *role =Z_EROFS_VLE_WORK_PRIMARY ; + *f->role =Z_EROFS_VLE_WORK_PRIMARY ;return work; }static struct z_erofs_vle_work * -z_erofs_vle_work_register (struct super_block *sb, -struct z_erofs_vle_workgroup **grp_ret, -struct erofs_map_blocks *map, -pgoff_t index,unsigned pageofs, -enum z_erofs_vle_work_role *role, -z_erofs_vle_owned_workgrp_t *owned_head, -bool *hosted) +z_erofs_vle_work_register (const struct z_erofs_vle_work_finder *f, +struct erofs_map_blocks *map) { -bool newgrp = false; -struct z_erofs_vle_workgroup *grp = *grp_ret; +bool gnew = false; +struct z_erofs_vle_workgroup *grp = *f->grp_ret;struct z_erofs_vle_work *work;#ifndef CONFIG_EROFS_FS_ZIP_MULTIREF
@@ -376,7 +377,7 @@ static inline bool try_to_claim_workgroup(if (unlikely (grp ==NULL ))return ERR_PTR (-ENOMEM ); - grp->obj.index = index; + grp->obj.index = f->idx; grp->llen = map->m_llen; z_erofs_vle_set_workgrp_fmt(grp,
@@ -386,13 +387,13 @@ static inline bool try_to_claim_workgroup(atomic_set (&grp->obj.refcount,1 );/* new workgrps have been claimed as type 1 */ -WRITE_ONCE (grp->next, *owned_head); +WRITE_ONCE (grp->next, *f->owned_head);/* primary and followed work for all new workgrps */ - *role =Z_EROFS_VLE_WORK_PRIMARY_FOLLOWED ; + *f->role =Z_EROFS_VLE_WORK_PRIMARY_FOLLOWED ;/* it should be submitted by ourselves */ - *hosted = true; + *f->hosted = true; - newgrp = true; + gnew = true;#ifdef CONFIG_EROFS_FS_ZIP_MULTIREF skip:/* currently unimplemented */
@@ -400,12 +401,12 @@ static inline bool try_to_claim_workgroup(#else work =z_erofs_vle_grab_primary_work (grp);#endif - work->pageofs = pageofs; + work->pageofs = f->pageofs;mutex_init (&work->lock); -if (newgrp) { -int err =erofs_register_workgroup (sb, &grp->obj,0 ); +if (gnew) { +int err =erofs_register_workgroup (f->sb, &grp->obj,0 );if (err) {kmem_cache_free (z_erofs_workgroup_cachep, grp);
@@ -413,7 +414,7 @@ static inline bool try_to_claim_workgroup( } } - *owned_head = *grp_ret = grp; + *f->owned_head = *f->grp_ret = grp;mutex_lock (&work->lock);return work;
@@ -440,9 +441,16 @@ static int z_erofs_vle_work_iter_begin(struct z_erofs_vle_work_builder *builder, z_erofs_vle_owned_workgrp_t *owned_head) {const unsigned clusterpages =erofs_clusterpages (EROFS_SB (sb)); -const erofs_blk_t index =erofs_blknr (map->m_pa); -const unsigned pageofs = map->m_la & ~PAGE_MASK ;struct z_erofs_vle_workgroup *grp; +const struct z_erofs_vle_work_finder finder = { + .sb = sb, + .idx =erofs_blknr (map->m_pa), + .pageofs = map->m_la & ~PAGE_MASK , + .grp_ret = &grp, + .role = &builder->role, + .owned_head = owned_head, + .hosted = &builder->hosted + };struct z_erofs_vle_work *work;DBG_BUGON (builder->work !=NULL );
@@ -454,16 +462,13 @@ static int z_erofs_vle_work_iter_begin(struct z_erofs_vle_work_builder *builder,DBG_BUGON (erofs_blkoff (map->m_pa)); repeat: - work =z_erofs_vle_work_lookup (sb, index, - pageofs, &grp, &builder->role, owned_head, &builder->hosted); + work =z_erofs_vle_work_lookup (&finder);if (work !=NULL ) {__update_workgrp_llen (grp, map->m_llen); goto got_it; } - work =z_erofs_vle_work_register (sb, &grp, map, index, pageofs, - &builder->role, owned_head, &builder->hosted); - + work =z_erofs_vle_work_register (&finder, map);if (unlikely (work ==ERR_PTR (-EAGAIN ))) goto repeat;
Signature · 1 line
1.9.1
PATCH RESEND 2/10 staging: erofs: rearrange vle clustertype definitions
This patch moves vle clustertype definitions to erofs_fs.h since they are part of on-disk format.
It also adds compile time check for Z_EROFS_VLE_DI_CLUSTER_TYPE_BITS
---
RESEND:
- add `Reviewed-by: Chao Yu <yuchao0 at huawei.com>'
- no logic change
drivers/staging/erofs/erofs_fs.h | 11 +++++++++++ drivers/staging/erofs/unzip_vle.c | 8 -------- 2 files changed, 11 insertions(+), 8 deletions(-)
drivers/staging/erofs/erofs_fs.h +11 -0
@@ -202,6 +202,14 @@ struct erofs_extent_header {* di_u.delta[1] = distance to its corresponding tail cluster * (di_advise could be 0, 1 or 2) */ +enum { +Z_EROFS_VLE_CLUSTER_TYPE_PLAIN , +Z_EROFS_VLE_CLUSTER_TYPE_HEAD , +Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD , +Z_EROFS_VLE_CLUSTER_TYPE_RESERVED , +Z_EROFS_VLE_CLUSTER_TYPE_MAX +}; +#define Z_EROFS_VLE_DI_CLUSTER_TYPE_BITS 2#define Z_EROFS_VLE_DI_CLUSTER_TYPE_BIT 0
@@ -260,6 +268,9 @@ static inline void erofs_check_ondisk_layout_definitions(void)BUILD_BUG_ON (sizeof (struct erofs_extent_header ) !=16 );BUILD_BUG_ON (sizeof (struct z_erofs_vle_decompressed_index ) !=8 );BUILD_BUG_ON (sizeof (struct erofs_dirent ) !=12 ); + +BUILD_BUG_ON (BIT (Z_EROFS_VLE_DI_CLUSTER_TYPE_BITS ) < + Z_EROFS_VLE_CLUSTER_TYPE_MAX - 1); }#endif
drivers/staging/erofs/unzip_vle.c +0 -8
@@ -1416,14 +1416,6 @@ static int z_erofs_vle_normalaccess_readpages(#define __vle_cluster_type (advise) __vle_cluster_advise(advise, \ Z_EROFS_VLE_DI_CLUSTER_TYPE_BIT, Z_EROFS_VLE_DI_CLUSTER_TYPE_BITS) -enum { -Z_EROFS_VLE_CLUSTER_TYPE_PLAIN , -Z_EROFS_VLE_CLUSTER_TYPE_HEAD , -Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD , -Z_EROFS_VLE_CLUSTER_TYPE_RESERVED , -Z_EROFS_VLE_CLUSTER_TYPE_MAX -}; -#define vle_cluster_type (di) \ __vle_cluster_type((di)->di_advise)
Signature · 1 line
1.9.1
PATCH v2 3/10 staging: erofs: fix vle_decompressed_index_clusterofs
In reply to Gao XiangThis patch adds error handing code, and fixes a missing endian conversion in vle_decompressed_index_clusterofs.
---
change log v2:
- change the commit message;
- I personally think this patch is clear enough, therefore I don't spilt into more small patches.
drivers/staging/erofs/unzip_vle.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-)
drivers/staging/erofs/unzip_vle.c +15 -11
@@ -1419,24 +1419,24 @@ static int z_erofs_vle_normalaccess_readpages(#define vle_cluster_type (di) \ __vle_cluster_type((di)->di_advise) -static inline unsigned -vle_compressed_index_clusterofs (unsigned clustersize, -struct z_erofs_vle_decompressed_index *di) +static inline int +vle_decompressed_index_clusterofs (unsigned int *clusterofs, +unsigned int clustersize, +struct z_erofs_vle_decompressed_index *di) { -debugln ("%s, vle=%pK, advise=%x (type %u), clusterofs=%x blkaddr=%x" , - __func__, di, di->di_advise,vle_cluster_type (di), - di->di_clusterofs, di->di_u.blkaddr); -switch (vle_cluster_type (di)) {case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD : + *clusterofs = clustersize;break ;case Z_EROFS_VLE_CLUSTER_TYPE_PLAIN :case Z_EROFS_VLE_CLUSTER_TYPE_HEAD : -return di->di_clusterofs; + *clusterofs =le16_to_cpu (di->di_clusterofs); +break ;default : -BUG_ON (1 ); +DBG_BUGON (1 ); +return -EIO ; } -return clustersize; +return 0 ; } static inline erofs_blk_t
@@ -1581,7 +1581,11 @@ int z_erofs_map_blocks_iter(struct inode *inode,debugln ("%s, lcn %u e_blkaddr %u e_blkoff %u" , __func__, lcn, e_blkaddr,vle_extent_blkoff (inode, lcn)); - logical_cluster_ofs =vle_compressed_index_clusterofs (clustersize, di); + err =vle_decompressed_index_clusterofs (&logical_cluster_ofs, + clustersize, di); +if (unlikely (err)) + goto unmap_out; +if (!initial) {/* [walking mode] 'map' has been already initialized */ map->m_llen += logical_cluster_ofs;
Signature · 1 line
1.9.1
PATCH v2 3/10 staging: erofs: fix vle_decompressed_index_clusterofs
Quoted 4 lines · Gao Xiang
This patch adds error handing code, and fixes a missing endian conversion in
vle_decompressed_index_clusterofs.Signed-off-by Gao Xiang <gaoxiang25 at huawei.com>
Thanks,
PATCH v3 4/10 staging: erofs: fix a missing endian conversion
In reply to Gao XiangThis patch fixes a missing endian conversion invle_get_logical_extent_head.
---
change log v3:
- spilt into small patches at Chao's suggestion.
drivers/staging/erofs/unzip_vle.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/staging/erofs/unzip_vle.c +5 -3
@@ -1488,6 +1488,7 @@ static erofs_off_t vle_get_logical_extent_head(struct super_block *const sb = inode->i_sb;const unsigned int clusterbits =EROFS_SB (sb)->clusterbits;const unsigned int clustersize =1 << clusterbits; +unsigned delta0;if (page->index != blkaddr) {kunmap_atomic (*kaddr_iter);
@@ -1502,12 +1503,13 @@ static erofs_off_t vle_get_logical_extent_head( di = *kaddr_iter +vle_extent_blkoff (inode, lcn);switch (vle_cluster_type (di)) {case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD : -BUG_ON (!di->di_u.delta[0 ]); -BUG_ON (lcn < di->di_u.delta[0 ]); + delta0 =le16_to_cpu (di->di_u.delta[0 ]); +DBG_BUGON (!delta0); +DBG_BUGON (lcn < delta0); ofs =vle_get_logical_extent_head (inode, page_iter, kaddr_iter, - lcn - di->di_u.delta[0 ], pcn, flags); + lcn - delta0, pcn, flags);break ;case Z_EROFS_VLE_CLUSTER_TYPE_PLAIN : *flags ^=EROFS_MAP_ZIPPED ;
Signature · 1 line
1.9.1
PATCH v3 4/10 staging: erofs: fix a missing endian conversion
Quoted 4 lines · Gao Xiang
This patch fixes a missing endian conversion in
vle_get_logical_extent_head.Signed-off-by Gao Xiang <gaoxiang25 at huawei.com>
Thanks,
PATCH v3 5/10 staging: erofs: fix integer overflow on 32-bit platform
In reply to Gao XiangThis patch fixes integer overflow on multiplication of 32-bit lcn in z_erofs_map_blocks_iter.
---
change log v3:
- spilt into small patches at Chao's suggestion.
drivers/staging/erofs/unzip_vle.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/staging/erofs/unzip_vle.c +4 -4
@@ -1515,7 +1515,7 @@ static erofs_off_t vle_get_logical_extent_head( *flags ^=EROFS_MAP_ZIPPED ;case Z_EROFS_VLE_CLUSTER_TYPE_HEAD :/* clustersize should be a power of two */ - ofs = ((unsigned long long )lcn << clusterbits) + + ofs = ((u64 )lcn << clusterbits) + (le16_to_cpu (di->di_clusterofs) & (clustersize -1 )); *pcn =le32_to_cpu (di->di_u.blkaddr);break ;
@@ -1597,7 +1597,7 @@ int z_erofs_map_blocks_iter(struct inode *inode,/* by default, compressed */ map->m_flags |=EROFS_MAP_ZIPPED ; - end = (u64)(lcn +1 ) * clustersize; + end = ((u64 )lcn +1 ) * clustersize; cluster_type =vle_cluster_type (di);
@@ -1613,7 +1613,7 @@ int z_erofs_map_blocks_iter(struct inode *inode, }if (ofs_rem > logical_cluster_ofs) { - ofs = lcn * clustersize | logical_cluster_ofs; + ofs = (u64 )lcn * clustersize | logical_cluster_ofs; pcn =le32_to_cpu (di->di_u.blkaddr);break ; }
@@ -1625,7 +1625,7 @@ int z_erofs_map_blocks_iter(struct inode *inode, err = -EIO ; goto unmap_out; } - end = (lcn-- * clustersize) | logical_cluster_ofs; + end = ((u64 )lcn-- * clustersize) | logical_cluster_ofs;/* fallthrough */ case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD :/* get the correspoinding first chunk */
Signature · 1 line
1.9.1
PATCH v3 5/10 staging: erofs: fix integer overflow on 32-bit platform
Quoted 4 lines · Gao Xiang
This patch fixes integer overflow on multiplication of 32-bit lcn in
z_erofs_map_blocks_iter.Signed-off-by Gao Xiang <gaoxiang25 at huawei.com>
Thanks,
PATCH v4 5/10 staging: erofs: fix integer overflow on 32-bit platform
From: Gao Xiang <[email protected]>
This patch fixes integer overflow on multiplication of 32-bit `lcn' in z_erofs_map_blocks_iter.
---
change log v4:
- fix commit message a bit.
change log v3:
- spilt into small patches at Chao's suggestion.
drivers/staging/erofs/unzip_vle.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/staging/erofs/unzip_vle.c +4 -4
@@ -1513,7 +1513,7 @@ static erofs_off_t vle_get_logical_extent_head( *flags ^=EROFS_MAP_ZIPPED ;case Z_EROFS_VLE_CLUSTER_TYPE_HEAD :/* clustersize should be a power of two */ - ofs = ((unsigned long long )lcn << clusterbits) + + ofs = ((u64 )lcn << clusterbits) + (le16_to_cpu (di->di_clusterofs) & (clustersize -1 )); *pcn =le32_to_cpu (di->di_u.blkaddr);break ;
@@ -1595,7 +1595,7 @@ int z_erofs_map_blocks_iter(struct inode *inode,/* by default, compressed */ map->m_flags |=EROFS_MAP_ZIPPED ; - end = (u64)(lcn +1 ) * clustersize; + end = ((u64 )lcn +1 ) * clustersize; cluster_type =vle_cluster_type (di);
@@ -1611,7 +1611,7 @@ int z_erofs_map_blocks_iter(struct inode *inode, }if (ofs_rem > logical_cluster_ofs) { - ofs = lcn * clustersize | logical_cluster_ofs; + ofs = (u64 )lcn * clustersize | logical_cluster_ofs; pcn =le32_to_cpu (di->di_u.blkaddr);break ; }
@@ -1623,7 +1623,7 @@ int z_erofs_map_blocks_iter(struct inode *inode, err = -EIO ; goto unmap_out; } - end = (lcn-- * clustersize) | logical_cluster_ofs; + end = ((u64 )lcn-- * clustersize) | logical_cluster_ofs;/* fallthrough */ case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD :/* get the correspoinding first chunk */
Signature · 1 line
2.7.4
PATCH v3 6/10 staging: erofs: fix compression mapping beyond EOF
In reply to Gao XiangLogical address of EOF LTP mapping should start at inode->i_size' rather than inode->i_size - 1' to `m_la(in) + 1 - inode->i_size', fix it.
---
change log v3:
- spilt into small patches at Chao's suggestion.
drivers/staging/erofs/unzip_vle.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/erofs/unzip_vle.c +1 -1
@@ -1550,7 +1550,7 @@ int z_erofs_map_blocks_iter(struct inode *inode,if (unlikely (map->m_la >= inode->i_size)) {BUG_ON (!initial); map->m_llen = map->m_la +1 - inode->i_size; - map->m_la = inode->i_size -1 ; + map->m_la = inode->i_size; map->m_flags =0 ; goto out; }
Signature · 1 line
1.9.1
PATCH v3 6/10 staging: erofs: fix compression mapping beyond EOF
Quoted 5 lines · Gao Xiang
Logical address of EOF LTP mapping should start at
inode->i_size' rather thaninode->i_size- 1' to `m_la(in) + 1 -inode->i_size', fix it.Signed-off-by Gao Xiang <gaoxiang25 at huawei.com>
Thanks,
PATCH v4 6/10 staging: erofs: fix compression mapping beyond EOF
From: Gao Xiang <[email protected]>
Logical address of EOF LTP mapping should start at inode->i_size' rather than inode->i_size - 1' to `m_la(in)', fix it.
---
change log v4:
- fix the description m_la(in) + 1 - inode->i_size' to m_la(in)' in the commit message.
change log v3:
- spilt into small patches at Chao's suggestion.
Hi Chao,
Please help use this commit message. Thanks.
Thanks,
Gao Xiang
drivers/staging/erofs/unzip_vle.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/erofs/unzip_vle.c +1 -1
@@ -1548,7 +1548,7 @@ int z_erofs_map_blocks_iter(struct inode *inode,if (unlikely (map->m_la >= inode->i_size)) {BUG_ON (!initial); map->m_llen = map->m_la +1 - inode->i_size; - map->m_la = inode->i_size -1 ; + map->m_la = inode->i_size; map->m_flags =0 ; goto out; }
Signature · 1 line
2.7.4
PATCH v3 7/10 staging: erofs: clean up z_erofs_map_blocks_iter
In reply to Gao XiangThis patch mainly introduces `vle_map_blocks_iter_ctx' to clean up z_erofs_map_blocks_iter and vle_get_logical_extent_head.
It changes the return value of vle_get_logical_extent_head' to int for the later error handing. In addition, it also renames pcn' to pblk' since only pblk' exists in erofs compression ondisk format.
---
change log v3:
- spilt into small patches at Chao's suggestion.
drivers/staging/erofs/unzip_vle.c | 139 +++++++++++++++++++++----------------- 1 file changed, 77 insertions(+), 62 deletions(-)
drivers/staging/erofs/unzip_vle.c +77 -62
@@ -1410,6 +1410,13 @@ static int z_erofs_vle_normalaccess_readpages( .readpages = z_erofs_vle_normalaccess_readpages, }; +/* +* Variable-sized Logical Extent (Fixed Physical Cluster) Compression Mode +* --- +* VLE compression mode attempts to compress a number of logical data into +* a physical cluster with a fixed size. +* VLE compression mode uses "struct z_erofs_vle_decompressed_index". +*/ #define __vle_cluster_advise (x, bit, bits) \ ((le16_to_cpu(x) >> (bit)) & ((1 << (bits)) - 1))
@@ -1465,90 +1472,95 @@ static int z_erofs_vle_normalaccess_readpages(return erofs_blkoff (iloc (sbi, vi->nid) + ofs); } -/* -* Variable-sized Logical Extent (Fixed Physical Cluster) Compression Mode -* --- -* VLE compression mode attempts to compress a number of logical data into -* a physical cluster with a fixed size. -* VLE compression mode uses "struct z_erofs_vle_decompressed_index". -*/ -static erofs_off_t vle_get_logical_extent_head ( -struct inode *inode, -struct page **page_iter, -void **kaddr_iter, -unsigned lcn,/* logical cluster number */ -erofs_blk_t *pcn, -unsigned *flags) +struct vle_map_blocks_iter_ctx { +struct inode *inode; +struct super_block *sb; +unsigned int clusterbits; + +struct page **mpage_ret; +void **kaddr_ret; +}; + +static int +vle_get_logical_extent_head (const struct vle_map_blocks_iter_ctx *ctx, +unsigned int lcn,/* logical cluster number */ +unsigned long long *ofs, +erofs_blk_t *pblk, +unsigned int *flags) { -/* for extent meta */ -struct page *page = *page_iter; -erofs_blk_t blkaddr =vle_extent_blkaddr (inode, lcn); +const unsigned int clustersize =1 << ctx->clusterbits; +const erofs_blk_t mblk =vle_extent_blkaddr (ctx->inode, lcn); +struct page *mpage = *ctx->mpage_ret;/* extent metapage */ +struct z_erofs_vle_decompressed_index *di; -unsigned long long ofs; -struct super_block *const sb = inode->i_sb; -const unsigned int clusterbits =EROFS_SB (sb)->clusterbits; -const unsigned int clustersize =1 << clusterbits; -unsigned delta0; - -if (page->index != blkaddr) { -kunmap_atomic (*kaddr_iter); -unlock_page (page); -put_page (page); +unsigned int cluster_type, delta0; + +if (mpage->index != mblk) { +kunmap_atomic (*ctx->kaddr_ret); +unlock_page (mpage); +put_page (mpage); - page =erofs_get_meta_page_nofail (sb, blkaddr, false); - *page_iter = page; - *kaddr_iter =kmap_atomic (page); + mpage =erofs_get_meta_page_nofail (ctx->sb, mblk, false); + *ctx->mpage_ret = mpage; + *ctx->kaddr_ret =kmap_atomic (mpage); } - di = *kaddr_iter +vle_extent_blkoff (inode, lcn); -switch (vle_cluster_type (di)) { + di = *ctx->kaddr_ret +vle_extent_blkoff (ctx->inode, lcn); + + cluster_type =vle_cluster_type (di); +switch (cluster_type) {case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD : delta0 =le16_to_cpu (di->di_u.delta[0 ]);DBG_BUGON (!delta0);DBG_BUGON (lcn < delta0); - ofs =vle_get_logical_extent_head (inode, - page_iter, kaddr_iter, - lcn - delta0, pcn, flags); -break ; +return vle_get_logical_extent_head (ctx, + lcn - delta0, ofs, pblk, flags);case Z_EROFS_VLE_CLUSTER_TYPE_PLAIN : *flags ^=EROFS_MAP_ZIPPED ; +/* fallthrough */ case Z_EROFS_VLE_CLUSTER_TYPE_HEAD :/* clustersize should be a power of two */ - ofs = ((u64 )lcn << clusterbits) + + *ofs = ((u64 )lcn << ctx->clusterbits) + (le16_to_cpu (di->di_clusterofs) & (clustersize -1 )); - *pcn =le32_to_cpu (di->di_u.blkaddr); + *pblk =le32_to_cpu (di->di_u.blkaddr);break ;default :BUG_ON (1 ); } -return ofs; +return 0 ; }int z_erofs_map_blocks_iter (struct inode *inode,struct erofs_map_blocks *map,struct page **mpage_ret,int flags) { +void *kaddr; +const struct vle_map_blocks_iter_ctx ctx = { + .inode = inode, + .sb = inode->i_sb, + .clusterbits =EROFS_I_SB (inode)->clusterbits, + .mpage_ret = mpage_ret, + .kaddr_ret = &kaddr + }; +const unsigned int clustersize =1 << ctx.clusterbits; +/* if both m_(l,p)len are 0, regularize l_lblk, l_lofs, etc... */ +const bool initial = !map->m_llen; +/* logicial extent (start, end) offset */ unsigned long long ofs, end; -struct z_erofs_vle_decompressed_index *di; -erofs_blk_t e_blkaddr, pcn; -unsigned lcn, logical_cluster_ofs, cluster_type; +unsigned int lcn;u32 ofs_rem; + +erofs_blk_t mblk, pblk;struct page *mpage = *mpage_ret; -void *kaddr; -bool initial; -struct super_block *const sb = inode->i_sb; -const unsigned int clusterbits =EROFS_SB (sb)->clusterbits; -const unsigned int clustersize =1 << clusterbits; +struct z_erofs_vle_decompressed_index *di; +unsigned int cluster_type, logical_cluster_ofs;int err =0 ; -/* if both m_(l,p)len are 0, regularize l_lblk, l_lofs, etc... */ - initial = !map->m_llen; -/* when trying to read beyond EOF, leave it unmapped */ if (unlikely (map->m_la >= inode->i_size)) { -BUG_ON (!initial); +DBG_BUGON (!initial); map->m_llen = map->m_la +1 - inode->i_size; map->m_la = inode->i_size; map->m_flags =0 ;
@@ -1561,16 +1573,16 @@ int z_erofs_map_blocks_iter(struct inode *inode, ofs = map->m_la + map->m_llen;/* clustersize should be power of two */ - lcn = ofs >> clusterbits; + lcn = ofs >> ctx.clusterbits; ofs_rem = ofs & (clustersize -1 ); - e_blkaddr =vle_extent_blkaddr (inode, lcn); + mblk =vle_extent_blkaddr (inode, lcn); -if (mpage ==NULL || mpage->index != e_blkaddr) { +if (mpage ==NULL || mpage->index != mblk) {if (mpage !=NULL )put_page (mpage); - mpage =erofs_get_meta_page_nofail (sb, e_blkaddr, false); + mpage =erofs_get_meta_page_nofail (ctx.sb, mblk, false); *mpage_ret = mpage; }else {lock_page (mpage);
@@ -1580,8 +1592,8 @@ int z_erofs_map_blocks_iter(struct inode *inode, kaddr =kmap_atomic (mpage); di = kaddr +vle_extent_blkoff (inode, lcn); -debugln ("%s, lcn %u e_blkaddr %u e_blkoff %u" , __func__, lcn, - e_blkaddr,vle_extent_blkoff (inode, lcn)); +debugln ("%s, lcn %u mblk %u e_blkoff %u" , __func__, lcn, + mblk,vle_extent_blkoff (inode, lcn)); err =vle_decompressed_index_clusterofs (&logical_cluster_ofs, clustersize, di);
@@ -1608,13 +1620,13 @@ int z_erofs_map_blocks_iter(struct inode *inode,/* fallthrough */ case Z_EROFS_VLE_CLUSTER_TYPE_HEAD :if (ofs_rem == logical_cluster_ofs) { - pcn =le32_to_cpu (di->di_u.blkaddr); + pblk =le32_to_cpu (di->di_u.blkaddr); goto exact_hitted; }if (ofs_rem > logical_cluster_ofs) { ofs = (u64 )lcn * clustersize | logical_cluster_ofs; - pcn =le32_to_cpu (di->di_u.blkaddr); + pblk =le32_to_cpu (di->di_u.blkaddr);break ; }
@@ -1629,9 +1641,12 @@ int z_erofs_map_blocks_iter(struct inode *inode,/* fallthrough */ case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD :/* get the correspoinding first chunk */ - ofs =vle_get_logical_extent_head (inode, mpage_ret, - &kaddr, lcn, &pcn, &map->m_flags); + err =vle_get_logical_extent_head (&ctx, lcn, &ofs, + &pblk, &map->m_flags); mpage = *mpage_ret; + +if (unlikely (err)) + goto unmap_out;break ;default : errln("unknown cluster type %u at offset %llu of nid %llu",
@@ -1644,7 +1659,7 @@ int z_erofs_map_blocks_iter(struct inode *inode, exact_hitted: map->m_llen = end - ofs; map->m_plen = clustersize; - map->m_pa =blknr_to_addr (pcn); + map->m_pa =blknr_to_addr (pblk); map->m_flags |=EROFS_MAP_MAPPED ; unmap_out:kunmap_atomic (kaddr);
Signature · 1 line
1.9.1
PATCH v3 7/10 staging: erofs: clean up z_erofs_map_blocks_iter
Quoted 8 lines · Gao Xiang
This patch mainly introduces `vle_map_blocks_iter_ctx' to clean up
z_erofs_map_blocks_iterandvle_get_logical_extent_head.It changes the return value of
vle_get_logical_extent_head' to int for the later error handing. In addition, it also renamespcn' topblk' since onlypblk' exists in erofs compression ondisk format.Signed-off-by Gao Xiang <gaoxiang25 at huawei.com>
Thanks,
PATCH v3 8/10 staging: erofs: complete error handing of z_erofs_map_blocks_iter
In reply to Gao XiangThis patch completes error handing of z_erofs_map_blocks_iter and vle_get_logical_extent_head, including no memory and io error cases.
---
change log v3:
- spilt into small patches at Chao's suggestion.
drivers/staging/erofs/unzip_vle.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-)
drivers/staging/erofs/unzip_vle.c +26 -9
@@ -1500,7 +1500,11 @@ struct vle_map_blocks_iter_ctx {unlock_page (mpage);put_page (mpage); - mpage =erofs_get_meta_page_nofail (ctx->sb, mblk, false); + mpage =erofs_get_meta_page (ctx->sb, mblk, false); +if (IS_ERR (mpage)) { + *ctx->mpage_ret =NULL ; +return PTR_ERR (mpage); + } *ctx->mpage_ret = mpage; *ctx->kaddr_ret =kmap_atomic (mpage); }
@@ -1511,9 +1515,12 @@ struct vle_map_blocks_iter_ctx {switch (cluster_type) {case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD : delta0 =le16_to_cpu (di->di_u.delta[0 ]); -DBG_BUGON (!delta0); -DBG_BUGON (lcn < delta0); - +if (unlikely (!delta0 || delta0 > lcn)) { +errln ("invalid NONHEAD dl0 %u at lcn %u of nid %llu" , + delta0, lcn,EROFS_V (ctx->inode)->nid); +DBG_BUGON (1 ); +return -EIO ; + }return vle_get_logical_extent_head (ctx, lcn - delta0, ofs, pblk, flags);case Z_EROFS_VLE_CLUSTER_TYPE_PLAIN :
@@ -1526,7 +1533,10 @@ struct vle_map_blocks_iter_ctx { *pblk =le32_to_cpu (di->di_u.blkaddr);break ;default : -BUG_ON (1 ); +errln ("unknown cluster type %u at lcn %u of nid %llu" , + cluster_type, lcn,EROFS_V (ctx->inode)->nid); +DBG_BUGON (1 ); +return -EIO ; }return 0 ; }
@@ -1582,7 +1592,11 @@ int z_erofs_map_blocks_iter(struct inode *inode,if (mpage !=NULL )put_page (mpage); - mpage =erofs_get_meta_page_nofail (ctx.sb, mblk, false); + mpage =erofs_get_meta_page (ctx.sb, mblk, false); +if (IS_ERR (mpage)) { + err =PTR_ERR (mpage); + goto out; + } *mpage_ret = mpage; }else {lock_page (mpage);
@@ -1645,8 +1659,11 @@ int z_erofs_map_blocks_iter(struct inode *inode, &pblk, &map->m_flags); mpage = *mpage_ret; -if (unlikely (err)) - goto unmap_out; +if (unlikely (err)) { +if (mpage !=NULL ) + goto unmap_out; + goto out; + }break ;default : errln("unknown cluster type %u at offset %llu of nid %llu",
@@ -1670,7 +1687,7 @@ int z_erofs_map_blocks_iter(struct inode *inode, map->m_llen, map->m_plen, map->m_flags);/* aggressively BUG_ON iff CONFIG_EROFS_FS_DEBUG is on */ -DBG_BUGON (err <0 ); +DBG_BUGON (err <0 && err != -ENOMEM );return err; }
Signature · 1 line
1.9.1
PATCH v3 8/10 staging: erofs: complete error handing of z_erofs_map_blocks_iter
Quoted 5 lines · Gao Xiang
This patch completes error handing of
z_erofs_map_blocks_iterandvle_get_logical_extent_head, including no memory and io error cases.Signed-off-by Gao Xiang <gaoxiang25 at huawei.com>
Thanks,
PATCH v2 9/10 staging: erofs: fix a bug when appling cache strategy
In reply to Gao XiangAs described in Kconfig, the last compressed pack should be cached for further reading for either EROFS_FS_ZIP_CACHE_UNIPOLAR' or EROFS_FS_ZIP_CACHE_BIPOLAR' by design.
However, there is a bug in z_erofs_do_read_page, it will switch initial' to false' at the very beginning before it decides to cache the last compressed pack.
caching strategy should work properly after appling this patch.
---
change log v2:
- spilt into small patches at Chao's suggestion.
drivers/staging/erofs/unzip_vle.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/erofs/unzip_vle.c +1 -1
@@ -629,7 +629,7 @@ static int z_erofs_do_read_page(struct z_erofs_vle_frontend *fe,/* go ahead the next map_blocks */ debugln ("%s: [out-of-range] pos %llu" , __func__, offset + cur); -if (!z_erofs_vle_work_iter_end (builder)) +if (z_erofs_vle_work_iter_end (builder)) fe->initial = false; map->m_la = offset + cur;
Signature · 1 line
1.9.1
PATCH v2 9/10 staging: erofs: fix a bug when appling cache strategy
Quoted 11 lines · Gao Xiang
As described in
Kconfig, the last compressed pack should be cached for further reading for eitherEROFS_FS_ZIP_CACHE_UNIPOLAR' orEROFS_FS_ZIP_CACHE_BIPOLAR' by design.However, there is a bug in
z_erofs_do_read_page, it will switchinitial' tofalse' at the very beginning before it decides to cache the last compressed pack.caching strategy should work properly after appling this patch.
Signed-off-by Gao Xiang <gaoxiang25 at huawei.com>
Thanks,
PATCH v2 10/10 staging: erofs: complete error handing of z_erofs_do_read_page
In reply to Gao XiangThis patch completes error handing code of z_erofs_do_read_page. PG_error will be set when some read error happens, therefore z_erofs_onlinepage_endio will unlock this page without setting PG_uptodate.
---
change log v2:
- spilt into small patches at Chao's suggestion.
drivers/staging/erofs/unzip_vle.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
drivers/staging/erofs/unzip_vle.c +11 -9
@@ -611,7 +611,7 @@ static int z_erofs_do_read_page(struct z_erofs_vle_frontend *fe,enum z_erofs_page_type page_type;unsigned cur, end, spiltted, index; -int err; +int err =0 ;/* register locked file pages as online pages in pack */ z_erofs_onlinepage_init (page);
@@ -638,12 +638,11 @@ static int z_erofs_do_read_page(struct z_erofs_vle_frontend *fe,if (unlikely (err)) goto err_out; -/* deal with hole (FIXME! broken now) */ if (unlikely (!(map->m_flags &EROFS_MAP_MAPPED ))) goto hitted;DBG_BUGON (map->m_plen !=1 << sbi->clusterbits); -BUG_ON (erofs_blkoff (map->m_pa)); +DBG_BUGON (erofs_blkoff (map->m_pa)); err =z_erofs_vle_work_iter_begin (builder, sb, map, &fe->owned_head);if (unlikely (err))
@@ -688,7 +687,7 @@ static int z_erofs_do_read_page(struct z_erofs_vle_frontend *fe, err =z_erofs_vle_work_add_page (builder, newpage,Z_EROFS_PAGE_TYPE_EXCLUSIVE ); -if (!err) +if (likely (!err)) goto retry; }
@@ -699,9 +698,10 @@ static int z_erofs_do_read_page(struct z_erofs_vle_frontend *fe,/* FIXME! avoid the last relundant fixup & endio */ z_erofs_onlinepage_fixup (page, index, true); - ++spiltted; -/* also update nr_pages and increase queued_pages */ +/* bump up the number of spiltted parts of a page */ + ++spiltted; +/* also update nr_pages */ work->nr_pages =max_t (pgoff_t, work->nr_pages, index +1 ); next_part:/* can be used for verification */
@@ -711,16 +711,18 @@ static int z_erofs_do_read_page(struct z_erofs_vle_frontend *fe,if (end >0 ) goto repeat; +out:/* FIXME! avoid the last relundant fixup & endio */ z_erofs_onlinepage_endio (page);debugln ("%s, finish page: %pK spiltted: %u map->m_llen %llu" , __func__, page, spiltted, map->m_llen); -return 0 ; +return err; +/* if some error occurred while processing this page */ err_out: -/* TODO: the missing error handing cases */ -return err; +SetPageError (page); + goto out; }static void z_erofs_vle_unzip_kickoff (void *ptr,int bios)
Signature · 1 line
1.9.1
PATCH v2 10/10 staging: erofs: complete error handing of z_erofs_do_read_page
Quoted 6 lines · Gao Xiang
This patch completes error handing code of
z_erofs_do_read_page.PG_errorwill be set when some read error happens, thereforez_erofs_onlinepage_endiowill unlock this page without settingPG_uptodate.Signed-off-by Gao Xiang <gaoxiang25 at huawei.com>
Thanks,