From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4DDA1C7EE2E for ; Fri, 9 Jun 2023 09:39:07 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QcwyK3f1kz3f86 for ; Fri, 9 Jun 2023 19:39:05 +1000 (AEST) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.alibaba.com (client-ip=115.124.30.119; helo=out30-119.freemail.mail.aliyun.com; envelope-from=hsiangkao@linux.alibaba.com; receiver=) Received: from out30-119.freemail.mail.aliyun.com (out30-119.freemail.mail.aliyun.com [115.124.30.119]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Qcwy85cCYz3f05 for ; Fri, 9 Jun 2023 19:38:55 +1000 (AEST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R181e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045176;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0Vkhc1h9_1686303529; Received: from 30.97.48.228(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0Vkhc1h9_1686303529) by smtp.aliyun-inc.com; Fri, 09 Jun 2023 17:38:50 +0800 Message-ID: <2a8a3417-b72d-c8aa-ed3c-dad50d99be43@linux.alibaba.com> Date: Fri, 9 Jun 2023 17:38:48 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH 1/4] erofs-utils: lib: refactor erofs compressors init To: Guo Xuenan , jefflexu@linux.alibaba.com, linux-erofs@lists.ozlabs.org References: <20230609085041.14987-1-guoxuenan@huawei.com> <20230609085041.14987-2-guoxuenan@huawei.com> From: Gao Xiang In-Reply-To: <20230609085041.14987-2-guoxuenan@huawei.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: linux-erofs@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development of Linux EROFS file system List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jack.qiu@huawei.com Errors-To: linux-erofs-bounces+linux-erofs=archiver.kernel.org@lists.ozlabs.org Sender: "Linux-erofs" On 2023/6/9 16:50, Guo Xuenan via Linux-erofs wrote: > refactor compressor code using constructor. > > Signed-off-by: Guo Xuenan > --- > 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