Whamcloud - gitweb
e2fsck: allow admin specify number of threads
[tools/e2fsprogs.git] / e2fsck / unix.c
index c0aa479..fb1c419 100644 (file)
@@ -826,6 +826,10 @@ static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx)
 #ifdef CONFIG_JBD_DEBUG
        char            *jbd_debug;
 #endif
+#ifdef HAVE_PTHREAD
+       char            *pm;
+       unsigned long   thread_num;
+#endif
        unsigned long long phys_mem_kb, blk;
 
        retval = e2fsck_allocate_context(&ctx);
@@ -858,7 +862,7 @@ static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx)
        ctx->readahead_kb = ~0ULL;
 
 #ifdef HAVE_PTHREAD
-       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)
 #else
        while ((c = getopt(argc, argv, "panyrcC:B:dE:fvtFVM:b:I:j:P:l:L:N:SsDkz:")) != EOF)
 #endif
@@ -904,7 +908,18 @@ static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx)
                        break;
 #ifdef HAVE_PTHREAD
                case 'm':
+                       thread_num = strtoul(optarg, &pm, 0);
+                       if (*pm)
+                               fatal_error(ctx,
+                                       _("Invalid multiple thread num.\n"));
+                       if (thread_num > E2FSCK_MAX_THREADS) {
+                               fprintf(stderr,
+                                       _("threads %lu too large (max %lu)\n"),
+                                       thread_num, E2FSCK_MAX_THREADS);
+                               fatal_error(ctx, 0);
+                       }
                        ctx->options |= E2F_OPT_MULTITHREAD;
+                       ctx->fs_num_threads = thread_num;
                        break;
 #endif
                case 'n':