Linux-EROFS Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] erofs-utils: code-refactoring for erofs compressor
@ 2023-06-09  8:50 Guo Xuenan via Linux-erofs
  2023-06-09  8:50 ` [PATCH 1/4] erofs-utils: lib: refactor erofs compressors init Guo Xuenan via Linux-erofs
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Guo Xuenan via Linux-erofs @ 2023-06-09  8:50 UTC (permalink / raw)
  To: hsiangkao, jefflexu, linux-erofs; +Cc: jack.qiu

simplify and unify erofs compressor code.

Guo Xuenan (4):
  erofs-utils: lib: refactor erofs compressors init
  erofs-utils: lib: unify all identical compressor print function
  erofs-utils: simplify erofs compressor init and exit
  erofs-utils: dump: add some superblock fields

 dump/main.c              |  11 +++
 fsck/main.c              |  15 +---
 include/erofs/compress.h |   4 +-
 include/erofs/internal.h |   1 +
 lib/compress.c           |  81 +++++++------------
 lib/compressor.c         | 169 +++++++++++++++++++++++++++++----------
 lib/compressor.h         |  24 ++++--
 lib/compressor_liblzma.c |   8 +-
 lib/compressor_lz4.c     |   8 +-
 lib/compressor_lz4hc.c   |   9 ++-
 lib/super.c              |   5 ++
 mkfs/main.c              |  16 +---
 12 files changed, 213 insertions(+), 138 deletions(-)

-- 
2.31.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/4] erofs-utils: lib: refactor erofs compressors init
  2023-06-09  8:50 [PATCH 0/4] erofs-utils: code-refactoring for erofs compressor Guo Xuenan via Linux-erofs
@ 2023-06-09  8:50 ` Guo Xuenan via Linux-erofs
  2023-06-09  9:38   ` Gao Xiang
  2023-06-09  8:50 ` [PATCH 2/4] erofs-utils: lib: unify all identical compressor print function Guo Xuenan via Linux-erofs
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: Guo Xuenan via Linux-erofs @ 2023-06-09  8:50 UTC (permalink / raw)
  To: hsiangkao, jefflexu, linux-erofs; +Cc: jack.qiu

refactor compressor code using constructor.

Signed-off-by: Guo Xuenan <guoxuenan@huawei.com>
---
 lib/compressor.c         | 49 ++++++++++++++++++++++++++++++++++++++++
 lib/compressor.h         | 15 ++++++++++++
 lib/compressor_liblzma.c |  5 ++++
 lib/compressor_lz4.c     |  5 ++++
 lib/compressor_lz4hc.c   |  5 ++++
 5 files changed, 79 insertions(+)

diff --git a/lib/compressor.c b/lib/compressor.c
index 52eb761..0fa7105 100644
--- a/lib/compressor.c
+++ b/lib/compressor.c
@@ -22,6 +22,40 @@ static const struct erofs_compressor *compressors[] = {
 #endif
 };
 
+/* compressing configuration specified by users */
+static struct erofs_supported_algothrim {
+	int algtype;
+	const char *name;
+} erofs_supported_algothrims[] = {
+	{ Z_EROFS_COMPRESSION_LZ4, "lz4"},
+	{ Z_EROFS_COMPRESSION_LZ4, "lz4hc"},
+	{ Z_EROFS_COMPRESSION_LZMA, "lzma"},
+};
+
+static struct erofs_compressors_cfg erofs_ccfg;
+
+int erofs_compressor_num(void)
+{
+	return erofs_ccfg.erofs_ccfg_num;
+}
+
+void erofs_compressor_register(const char *name, const struct erofs_compressor *alg)
+{
+	int i;
+
+	for (i = 0; i < erofs_compressor_num(); i++) {
+		if (!strcmp(erofs_ccfg.compressors[i].name, name)) {
+			erofs_ccfg.compressors[i].handle.alg = alg;
+			return;
+		}
+	}
+
+	erofs_ccfg.compressors[i].name = name;
+	erofs_ccfg.compressors[i].handle.alg = alg;
+	erofs_ccfg.compressors[i].algorithmtype = erofs_supported_algothrims[i].algtype;
+	erofs_ccfg.erofs_ccfg_num = ++i;
+}
+
 int erofs_compress_destsize(const struct erofs_compress *c,
 			    const void *src, unsigned int *srcsize,
 			    void *dst, unsigned int dstsize, bool inblocks)
@@ -106,3 +140,18 @@ int erofs_compressor_exit(struct erofs_compress *c)
 		return c->alg->exit(c);
 	return 0;
 }
+
+void __attribute__((constructor(101))) __erofs_compressor_init(void)
+{
+	int i;
+
+	erofs_ccfg.erofs_ccfg_num = 0;
+	for (i = 0; i < ARRAY_SIZE(erofs_supported_algothrims); i++) {
+		erofs_compressor_register(erofs_supported_algothrims[i].name, NULL);
+	}
+}
+
+void __attribute__((destructor)) __erofs_compressor_exit(void)
+{
+	erofs_err("__erofs_compressor_exit");
+}
diff --git a/lib/compressor.h b/lib/compressor.h
index cf063f1..3c1b328 100644
--- a/lib/compressor.h
+++ b/lib/compressor.h
@@ -8,6 +8,7 @@
 #define __EROFS_LIB_COMPRESSOR_H
 
 #include "erofs/defs.h"
+#include "erofs/config.h"
 
 struct erofs_compress;
 
@@ -40,6 +41,18 @@ struct erofs_compress {
 	void *private_data;
 };
 
+struct compressor {
+	const char *name;
+	struct erofs_compress handle;
+	unsigned int algorithmtype;
+	bool enable;
+};
+
+struct erofs_compressors_cfg {
+	struct compressor compressors[EROFS_MAX_COMPR_CFGS];
+	int erofs_ccfg_num;
+};
+
 /* list of compression algorithms */
 extern const struct erofs_compressor erofs_compressor_lz4;
 extern const struct erofs_compressor erofs_compressor_lz4hc;
@@ -53,4 +66,6 @@ int erofs_compressor_setlevel(struct erofs_compress *c, int compression_level);
 int erofs_compressor_init(struct erofs_compress *c, char *alg_name);
 int erofs_compressor_exit(struct erofs_compress *c);
 
+void erofs_compressor_register(const char *name, const struct erofs_compressor *alg);
+int erofs_compressor_num(void);
 #endif
diff --git a/lib/compressor_liblzma.c b/lib/compressor_liblzma.c
index f274dce..b24139c 100644
--- a/lib/compressor_liblzma.c
+++ b/lib/compressor_liblzma.c
@@ -108,4 +108,9 @@ const struct erofs_compressor erofs_compressor_lzma = {
 	.setlevel = erofs_compressor_liblzma_setlevel,
 	.compress_destsize = erofs_liblzma_compress_destsize,
 };
+
+static void __attribute__((constructor)) register_lzma_compressor(void)
+{
+	erofs_compressor_register("lzma", &erofs_compressor_lzma);
+}
 #endif
