Whamcloud - gitweb
LU-8465 e2fsck: misc cleanups for pfsck 75/40075/2
authorAndreas Dilger <adilger@whamcloud.com>
Mon, 28 Sep 2020 19:21:16 +0000 (13:21 -0600)
committerAndreas Dilger <adilger@whamcloud.com>
Tue, 29 Sep 2020 03:53:53 +0000 (03:53 +0000)
Add -m option description to e2fsck.8 man page.

Rename e2fsck_struct fs_num_threads to pfs_num_threads to avoid
confusion with the ext2_filsys fs_num_threads field, and move
thread_info to be together with the other CONFIG_PFSCK fields.

Move ext2_filsys fs_num_threads to fit into the __u16 "pad" field
to avoid consuming one of the few remaining __u32 reserved fields.

Fix a few print format warnings.

Change-Id: Ie69fb51642e71ca5d0d242d9cdc12d29ff181f52
Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/40075
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Wang Shilong <wshilong@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
e2fsck/e2fsck.8.in
e2fsck/e2fsck.h
e2fsck/pass1.c
e2fsck/unix.c
e2fsck/util.c
lib/ext2fs/ext2fs.h

index 1b1c38f..63ae0bd 100644 (file)
@@ -8,7 +8,7 @@ e2fsck \- check a Linux ext2/ext3/ext4 file system
 .SH SYNOPSIS
 .B e2fsck
 [
-.B \-pacnyrdfkvtDFV
+.B \-pacnyrdfkmvtDFV
 ]
 [
 .B \-b
@@ -351,6 +351,12 @@ Set the bad blocks list to be the list of blocks specified by
 option, except the bad blocks list is cleared before the blocks listed
 in the file are added to the bad blocks list.)
 .TP
