Whamcloud - gitweb
LU-14953 e2fsck: pfsck progress report
authorLi Dongyang <dongyangli@ddn.com>
Mon, 30 Aug 2021 12:43:52 +0000 (22:43 +1000)
committerAndreas Dilger <adilger@whamcloud.com>
Mon, 19 Sep 2022 23:17:54 +0000 (17:17 -0600)
Re-enable progress support for pfsck.
To make it work, in pass1 before calling e2fsck_update_progress,
figure out the the progress for other threads as well.

Change-Id: Ia039aa20f35990b550680169c8b3670b4346ce8b
Signed-off-by: Li Dongyang <dongyangli@ddn.com>
Reviewed-on: https://review.whamcloud.com/44784
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
e2fsck/e2fsck.h
e2fsck/pass1.c
e2fsck/unix.c
tests/f_multithread_completion/expect.1 [deleted file]
tests/f_multithread_completion/expect.2 [deleted file]
tests/f_multithread_completion/image.gz [deleted symlink]
tests/f_multithread_completion/name [deleted file]
tests/f_multithread_completion/script [deleted file]

index 51fcd46..f1ebac8 100644 (file)
@@ -494,6 +494,7 @@ struct e2fsck_struct {
        pthread_rwlock_t         fs_fix_rwlock;
        /* protect block_found_map, block_dup_map */
        pthread_rwlock_t         fs_block_map_rwlock;
+       struct e2fsck_thread_info       *infos;
 #endif
 };
 
index a0d6bc3..8247cec 100644 (file)
@@ -3188,11 +3188,11 @@ static int e2fsck_pass1_thread_join(e2fsck_t global_ctx, e2fsck_t thread_ctx)
        return retval;
 }
 
-static int e2fsck_pass1_threads_join(struct e2fsck_thread_info *infos,
-                                    e2fsck_t global_ctx)
+static int e2fsck_pass1_threads_join(e2fsck_t global_ctx)
 {
        errcode_t rc;
        errcode_t ret = 0;
+       struct e2fsck_thread_info *infos = global_ctx->infos;
        struct e2fsck_thread_info *pinfo;
        int num_threads = global_ctx->pfs_num_threads;
        int i;
@@ -3221,6 +3221,7 @@ static int e2fsck_pass1_threads_join(struct e2fsck_thread_info *infos,
                }
        }
        free(infos);
+       global_ctx->infos = NULL;
 
        return ret;
 }
@@ -3305,8 +3306,7 @@ static dgrp_t ext2fs_get_avg_group(ext2_filsys fs)
 #endif
 }
 
-static int e2fsck_pass1_threads_start(struct e2fsck_thread_info **pinfo,
-                                     e2fsck_t global_ctx)
+static int e2fsck_pass1_threads_start(e2fsck_t global_ctx)
 {
        struct e2fsck_thread_info       *infos;
        pthread_attr_t                   attr;
@@ -3339,6 +3339,7 @@ static int e2fsck_pass1_threads_start(struct e2fsck_thread_info **pinfo,
                pthread_attr_destroy(&attr);
                return retval;
        }
+       global_ctx->infos = infos;
 
        average_group = ext2fs_get_avg_group(global_ctx->fs);
        for (i = 0; i < num_threads; i++) {
@@ -3379,26 +3380,24 @@ static int e2fsck_pass1_threads_start(struct e2fsck_thread_info **pinfo,
        }
 
        if (retval) {
-               e2fsck_pass1_threads_join(infos, global_ctx);
+               e2fsck_pass1_threads_join(global_ctx);
                return retval;
        }
-       *pinfo = infos;
        return 0;
 }
 
 static void e2fsck_pass1_multithread(e2fsck_t global_ctx)
 {
-       struct e2fsck_thread_info *infos = NULL;
        errcode_t retval;
 
-       retval = e2fsck_pass1_threads_start(&infos, global_ctx);
+       retval = e2fsck_pass1_threads_start(global_ctx);
        if (retval) {
                com_err(global_ctx->program_name, retval,
                        _("while starting pass1 threads\n"));
                goto out_abort;
        }
 
-       retval = e2fsck_pass1_threads_join(infos, global_ctx);
+       retval = e2fsck_pass1_threads_join(global_ctx);
        if (retval) {
                com_err(global_ctx->program_name, retval,
                        _("while joining pass1 threads\n"));
@@ -3444,7 +3443,10 @@ static errcode_t scan_callback(ext2_filsys fs,
 {
        struct scan_callback_struct *scan_struct;
        e2fsck_t ctx;
+       dgrp_t cur = group + 1;
        struct e2fsck_thread *tinfo;
+       struct e2fsck_thread_info *pinfo, *infos;
+       int i;
 
        scan_struct = (struct scan_callback_struct *) priv_data;
        ctx = scan_struct->ctx;
@@ -3453,8 +3455,28 @@ static errcode_t scan_callback(ext2_filsys fs,
                       scan_struct->inodes_to_process,
                       scan_struct->process_inode_count);
 
+#ifdef HAVE_PTHREAD
+       if (ctx->global_ctx) {
+               cur = 0;
+               infos = ctx->global_ctx->infos;
+               for (i = 0; i < ctx->global_ctx->pfs_num_threads; i++) {
+                       pinfo = &infos[i];
+
+                       if (!pinfo->eti_started)
+                               continue;
+
+                       tinfo = &pinfo->eti_thread_ctx->thread_info;
+                       if (ctx == pinfo->eti_thread_ctx)
+                               cur += group + 1 - tinfo->et_group_start;
+                       else
+                               cur += tinfo->et_group_next -
+                                       tinfo->et_group_start;
+               }
+       }
+#endif
+
        if (ctx->progress)
-               if ((ctx->progress)(ctx, 1, group+1,
+               if ((ctx->progress)(ctx, 1, cur,
                                    ctx->fs->group_desc_count))
                        return EXT2_ET_CANCEL_REQUESTED;
 
index 92e65ef..6ca6f45 100644 (file)
@@ -1049,11 +1049,6 @@ static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx)
                                _("The -m option should be used together with one of -p/-y/-n options."));
                        fatal_error(ctx, 0);
                }
-               if (ctx->progress) {
-                       com_err(ctx->program_name, 0, "%s",
-                               _("Only one of the options -C or -m may be specified."));
-                       fatal_error(ctx, 0);
-               }
        }
 #endif
        if (ctx->options & E2F_OPT_NO)
@@ -1162,12 +1157,10 @@ static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx)
 #ifdef SA_RESTART
        sa.sa_flags = SA_RESTART;
 #endif
-       if ((ctx->options & E2F_OPT_MULTITHREAD) == 0) {
-               sa.sa_handler = signal_progress_on;
-               sigaction(SIGUSR1, &sa, 0);
-               sa.sa_handler = signal_progress_off;
-               sigaction(SIGUSR2, &sa, 0);
-       }
+       sa.sa_handler = signal_progress_on;
+       sigaction(SIGUSR1, &sa, 0);
+       sa.sa_handler = signal_progress_off;
+       sigaction(SIGUSR2, &sa, 0);
 #endif
 
        /* Update our PATH to include /sbin if we need to run badblocks  */
diff --git a/tests/f_multithread_completion/expect.1 b/tests/f_multithread_completion/expect.1
deleted file mode 100644 (file)
index 61cac9b..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-../e2fsck/e2fsck: Only one of the options -C or -m may be specified.
-Exit status is 8
diff --git a/tests/f_multithread_completion/expect.2 b/tests/f_multithread_completion/expect.2
deleted file mode 100644 (file)
index e2b954d..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-ext2fs_open2: Bad magic number in super-block
-../e2fsck/e2fsck: Superblock invalid, trying backup blocks...
-Pass 1: Checking inodes, blocks, and sizes
-Pass 2: Checking directory structure
-Pass 3: Checking directory connectivity
-Pass 4: Checking reference counts
-Pass 5: Checking group summary information
-Free blocks count wrong for group #0 (7987, counted=7982).
-Fix? yes
-
-Free blocks count wrong (11602, counted=11597).
-Fix? yes
-
-Free inodes count wrong for group #0 (1493, counted=1488).
-Fix? yes
-
-Free inodes count wrong (2997, counted=2992).
-Fix? yes
-
-
-test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
-test_filesys: 16/3008 files (0.0% non-contiguous), 403/12000 blocks
-Exit status is 1
diff --git a/tests/f_multithread_completion/image.gz b/tests/f_multithread_completion/image.gz
deleted file mode 120000 (symlink)
index 0fd4001..0000000
+++ /dev/null
@@ -1 +0,0 @@
-../f_zero_super/image.gz
\ No newline at end of file
diff --git a/tests/f_multithread_completion/name b/tests/f_multithread_completion/name
deleted file mode 100644 (file)
index a959045..0000000
+++ /dev/null
@@ -1 +0,0 @@
-test "e2fsck -m" option conflicts with "-C"
\ No newline at end of file
diff --git a/tests/f_multithread_completion/script b/tests/f_multithread_completion/script
deleted file mode 100644 (file)
index 0ec1381..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-FSCK_OPT="-fy -m1 -C 1"
-SECOND_FSCK_OPT=-yf
-
-. $cmd_dir/run_e2fsck