diff --git a/lib/compressor_lz4.c b/lib/compressor_lz4.c
index b6f6e7e..a8adffe 100644
--- a/lib/compressor_lz4.c
+++ b/lib/compressor_lz4.c
@@ -45,3 +45,8 @@ const struct erofs_compressor erofs_compressor_lz4 = {
 	.exit = compressor_lz4_exit,
 	.compress_destsize = lz4_compress_destsize,
 };
+
+static void __attribute__((constructor)) register_lz4_compressor(void)
+{
+	erofs_compressor_register("lz4", &erofs_compressor_lz4);
+}
diff --git a/lib/compressor_lz4hc.c b/lib/compressor_lz4hc.c
index eec1c84..2b7e900 100644
--- a/lib/compressor_lz4hc.c
+++ b/lib/compressor_lz4hc.c
@@ -68,3 +68,8 @@ const struct erofs_compressor erofs_compressor_lz4hc = {
 	.setlevel = compressor_lz4hc_setlevel,
 	.compress_destsize = lz4hc_compress_destsize,
 };
+
+static void __attribute__((constructor)) register_lz4hc_compressor(void)
+{
+	erofs_compressor_register("lz4hc", &erofs_compressor_lz4hc);
+}
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/4] erofs-utils: lib: unify all identical compressor print function
  2023-06-09  8:50 [PATCH 0/4] erofs-utils: code-refactoring for erofs compressor Guo Xuenan via Linux-erofs
  2023-06-09  8:50 ` [PATCH 1/4] erofs-utils: lib: refactor erofs compressors init Guo Xuenan via Linux-erofs
@ 2023-06-09  8:50 ` Guo Xuenan via Linux-erofs
  2023-06-09  9:39   ` Gao Xiang
  2023-06-09  8:50 ` [PATCH 3/4] erofs-utils: simplify erofs compressor init and exit Guo Xuenan via Linux-erofs
  2023-06-09  8:50 ` [PATCH 4/4] erofs-utils: dump: add some superblock fields Guo Xuenan via Linux-erofs
  3 siblings, 1 reply; 9+ messages in thread
From: Guo Xuenan via Linux-erofs @ 2023-06-09  8:50 UTC (permalink / raw)
  To: hsiangkao, jefflexu, linux-erofs; +Cc: jack.qiu

{dump,fsck}.erofs use the same compressor print function,
available_compressors means which algothrims are currently
supported by binary tools.
supported_compressors including all algothrims that are ready
for erofs.

Signed-off-by: Guo Xuenan <guoxuenan@huawei.com>
---
 fsck/main.c              | 15 +-----------
 include/erofs/compress.h |  3 ++-
 lib/compressor.c         | 51 ++++++++++++++++++++++++++--------------
 mkfs/main.c              | 15 +-----------
 4 files changed, 38 insertions(+), 46 deletions(-)

diff --git a/fsck/main.c b/fsck/main.c
index f816bec..978d198 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -49,19 +49,6 @@ static struct option long_options[] = {
 	{0, 0, 0, 0},
 };
 
-static void print_available_decompressors(FILE *f, const char *delim)
-{
-	unsigned int i = 0;
-	const char *s;
-
-	while ((s = z_erofs_list_available_compressors(i)) != NULL) {
-		if (i++)
-			fputs(delim, f);
-		fputs(s, f);
-	}
-	fputc('\n', f);
-}
-
 static void usage(void)
 {
 	fputs("usage: [options] IMAGE\n\n"
@@ -84,7 +71,7 @@ static void usage(void)
 	      " --no-preserve-owner    extract as yourself\n"
 	      " --no-preserve-perms    apply user's umask when extracting permissions\n"
 	      "\nSupported algorithms are: ", stderr);
-	print_available_decompressors(stderr, ", ");
+	zerofs_print_available_compressors(stderr);
 }
 
 static void erofsfsck_print_version(void)
diff --git a/include/erofs/compress.h b/include/erofs/compress.h
index 08af9e3..714f304 100644
--- a/include/erofs/compress.h
+++ b/include/erofs/compress.h
@@ -22,7 +22,8 @@ int erofs_write_compressed_file(struct erofs_inode *inode, int fd);
 int z_erofs_compress_init(struct erofs_buffer_head *bh);
 int z_erofs_compress_exit(void);
 
-const char *z_erofs_list_available_compressors(unsigned int i);
+void zerofs_print_available_compressors(FILE *f);
+void zerofs_print_supported_compressors(FILE *f, unsigned int mask);
 
 static inline bool erofs_is_packed_inode(struct erofs_inode *inode)
 {
diff --git a/lib/compressor.c b/lib/compressor.c
index 0fa7105..5aee4e0 100644
--- a/lib/compressor.c
+++ b/lib/compressor.c
@@ -10,18 +10,6 @@
 
 #define EROFS_CONFIG_COMPR_DEF_BOUNDARY		(128)
 
-static const struct erofs_compressor *compressors[] = {
-#if LZ4_ENABLED
-#if LZ4HC_ENABLED
-		&erofs_compressor_lz4hc,
-#endif
-		&erofs_compressor_lz4,
-#endif
-#if HAVE_LIBLZMA
-		&erofs_compressor_lzma,
-#endif
-};
-
 /* compressing configuration specified by users */
 static struct erofs_supported_algothrim {
 	int algtype;
@@ -85,9 +73,38 @@ int erofs_compress_destsize(const struct erofs_compress *c,
 	return ret;
 }
 
-const char *z_erofs_list_available_compressors(unsigned int i)
+void zerofs_print_supported_compressors(FILE *f, unsigned int mask)
+{
+	unsigned int i = 0;
+	int comma = false;
+	const char *s;
+
+	while (i < erofs_compressor_num()) {
+		s = erofs_ccfg.compressors[i].name;
+		if (s && (mask & (1 << erofs_ccfg.compressors[i++].algorithmtype))) {
+			if (comma)
+				fputs(", ", f);
+			else
+				comma = true;
+			fputs(s, f);
+		}
+	}
+	fputc('\n', f);
+}
+
+void zerofs_print_available_compressors(FILE *f)
 {
-	return i >= ARRAY_SIZE(compressors) ? NULL : compressors[i]->name;
+	unsigned int i = 0;
+	const char *s;
+
+	while (i < erofs_compressor_num() &&
+			erofs_ccfg.compressors[i].handle.alg &&
+			(s = erofs_ccfg.compressors[i].name)) {
+		if (i++)
+			fputs(", ", f);
+		fputs(s, f);
+	}
+	fputc('\n', f);
 }
 
 int erofs_compressor_setlevel(struct erofs_compress *c, int compression_level)
@@ -120,11 +137,11 @@ int erofs_compressor_init(struct erofs_compress *c, char *alg_name)
 	}
 
 	ret = -EINVAL;
-	for (i = 0; i < ARRAY_SIZE(compressors); ++i) {
-		if (alg_name && strcmp(alg_name, compressors[i]->name))
+	for (i = 0; i < erofs_compressor_num(); ++i) {
+		if (alg_name && strcmp(alg_name, erofs_ccfg.compressors[i].name))
 			continue;
 
-		ret = compressors[i]->init(c);
+		ret = erofs_ccfg.compressors[i].handle.alg->init(c);
 		if (!ret) {
 			DBG_BUGON(!c->alg);
 			return 0;
diff --git a/mkfs/main.c b/mkfs/main.c
index ac208e5..dbd168e 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -66,19 +66,6 @@ static struct option long_options[] = {
 	{0, 0, 0, 0},
 };
 
-static void print_available_compressors(FILE *f, const char *delim)
-{
-	unsigned int i = 0;
-	const char *s;
-
-	while ((s = z_erofs_list_available_compressors(i)) != NULL) {
-		if (i++)
-			fputs(delim, f);
-		fputs(s, f);
-	}
-	fputc('\n', f);
-}
-
 static void usage(void)
 {
 	fputs("usage: [options] FILE DIRECTORY\n\n"
@@ -126,7 +113,7 @@ static void usage(void)
 	      " --block-list-file=X   X=block_list file\n"
 #endif
 	      "\nAvailable compressors are: ", stderr);
-	print_available_compressors(stderr, ", ");
+	zerofs_print_available_compressors(stderr);
 }
 
 static unsigned int pclustersize_packed, pclustersize_max;
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/4] erofs-utils: simplify erofs compressor init and exit
  2023-06-09  8:50 [PATCH 0/4] erofs-utils: code-refactoring for erofs compressor Guo Xuenan via Linux-erofs
  2023-06-09  8:50 ` [PATCH 1/4] erofs-utils: lib: refactor erofs compressors init Guo Xuenan via Linux-erofs
  2023-06-09  8:50 ` [PATCH 2/4] erofs-utils: lib: unify all identical compressor print function Guo Xuenan via Linux-erofs
@ 2023-06-09  8:50 ` Guo Xuenan via Linux-erofs
  2023-06-09  8:50 ` [PATCH 4/4] erofs-utils: dump: add some superblock fields Guo Xuenan via Linux-erofs
  3 siblings, 0 replies; 9+ messages in thread
From: Guo Xuenan via Linux-erofs @ 2023-06-09  8:50 UTC (permalink / raw)
  To: hsiangkao, jefflexu, linux-erofs; +Cc: jack.qiu

since the compressor is independent in erofs-utils, rework the
compessor code using destructor and constructor, to make adding
a new algothrim easier.

Signed-off-by: Guo Xuenan <guoxuenan@huawei.com>
---
 include/erofs/compress.h |   1 -
 lib/compress.c           |  81 +++++++++++------------------
 lib/compressor.c         | 109 +++++++++++++++++++++++----------------
 lib/compressor.h         |   9 +---
 lib/compressor_liblzma.c |   3 +-
 lib/compressor_lz4.c     |   3 +-
 lib/compressor_lz4hc.c   |   4 +-
 mkfs/main.c              |   1 -
 8 files changed, 99 insertions(+), 112 deletions(-)

diff --git a/include/erofs/compress.h b/include/erofs/compress.h
index 714f304..81015b2 100644
--- a/include/erofs/compress.h
+++ b/include/erofs/compress.h
@@ -20,7 +20,6 @@ void z_erofs_drop_inline_pcluster(struct erofs_inode *inode);
 int erofs_write_compressed_file(struct erofs_inode *inode, int fd);
 
 int z_erofs_compress_init(struct erofs_buffer_head *bh);
-int z_erofs_compress_exit(void);
 
 void zerofs_print_available_compressors(FILE *f);
 void zerofs_print_supported_compressors(FILE *f, unsigned int mask);
diff --git a/lib/compress.c b/lib/compress.c
index 14d228f..567f11e 100644
--- a/lib/compress.c
+++ b/lib/compress.c
@@ -21,19 +21,12 @@
 #include "erofs/compress_hints.h"
 #include "erofs/fragments.h"
 
-/* compressing configuration specified by users */
-struct erofs_compress_cfg {
-	struct erofs_compress handle;
-	unsigned int algorithmtype;
-	bool enable;
-} erofs_ccfg[EROFS_MAX_COMPR_CFGS];
-
 struct z_erofs_vle_compress_ctx {
 	u8 queue[EROFS_CONFIG_COMPR_MAX_SZ * 2];
 	struct z_erofs_inmem_extent e;	/* (lookahead) extent */
 
 	struct erofs_inode *inode;
-	struct erofs_compress_cfg *ccfg;
+	struct compressor *compressor;
 
 	u8 *metacur;
 	unsigned int head, tail;
@@ -382,7 +375,7 @@ static int vle_compress_one(struct z_erofs_vle_compress_ctx *ctx)
 	static char dstbuf[EROFS_CONFIG_COMPR_MAX_SZ + EROFS_MAX_BLOCK_SIZE];
 	struct erofs_inode *inode = ctx->inode;
 	char *const dst = dstbuf + erofs_blksiz();
-	struct erofs_compress *const h = &ctx->ccfg->handle;
+	struct erofs_compress *const h = &ctx->compressor->handle;
 	unsigned int len = ctx->tail - ctx->head;
 	bool is_packed_inode = erofs_is_packed_inode(inode);
 	bool final = !ctx->remaining;
@@ -842,6 +835,7 @@ int erofs_write_compressed_file(struct erofs_inode *inode, int fd)
 	static struct z_erofs_vle_compress_ctx ctx;
 	erofs_blk_t blkaddr, compressed_blocks;
 	unsigned int legacymetasize;
+	int ccfg_idx;
 	int ret;
 	u8 *compressmeta = malloc(vle_compressmeta_capacity(inode->i_size));
 
@@ -874,18 +868,18 @@ int erofs_write_compressed_file(struct erofs_inode *inode, int fd)
 	if (cfg.c_fragments && !cfg.c_dedupe)
 		inode->z_advise |= Z_EROFS_ADVISE_INTERLACED_PCLUSTER;
 
+	ccfg_idx = erofs_get_compressor_by_name(cfg.c_compr_alg[0]);
 #ifndef NDEBUG
 	if (cfg.c_random_algorithms) {
 		while (1) {
-			inode->z_algorithmtype[0] =
-				rand() % EROFS_MAX_COMPR_CFGS;
-			if (erofs_ccfg[inode->z_algorithmtype[0]].enable)
+			ccfg_idx = rand() % erofs_compressor_num();
+			if (erofs_ccfg.compressors[ccfg_idx].enable)
 				break;
 		}
 	}
 #endif
-	ctx.ccfg = &erofs_ccfg[inode->z_algorithmtype[0]];
-	inode->z_algorithmtype[0] = ctx.ccfg[0].algorithmtype;
+	ctx.compressor = &erofs_ccfg.compressors[ccfg_idx];
+	inode->z_algorithmtype[0] = ctx.compressor->algorithmtype;
 	inode->z_algorithmtype[1] = 0;
 
 	inode->idata_size = 0;
@@ -1020,15 +1014,6 @@ err_free_meta:
 	return ret;
 }
 
-static int erofs_get_compress_algorithm_id(const char *name)
-{
-	if (!strcmp(name, "lz4") || !strcmp(name, "lz4hc"))
-		return Z_EROFS_COMPRESSION_LZ4;
-	if (!strcmp(name, "lzma"))
-		return Z_EROFS_COMPRESSION_LZMA;
-	return -ENOTSUP;
-}
-
 int z_erofs_build_compr_cfgs(struct erofs_buffer_head *sb_bh)
 {
 	struct erofs_buffer_head *bh = sb_bh;
@@ -1085,26 +1070,33 @@ int z_erofs_build_compr_cfgs(struct erofs_buffer_head *sb_bh)
 
 int z_erofs_compress_init(struct erofs_buffer_head *sb_bh)
 {
-	int i, ret;
+	int i, k, ret;
 
 	for (i = 0; cfg.c_compr_alg[i]; ++i) {
-		ret = erofs_compressor_init(&erofs_ccfg[i].handle,
-					     cfg.c_compr_alg[i]);
-		if (ret)
-			return ret;
+		struct compressor *compressor = NULL;
 
-		ret = erofs_compressor_setlevel(&erofs_ccfg[i].handle,
-						cfg.c_compr_level[i]);
-		if (ret)
-			return ret;
+		k = erofs_get_compressor_by_name(cfg.c_compr_alg[i]);
+		if (k < 0) {
+			erofs_warn("Cannot find valid compressor for %s!", cfg.c_compr_alg[i]);
+			continue;
+		}
 
-		ret = erofs_get_compress_algorithm_id(cfg.c_compr_alg[i]);
-		if (ret < 0)
+		if (!erofs_ccfg.compressors[k].handle.alg) {
+			erofs_err("compressor %s not available!", cfg.c_compr_alg[i]);
+			return -EINVAL;
+		}
+
+		compressor = &erofs_ccfg.compressors[k];
+		ret = erofs_compressor_setlevel(&compressor->handle, cfg.c_compr_level[i]);
+		if (ret) {
+			erofs_err("compressor %s invalid compress level %d!",
+				cfg.c_compr_alg[i], cfg.c_compr_level[i]);
 			return ret;
-		erofs_ccfg[i].algorithmtype = ret;
-		erofs_ccfg[i].enable = true;
-		sbi.available_compr_algs |= 1 << ret;
-		if (ret != Z_EROFS_COMPRESSION_LZ4)
+		}
+
+		erofs_ccfg.compressors[k].enable = true;
+		sbi.available_compr_algs |= 1 << erofs_ccfg.compressors[k].algorithmtype;
+		if (erofs_ccfg.compressors[k].algorithmtype != Z_EROFS_COMPRESSION_LZ4)
 			erofs_sb_set_compr_cfgs();
 	}
 
@@ -1138,20 +1130,7 @@ int z_erofs_compress_init(struct erofs_buffer_head *sb_bh)
 	}
 
 	if (erofs_sb_has_compr_cfgs()) {
-		sbi.available_compr_algs |= 1 << ret;
 		return z_erofs_build_compr_cfgs(sb_bh);
 	}
 	return 0;
 }
-
-int z_erofs_compress_exit(void)
-{
-	int i, ret;
-
-	for (i = 0; cfg.c_compr_alg[i]; ++i) {
-		ret = erofs_compressor_exit(&erofs_ccfg[i].handle);
-		if (ret)
-			return ret;
-	}
-	return 0;
-}
diff --git a/lib/compressor.c b/lib/compressor.c
index 5aee4e0..4ba2d53 100644
--- a/lib/compressor.c
+++ b/lib/compressor.c
@@ -10,6 +10,11 @@
 
 #define EROFS_CONFIG_COMPR_DEF_BOUNDARY		(128)
 
+/* for enable compressor constructor */
+extern bool enable_constructor_lz4;
+extern bool enable_constructor_lz4hc;
+extern bool enable_constructor_lzma;
+
 /* compressing configuration specified by users */
 static struct erofs_supported_algothrim {
 	int algtype;
@@ -20,7 +25,25 @@ static struct erofs_supported_algothrim {
 	{ Z_EROFS_COMPRESSION_LZMA, "lzma"},
 };
 
-static struct erofs_compressors_cfg erofs_ccfg;
+struct erofs_compressors_cfg erofs_ccfg;
+
+static void erofs_init_compressor(struct compressor *compressor,
+	const struct erofs_compressor *alg)
+{
+
+	compressor->handle.alg = alg;
+
+	/* should be written in "minimum compression ratio * 100" */
+	compressor->handle.compress_threshold = 100;
+
+	/* optimize for 4k size page */
+	compressor->handle.destsize_alignsize = erofs_blksiz();
+	compressor->handle.destsize_redzone_begin = erofs_blksiz() - 16;
+	compressor->handle.destsize_redzone_end = EROFS_CONFIG_COMPR_DEF_BOUNDARY;
+
+	if (alg && alg->init)
+		alg->init(&compressor->handle);
+}
 
 int erofs_compressor_num(void)
 {
@@ -33,17 +56,38 @@ void erofs_compressor_register(const char *name, const struct erofs_compressor *
 
 	for (i = 0; i < erofs_compressor_num(); i++) {
 		if (!strcmp(erofs_ccfg.compressors[i].name, name)) {
-			erofs_ccfg.compressors[i].handle.alg = alg;
+			erofs_init_compressor(&erofs_ccfg.compressors[i], alg);
 			return;
 		}
 	}
 
 	erofs_ccfg.compressors[i].name = name;
-	erofs_ccfg.compressors[i].handle.alg = alg;
 	erofs_ccfg.compressors[i].algorithmtype = erofs_supported_algothrims[i].algtype;
+	erofs_init_compressor(&erofs_ccfg.compressors[i], alg);
 	erofs_ccfg.erofs_ccfg_num = ++i;
 }
 
+int erofs_get_compressor_by_name(const char *name)
+{
+	int i;
+
+	for (i = 0; i < erofs_compressor_num(); i++) {
+		if (!strcmp(erofs_ccfg.compressors[i].name, name)) {
+			return i;
+		}
+	}
+	return -EINVAL;
+}
+
+static void erofs_compressor_unregister(struct erofs_compress *c)
+{
+	const struct erofs_compressor *alg = c->alg;
+
+	if (alg && alg->exit)
+		alg->exit(c);
+	c->alg = NULL;
+}
+
 int erofs_compress_destsize(const struct erofs_compress *c,
 			    const void *src, unsigned int *srcsize,
 			    void *dst, unsigned int dstsize, bool inblocks)
@@ -119,46 +163,7 @@ int erofs_compressor_setlevel(struct erofs_compress *c, int compression_level)
 	return 0;
 }
 
-int erofs_compressor_init(struct erofs_compress *c, char *alg_name)
-{
-	int ret, i;
-
-	/* should be written in "minimum compression ratio * 100" */
-	c->compress_threshold = 100;
-
-	/* optimize for 4k size page */
-	c->destsize_alignsize = erofs_blksiz();
-	c->destsize_redzone_begin = erofs_blksiz() - 16;
-	c->destsize_redzone_end = EROFS_CONFIG_COMPR_DEF_BOUNDARY;
-
-	if (!alg_name) {
-		c->alg = NULL;
-		return 0;
-	}
-
-	ret = -EINVAL;
-	for (i = 0; i < erofs_compressor_num(); ++i) {
-		if (alg_name && strcmp(alg_name, erofs_ccfg.compressors[i].name))
-			continue;
-
-		ret = erofs_ccfg.compressors[i].handle.alg->init(c);
-		if (!ret) {
-			DBG_BUGON(!c->alg);
-			return 0;
-		}
-	}
-	erofs_err("Cannot find a valid compressor %s", alg_name);
-	return ret;
-}
-
-int erofs_compressor_exit(struct erofs_compress *c)
-{
-	if (c->alg && c->alg->exit)
-		return c->alg->exit(c);
-	return 0;
-}
-
-void __attribute__((constructor(101))) __erofs_compressor_init(void)
+void __attribute__((constructor(101))) erofs_compressor_init(void)
 {
 	int i;
 
@@ -166,9 +171,23 @@ void __attribute__((constructor(101))) __erofs_compressor_init(void)
 	for (i = 0; i < ARRAY_SIZE(erofs_supported_algothrims); i++) {
 		erofs_compressor_register(erofs_supported_algothrims[i].name, NULL);
 	}
+
+#if LZ4_ENABLED
+	enable_constructor_lz4 = true;
+#endif
+#if LZ4HC_ENABLED
+	enable_constructor_lz4hc = true;
+#endif
+#if HAVE_LIBLZMA
+	enable_constructor_lzma = true;
+#endif
 }
 
-void __attribute__((destructor)) __erofs_compressor_exit(void)
+void __attribute__((destructor)) erofs_compressor_exit(void)
 {
-	erofs_err("__erofs_compressor_exit");
+	int i;
+
+	for (i = 0; i < erofs_compressor_num(); ++i) {
+		erofs_compressor_unregister(&erofs_ccfg.compressors[i].handle);
+	}
 }
diff --git a/lib/compressor.h b/lib/compressor.h
index 3c1b328..00f4264 100644
--- a/lib/compressor.h
+++ b/lib/compressor.h
@@ -13,8 +13,6 @@
 struct erofs_compress;
 
 struct erofs_compressor {
-	const char *name;
-
 	int default_level;
 	int best_level;
 
@@ -54,18 +52,15 @@ struct erofs_compressors_cfg {
 };
 
 /* list of compression algorithms */
-extern const struct erofs_compressor erofs_compressor_lz4;
-extern const struct erofs_compressor erofs_compressor_lz4hc;
-extern const struct erofs_compressor erofs_compressor_lzma;
+extern struct erofs_compressors_cfg erofs_ccfg;
 
 int erofs_compress_destsize(const struct erofs_compress *c,
 			    const void *src, unsigned int *srcsize,
 			    void *dst, unsigned int dstsize, bool inblocks);
 
 int erofs_compressor_setlevel(struct erofs_compress *c, int compression_level);
-int erofs_compressor_init(struct erofs_compress *c, char *alg_name);
-int erofs_compressor_exit(struct erofs_compress *c);
 
 void erofs_compressor_register(const char *name, const struct erofs_compressor *alg);
 int erofs_compressor_num(void);
+int erofs_get_compressor_by_name(const char *name);
 #endif
diff --git a/lib/compressor_liblzma.c b/lib/compressor_liblzma.c
index b24139c..23ab630 100644
--- a/lib/compressor_liblzma.c
+++ b/lib/compressor_liblzma.c
@@ -88,7 +88,6 @@ static int erofs_compressor_liblzma_init(struct erofs_compress *c)
 {
 	struct erofs_liblzma_context *ctx;
 
-	c->alg = &erofs_compressor_lzma;
 	ctx = malloc(sizeof(*ctx));
 	if (!ctx)
 		return -ENOMEM;
@@ -100,7 +99,6 @@ static int erofs_compressor_liblzma_init(struct erofs_compress *c)
 }
 
 const struct erofs_compressor erofs_compressor_lzma = {
-	.name = "lzma",
 	.default_level = LZMA_PRESET_DEFAULT,
 	.best_level = 109,
 	.init = erofs_compressor_liblzma_init,
@@ -109,6 +107,7 @@ const struct erofs_compressor erofs_compressor_lzma = {
 	.compress_destsize = erofs_liblzma_compress_destsize,
 };
 
+bool enable_constructor_lzma;
 static void __attribute__((constructor)) register_lzma_compressor(void)
 {
 	erofs_compressor_register("lzma", &erofs_compressor_lzma);
diff --git a/lib/compressor_lz4.c b/lib/compressor_lz4.c
index a8adffe..ef4d986 100644
--- a/lib/compressor_lz4.c
+++ b/lib/compressor_lz4.c
@@ -32,13 +32,11 @@ static int compressor_lz4_exit(struct erofs_compress *c)
 
 static int compressor_lz4_init(struct erofs_compress *c)
 {
-	c->alg = &erofs_compressor_lz4;
 	sbi.lz4_max_distance = LZ4_DISTANCE_MAX;
 	return 0;
 }
 
 const struct erofs_compressor erofs_compressor_lz4 = {
-	.name = "lz4",
 	.default_level = 0,
 	.best_level = 0,
 	.init = compressor_lz4_init,
@@ -46,6 +44,7 @@ const struct erofs_compressor erofs_compressor_lz4 = {
 	.compress_destsize = lz4_compress_destsize,
 };
 
+bool enable_constructor_lz4;
 static void __attribute__((constructor)) register_lz4_compressor(void)
 {
 	erofs_compressor_register("lz4", &erofs_compressor_lz4);
diff --git a/lib/compressor_lz4hc.c b/lib/compressor_lz4hc.c
index 2b7e900..c5ce1a3 100644
--- a/lib/compressor_lz4hc.c
+++ b/lib/compressor_lz4hc.c
@@ -38,8 +38,6 @@ static int compressor_lz4hc_exit(struct erofs_compress *c)
 
 static int compressor_lz4hc_init(struct erofs_compress *c)
 {
-	c->alg = &erofs_compressor_lz4hc;
-
 	c->private_data = LZ4_createStreamHC();
 	if (!c->private_data)
 		return -ENOMEM;
@@ -60,7 +58,6 @@ static int compressor_lz4hc_setlevel(struct erofs_compress *c,
 }
 
 const struct erofs_compressor erofs_compressor_lz4hc = {
-	.name = "lz4hc",
 	.default_level = LZ4HC_CLEVEL_DEFAULT,
 	.best_level = LZ4HC_CLEVEL_MAX,
 	.init = compressor_lz4hc_init,
@@ -69,6 +66,7 @@ const struct erofs_compressor erofs_compressor_lz4hc = {
 	.compress_destsize = lz4hc_compress_destsize,
 };
 
+bool enable_constructor_lz4hc;
 static void __attribute__((constructor)) register_lz4hc_compressor(void)
 {
 	erofs_compressor_register("lz4hc", &erofs_compressor_lz4hc);
diff --git a/mkfs/main.c b/mkfs/main.c
index dbd168e..6bf0472 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -916,7 +916,6 @@ int main(int argc, char **argv)
 	if (!err && erofs_sb_has_sb_chksum())
 		err = erofs_mkfs_superblock_csum_set();
 exit:
-	z_erofs_compress_exit();
 	z_erofs_dedupe_exit();
 #ifdef WITH_ANDROID
 	erofs_droid_blocklist_fclose();
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 4/4] erofs-utils: dump: add some superblock fields
  2023-06-09  8:50 [PATCH 0/4] erofs-utils: code-refactoring for erofs compressor Guo Xuenan via Linux-erofs
                   ` (2 preceding siblings ...)
  2023-06-09  8:50 ` [PATCH 3/4] erofs-utils: simplify erofs compressor init and exit Guo Xuenan via Linux-erofs
@ 2023-06-09  8:50 ` Guo Xuenan via Linux-erofs
  2023-06-09  9:40   ` Gao Xiang
  3 siblings, 1 reply; 9+ messages in thread
From: Guo Xuenan via Linux-erofs @ 2023-06-09  8:50 UTC (permalink / raw)
  To: hsiangkao, jefflexu, linux-erofs; +Cc: jack.qiu

dump.erofs show compression algorithms and sb_extslots,
and update feature information.

The proposed super block info is shown as below:
Filesystem magic number:                      0xE0F5E1E2
Filesystem blocks:                            4624
Filesystem inode metadata start block:        0
Filesystem shared xattr metadata start block: 0
Filesystem root nid:                          37
Filesystem compr_algs:                        lz4, lz4hc, lzma
Filesystem sb_extslots:                       0
Filesystem inode count:                       6131
Filesystem created:                           Wed Jun  7 17:15:44 2023
Filesystem features:                          sb_csum mtime 0padding compr_cfgs big_pcluster
Filesystem UUID:                              not available

Signed-off-by: Guo Xuenan <guoxuenan@huawei.com>
---
 dump/main.c              | 11 +++++++++++
 include/erofs/internal.h |  1 +
 lib/super.c              |  5 +++++
 3 files changed, 17 insertions(+)

diff --git a/dump/main.c b/dump/main.c
index ae1ffa0..2cb412d 100644
--- a/dump/main.c
+++ b/dump/main.c
@@ -94,12 +94,14 @@ static struct erofsdump_feature feature_lists[] = {
 	{ true, EROFS_FEATURE_COMPAT_SB_CHKSUM, "sb_csum" },
 	{ true, EROFS_FEATURE_COMPAT_MTIME, "mtime" },
 	{ false, EROFS_FEATURE_INCOMPAT_ZERO_PADDING, "0padding" },
+	{ false, EROFS_FEATURE_INCOMPAT_COMPR_CFGS, "compr_cfgs" },
 	{ false, EROFS_FEATURE_INCOMPAT_BIG_PCLUSTER, "big_pcluster" },
 	{ false, EROFS_FEATURE_INCOMPAT_CHUNKED_FILE, "chunked_file" },
 	{ false, EROFS_FEATURE_INCOMPAT_DEVICE_TABLE, "device_table" },
 	{ false, EROFS_FEATURE_INCOMPAT_ZTAILPACKING, "ztailpacking" },
 	{ false, EROFS_FEATURE_INCOMPAT_FRAGMENTS, "fragments" },
 	{ false, EROFS_FEATURE_INCOMPAT_DEDUPE, "dedupe" },
+	{ false, EROFS_FEATURE_INCOMPAT_XATTR_PREFIXES, "xattr_prefixes" },
 };
 
 static int erofsdump_readdir(struct erofs_dir_context *ctx);
@@ -609,6 +611,15 @@ static void erofsdump_show_superblock(void)
 	if (erofs_sb_has_fragments() && sbi.packed_nid > 0)
 		fprintf(stdout, "Filesystem packed nid:                        %llu\n",
 			sbi.packed_nid | 0ULL);
+	if (erofs_sb_has_compr_cfgs()) {
+		fprintf(stdout, "Filesystem compr_algs:                        ");
+		zerofs_print_supported_compressors(stdout, sbi.available_compr_algs);
+	} else {
+		fprintf(stdout, "Filesystem lz4_max_dist:                      %u\n",
+			sbi.lz4_max_distance | 0U);
+	}
+	fprintf(stdout, "Filesystem sb_extslots:                       %u\n",
+			sbi.extslots | 0U);
 	fprintf(stdout, "Filesystem inode count:                       %llu\n",
 			sbi.inos | 0ULL);
 	fprintf(stdout, "Filesystem created:                           %s",
diff --git a/include/erofs/internal.h b/include/erofs/internal.h
index ab964d4..95e49aa 100644
--- a/include/erofs/internal.h
+++ b/include/erofs/internal.h
@@ -74,6 +74,7 @@ struct erofs_sb_info {
 	u32 feature_incompat;
 	u64 build_time;
 	u32 build_time_nsec;
+	u8 extslots;
 
 	unsigned char islotbits;
 	unsigned char blkszbits;
diff --git a/lib/super.c b/lib/super.c
index 820c883..102a527 100644
--- a/lib/super.c
+++ b/lib/super.c
@@ -105,11 +105,16 @@ int erofs_read_superblock(void)
 	sbi.packed_nid = le64_to_cpu(dsb->packed_nid);
 	sbi.inos = le64_to_cpu(dsb->inos);
 	sbi.checksum = le32_to_cpu(dsb->checksum);
+	sbi.extslots = dsb->sb_extslots;
 
 	sbi.build_time = le64_to_cpu(dsb->build_time);
 	sbi.build_time_nsec = le32_to_cpu(dsb->build_time_nsec);
 
 	memcpy(&sbi.uuid, dsb->uuid, sizeof(dsb->uuid));
+	if (erofs_sb_has_compr_cfgs())
+		sbi.available_compr_algs = le16_to_cpu(dsb->u1.available_compr_algs);
+	else
+		sbi.lz4_max_distance = le16_to_cpu(dsb->u1.lz4_max_distance);
 	return erofs_init_devices(&sbi, dsb);
 }
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/4] erofs-utils: lib: refactor erofs compressors init
  2023-06-09  8:50 ` [PATCH 1/4] erofs-utils: lib: refactor erofs compressors init Guo Xuenan via Linux-erofs