+.B \-m " threads"
+Run e2fsck with up to the specified number of
+.IR threads .
+The actual number of threads may be lower, if the filesystem does not
+have enough block groups to effectively parallelize the workload.
+.TP
 .B \-n
 Open the filesystem read-only, and assume an answer of `no' to all
 questions.  Allows
index 31c7fa4..6ef58b1 100644 (file)
@@ -271,8 +271,8 @@ struct e2fsck_thread {
        dgrp_t          et_group_next;
        /* Scanned inode number */
        ext2_ino_t      et_inode_number;
-       char            et_log_buf[2048];
        char            et_log_length;
+       char            et_log_buf[2048];
 };
 #endif
 
@@ -449,11 +449,6 @@ struct e2fsck_struct {
        ext2_ino_t              stashed_ino;
        struct ext2_inode       *stashed_inode;
 
-       /* if @global_ctx is null, this field is unused */
-#ifdef CONFIG_PFSCK
-       struct e2fsck_thread     thread_info;
-#endif
-
        /*
         * Directory information
         */
@@ -497,8 +492,11 @@ struct e2fsck_struct {
        __u32                   fs_fragmented_dir;
        __u32                   large_files;
        __u32                   extent_depth_count[MAX_EXTENT_DEPTH_COUNT];
+
 #ifdef CONFIG_PFSCK
-       __u32                    fs_num_threads;
+       /* if @global_ctx is null, this field is unused */
+       struct e2fsck_thread     thread_info;
+       __u32                    pfs_num_threads;
        __u32                    mmp_update_thread;
        int                      fs_need_locking;
        /* serialize fix operation for multiple threads */
@@ -730,7 +728,7 @@ int check_backup_super_block(e2fsck_t ctx);
 void check_resize_inode(e2fsck_t ctx);
 
 /* util.c */
-#define E2FSCK_MAX_THREADS     (65536)
+#define E2FSCK_MAX_THREADS     (65535)
 extern void *e2fsck_allocate_memory(e2fsck_t ctx, unsigned long size,
                                    const char *description);
 extern int ask(e2fsck_t ctx, const char * string, int def);
index 8c8e0de..b98b2f6 100644 (file)
@@ -1464,7 +1464,7 @@ static void e2fsck_pass1_set_thread_num(e2fsck_t ctx)
 {
        unsigned flexbg_size = 1;
        ext2_filsys fs = ctx->fs;
-       int num_threads = ctx->fs_num_threads;
+       int num_threads = ctx->pfs_num_threads;
        int max_threads;
 
        if (num_threads < 1) {
@@ -1484,6 +1484,8 @@ static void e2fsck_pass1_set_thread_num(e2fsck_t ctx)
        max_threads = fs->group_desc_count / flexbg_size;
        if (max_threads == 0)
                max_threads = 1;
+       if (max_threads > E2FSCK_MAX_THREADS)
+               max_threads = E2FSCK_MAX_THREADS;
 
        if (num_threads > max_threads) {
                fprintf(stderr, "Use max possible thread num: %d instead\n",
@@ -1491,7 +1493,7 @@ static void e2fsck_pass1_set_thread_num(e2fsck_t ctx)
                num_threads = max_threads;
        }
 out:
-       ctx->fs_num_threads = num_threads;
+       ctx->pfs_num_threads = num_threads;
        ctx->fs->fs_num_threads = num_threads;
 }
 #endif
@@ -1519,7 +1521,7 @@ static errcode_t e2fsck_pass1_prepare(e2fsck_t ctx)
 
 #ifdef CONFIG_PFSCK
        /* don't use more than 1/10 of memory for threads checking */
-       readahead_kb = get_memory_size() / (10 * ctx->fs_num_threads);
+       readahead_kb = get_memory_size() / (10 * ctx->pfs_num_threads);
        /* maybe better disable RA if this is too small? */
        if (ctx->readahead_kb > readahead_kb)
                ctx->readahead_kb = readahead_kb;
@@ -1577,7 +1579,7 @@ static errcode_t e2fsck_pass1_prepare(e2fsck_t ctx)
 #ifdef CONFIG_PFSCK
        pthread_rwlock_init(&ctx->fs_fix_rwlock, NULL);
        pthread_rwlock_init(&ctx->fs_block_map_rwlock, NULL);
-       if (ctx->fs_num_threads > 1)
+       if (ctx->pfs_num_threads > 1)
                ctx->fs_need_locking = 1;
 #endif
 
@@ -1838,7 +1840,7 @@ void e2fsck_pass1_run(e2fsck_t ctx)
        if (ctx->global_ctx) {
                if (ctx->options & E2F_OPT_DEBUG &&
                    ctx->options & E2F_OPT_MULTITHREAD)
-                       fprintf(stderr, "thread %d jumping to group %d\n",
+                       fprintf(stderr, "thread %d jumping to group %u\n",
                                        ctx->thread_info.et_thread_index,
                                        ctx->thread_info.et_group_start);
                pctx.errcode = ext2fs_inode_scan_goto_blockgroup(scan,
@@ -3403,11 +3405,11 @@ static int e2fsck_pass1_thread_join(e2fsck_t global_ctx, e2fsck_t thread_ctx)
 static int e2fsck_pass1_threads_join(struct e2fsck_thread_info *infos,
                                     e2fsck_t global_ctx)
 {
-       errcode_t                        rc;
-       errcode_t                        ret = 0;
-       int                              i;
-       struct e2fsck_thread_info       *pinfo;
-       int                              num_threads = global_ctx->fs_num_threads;
+       errcode_t rc;
+       errcode_t ret = 0;
+       struct e2fsck_thread_info *pinfo;
+       int num_threads = global_ctx->pfs_num_threads;
+       int i;
 
        /* merge invalid bitmaps will recalculate it */
        global_ctx->invalid_bitmaps = 0;
@@ -3473,7 +3475,7 @@ static void *e2fsck_pass1_thread(void *arg)
 out:
        if (thread_ctx->options & E2F_OPT_MULTITHREAD)
                log_out(thread_ctx,
-                       _("Scanned group range [%lu, %lu), inodes %lu\n"),
+                       _("Scanned group range [%u, %u), inodes %u\n"),
                        thread_ctx->thread_info.et_group_start,
                        thread_ctx->thread_info.et_group_end,
                        thread_ctx->thread_info.et_inode_number);
@@ -3499,7 +3501,7 @@ static int e2fsck_pass1_threads_start(struct e2fsck_thread_info **pinfo,
        int                              i;
        e2fsck_t                         thread_ctx;
        dgrp_t                           average_group;
-       int                              num_threads = global_ctx->fs_num_threads;
+       int num_threads = global_ctx->pfs_num_threads;
 #ifdef DEBUG_THREADS
        struct e2fsck_thread_debug       thread_debug =
                {PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0};
@@ -3603,8 +3605,7 @@ void e2fsck_pass1(e2fsck_t ctx)
        if (retval)
                return;
 #ifdef CONFIG_PFSCK
-       if (ctx->fs_num_threads > 1 ||
-           ctx->options & E2F_OPT_MULTITHREAD) {
+       if (ctx->pfs_num_threads > 1 || ctx->options & E2F_OPT_MULTITHREAD) {
                need_single = 0;
                e2fsck_pass1_multithread(ctx);
        }
index 0b9f398..ebb1b84 100644 (file)
@@ -1006,12 +1006,12 @@ static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx)
                                        _("Invalid multiple thread num.\n"));
                        if (thread_num > E2FSCK_MAX_THREADS) {
                                fprintf(stderr,
-                                       _("threads %lu too large (max %lu)\n"),
+                                       _("threads %lu too large (max %u)\n"),
                                        thread_num, E2FSCK_MAX_THREADS);
                                fatal_error(ctx, 0);
                        }
                        ctx->options |= E2F_OPT_MULTITHREAD;
-                       ctx->fs_num_threads = thread_num;
+                       ctx->pfs_num_threads = thread_num;
                        break;
 #endif
                case 'n':
index c8a66c5..6719188 100644 (file)
@@ -186,7 +186,7 @@ void *e2fsck_allocate_memory(e2fsck_t ctx, unsigned long size,
        printf("Allocating %u bytes for %s...\n", size, description);
 #endif
        if (ext2fs_get_memzero(size, &ret)) {
-               sprintf(buf, "Can't allocate %u bytes for %s\n",
+               sprintf(buf, "Can't allocate %lu bytes for %s\n",
                        size, description);
                fatal_error(ctx, buf);
        }
index ba94b28..c1231f6 100644 (file)
@@ -254,12 +254,11 @@ struct struct_ext2_filsys {
        time_t                          now;
        int                             cluster_ratio_bits;
        __u16                           default_bitmap_type;
-       __u16                           pad;
-       __u32                           fs_num_threads;
+       __u16                           fs_num_threads;
        /*
         * Reserved for future expansion
         */
-       __u32                           reserved[4];
+       __u32                           reserved[5];
 
        /*
         * Reserved for the use of the calling application.