Signed-off-by: Gao Xiang <hsiang...@linux.alibaba.com>
---
 include/erofs/config.h   | 1 -
 include/erofs/importer.h | 1 +
 lib/inode.c              | 9 +++++++--
 mkfs/main.c              | 7 ++++---
 4 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/include/erofs/config.h b/include/erofs/config.h
index 418e9b6..40a2011 100644
--- a/include/erofs/config.h
+++ b/include/erofs/config.h
@@ -94,7 +94,6 @@ struct erofs_configure {
 #ifdef EROFS_MT_ENABLED
        u64 c_mkfs_segment_size;
        u32 c_mt_workers;
-       u32 c_mt_async_queue_limit;
 #endif
 #ifdef WITH_ANDROID
        char *target_out_path;
diff --git a/include/erofs/importer.h b/include/erofs/importer.h
index 9aa032b..0382913 100644
--- a/include/erofs/importer.h
+++ b/include/erofs/importer.h
@@ -14,6 +14,7 @@ extern "C"
 
 struct erofs_importer_params {
        char *source;
+       u32 mt_async_queue_limit;
        bool no_datainline;
 };
 
diff --git a/lib/inode.c b/lib/inode.c
index ae1c39c..9a5b67c 100644
--- a/lib/inode.c
+++ b/lib/inode.c
@@ -2023,6 +2023,7 @@ static int erofs_get_fdlimit(void)
 static int erofs_mkfs_build_tree(struct erofs_mkfs_buildtree_ctx *ctx)
 {
        struct erofs_importer *im = ctx->im;
+       struct erofs_importer_params *params = im->params;
        struct erofs_sb_info *sbi = im->sbi;
        struct erofs_mkfs_dfops *q;
        int err, err2;
@@ -2032,8 +2033,12 @@ static int erofs_mkfs_build_tree(struct 
erofs_mkfs_buildtree_ctx *ctx)
        if (!q)
                return -ENOMEM;
 
-       if (cfg.c_mt_async_queue_limit) {
-               q->entries = cfg.c_mt_async_queue_limit;
+       if (params->mt_async_queue_limit) {
+               q->entries = params->mt_async_queue_limit;
+               if (q->entries & (q->entries - 1)) {
+                       free(q);
+                       return -EINVAL;
+               }
        } else {
                err = roundup_pow_of_two(erofs_get_fdlimit()) >> 1;
                q->entries = err && err < 32768 ? err : 32768;
diff --git a/mkfs/main.c b/mkfs/main.c
index 2040b62..bf2aa47 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -860,7 +860,8 @@ static int mkfs_parse_sources(int argc, char *argv[], int 
optind)
        return 0;
 }
 
-static int mkfs_parse_options_cfg(int argc, char *argv[])
+static int mkfs_parse_options_cfg(struct erofs_importer_params *params,
+                                 int argc, char *argv[])
 {
        char *endptr;
        int opt, i, err;
@@ -1195,7 +1196,7 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
                        break;
 #ifdef EROFS_MT_ENABLED
                case 530:
-                       cfg.c_mt_async_queue_limit = strtoul(optarg, &endptr, 
0);
+                       params->mt_async_queue_limit = strtoul(optarg, &endptr, 
0);
                        if (*endptr != '\0') {
                                erofs_err("invalid async-queue-limit %s", 
optarg);
                                return -EINVAL;
@@ -1497,7 +1498,7 @@ int main(int argc, char **argv)
        erofs_mkfs_default_options();
        erofs_importer_preset(&importer_params);
 
-       err = mkfs_parse_options_cfg(argc, argv);
+       err = mkfs_parse_options_cfg(&importer_params, argc, argv);
        erofs_show_progs(argc, argv);
        if (err) {
                if (err == -EINVAL)
-- 
2.43.5


Reply via email to