From: Wang Shilong <wshilong@xxxxxxx> Signed-off-by: Wang Shilong <wshilong@xxxxxxx> --- e2fsck/e2fsck.h | 1 + e2fsck/pass1.c | 8 ++++++-- e2fsck/unix.c | 3 ++- tests/f_multithread/script | 2 +- tests/f_multithread_completion/script | 2 +- tests/f_multithread_logfile/script | 2 +- tests/f_multithread_no/script | 2 +- tests/f_multithread_preen/script | 2 +- tests/f_multithread_yes/script | 2 +- 9 files changed, 15 insertions(+), 9 deletions(-) diff --git a/e2fsck/e2fsck.h b/e2fsck/e2fsck.h index dcc5c2d6..cd1bab07 100644 --- a/e2fsck/e2fsck.h +++ b/e2fsck/e2fsck.h @@ -444,6 +444,7 @@ struct e2fsck_struct { __u32 fs_fragmented_dir; __u32 large_files; __u32 extent_depth_count[MAX_EXTENT_DEPTH_COUNT]; + __u32 fs_num_threads; /* serialize fix operation for multiple threads */ pthread_mutex_t fs_fix_mutex; /* protect block_found_map, block_dup_map */ diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c index a73d35fd..40fe6b36 100644 --- a/e2fsck/pass1.c +++ b/e2fsck/pass1.c @@ -3114,11 +3114,14 @@ static void init_ext2_max_sizes() static void e2fsck_pass1_multithread(e2fsck_t global_ctx) { struct e2fsck_thread_info *infos = NULL; - int num_threads = 1; + int num_threads = global_ctx->fs_num_threads; errcode_t retval; unsigned flexbg_size = 1; int max_threads; + if (num_threads < 1) + num_threads = 1; + retval = _e2fsck_pass1_prepare(global_ctx); if (retval) goto out_abort; @@ -3136,11 +3139,12 @@ static void e2fsck_pass1_multithread(e2fsck_t global_ctx) int times = max_threads / num_threads; if (times == 0) - num_threads = 1; + num_threads = max_threads; else num_threads = max_threads / times; } + global_ctx->fs_num_threads = num_threads; init_ext2_max_sizes(); retval = e2fsck_pass1_threads_start(&infos, num_threads, global_ctx); if (retval) { diff --git a/e2fsck/unix.c b/e2fsck/unix.c index 3124019a..485899b3 100644 --- a/e2fsck/unix.c +++ b/e2fsck/unix.c @@ -848,7 +848,7 @@ static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx) phys_mem_kb = get_memory_size() / 1024; ctx->readahead_kb = ~0ULL; - while ((c = getopt(argc, argv, "pamnyrcC:B:dE:fvtFVM:b:I:j:P:l:L:N:SsDkz:")) != EOF) + while ((c = getopt(argc, argv, "pam:nyrcC:B:dE:fvtFVM:b:I:j:P:l:L:N:SsDkz:")) != EOF) switch (c) { case 'C': ctx->progress = e2fsck_update_progress; @@ -891,6 +891,7 @@ static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx) break; case 'm': ctx->options |= E2F_OPT_MULTITHREAD; + ctx->fs_num_threads = atoi(optarg); break; case 'n': if (ctx->options & (E2F_OPT_YES|E2F_OPT_PREEN)) diff --git a/tests/f_multithread/script b/tests/f_multithread/script index 0fe96cd0..83cd0f03 100644 --- a/tests/f_multithread/script +++ b/tests/f_multithread/script @@ -1,4 +1,4 @@ -FSCK_OPT="-fy -m" +FSCK_OPT="-fy -m1" SECOND_FSCK_OPT=-yf . $cmd_dir/run_e2fsck diff --git a/tests/f_multithread_completion/script b/tests/f_multithread_completion/script index bf23cd61..0ec13816 100644 --- a/tests/f_multithread_completion/script +++ b/tests/f_multithread_completion/script @@ -1,4 +1,4 @@ -FSCK_OPT="-fy -m -C 1" +FSCK_OPT="-fy -m1 -C 1" SECOND_FSCK_OPT=-yf . $cmd_dir/run_e2fsck diff --git a/tests/f_multithread_logfile/script b/tests/f_multithread_logfile/script index d7042a03..ae497298 100644 --- a/tests/f_multithread_logfile/script +++ b/tests/f_multithread_logfile/script @@ -1,5 +1,5 @@ LOG_FNAME="f_multithread_logfile_xxx" -FSCK_OPT="-fy -m -y -E log_filename=$LOG_FNAME" +FSCK_OPT="-fy -m1 -y -E log_filename=$LOG_FNAME" SKIP_VERIFY="true" ONE_PASS_ONLY="true" SKIP_CLEANUP="true" diff --git a/tests/f_multithread_no/script b/tests/f_multithread_no/script index b93deb3a..db791e11 100644 --- a/tests/f_multithread_no/script +++ b/tests/f_multithread_no/script @@ -1,4 +1,4 @@ -FSCK_OPT="-fn -m" +FSCK_OPT="-fn -m1" SECOND_FSCK_OPT=-yf . $cmd_dir/run_e2fsck diff --git a/tests/f_multithread_preen/script b/tests/f_multithread_preen/script index ecb79cd6..8965f4a7 100644 --- a/tests/f_multithread_preen/script +++ b/tests/f_multithread_preen/script @@ -1,4 +1,4 @@ -FSCK_OPT="-fp -m" +FSCK_OPT="-fp -m1" SECOND_FSCK_OPT=-yf . $cmd_dir/run_e2fsck diff --git a/tests/f_multithread_yes/script b/tests/f_multithread_yes/script index 38891f6a..8b4aa9b8 100644 --- a/tests/f_multithread_yes/script +++ b/tests/f_multithread_yes/script @@ -1,4 +1,4 @@ -FSCK_OPT="-f -m" +FSCK_OPT="-f -m1" SECOND_FSCK_OPT=-yf . $cmd_dir/run_e2fsck -- 2.25.4