Commit 5a7cce82 authored by Gao Xiang's avatar Gao Xiang

erofs: refine z_erofs_{init,exit}_subsystem()

Introduce z_erofs_{init,exit}_decompressor() to unexport
z_erofs_{deflate,lzma,zstd}_{init,exit}().

Besides, call them in z_erofs_{init,exit}_subsystem()
for simplicity.
Signed-off-by: default avatarGao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20240709094106.3018109-2-hsiangkao@linux.alibaba.com
parent 392d20cc
...@@ -24,6 +24,8 @@ struct z_erofs_decompressor { ...@@ -24,6 +24,8 @@ struct z_erofs_decompressor {
void *data, int size); void *data, int size);
int (*decompress)(struct z_erofs_decompress_req *rq, int (*decompress)(struct z_erofs_decompress_req *rq,
struct page **pagepool); struct page **pagepool);
int (*init)(void);
void (*exit)(void);
char *name; char *name;
}; };
...@@ -88,4 +90,6 @@ extern const struct z_erofs_decompressor *z_erofs_decomp[]; ...@@ -88,4 +90,6 @@ 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);
int __init z_erofs_init_decompressor(void);
void z_erofs_exit_decompressor(void);
#endif #endif
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
/* /*
* Copyright (C) 2019 HUAWEI, Inc. * Copyright (C) 2019 HUAWEI, Inc.
* https://www.huawei.com/ * https://www.huawei.com/
* Copyright (C) 2024 Alibaba Cloud
*/ */
#include "compress.h" #include "compress.h"
#include <linux/lz4.h> #include <linux/lz4.h>
...@@ -383,6 +384,8 @@ const struct z_erofs_decompressor *z_erofs_decomp[] = { ...@@ -383,6 +384,8 @@ const struct z_erofs_decompressor *z_erofs_decomp[] = {
[Z_EROFS_COMPRESSION_LZ4] = &(const struct z_erofs_decompressor) { [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,
.init = z_erofs_gbuf_init,
.exit = z_erofs_gbuf_exit,
.name = "lz4" .name = "lz4"
}, },
#ifdef CONFIG_EROFS_FS_ZIP_LZMA #ifdef CONFIG_EROFS_FS_ZIP_LZMA
...@@ -446,3 +449,28 @@ int z_erofs_parse_cfgs(struct super_block *sb, struct erofs_super_block *dsb) ...@@ -446,3 +449,28 @@ int z_erofs_parse_cfgs(struct super_block *sb, struct erofs_super_block *dsb)
erofs_put_metabuf(&buf); erofs_put_metabuf(&buf);
return ret; return ret;
} }
int __init z_erofs_init_decompressor(void)
{
int i, err;
for (i = 0; i < Z_EROFS_COMPRESSION_MAX; ++i) {
err = z_erofs_decomp[i] ? z_erofs_decomp[i]->init() : 0;
if (err) {
while (--i)
if (z_erofs_decomp[i])
z_erofs_decomp[i]->exit();
return err;
}
}
return 0;
}
void z_erofs_exit_decompressor(void)
{
int i;
for (i = 0; i < Z_EROFS_COMPRESSION_MAX; ++i)
if (z_erofs_decomp[i])
z_erofs_decomp[i]->exit();
}
...@@ -15,7 +15,7 @@ static DECLARE_WAIT_QUEUE_HEAD(z_erofs_deflate_wq); ...@@ -15,7 +15,7 @@ static DECLARE_WAIT_QUEUE_HEAD(z_erofs_deflate_wq);
module_param_named(deflate_streams, z_erofs_deflate_nstrms, uint, 0444); module_param_named(deflate_streams, z_erofs_deflate_nstrms, uint, 0444);
void z_erofs_deflate_exit(void) static void z_erofs_deflate_exit(void)
{ {
/* there should be no running fs instance */ /* there should be no running fs instance */
while (z_erofs_deflate_avail_strms) { while (z_erofs_deflate_avail_strms) {
...@@ -41,7 +41,7 @@ void z_erofs_deflate_exit(void) ...@@ -41,7 +41,7 @@ void z_erofs_deflate_exit(void)
} }
} }
int __init z_erofs_deflate_init(void) static int __init z_erofs_deflate_init(void)
{ {
/* by default, use # of possible CPUs instead */ /* by default, use # of possible CPUs instead */
if (!z_erofs_deflate_nstrms) if (!z_erofs_deflate_nstrms)
...@@ -256,5 +256,7 @@ static int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq, ...@@ -256,5 +256,7 @@ static int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,
const struct z_erofs_decompressor z_erofs_deflate_decomp = { const struct z_erofs_decompressor z_erofs_deflate_decomp = {
.config = z_erofs_load_deflate_config, .config = z_erofs_load_deflate_config,
.decompress = z_erofs_deflate_decompress, .decompress = z_erofs_deflate_decompress,
.init = z_erofs_deflate_init,
.exit = z_erofs_deflate_exit,
.name = "deflate", .name = "deflate",
}; };
...@@ -18,7 +18,7 @@ static DECLARE_WAIT_QUEUE_HEAD(z_erofs_lzma_wq); ...@@ -18,7 +18,7 @@ static DECLARE_WAIT_QUEUE_HEAD(z_erofs_lzma_wq);
module_param_named(lzma_streams, z_erofs_lzma_nstrms, uint, 0444); module_param_named(lzma_streams, z_erofs_lzma_nstrms, uint, 0444);
void z_erofs_lzma_exit(void) static void z_erofs_lzma_exit(void)
{ {
/* there should be no running fs instance */ /* there should be no running fs instance */
while (z_erofs_lzma_avail_strms) { while (z_erofs_lzma_avail_strms) {
...@@ -46,7 +46,7 @@ void z_erofs_lzma_exit(void) ...@@ -46,7 +46,7 @@ void z_erofs_lzma_exit(void)
} }
} }
int __init z_erofs_lzma_init(void) static int __init z_erofs_lzma_init(void)
{ {
unsigned int i; unsigned int i;
...@@ -297,5 +297,7 @@ static int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq, ...@@ -297,5 +297,7 @@ static int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq,
const struct z_erofs_decompressor z_erofs_lzma_decomp = { const struct z_erofs_decompressor z_erofs_lzma_decomp = {
.config = z_erofs_load_lzma_config, .config = z_erofs_load_lzma_config,
.decompress = z_erofs_lzma_decompress, .decompress = z_erofs_lzma_decompress,
.init = z_erofs_lzma_init,
.exit = z_erofs_lzma_exit,
.name = "lzma" .name = "lzma"
}; };
...@@ -34,7 +34,7 @@ static struct z_erofs_zstd *z_erofs_isolate_strms(bool all) ...@@ -34,7 +34,7 @@ static struct z_erofs_zstd *z_erofs_isolate_strms(bool all)
return strm; return strm;
} }
void z_erofs_zstd_exit(void) static void z_erofs_zstd_exit(void)
{ {
while (z_erofs_zstd_avail_strms) { while (z_erofs_zstd_avail_strms) {
struct z_erofs_zstd *strm, *n; struct z_erofs_zstd *strm, *n;
...@@ -49,7 +49,7 @@ void z_erofs_zstd_exit(void) ...@@ -49,7 +49,7 @@ void z_erofs_zstd_exit(void)
} }
} }
int __init z_erofs_zstd_init(void) static int __init z_erofs_zstd_init(void)
{ {
/* by default, use # of possible CPUs instead */ /* by default, use # of possible CPUs instead */
if (!z_erofs_zstd_nstrms) if (!z_erofs_zstd_nstrms)
...@@ -281,5 +281,7 @@ static int z_erofs_zstd_decompress(struct z_erofs_decompress_req *rq, ...@@ -281,5 +281,7 @@ static int z_erofs_zstd_decompress(struct z_erofs_decompress_req *rq,
const struct z_erofs_decompressor z_erofs_zstd_decomp = { const struct z_erofs_decompressor z_erofs_zstd_decomp = {
.config = z_erofs_load_zstd_config, .config = z_erofs_load_zstd_config,
.decompress = z_erofs_zstd_decompress, .decompress = z_erofs_zstd_decompress,
.init = z_erofs_zstd_init,
.exit = z_erofs_zstd_exit,
.name = "zstd", .name = "zstd",
}; };
...@@ -454,8 +454,8 @@ void erofs_shrinker_register(struct super_block *sb); ...@@ -454,8 +454,8 @@ void erofs_shrinker_register(struct super_block *sb);
void erofs_shrinker_unregister(struct super_block *sb); void erofs_shrinker_unregister(struct super_block *sb);
int __init erofs_init_shrinker(void); int __init erofs_init_shrinker(void);
void erofs_exit_shrinker(void); void erofs_exit_shrinker(void);
int __init z_erofs_init_zip_subsystem(void); int __init z_erofs_init_subsystem(void);
void z_erofs_exit_zip_subsystem(void); void z_erofs_exit_subsystem(void);
int erofs_try_to_free_all_cached_folios(struct erofs_sb_info *sbi, int erofs_try_to_free_all_cached_folios(struct erofs_sb_info *sbi,
struct erofs_workgroup *egrp); struct erofs_workgroup *egrp);
int z_erofs_map_blocks_iter(struct inode *inode, struct erofs_map_blocks *map, int z_erofs_map_blocks_iter(struct inode *inode, struct erofs_map_blocks *map,
...@@ -472,37 +472,11 @@ static inline void erofs_shrinker_register(struct super_block *sb) {} ...@@ -472,37 +472,11 @@ static inline void erofs_shrinker_register(struct super_block *sb) {}
static inline void erofs_shrinker_unregister(struct super_block *sb) {} static inline void erofs_shrinker_unregister(struct super_block *sb) {}
static inline int erofs_init_shrinker(void) { return 0; } static inline int erofs_init_shrinker(void) { return 0; }
static inline void erofs_exit_shrinker(void) {} static inline void erofs_exit_shrinker(void) {}
static inline int z_erofs_init_zip_subsystem(void) { return 0; } static inline int z_erofs_init_subsystem(void) { return 0; }
static inline void z_erofs_exit_zip_subsystem(void) {} static inline void z_erofs_exit_subsystem(void) {}
static inline int z_erofs_gbuf_init(void) { return 0; }
static inline void z_erofs_gbuf_exit(void) {}
static inline int erofs_init_managed_cache(struct super_block *sb) { return 0; } static inline int erofs_init_managed_cache(struct super_block *sb) { return 0; }
#endif /* !CONFIG_EROFS_FS_ZIP */ #endif /* !CONFIG_EROFS_FS_ZIP */
#ifdef CONFIG_EROFS_FS_ZIP_LZMA
int __init z_erofs_lzma_init(void);
void z_erofs_lzma_exit(void);
#else
static inline int z_erofs_lzma_init(void) { return 0; }
static inline int z_erofs_lzma_exit(void) { 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);
#else
static inline int z_erofs_deflate_init(void) { return 0; }
static inline int z_erofs_deflate_exit(void) { return 0; }
#endif /* !CONFIG_EROFS_FS_ZIP_DEFLATE */
#ifdef CONFIG_EROFS_FS_ZIP_ZSTD
int __init z_erofs_zstd_init(void);
void z_erofs_zstd_exit(void);
#else
static inline int z_erofs_zstd_init(void) { return 0; }
static inline int z_erofs_zstd_exit(void) { return 0; }
#endif /* !CONFIG_EROFS_FS_ZIP_ZSTD */
#ifdef CONFIG_EROFS_FS_ONDEMAND #ifdef CONFIG_EROFS_FS_ONDEMAND
int erofs_fscache_register_fs(struct super_block *sb); int erofs_fscache_register_fs(struct super_block *sb);
void erofs_fscache_unregister_fs(struct super_block *sb); void erofs_fscache_unregister_fs(struct super_block *sb);
......
...@@ -849,23 +849,7 @@ static int __init erofs_module_init(void) ...@@ -849,23 +849,7 @@ static int __init erofs_module_init(void)
if (err) if (err)
goto shrinker_err; goto shrinker_err;
err = z_erofs_lzma_init(); err = z_erofs_init_subsystem();
if (err)
goto lzma_err;
err = z_erofs_deflate_init();
if (err)
goto deflate_err;
err = z_erofs_zstd_init();
if (err)
goto zstd_err;
err = z_erofs_gbuf_init();
if (err)
goto gbuf_err;
err = z_erofs_init_zip_subsystem();
if (err) if (err)
goto zip_err; goto zip_err;
...@@ -882,16 +866,8 @@ static int __init erofs_module_init(void) ...@@ -882,16 +866,8 @@ static int __init erofs_module_init(void)
fs_err: fs_err:
erofs_exit_sysfs(); erofs_exit_sysfs();
sysfs_err: sysfs_err:
z_erofs_exit_zip_subsystem(); z_erofs_exit_subsystem();
zip_err: zip_err:
z_erofs_gbuf_exit();
gbuf_err:
z_erofs_zstd_exit();
zstd_err:
z_erofs_deflate_exit();
deflate_err:
z_erofs_lzma_exit();
lzma_err:
erofs_exit_shrinker(); erofs_exit_shrinker();
shrinker_err: shrinker_err:
kmem_cache_destroy(erofs_inode_cachep); kmem_cache_destroy(erofs_inode_cachep);
...@@ -906,13 +882,9 @@ static void __exit erofs_module_exit(void) ...@@ -906,13 +882,9 @@ static void __exit erofs_module_exit(void)
rcu_barrier(); rcu_barrier();
erofs_exit_sysfs(); erofs_exit_sysfs();
z_erofs_exit_zip_subsystem(); z_erofs_exit_subsystem();
z_erofs_zstd_exit();
z_erofs_deflate_exit();
z_erofs_lzma_exit();
erofs_exit_shrinker(); erofs_exit_shrinker();
kmem_cache_destroy(erofs_inode_cachep); kmem_cache_destroy(erofs_inode_cachep);
z_erofs_gbuf_exit();
} }
static int erofs_statfs(struct dentry *dentry, struct kstatfs *buf) static int erofs_statfs(struct dentry *dentry, struct kstatfs *buf)
......
...@@ -446,44 +446,51 @@ static inline int erofs_cpu_hotplug_init(void) { return 0; } ...@@ -446,44 +446,51 @@ static inline int erofs_cpu_hotplug_init(void) { return 0; }
static inline void erofs_cpu_hotplug_destroy(void) {} static inline void erofs_cpu_hotplug_destroy(void) {}
#endif #endif
void z_erofs_exit_zip_subsystem(void) void z_erofs_exit_subsystem(void)
{ {
erofs_cpu_hotplug_destroy(); erofs_cpu_hotplug_destroy();
erofs_destroy_percpu_workers(); erofs_destroy_percpu_workers();
destroy_workqueue(z_erofs_workqueue); destroy_workqueue(z_erofs_workqueue);
z_erofs_destroy_pcluster_pool(); z_erofs_destroy_pcluster_pool();
z_erofs_exit_decompressor();
} }
int __init z_erofs_init_zip_subsystem(void) int __init z_erofs_init_subsystem(void)
{ {
int err = z_erofs_create_pcluster_pool(); int err = z_erofs_init_decompressor();
if (err) if (err)
goto out_error_pcluster_pool; goto err_decompressor;
err = z_erofs_create_pcluster_pool();
if (err)
goto err_pcluster_pool;
z_erofs_workqueue = alloc_workqueue("erofs_worker", z_erofs_workqueue = alloc_workqueue("erofs_worker",
WQ_UNBOUND | WQ_HIGHPRI, num_possible_cpus()); WQ_UNBOUND | WQ_HIGHPRI, num_possible_cpus());
if (!z_erofs_workqueue) { if (!z_erofs_workqueue) {
err = -ENOMEM; err = -ENOMEM;
goto out_error_workqueue_init; goto err_workqueue_init;
} }
err = erofs_init_percpu_workers(); err = erofs_init_percpu_workers();
if (err) if (err)
goto out_error_pcpu_worker; goto err_pcpu_worker;
err = erofs_cpu_hotplug_init(); err = erofs_cpu_hotplug_init();
if (err < 0) if (err < 0)
goto out_error_cpuhp_init; goto err_cpuhp_init;
return err; return err;
out_error_cpuhp_init: err_cpuhp_init:
erofs_destroy_percpu_workers(); erofs_destroy_percpu_workers();
out_error_pcpu_worker: err_pcpu_worker:
destroy_workqueue(z_erofs_workqueue); destroy_workqueue(z_erofs_workqueue);
out_error_workqueue_init: err_workqueue_init:
z_erofs_destroy_pcluster_pool(); z_erofs_destroy_pcluster_pool();
out_error_pcluster_pool: err_pcluster_pool:
z_erofs_exit_decompressor();
err_decompressor:
return err; return err;
} }
......
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