Commit 392d20cc authored by Gao Xiang's avatar Gao Xiang

erofs: move each decompressor to its own source file

Thus *_config() function declarations can be avoided.
Signed-off-by: default avatarGao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20240709094106.3018109-1-hsiangkao@linux.alibaba.com
parent 2080ca1e
...@@ -81,21 +81,11 @@ static inline bool z_erofs_put_shortlivedpage(struct page **pagepool, ...@@ -81,21 +81,11 @@ static inline bool z_erofs_put_shortlivedpage(struct page **pagepool,
return true; return true;
} }
extern const struct z_erofs_decompressor z_erofs_lzma_decomp;
extern const struct z_erofs_decompressor z_erofs_deflate_decomp;
extern const struct z_erofs_decompressor z_erofs_zstd_decomp;
extern const struct z_erofs_decompressor *z_erofs_decomp[];
int z_erofs_fixup_insize(struct z_erofs_decompress_req *rq, const char *padbuf, int z_erofs_fixup_insize(struct z_erofs_decompress_req *rq, const char *padbuf,
unsigned int padbufsize); unsigned int padbufsize);
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_load_zstd_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,
struct page **pagepool);
int z_erofs_zstd_decompress(struct z_erofs_decompress_req *rq,
struct page **pgpl);
#endif #endif
...@@ -371,40 +371,28 @@ static int z_erofs_transform_plain(struct z_erofs_decompress_req *rq, ...@@ -371,40 +371,28 @@ static int z_erofs_transform_plain(struct z_erofs_decompress_req *rq,
return 0; return 0;
} }
const struct z_erofs_decompressor erofs_decompressors[] = { const struct z_erofs_decompressor *z_erofs_decomp[] = {
[Z_EROFS_COMPRESSION_SHIFTED] = { [Z_EROFS_COMPRESSION_SHIFTED] = &(const struct z_erofs_decompressor) {
.decompress = z_erofs_transform_plain, .decompress = z_erofs_transform_plain,
.name = "shifted" .name = "shifted"
}, },
[Z_EROFS_COMPRESSION_INTERLACED] = { [Z_EROFS_COMPRESSION_INTERLACED] = &(const struct z_erofs_decompressor) {
.decompress = z_erofs_transform_plain, .decompress = z_erofs_transform_plain,
.name = "interlaced" .name = "interlaced"
}, },
[Z_EROFS_COMPRESSION_LZ4] = { [Z_EROFS_COMPRESSION_LZ4] = &(const struct z_erofs_decompressor) {
.config = z_erofs_load_lz4_config, .config = z_erofs_load_lz4_config,
.decompress = z_erofs_lz4_decompress, .decompress = z_erofs_lz4_decompress,
.name = "lz4" .name = "lz4"
}, },
#ifdef CONFIG_EROFS_FS_ZIP_LZMA #ifdef CONFIG_EROFS_FS_ZIP_LZMA
[Z_EROFS_COMPRESSION_LZMA] = { [Z_EROFS_COMPRESSION_LZMA] = &z_erofs_lzma_decomp,
.config = z_erofs_load_lzma_config,
.decompress = z_erofs_lzma_decompress,
.name = "lzma"
},
#endif #endif
#ifdef CONFIG_EROFS_FS_ZIP_DEFLATE #ifdef CONFIG_EROFS_FS_ZIP_DEFLATE
[Z_EROFS_COMPRESSION_DEFLATE] = { [Z_EROFS_COMPRESSION_DEFLATE] = &z_erofs_deflate_decomp,
.config = z_erofs_load_deflate_config,
.decompress = z_erofs_deflate_decompress,
.name = "deflate"
},
#endif #endif
#ifdef CONFIG_EROFS_FS_ZIP_ZSTD #ifdef CONFIG_EROFS_FS_ZIP_ZSTD
[Z_EROFS_COMPRESSION_ZSTD] = { [Z_EROFS_COMPRESSION_ZSTD] = &z_erofs_zstd_decomp,
.config = z_erofs_load_zstd_config,
.decompress = z_erofs_zstd_decompress,
.name = "zstd"
},
#endif #endif
}; };
...@@ -432,6 +420,7 @@ int z_erofs_parse_cfgs(struct super_block *sb, struct erofs_super_block *dsb) ...@@ -432,6 +420,7 @@ int z_erofs_parse_cfgs(struct super_block *sb, struct erofs_super_block *dsb)
offset = EROFS_SUPER_OFFSET + sbi->sb_size; offset = EROFS_SUPER_OFFSET + sbi->sb_size;
alg = 0; alg = 0;
for (algs = sbi->available_compr_algs; algs; algs >>= 1, ++alg) { for (algs = sbi->available_compr_algs; algs; algs >>= 1, ++alg) {
const struct z_erofs_decompressor *dec = z_erofs_decomp[alg];
void *data; void *data;
if (!(algs & 1)) if (!(algs & 1))
...@@ -443,16 +432,13 @@ int z_erofs_parse_cfgs(struct super_block *sb, struct erofs_super_block *dsb) ...@@ -443,16 +432,13 @@ int z_erofs_parse_cfgs(struct super_block *sb, struct erofs_super_block *dsb)
break; break;
} }
if (alg >= ARRAY_SIZE(erofs_decompressors) || if (alg < Z_EROFS_COMPRESSION_MAX && dec && dec->config) {
!erofs_decompressors[alg].config) { ret = dec->config(sb, dsb, data, size);
} else {
erofs_err(sb, "algorithm %d isn't enabled on this kernel", erofs_err(sb, "algorithm %d isn't enabled on this kernel",
alg); alg);
ret = -EOPNOTSUPP; ret = -EOPNOTSUPP;
} else {
ret = erofs_decompressors[alg].config(sb,
dsb, data, size);
} }
kfree(data); kfree(data);
if (ret) if (ret)
break; break;
......
...@@ -49,7 +49,7 @@ int __init z_erofs_deflate_init(void) ...@@ -49,7 +49,7 @@ int __init z_erofs_deflate_init(void)
return 0; return 0;
} }
int z_erofs_load_deflate_config(struct super_block *sb, static int z_erofs_load_deflate_config(struct super_block *sb,
struct erofs_super_block *dsb, void *data, int size) struct erofs_super_block *dsb, void *data, int size)
{ {
struct z_erofs_deflate_cfgs *dfl = data; struct z_erofs_deflate_cfgs *dfl = data;
...@@ -97,8 +97,8 @@ int z_erofs_load_deflate_config(struct super_block *sb, ...@@ -97,8 +97,8 @@ int z_erofs_load_deflate_config(struct super_block *sb,
return -ENOMEM; return -ENOMEM;
} }
int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq, static int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,
struct page **pgpl) struct page **pgpl)
{ {
const unsigned int nrpages_out = const unsigned int nrpages_out =
PAGE_ALIGN(rq->pageofs_out + rq->outputsize) >> PAGE_SHIFT; PAGE_ALIGN(rq->pageofs_out + rq->outputsize) >> PAGE_SHIFT;
...@@ -252,3 +252,9 @@ int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq, ...@@ -252,3 +252,9 @@ int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,
wake_up(&z_erofs_deflate_wq); wake_up(&z_erofs_deflate_wq);
return err; return err;
} }
const struct z_erofs_decompressor z_erofs_deflate_decomp = {
.config = z_erofs_load_deflate_config,
.decompress = z_erofs_deflate_decompress,
.name = "deflate",
};
...@@ -70,7 +70,7 @@ int __init z_erofs_lzma_init(void) ...@@ -70,7 +70,7 @@ int __init z_erofs_lzma_init(void)
return 0; return 0;
} }
int z_erofs_load_lzma_config(struct super_block *sb, static int z_erofs_load_lzma_config(struct super_block *sb,
struct erofs_super_block *dsb, void *data, int size) struct erofs_super_block *dsb, void *data, int size)
{ {
static DEFINE_MUTEX(lzma_resize_mutex); static DEFINE_MUTEX(lzma_resize_mutex);
...@@ -147,8 +147,8 @@ int z_erofs_load_lzma_config(struct super_block *sb, ...@@ -147,8 +147,8 @@ int z_erofs_load_lzma_config(struct super_block *sb,
return err; return err;
} }
int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq, static int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq,
struct page **pgpl) struct page **pgpl)
{ {
const unsigned int nrpages_out = const unsigned int nrpages_out =
PAGE_ALIGN(rq->pageofs_out + rq->outputsize) >> PAGE_SHIFT; PAGE_ALIGN(rq->pageofs_out + rq->outputsize) >> PAGE_SHIFT;
...@@ -293,3 +293,9 @@ int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq, ...@@ -293,3 +293,9 @@ int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq,
wake_up(&z_erofs_lzma_wq); wake_up(&z_erofs_lzma_wq);
return err; return err;
} }
const struct z_erofs_decompressor z_erofs_lzma_decomp = {
.config = z_erofs_load_lzma_config,
.decompress = z_erofs_lzma_decompress,
.name = "lzma"
};
...@@ -72,7 +72,7 @@ int __init z_erofs_zstd_init(void) ...@@ -72,7 +72,7 @@ int __init z_erofs_zstd_init(void)
return 0; return 0;
} }
int z_erofs_load_zstd_config(struct super_block *sb, static int z_erofs_load_zstd_config(struct super_block *sb,
struct erofs_super_block *dsb, void *data, int size) struct erofs_super_block *dsb, void *data, int size)
{ {
static DEFINE_MUTEX(zstd_resize_mutex); static DEFINE_MUTEX(zstd_resize_mutex);
...@@ -135,8 +135,8 @@ int z_erofs_load_zstd_config(struct super_block *sb, ...@@ -135,8 +135,8 @@ int z_erofs_load_zstd_config(struct super_block *sb,
return strm ? -ENOMEM : 0; return strm ? -ENOMEM : 0;
} }
int z_erofs_zstd_decompress(struct z_erofs_decompress_req *rq, static int z_erofs_zstd_decompress(struct z_erofs_decompress_req *rq,
struct page **pgpl) struct page **pgpl)
{ {
const unsigned int nrpages_out = const unsigned int nrpages_out =
PAGE_ALIGN(rq->pageofs_out + rq->outputsize) >> PAGE_SHIFT; PAGE_ALIGN(rq->pageofs_out + rq->outputsize) >> PAGE_SHIFT;
...@@ -277,3 +277,9 @@ int z_erofs_zstd_decompress(struct z_erofs_decompress_req *rq, ...@@ -277,3 +277,9 @@ int z_erofs_zstd_decompress(struct z_erofs_decompress_req *rq,
wake_up(&z_erofs_zstd_wq); wake_up(&z_erofs_zstd_wq);
return err; return err;
} }
const struct z_erofs_decompressor z_erofs_zstd_decomp = {
.config = z_erofs_load_zstd_config,
.decompress = z_erofs_zstd_decompress,
.name = "zstd",
};
...@@ -1213,7 +1213,7 @@ static int z_erofs_decompress_pcluster(struct z_erofs_decompress_backend *be, ...@@ -1213,7 +1213,7 @@ static int z_erofs_decompress_pcluster(struct z_erofs_decompress_backend *be,
struct z_erofs_pcluster *pcl = be->pcl; struct z_erofs_pcluster *pcl = be->pcl;
unsigned int pclusterpages = z_erofs_pclusterpages(pcl); unsigned int pclusterpages = z_erofs_pclusterpages(pcl);
const struct z_erofs_decompressor *decomp = const struct z_erofs_decompressor *decomp =
&erofs_decompressors[pcl->algorithmformat]; z_erofs_decomp[pcl->algorithmformat];
int i, err2; int i, err2;
struct page *page; struct page *page;
bool overlapped; bool overlapped;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment