Linux-EROFS Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Gao Xiang <hsiangkao@linux.alibaba.com>
To: Guo Xuenan <guoxuenan@huawei.com>,
	jefflexu@linux.alibaba.com, linux-erofs@lists.ozlabs.org
Cc: jack.qiu@huawei.com
Subject: Re: [PATCH 1/4] erofs-utils: lib: refactor erofs compressors init
Date: Fri, 9 Jun 2023 17:38:48 +0800	[thread overview]
Message-ID: <2a8a3417-b72d-c8aa-ed3c-dad50d99be43@linux.alibaba.com> (raw)
In-Reply-To: <20230609085041.14987-2-guoxuenan@huawei.com>



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

  reply	other threads:[~2023-06-09  9:39 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2a8a3417-b72d-c8aa-ed3c-dad50d99be43@linux.alibaba.com \
    --to=hsiangkao@linux.alibaba.com \
    --cc=guoxuenan@huawei.com \
    --cc=jack.qiu@huawei.com \
    --cc=jefflexu@linux.alibaba.com \
    --cc=linux-erofs@lists.ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox