[PATCH] erofs-utils: support randomizing algorithms in debugging mode
Gao Xiang
hsiangkao at linux.alibaba.com
Wed Feb 22 21:39:23 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 | 11 +++++++++++
mkfs/main.c | 5 +++++
3 files changed, 17 insertions(+)
diff --git a/include/erofs/config.h b/include/erofs/config.h
index 17db98c..7b64d89 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 012a90c..4c314e7 100644
--- a/lib/compress.c
+++ b/lib/compress.c
@@ -860,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_CFG;
+ 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;
@@ -1075,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 bb3628f..206a669 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.36.1
More information about the Linux-erofs
mailing list