@ 2023-06-09  9:38   ` Gao Xiang
  2023-06-12  3:04     ` Guo Xuenan
  0 siblings, 1 reply; 9+ messages in thread
From: Gao Xiang @ 2023-06-09  9:38 UTC (permalink / raw)
  To: Guo Xuenan, jefflexu, linux-erofs; +Cc: jack.qiu



On 2023/6/9 16:50, Guo Xuenan via Linux-erofs wrote:
> refactor compressor code using constructor.
> 
> Signed-off-by: Guo Xuenan <guoxuenan@huawei.com>
> ---
>   lib/compressor.c         | 49 ++++++++++++++++++++++++++++++++++++++++
>   lib/compressor.h         | 15 ++++++++++++
>   lib/compressor_liblzma.c |  5 ++++
>   lib/compressor_lz4.c     |  5 ++++
>   lib/compressor_lz4hc.c   |  5 ++++
>   5 files changed, 79 insertions(+)
> 
> diff --git a/lib/compressor.c b/lib/compressor.c
> index 52eb761..0fa7105 100644
> --- a/lib/compressor.c
> +++ b/lib/compressor.c
> @@ -22,6 +22,40 @@ static const struct erofs_compressor *compressors[] = {
>   #endif
>   };
>   
> +/* compressing configuration specified by users */
> +static struct erofs_supported_algothrim {
> +	int algtype;
> +	const char *name;
> +} erofs_supported_algothrims[] = {
> +	{ Z_EROFS_COMPRESSION_LZ4, "lz4"},
> +	{ Z_EROFS_COMPRESSION_LZ4, "lz4hc"},
> +	{ Z_EROFS_COMPRESSION_LZMA, "lzma"},
> +};
> +
> +static struct erofs_compressors_cfg erofs_ccfg;
> +
> +int erofs_compressor_num(void)
> +{
> +	return erofs_ccfg.erofs_ccfg_num;



> +}
> +
> +void erofs_compressor_register(const char *name, const struct erofs_compressor *alg)
> +{
> +	int i;
> +
> +	for (i = 0; i < erofs_compressor_num(); i++) {
> +		if (!strcmp(erofs_ccfg.compressors[i].name, name)) {
> +			erofs_ccfg.compressors[i].handle.alg = alg;

should we return error?  and also, why we need dynamicly
register algorithms? liberofs expects to have given
algorithms all the time...

> +			return;
> +		}
> +	}
> +
> +	erofs_ccfg.compressors[i].name = name;
> +	erofs_ccfg.compressors[i].handle.alg = alg;
> +	erofs_ccfg.compressors[i].algorithmtype = erofs_supported_algothrims[i].algtype;
> +	erofs_ccfg.erofs_ccfg_num = ++i;
> +}
> +
>   int erofs_compress_destsize(const struct erofs_compress *c,
>   			    const void *src, unsigned int *srcsize,
>   			    void *dst, unsigned int dstsize, bool inblocks)
> @@ -106,3 +140,18 @@ int erofs_compressor_exit(struct erofs_compress *c)
>   		return c->alg->exit(c);
>   	return 0;
>   }
> +
> +void __attribute__((constructor(101))) __erofs_compressor_init(void)


