erofs: simplify compression configuration parser
PATCH 1/1 erofs: simplify compression configuration parser
Move erofs_load_compr_cfgs() into decompressor.c as well as introduce a callback instead of a hard-coded switch for each algorithm for simplicity.
--- fs/erofs/compress.h | 6 +++ fs/erofs/decompressor.c | 60 ++++++++++++++++++++++++++- fs/erofs/decompressor_deflate.c | 5 ++- fs/erofs/decompressor_lzma.c | 4 +- fs/erofs/internal.h | 38 +---------------- fs/erofs/super.c | 72 ++++----------------------------- 6 files changed, 78 insertions(+), 107 deletions(-)
fs/erofs/compress.h +6 -0
@@ -21,6 +21,8 @@ struct z_erofs_decompress_req { };struct z_erofs_decompressor { +int (*config)(struct super_block *sb,struct erofs_super_block *dsb, +void *data,int size);int (*decompress)(struct z_erofs_decompress_req *rq,struct page **pagepool);char *name;
@@ -92,6 +94,10 @@ int z_erofs_fixup_insize(struct z_erofs_decompress_req *rq, const char *padbuf,extern const struct z_erofs_decompressor erofs_decompressors[];/* prototypes for specific algorithms */ +int z_erofs_load_lzma_config (struct super_block *sb, +struct erofs_super_block *dsb,void *data,int size); +int z_erofs_load_deflate_config (struct super_block *sb, +struct erofs_super_block *dsb,void *data,int size);int z_erofs_lzma_decompress (struct z_erofs_decompress_req *rq,struct page **pagepool); int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,
fs/erofs/decompressor.c +58 -2
87 lines not on this page · raw message
fs/erofs/decompressor_deflate.c +3 -2
@@ -77,9 +77,10 @@ int __init z_erofs_deflate_init(void) }int z_erofs_load_deflate_config (struct super_block *sb, -struct erofs_super_block *dsb, -struct z_erofs_deflate_cfgs *dfl,int size) +struct erofs_super_block *dsb,void *data,int size) { +struct z_erofs_deflate_cfgs *dfl = data; +if (!dfl || size <sizeof (struct z_erofs_deflate_cfgs )) {erofs_err (sb,"invalid deflate cfgs, size=%u" , size);return -EINVAL ;
fs/erofs/decompressor_lzma.c +2 -2
@@ -72,10 +72,10 @@ int __init z_erofs_lzma_init(void) }int z_erofs_load_lzma_config (struct super_block *sb, -struct erofs_super_block *dsb, -struct z_erofs_lzma_cfgs *lzma,int size) +struct erofs_super_block *dsb,void *data,int size) {static DEFINE_MUTEX (lzma_resize_mutex); +struct z_erofs_lzma_cfgs *lzma = data;unsigned int dict_size, i;struct z_erofs_lzma *strm, *head =NULL ;int err;
fs/erofs/internal.h +1 -37
@@ -469,9 +469,6 @@ int __init z_erofs_init_zip_subsystem(void);void z_erofs_exit_zip_subsystem (void );int erofs_try_to_free_all_cached_pages (struct erofs_sb_info *sbi,struct erofs_workgroup *egrp); -int z_erofs_load_lz4_config (struct super_block *sb, -struct erofs_super_block *dsb, -struct z_erofs_lz4_cfgs *lz4,int len);int z_erofs_map_blocks_iter (struct inode *inode,struct erofs_map_blocks *map,int flags);void *erofs_get_pcpubuf (unsigned int requiredpages);
@@ -480,6 +477,7 @@ int erofs_pcpubuf_growsize(unsigned int nrpages);void __init erofs_pcpubuf_init (void );void erofs_pcpubuf_exit (void );int erofs_init_managed_cache (struct super_block *sb); +int z_erofs_parse_cfgs (struct super_block *sb,struct erofs_super_block *dsb);#else static inline void erofs_shrinker_register (struct super_block *sb) {}static inline void erofs_shrinker_unregister (struct super_block *sb) {}
@@ -487,16 +485,6 @@ static inline int erofs_init_shrinker(void) { return 0; }static inline void erofs_exit_shrinker (void ) {}static inline int z_erofs_init_zip_subsystem (void ) {return 0 ; }static inline void z_erofs_exit_zip_subsystem (void ) {} -static inline int z_erofs_load_lz4_config (struct super_block *sb, -struct erofs_super_block *dsb, -struct z_erofs_lz4_cfgs *lz4,int len) -{ -if (lz4 || dsb->u1.lz4_max_distance) { -erofs_err (sb,"lz4 algorithm isn't enabled" ); -return -EINVAL ; - } -return 0 ; -}static inline void erofs_pcpubuf_init (void ) {}static inline void erofs_pcpubuf_exit (void ) {}static inline int erofs_init_managed_cache (struct super_block *sb) {return 0 ; }
@@ -505,41 +493,17 @@ static inline int erofs_init_managed_cache(struct super_block *sb) { return 0; }#ifdef CONFIG_EROFS_FS_ZIP_LZMA int __init z_erofs_lzma_init (void );void z_erofs_lzma_exit (void ); -int z_erofs_load_lzma_config (struct super_block *sb, -struct erofs_super_block *dsb, -struct z_erofs_lzma_cfgs *lzma,int size);#else static inline int z_erofs_lzma_init (void ) {return 0 ; }static inline int z_erofs_lzma_exit (void ) {return 0 ; } -static inline int z_erofs_load_lzma_config (struct super_block *sb, -struct erofs_super_block *dsb, -struct z_erofs_lzma_cfgs *lzma,int size) { -if (lzma) { -erofs_err (sb,"lzma algorithm isn't enabled" ); -return -EINVAL ; - } -return 0 ; -}#endif /* !CONFIG_EROFS_FS_ZIP_LZMA */ #ifdef CONFIG_EROFS_FS_ZIP_DEFLATE int __init z_erofs_deflate_init (void );void z_erofs_deflate_exit (void ); -int z_erofs_load_deflate_config (struct super_block *sb, -struct erofs_super_block *dsb, -struct z_erofs_deflate_cfgs *dfl,int size);#else static inline int z_erofs_deflate_init (void ) {return 0 ; }static inline int z_erofs_deflate_exit (void ) {return 0 ; } -static inline int z_erofs_load_deflate_config (struct super_block *sb, -struct erofs_super_block *dsb, -struct z_erofs_deflate_cfgs *dfl,int size) { -if (dfl) { -erofs_err (sb,"deflate algorithm isn't enabled" ); -return -EINVAL ; - } -return 0 ; -}#endif /* !CONFIG_EROFS_FS_ZIP_DEFLATE */ #ifdef CONFIG_EROFS_FS_ONDEMAND
fs/erofs/super.c +8 -64
86 lines not on this page · raw message
Signature · 1 line
2.39.3
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi Gao,
kernel test robot noticed the following build warnings:
[auto build test WARNING on xiang-erofs/dev-test]
[also build test WARNING on xiang-erofs/dev xiang-erofs/fixes linus/master v6.6-rc6 next-20231020] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Gao-Xiang/erofs-simplify-compression-configuration-parser/20231021-100253 base: https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git dev-test patch link: https://lore.kernel.org/r/20231021020109.1646299-1-hsiangkao%40linux.alibaba.com patch subject: [PATCH] erofs: simplify compression configuration parser config: m68k-allyesconfig (https://download.01.org/0day-ci/archive/20231021/[email protected]/config) compiler: m68k-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231021/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> fs/erofs/decompressor.c:27:5: warning: no previous prototype for 'z_erofs_load_lz4_config' [-Wmissing-prototypes]
27 | int z_erofs_load_lz4_config(struct super_block *sb,
| ^~~~~~~~~~~~~~~~~~~~~~~
vim +/z_erofs_load_lz4_config +27 fs/erofs/decompressor.c
d67aee76d41861 Gao Xiang 2021-12-28 26
5d50538fc567c6 Huang Jianan 2021-03-29 @27 int z_erofs_load_lz4_config(struct super_block *sb,
51fd9879fa6135 Gao Xiang 2023-10-21 28 struct erofs_super_block *dsb, void *data, int size)
5d50538fc567c6 Huang Jianan 2021-03-29 29 {
4fea63f7d76e42 Gao Xiang 2021-04-07 30 struct erofs_sb_info *sbi = EROFS_SB(sb);
51fd9879fa6135 Gao Xiang 2023-10-21 31 struct z_erofs_lz4_cfgs *lz4 = data;
46249cded18ac0 Gao Xiang 2021-03-29 32 u16 distance;
46249cded18ac0 Gao Xiang 2021-03-29 33
46249cded18ac0 Gao Xiang 2021-03-29 34 if (lz4) {
46249cded18ac0 Gao Xiang 2021-03-29 35 if (size < sizeof(struct z_erofs_lz4_cfgs)) {
46249cded18ac0 Gao Xiang 2021-03-29 36 erofs_err(sb, "invalid lz4 cfgs, size=%u", size);
46249cded18ac0 Gao Xiang 2021-03-29 37 return -EINVAL;
46249cded18ac0 Gao Xiang 2021-03-29 38 }
46249cded18ac0 Gao Xiang 2021-03-29 39 distance = le16_to_cpu(lz4->max_distance);
4fea63f7d76e42 Gao Xiang 2021-04-07 40
4fea63f7d76e42 Gao Xiang 2021-04-07 41 sbi->lz4.max_pclusterblks = le16_to_cpu(lz4->max_pclusterblks);
4fea63f7d76e42 Gao Xiang 2021-04-07 42 if (!sbi->lz4.max_pclusterblks) {
4fea63f7d76e42 Gao Xiang 2021-04-07 43 sbi->lz4.max_pclusterblks = 1; /* reserved case */
4fea63f7d76e42 Gao Xiang 2021-04-07 44 } else if (sbi->lz4.max_pclusterblks >
3acea5fc335420 Jingbo Xu 2023-03-13 45 erofs_blknr(sb, Z_EROFS_PCLUSTER_MAX_SIZE)) {
4fea63f7d76e42 Gao Xiang 2021-04-07 46 erofs_err(sb, "too large lz4 pclusterblks %u",
4fea63f7d76e42 Gao Xiang 2021-04-07 47 sbi->lz4.max_pclusterblks);
4fea63f7d76e42 Gao Xiang 2021-04-07 48 return -EINVAL;
4fea63f7d76e42 Gao Xiang 2021-04-07 49 }
46249cded18ac0 Gao Xiang 2021-03-29 50 } else {
14373711dd54be Gao Xiang 2021-03-29 51 distance = le16_to_cpu(dsb->u1.lz4_max_distance);
4fea63f7d76e42 Gao Xiang 2021-04-07 52 sbi->lz4.max_pclusterblks = 1;
46249cded18ac0 Gao Xiang 2021-03-29 53 }
5d50538fc567c6 Huang Jianan 2021-03-29 54
4fea63f7d76e42 Gao Xiang 2021-04-07 55 sbi->lz4.max_distance_pages = distance ?
5d50538fc567c6 Huang Jianan 2021-03-29 56 DIV_ROUND_UP(distance, PAGE_SIZE) + 1 :
5d50538fc567c6 Huang Jianan 2021-03-29 57 LZ4_MAX_DISTANCE_PAGES;
4fea63f7d76e42 Gao Xiang 2021-04-07 58 return erofs_pcpubuf_growsize(sbi->lz4.max_pclusterblks);
5d50538fc567c6 Huang Jianan 2021-03-29 59 }
5d50538fc567c6 Huang Jianan 2021-03-29 60 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Gao Xiang
maintainerPATCH v2 1/1 erofs: simplify compression configuration parser
In reply to Gao XiangFrom: Gao Xiang <[email protected]>
Move erofs_load_compr_cfgs() into decompressor.c as well as introduce a callback instead of a hard-coded switch for each algorithm for simplicity.
---
v2:
- fix build warning of -Wmissing-declarations
https://lore.kernel.org/r/[email protected]
fs/erofs/compress.h | 6 +++ fs/erofs/decompressor.c | 62 ++++++++++++++++++++++++++-- fs/erofs/decompressor_deflate.c | 5 ++- fs/erofs/decompressor_lzma.c | 4 +- fs/erofs/internal.h | 38 +---------------- fs/erofs/super.c | 72 ++++----------------------------- 6 files changed, 79 insertions(+), 108 deletions(-)
fs/erofs/compress.h +6 -0
@@ -21,6 +21,8 @@ struct z_erofs_decompress_req { };struct z_erofs_decompressor { +int (*config)(struct super_block *sb,struct erofs_super_block *dsb, +void *data,int size);int (*decompress)(struct z_erofs_decompress_req *rq,struct page **pagepool);char *name;
@@ -92,6 +94,10 @@ int z_erofs_fixup_insize(struct z_erofs_decompress_req *rq, const char *padbuf,extern const struct z_erofs_decompressor erofs_decompressors[];/* prototypes for specific algorithms */ +int z_erofs_load_lzma_config (struct super_block *sb, +struct erofs_super_block *dsb,void *data,int size); +int z_erofs_load_deflate_config (struct super_block *sb, +struct erofs_super_block *dsb,void *data,int size);int z_erofs_lzma_decompress (struct z_erofs_decompress_req *rq,struct page **pagepool); int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,
fs/erofs/decompressor.c +59 -3
89 lines not on this page · raw message
fs/erofs/decompressor_deflate.c +3 -2
@@ -77,9 +77,10 @@ int __init z_erofs_deflate_init(void) }int z_erofs_load_deflate_config (struct super_block *sb, -struct erofs_super_block *dsb, -struct z_erofs_deflate_cfgs *dfl,int size) +struct erofs_super_block *dsb,void *data,int size) { +struct z_erofs_deflate_cfgs *dfl = data; +if (!dfl || size <sizeof (struct z_erofs_deflate_cfgs )) {erofs_err (sb,"invalid deflate cfgs, size=%u" , size);return -EINVAL ;
fs/erofs/decompressor_lzma.c +2 -2
@@ -72,10 +72,10 @@ int __init z_erofs_lzma_init(void) }int z_erofs_load_lzma_config (struct super_block *sb, -struct erofs_super_block *dsb, -struct z_erofs_lzma_cfgs *lzma,int size) +struct erofs_super_block *dsb,void *data,int size) {static DEFINE_MUTEX (lzma_resize_mutex); +struct z_erofs_lzma_cfgs *lzma = data;unsigned int dict_size, i;struct z_erofs_lzma *strm, *head =NULL ;int err;
fs/erofs/internal.h +1 -37
@@ -469,9 +469,6 @@ int __init z_erofs_init_zip_subsystem(void);void z_erofs_exit_zip_subsystem (void );int erofs_try_to_free_all_cached_pages (struct erofs_sb_info *sbi,struct erofs_workgroup *egrp); -int z_erofs_load_lz4_config (struct super_block *sb, -struct erofs_super_block *dsb, -struct z_erofs_lz4_cfgs *lz4,int len);int z_erofs_map_blocks_iter (struct inode *inode,struct erofs_map_blocks *map,int flags);void *erofs_get_pcpubuf (unsigned int requiredpages);
@@ -480,6 +477,7 @@ int erofs_pcpubuf_growsize(unsigned int nrpages);void __init erofs_pcpubuf_init (void );void erofs_pcpubuf_exit (void );int erofs_init_managed_cache (struct super_block *sb); +int z_erofs_parse_cfgs (struct super_block *sb,struct erofs_super_block *dsb);#else static inline void erofs_shrinker_register (struct super_block *sb) {}static inline void erofs_shrinker_unregister (struct super_block *sb) {}
@@ -487,16 +485,6 @@ static inline int erofs_init_shrinker(void) { return 0; }static inline void erofs_exit_shrinker (void ) {}static inline int z_erofs_init_zip_subsystem (void ) {return 0 ; }static inline void z_erofs_exit_zip_subsystem (void ) {} -static inline int z_erofs_load_lz4_config (struct super_block *sb, -struct erofs_super_block *dsb, -struct z_erofs_lz4_cfgs *lz4,int len) -{ -if (lz4 || dsb->u1.lz4_max_distance) { -erofs_err (sb,"lz4 algorithm isn't enabled" ); -return -EINVAL ; - } -return 0 ; -}static inline void erofs_pcpubuf_init (void ) {}static inline void erofs_pcpubuf_exit (void ) {}static inline int erofs_init_managed_cache (struct super_block *sb) {return 0 ; }
@@ -505,41 +493,17 @@ static inline int erofs_init_managed_cache(struct super_block *sb) { return 0; }#ifdef CONFIG_EROFS_FS_ZIP_LZMA int __init z_erofs_lzma_init (void );void z_erofs_lzma_exit (void ); -int z_erofs_load_lzma_config (struct super_block *sb, -struct erofs_super_block *dsb, -struct z_erofs_lzma_cfgs *lzma,int size);#else static inline int z_erofs_lzma_init (void ) {return 0 ; }static inline int z_erofs_lzma_exit (void ) {return 0 ; } -static inline int z_erofs_load_lzma_config (struct super_block *sb, -struct erofs_super_block *dsb, -struct z_erofs_lzma_cfgs *lzma,int size) { -if (lzma) { -erofs_err (sb,"lzma algorithm isn't enabled" ); -return -EINVAL ; - } -return 0 ; -}#endif /* !CONFIG_EROFS_FS_ZIP_LZMA */ #ifdef CONFIG_EROFS_FS_ZIP_DEFLATE int __init z_erofs_deflate_init (void );void z_erofs_deflate_exit (void ); -int z_erofs_load_deflate_config (struct super_block *sb, -struct erofs_super_block *dsb, -struct z_erofs_deflate_cfgs *dfl,int size);#else static inline int z_erofs_deflate_init (void ) {return 0 ; }static inline int z_erofs_deflate_exit (void ) {return 0 ; } -static inline int z_erofs_load_deflate_config (struct super_block *sb, -struct erofs_super_block *dsb, -struct z_erofs_deflate_cfgs *dfl,int size) { -if (dfl) { -erofs_err (sb,"deflate algorithm isn't enabled" ); -return -EINVAL ; - } -return 0 ; -}#endif /* !CONFIG_EROFS_FS_ZIP_DEFLATE */ #ifdef CONFIG_EROFS_FS_ONDEMAND
fs/erofs/super.c +8 -64
86 lines not on this page · raw message
Signature · 1 line
2.30.2
Quoted 7 lines · Gao Xiang
From: Gao Xiang <[email protected]>
Move
erofs_load_compr_cfgs()intodecompressor.cas well as introduce a callback instead of a hard-coded switch for each algorithm for simplicity.Signed-off-by Gao Xiang <[email protected]>
Thanks,