Skip to content

Commit 5a7cce8

Browse files
committed
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: Gao Xiang <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 392d20c commit 5a7cce8

File tree

8 files changed

+69
-78
lines changed

8 files changed

+69
-78
lines changed

fs/erofs/compress.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ struct z_erofs_decompressor {
2424
void *data, int size);
2525
int (*decompress)(struct z_erofs_decompress_req *rq,
2626
struct page **pagepool);
27+
int (*init)(void);
28+
void (*exit)(void);
2729
char *name;
2830
};
2931

@@ -88,4 +90,6 @@ extern const struct z_erofs_decompressor *z_erofs_decomp[];
8890

8991
int z_erofs_fixup_insize(struct z_erofs_decompress_req *rq, const char *padbuf,
9092
unsigned int padbufsize);
93+
int __init z_erofs_init_decompressor(void);
94+
void z_erofs_exit_decompressor(void);
9195
#endif

fs/erofs/decompressor.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/*
33
* Copyright (C) 2019 HUAWEI, Inc.
44
* https://www.huawei.com/
5+
* Copyright (C) 2024 Alibaba Cloud
56
*/
67
#include "compress.h"
78
#include <linux/lz4.h>
@@ -383,6 +384,8 @@ const struct z_erofs_decompressor *z_erofs_decomp[] = {
383384
[Z_EROFS_COMPRESSION_LZ4] = &(const struct z_erofs_decompressor) {
384385
.config = z_erofs_load_lz4_config,
385386
.decompress = z_erofs_lz4_decompress,
387+
.init = z_erofs_gbuf_init,
388+
.exit = z_erofs_gbuf_exit,
386389
.name = "lz4"
387390
},
388391
#ifdef CONFIG_EROFS_FS_ZIP_LZMA
@@ -446,3 +449,28 @@ int z_erofs_parse_cfgs(struct super_block *sb, struct erofs_super_block *dsb)
446449
erofs_put_metabuf(&buf);
447450
return ret;
448451
}
452+
453+
int __init z_erofs_init_decompressor(void)
454+
{
455+
int i, err;
456+
457+
for (i = 0; i < Z_EROFS_COMPRESSION_MAX; ++i) {
458+
err = z_erofs_decomp[i] ? z_erofs_decomp[i]->init() : 0;
459+
if (err) {
460+
while (--i)
461+
if (z_erofs_decomp[i])
462+
z_erofs_decomp[i]->exit();
463+
return err;
464+
}
465+
}
466+
return 0;
467+
}
468+
469+
void z_erofs_exit_decompressor(void)
470+
{
471+
int i;
472+
473+
for (i = 0; i < Z_EROFS_COMPRESSION_MAX; ++i)
474+
if (z_erofs_decomp[i])
475+
z_erofs_decomp[i]->exit();
476+
}

fs/erofs/decompressor_deflate.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ static DECLARE_WAIT_QUEUE_HEAD(z_erofs_deflate_wq);
1515

1616
module_param_named(deflate_streams, z_erofs_deflate_nstrms, uint, 0444);
1717

18-
void z_erofs_deflate_exit(void)
18+
static void z_erofs_deflate_exit(void)
1919
{
2020
/* there should be no running fs instance */
2121
while (z_erofs_deflate_avail_strms) {
@@ -41,7 +41,7 @@ void z_erofs_deflate_exit(void)
4141
}
4242
}
4343

44-
int __init z_erofs_deflate_init(void)
44+
static int __init z_erofs_deflate_init(void)
4545
{
4646
/* by default, use # of possible CPUs instead */
4747
if (!z_erofs_deflate_nstrms)
@@ -256,5 +256,7 @@ static int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,
256256
const struct z_erofs_decompressor z_erofs_deflate_decomp = {
257257
.config = z_erofs_load_deflate_config,
258258
.decompress = z_erofs_deflate_decompress,
259+
.init = z_erofs_deflate_init,
260+
.exit = z_erofs_deflate_exit,
259261
.name = "deflate",
260262
};

fs/erofs/decompressor_lzma.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static DECLARE_WAIT_QUEUE_HEAD(z_erofs_lzma_wq);
1818

1919
module_param_named(lzma_streams, z_erofs_lzma_nstrms, uint, 0444);
2020

21-
void z_erofs_lzma_exit(void)
21+
static void z_erofs_lzma_exit(void)
2222
{
2323
/* there should be no running fs instance */
2424
while (z_erofs_lzma_avail_strms) {
@@ -46,7 +46,7 @@ void z_erofs_lzma_exit(void)
4646
}
4747
}
4848

49-
int __init z_erofs_lzma_init(void)
49+
static int __init z_erofs_lzma_init(void)
5050
{
5151
unsigned int i;
5252

@@ -297,5 +297,7 @@ static int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq,
297297
const struct z_erofs_decompressor z_erofs_lzma_decomp = {
298298
.config = z_erofs_load_lzma_config,
299299
.decompress = z_erofs_lzma_decompress,
300+
.init = z_erofs_lzma_init,
301+
.exit = z_erofs_lzma_exit,
300302
.name = "lzma"
301303
};

fs/erofs/decompressor_zstd.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static struct z_erofs_zstd *z_erofs_isolate_strms(bool all)
3434
return strm;
3535
}
3636

37-
void z_erofs_zstd_exit(void)
37+
static void z_erofs_zstd_exit(void)
3838
{
3939
while (z_erofs_zstd_avail_strms) {
4040
struct z_erofs_zstd *strm, *n;
@@ -49,7 +49,7 @@ void z_erofs_zstd_exit(void)
4949
}
5050
}
5151

52-
int __init z_erofs_zstd_init(void)
52+
static int __init z_erofs_zstd_init(void)
5353
{
5454
/* by default, use # of possible CPUs instead */
5555
if (!z_erofs_zstd_nstrms)
@@ -281,5 +281,7 @@ static int z_erofs_zstd_decompress(struct z_erofs_decompress_req *rq,
281281
const struct z_erofs_decompressor z_erofs_zstd_decomp = {
282282
.config = z_erofs_load_zstd_config,
283283
.decompress = z_erofs_zstd_decompress,
284+
.init = z_erofs_zstd_init,
285+
.exit = z_erofs_zstd_exit,
284286
.name = "zstd",
285287
};

fs/erofs/internal.h

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,8 @@ void erofs_shrinker_register(struct super_block *sb);
454454
void erofs_shrinker_unregister(struct super_block *sb);
455455
int __init erofs_init_shrinker(void);
456456
void erofs_exit_shrinker(void);
457-
int __init z_erofs_init_zip_subsystem(void);
458-
void z_erofs_exit_zip_subsystem(void);
457+
int __init z_erofs_init_subsystem(void);
458+
void z_erofs_exit_subsystem(void);
459459
int erofs_try_to_free_all_cached_folios(struct erofs_sb_info *sbi,
460460
struct erofs_workgroup *egrp);
461461
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) {}
472472
static inline void erofs_shrinker_unregister(struct super_block *sb) {}
473473
static inline int erofs_init_shrinker(void) { return 0; }
474474
static inline void erofs_exit_shrinker(void) {}
475-
static inline int z_erofs_init_zip_subsystem(void) { return 0; }
476-
static inline void z_erofs_exit_zip_subsystem(void) {}
477-
static inline int z_erofs_gbuf_init(void) { return 0; }
478-
static inline void z_erofs_gbuf_exit(void) {}
475+
static inline int z_erofs_init_subsystem(void) { return 0; }
476+
static inline void z_erofs_exit_subsystem(void) {}
479477
static inline int erofs_init_managed_cache(struct super_block *sb) { return 0; }
480478
#endif /* !CONFIG_EROFS_FS_ZIP */
481479

482-
#ifdef CONFIG_EROFS_FS_ZIP_LZMA
483-
int __init z_erofs_lzma_init(void);
484-
void z_erofs_lzma_exit(void);
485-
#else
486-
static inline int z_erofs_lzma_init(void) { return 0; }
487-
static inline int z_erofs_lzma_exit(void) { return 0; }
488-
#endif /* !CONFIG_EROFS_FS_ZIP_LZMA */
489-
490-
#ifdef CONFIG_EROFS_FS_ZIP_DEFLATE
491-
int __init z_erofs_deflate_init(void);
492-
void z_erofs_deflate_exit(void);
493-
#else
494-
static inline int z_erofs_deflate_init(void) { return 0; }
495-
static inline int z_erofs_deflate_exit(void) { return 0; }
496-
#endif /* !CONFIG_EROFS_FS_ZIP_DEFLATE */
497-
498-
#ifdef CONFIG_EROFS_FS_ZIP_ZSTD
499-
int __init z_erofs_zstd_init(void);
500-
void z_erofs_zstd_exit(void);
501-
#else
502-
static inline int z_erofs_zstd_init(void) { return 0; }
503-
static inline int z_erofs_zstd_exit(void) { return 0; }
504-
#endif /* !CONFIG_EROFS_FS_ZIP_ZSTD */
505-
506480
#ifdef CONFIG_EROFS_FS_ONDEMAND
507481
int erofs_fscache_register_fs(struct super_block *sb);
508482
void erofs_fscache_unregister_fs(struct super_block *sb);

fs/erofs/super.c

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -849,23 +849,7 @@ static int __init erofs_module_init(void)
849849
if (err)
850850
goto shrinker_err;
851851

852-
err = z_erofs_lzma_init();
853-
if (err)
854-
goto lzma_err;
855-
856-
err = z_erofs_deflate_init();
857-
if (err)
858-
goto deflate_err;
859-
860-
err = z_erofs_zstd_init();
861-
if (err)
862-
goto zstd_err;
863-
864-
err = z_erofs_gbuf_init();
865-
if (err)
866-
goto gbuf_err;
867-
868-
err = z_erofs_init_zip_subsystem();
852+
err = z_erofs_init_subsystem();
869853
if (err)
870854
goto zip_err;
871855

@@ -882,16 +866,8 @@ static int __init erofs_module_init(void)
882866
fs_err:
883867
erofs_exit_sysfs();
884868
sysfs_err:
885-
z_erofs_exit_zip_subsystem();
869+
z_erofs_exit_subsystem();
886870
zip_err:
887-
z_erofs_gbuf_exit();
888-
gbuf_err:
889-
z_erofs_zstd_exit();
890-
zstd_err:
891-
z_erofs_deflate_exit();
892-
deflate_err:
893-
z_erofs_lzma_exit();
894-
lzma_err:
895871
erofs_exit_shrinker();
896872
shrinker_err:
897873
kmem_cache_destroy(erofs_inode_cachep);
@@ -906,13 +882,9 @@ static void __exit erofs_module_exit(void)
906882
rcu_barrier();
907883

908884
erofs_exit_sysfs();
909-
z_erofs_exit_zip_subsystem();
910-
z_erofs_zstd_exit();
911-
z_erofs_deflate_exit();
912-
z_erofs_lzma_exit();
885+
z_erofs_exit_subsystem();
913886
erofs_exit_shrinker();
914887
kmem_cache_destroy(erofs_inode_cachep);
915-
z_erofs_gbuf_exit();
916888
}
917889

918890
static int erofs_statfs(struct dentry *dentry, struct kstatfs *buf)

fs/erofs/zdata.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -446,44 +446,51 @@ static inline int erofs_cpu_hotplug_init(void) { return 0; }
446446
static inline void erofs_cpu_hotplug_destroy(void) {}
447447
#endif
448448

449-
void z_erofs_exit_zip_subsystem(void)
449+
void z_erofs_exit_subsystem(void)
450450
{
451451
erofs_cpu_hotplug_destroy();
452452
erofs_destroy_percpu_workers();
453453
destroy_workqueue(z_erofs_workqueue);
454454
z_erofs_destroy_pcluster_pool();
455+
z_erofs_exit_decompressor();
455456
}
456457

457-
int __init z_erofs_init_zip_subsystem(void)
458+
int __init z_erofs_init_subsystem(void)
458459
{
459-
int err = z_erofs_create_pcluster_pool();
460+
int err = z_erofs_init_decompressor();
460461

461462
if (err)
462-
goto out_error_pcluster_pool;
463+
goto err_decompressor;
464+
465+
err = z_erofs_create_pcluster_pool();
466+
if (err)
467+
goto err_pcluster_pool;
463468

464469
z_erofs_workqueue = alloc_workqueue("erofs_worker",
465470
WQ_UNBOUND | WQ_HIGHPRI, num_possible_cpus());
466471
if (!z_erofs_workqueue) {
467472
err = -ENOMEM;
468-
goto out_error_workqueue_init;
473+
goto err_workqueue_init;
469474
}
470475

471476
err = erofs_init_percpu_workers();
472477
if (err)
473-
goto out_error_pcpu_worker;
478+
goto err_pcpu_worker;
474479

475480
err = erofs_cpu_hotplug_init();
476481
if (err < 0)
477-
goto out_error_cpuhp_init;
482+
goto err_cpuhp_init;
478483
return err;
479484

480-
out_error_cpuhp_init:
485+
err_cpuhp_init:
481486
erofs_destroy_percpu_workers();
482-
out_error_pcpu_worker:
487+
err_pcpu_worker:
483488
destroy_workqueue(z_erofs_workqueue);
484-
out_error_workqueue_init:
489+
err_workqueue_init:
485490
z_erofs_destroy_pcluster_pool();
486-
out_error_pcluster_pool:
491+
err_pcluster_pool:
492+
z_erofs_exit_decompressor();
493+
err_decompressor:
487494
return err;
488495
}
489496

0 commit comments

Comments
 (0)