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 A3245C636D6 for ; Wed, 22 Feb 2023 19:12:09 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4PMQkw1dwRz3c9x for ; Thu, 23 Feb 2023 06:12:08 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.alibaba.com (client-ip=115.124.30.133; helo=out30-133.freemail.mail.aliyun.com; envelope-from=hsiangkao@linux.alibaba.com; receiver=) Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) (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 4PMQkq0fMDz3c9x for ; Thu, 23 Feb 2023 06:12:02 +1100 (AEDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R571e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045192;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=2;SR=0;TI=SMTPD_---0VcHhJLC_1677093116; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VcHhJLC_1677093116) by smtp.aliyun-inc.com; Thu, 23 Feb 2023 03:11:58 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org Subject: [PATCH v2 3/3] erofs-utils: support randomizing algorithms in debugging mode Date: Thu, 23 Feb 2023 03:11:48 +0800 Message-Id: <20230222191148.112677-3-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20230222191148.112677-1-hsiangkao@linux.alibaba.com> References: <20230222191148.112677-1-hsiangkao@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: Gao Xiang Errors-To: linux-erofs-bounces+linux-erofs=archiver.kernel.org@lists.ozlabs.org Sender: "Linux-erofs" It's used for multiple algorithms selftest. Signed-off-by: Gao Xiang --- include/erofs/config.h | 1 + lib/compress.c | 12 ++++++++++++ mkfs/main.c | 5 +++++ 3 files changed, 18 insertions(+) diff --git a/include/erofs/config.h b/include/erofs/config.h index aee2815..39a6162 100644 --- a/include/erofs/config.h +++ b/include/erofs/config.h @@ -41,6 +41,7 @@ struct erofs_configure { bool c_legacy_compress; #ifndef NDEBUG bool c_random_pclusterblks; + bool c_random_algorithms; #endif char c_timeinherit; char c_chunkbits; diff --git a/lib/compress.c b/lib/compress.c index b1185bd..0aaec30 100644 --- a/lib/compress.c +++ b/lib/compress.c @@ -25,6 +25,7 @@ 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 { @@ -859,6 +860,16 @@ 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; +#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) + break; + } + } +#endif ctx.ccfg = &erofs_ccfg[inode->z_algorithmtype[0]]; inode->z_algorithmtype[0] = ctx.ccfg[0].algorithmtype; inode->z_algorithmtype[1] = 0; @@ -1074,6 +1085,7 @@ int z_erofs_compress_init(struct erofs_buffer_head *sb_bh) if (ret < 0) 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_sb_set_compr_cfgs(); diff --git a/mkfs/main.c b/mkfs/main.c index 2c3a3b7..d055902 100644 --- a/mkfs/main.c +++ b/mkfs/main.c @@ -45,6 +45,7 @@ static struct option long_options[] = { {"all-root", no_argument, NULL, 7}, #ifndef NDEBUG {"random-pclusterblks", no_argument, NULL, 8}, + {"random-algorithms", no_argument, NULL, 18}, #endif {"max-extent-bytes", required_argument, NULL, 9}, {"compress-hints", required_argument, NULL, 10}, @@ -111,6 +112,7 @@ static void usage(void) " --quiet quiet execution (do not write anything to standard output.)\n" #ifndef NDEBUG " --random-pclusterblks randomize pclusterblks for big pcluster (debugging only)\n" + " --random-algorithms randomize per-file algorithms (debugging only)\n" #endif " --mount-point=X X=prefix of target fs path (default: /)\n" #ifdef WITH_ANDROID @@ -370,6 +372,9 @@ static int mkfs_parse_options_cfg(int argc, char *argv[]) case 8: cfg.c_random_pclusterblks = true; break; + case 18: + cfg.c_random_algorithms = true; + break; #endif case 9: cfg.c_max_decompressed_extent_bytes = -- 2.24.4