[PATCH v2 3/3] erofs-utils: support randomizing algorithms in debugging mode
Gao Xiang
hsiangkao at linux.alibaba.com
Thu Feb 23 06:11:48 AEDT 2023
It's used for multiple algorithms selftest.
Signed-off-by: Gao Xiang <hsiangkao at linux.alibaba.com>
---
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
More information about the Linux-erofs
mailing list