Honestly I don't like __attribute__((constructor)) and
__attribute__((destructor)) which could causes unexpected behaviors and
not good at compatiability.

Thanks,
Gao Xiang

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/4] erofs-utils: lib: unify all identical compressor print function
  2023-06-09  8:50 ` [PATCH 2/4] erofs-utils: lib: unify all identical compressor print function Guo Xuenan via Linux-erofs
@ 2023-06-09  9:39   ` Gao Xiang
  0 siblings, 0 replies; 9+ messages in thread
From: Gao Xiang @ 2023-06-09  9:39 UTC (permalink / raw)
  To: Guo Xuenan, jefflexu, linux-erofs; +Cc: jack.qiu



On 2023/6/9 16:50, Guo Xuenan via Linux-erofs wrote:
> {dump,fsck}.erofs use the same compressor print function,
> available_compressors means which algothrims are currently
> supported by binary tools.
> supported_compressors including all algothrims that are ready
> for erofs.
> 
> Signed-off-by: Guo Xuenan <guoxuenan@huawei.com>
> ---
>   fsck/main.c              | 15 +-----------
>   include/erofs/compress.h |  3 ++-
>   lib/compressor.c         | 51 ++++++++++++++++++++++++++--------------
>   mkfs/main.c              | 15 +-----------
>   4 files changed, 38 insertions(+), 46 deletions(-)
> 
> diff --git a/fsck/main.c b/fsck/main.c
> index f816bec..978d198 100644
> --- a/fsck/main.c
> +++ b/fsck/main.c
> @@ -49,19 +49,6 @@ static struct option long_options[] = {
>   	{0, 0, 0, 0},
>   };
>   
> -static void print_available_decompressors(FILE *f, const char *delim)
> -{
> -	unsigned int i = 0;
> -	const char *s;
> -
> -	while ((s = z_erofs_list_available_compressors(i)) != NULL) {
> -		if (i++)
> -			fputs(delim, f);
> -		fputs(s, f);
> -	}
> -	fputc('\n', f);
> -}
> -
>   static void usage(void)
>   {
>   	fputs("usage: [options] IMAGE\n\n"
> @@ -84,7 +71,7 @@ static void usage(void)
>   	      " --no-preserve-owner    extract as yourself\n"
>   	      " --no-preserve-perms    apply user's umask when extracting permissions\n"
>   	      "\nSupported algorithms are: ", stderr);
> -	print_available_decompressors(stderr, ", ");
> +	zerofs_print_available_compressors(stderr);

It'd be better to keep z_erofs for compression side.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 4/4] erofs-utils: dump: add some superblock fields
  2023-06-09  8:50 ` [PATCH 4/4] erofs-utils: dump: add some superblock fields Guo Xuenan via Linux-erofs
@ 2023-06-09  9:40   ` Gao Xiang
  0 siblings, 0 replies; 9+ messages in thread
From: Gao Xiang @ 2023-06-09  9:40 UTC (permalink / raw)
  To: Guo Xuenan, jefflexu, linux-erofs; +Cc: jack.qiu



On 2023/6/9 16:50, Guo Xuenan via Linux-erofs wrote:
> dump.erofs show compression algorithms and sb_extslots,
> and update feature information.
> 
> The proposed super block info is shown as below:
> Filesystem magic number:                      0xE0F5E1E2
> Filesystem blocks:                            4624
> Filesystem inode metadata start block:        0
> Filesystem shared xattr metadata start block: 0
> Filesystem root nid:                          37
> Filesystem compr_algs:                        lz4, lz4hc, lzma
> Filesystem sb_extslots:                       0
> Filesystem inode count:                       6131
> Filesystem created:                           Wed Jun  7 17:15:44 2023
> Filesystem features:                          sb_csum mtime 0padding compr_cfgs big_pcluster
> Filesystem UUID:                              not available
> 
> Signed-off-by: Guo Xuenan <guoxuenan@huawei.com>
> ---
>   dump/main.c              | 11 +++++++++++
>   include/erofs/internal.h |  1 +
>   lib/super.c              |  5 +++++
>   3 files changed, 17 insertions(+)
> 
> diff --git a/dump/main.c b/dump/main.c
> index ae1ffa0..2cb412d 100644
> --- a/dump/main.c
> +++ b/dump/main.c
> @@ -94,12 +94,14 @@ static struct erofsdump_feature feature_lists[] = {
>   	{ true, EROFS_FEATURE_COMPAT_SB_CHKSUM, "sb_csum" },
>   	{ true, EROFS_FEATURE_COMPAT_MTIME, "mtime" },
>   	{ false, EROFS_FEATURE_INCOMPAT_ZERO_PADDING, "0padding" },
> +	{ false, EROFS_FEATURE_INCOMPAT_COMPR_CFGS, "compr_cfgs" },
>   	{ false, EROFS_FEATURE_INCOMPAT_BIG_PCLUSTER, "big_pcluster" },
>   	{ false, EROFS_FEATURE_INCOMPAT_CHUNKED_FILE, "chunked_file" },
>   	{ false, EROFS_FEATURE_INCOMPAT_DEVICE_TABLE, "device_table" },
>   	{ false, EROFS_FEATURE_INCOMPAT_ZTAILPACKING, "ztailpacking" },
>   	{ false, EROFS_FEATURE_INCOMPAT_FRAGMENTS, "fragments" },
>   	{ false, EROFS_FEATURE_INCOMPAT_DEDUPE, "dedupe" },
> +	{ false, EROFS_FEATURE_INCOMPAT_XATTR_PREFIXES, "xattr_prefixes" },
>   };
>   
>   static int erofsdump_readdir(struct erofs_dir_context *ctx);
> @@ -609,6 +611,15 @@ static void erofsdump_show_superblock(void)
>   	if (erofs_sb_has_fragments() && sbi.packed_nid > 0)
>   		fprintf(stdout, "Filesystem packed nid:                        %llu\n",
>   			sbi.packed_nid | 0ULL);
> +	if (erofs_sb_has_compr_cfgs()) {
> +		fprintf(stdout, "Filesystem compr_algs:                        ");
> +		zerofs_print_supported_compressors(stdout, sbi.available_compr_algs);
> +	} else {
> +		fprintf(stdout, "Filesystem lz4_max_dist:                      %u\n",

lz4_max_distance is better, let's keep the on-disk full name.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/4] erofs-utils: lib: refactor erofs compressors init
  2023-06-09  9:38   ` Gao Xiang
@ 2023-06-12  3:04     ` Guo Xuenan
  0 siblings, 0 replies; 9+ messages in thread
From: Guo Xuenan @ 2023-06-12  3:04 UTC (permalink / raw)
  To: Gao Xiang, Guo Xuenan, jefflexu, linux-erofs; +Cc: jack.qiu

Hi Xiang,

On 2023/6/9 17:38, Gao Xiang wrote:
>
>
> On 2023/6/9 16:50, Guo Xuenan via Linux-erofs wrote:
>> refactor compressor code using constructor.
>>
>> Signed-off-by: Guo Xuenan <guoxuenan@huawei.com>
>> ---
>>   lib/compressor.c         | 49 ++++++++++++++++++++++++++++++++++++++++
>>   lib/compressor.h         | 15 ++++++++++++
>>   lib/compressor_liblzma.c |  5 ++++
>>   lib/compressor_lz4.c     |  5 ++++
>>   lib/compressor_lz4hc.c   |  5 ++++
>>   5 files changed, 79 insertions(+)
>>
>> diff --git a/lib/compressor.c b/lib/compressor.c
>> index 52eb761..0fa7105 100644
>> --- a/lib/compressor.c
>> +++ b/lib/compressor.c
>> @@ -22,6 +22,40 @@ static const struct erofs_compressor 
>> *compressors[] = {
>>   #endif
>>   };
>>   +/* compressing configuration specified by users */
>> +static struct erofs_supported_algothrim {
>> +    int algtype;
>> +    const char *name;
>> +} erofs_supported_algothrims[] = {
>> +    { Z_EROFS_COMPRESSION_LZ4, "lz4"},
>> +    { Z_EROFS_COMPRESSION_LZ4, "lz4hc"},
>> +    { Z_EROFS_COMPRESSION_LZMA, "lzma"},
>> +};
>> +
>> +static struct erofs_compressors_cfg erofs_ccfg;
>> +
>> +int erofs_compressor_num(void)
>> +{
>> +    return erofs_ccfg.erofs_ccfg_num;
>
>
>
>> +}
>> +
>> +void erofs_compressor_register(const char *name, const struct 
>> erofs_compressor *alg)
>> +{
>> +    int i;
>> +
>> +    for (i = 0; i < erofs_compressor_num(); i++) {
>> +        if (!strcmp(erofs_ccfg.compressors[i].name, name)) {
>> +            erofs_ccfg.compressors[i].handle.alg = alg;
>
> should we return error?  and also, why we need dynamicly
> register algorithms? liberofs expects to have given
> algorithms all the time...
>
>> +            return;
>> +        }
>> +    }
>> +
>> +    erofs_ccfg.compressors[i].name = name;
>> +    erofs_ccfg.compressors[i].handle.alg = alg;
>> +    erofs_ccfg.compressors[i].algorithmtype = 
>> erofs_supported_algothrims[i].algtype;
>> +    erofs_ccfg.erofs_ccfg_num = ++i;
>> +}
>> +
>>   int erofs_compress_destsize(const struct erofs_compress *c,
>>                   const void *src, unsigned int *srcsize,
>>                   void *dst, unsigned int dstsize, bool inblocks)
>> @@ -106,3 +140,18 @@ int erofs_compressor_exit(struct erofs_compress *c)
>>           return c->alg->exit(c);
>>       return 0;
>>   }
>> +
>> +void __attribute__((constructor(101))) __erofs_compressor_init(void)
>
>
> Honestly I don't like __attribute__((constructor)) and
> __attribute__((destructor)) which could causes unexpected behaviors and
> not good at compatiability.
>
OK,  will dorp them next version.
> Thanks,
> Gao Xiang

-- 
Best regards
Guo Xuenan


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-06-12  3:21 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-09  8:50 [PATCH 0/4] erofs-utils: code-refactoring for erofs compressor Guo Xuenan via Linux-erofs
2023-06-09  8:50 ` [PATCH 1/4] erofs-utils: lib: refactor erofs compressors init Guo Xuenan via Linux-erofs
2023-06-09  9:38   ` Gao Xiang
2023-06-12  3:04     ` Guo Xuenan
2023-06-09  8:50 ` [PATCH 2/4] erofs-utils: lib: unify all identical compressor print function Guo Xuenan via Linux-erofs
2023-06-09  9:39   ` Gao Xiang
2023-06-09  8:50 ` [PATCH 3/4] erofs-utils: simplify erofs compressor init and exit Guo Xuenan via Linux-erofs
2023-06-09  8:50 ` [PATCH 4/4] erofs-utils: dump: add some superblock fields Guo Xuenan via Linux-erofs
2023-06-09  9:40   ` Gao Xiang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox