Whamcloud - gitweb
LU-8465 e2fsck: add debug codes for multiple threads 54/36054/15
authorLi Xi <lixi@ddn.com>
Thu, 5 Sep 2019 11:40:36 +0000 (19:40 +0800)
committerAndreas Dilger <adilger@whamcloud.com>
Sat, 26 Sep 2020 04:41:26 +0000 (04:41 +0000)
These debug codes are added to run the multiple pass1 check
thread one by one in order. If all the codes are correct,
fsck of multiple threads should have exactly the same outcome
with single thread.

Change-Id: Ieb78a26611b3d5a4f21cc239e8616d215032c646
Signed-off-by: Li Xi <lixi@ddn.com>
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-on: https://review.whamcloud.com/36054
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
e2fsck/e2fsck.h
e2fsck/pass1.c

index 924e25a..b4e281a 100644 (file)
@@ -498,6 +498,18 @@ struct e2fsck_struct {
 };
 
 #ifdef CONFIG_PFSCK
+#ifdef DEBUG_THREADS
+/*
+ * Enabling DEBUG_THREADS would cause the parallel
+ * fsck threads run sequentially.
+ */
+struct e2fsck_thread_debug {
+       pthread_mutex_t etd_mutex;
+       pthread_cond_t  etd_cond;
+       int             etd_finished_threads;
+};
+#endif
+
 struct e2fsck_thread_info {
        /* ID returned by pthread_create() */
        pthread_t                eti_thread_id;
@@ -507,7 +519,11 @@ struct e2fsck_thread_info {
        int                      eti_started;
        /* Context used for this thread */
        e2fsck_t                 eti_thread_ctx;
+#ifdef DEBUG_THREADS
+       struct e2fsck_thread_debug      *eti_debug;
+#endif
 };
+
 #endif
 
 /* Data structures to evaluate whether an extent tree needs rebuilding. */
index 2232430..6d23549 100644 (file)
@@ -2896,6 +2896,18 @@ static void *e2fsck_pass1_thread(void *arg)
 {
        struct e2fsck_thread_info       *info = arg;
        e2fsck_t                         thread_ctx = info->eti_thread_ctx;
+#ifdef DEBUG_THREADS
+       struct e2fsck_thread_debug      *thread_debug = info->eti_debug;
+#endif
+
+#ifdef DEBUG_THREADS
+       pthread_mutex_lock(&thread_debug->etd_mutex);
+       while (info->eti_thread_index > thread_debug->etd_finished_threads) {
+               pthread_cond_wait(&thread_debug->etd_cond,
+                                 &thread_debug->etd_mutex);
+       }
+       pthread_mutex_unlock(&thread_debug->etd_mutex);
+#endif
 
 #ifdef HAVE_SETJMP_H
        /*
@@ -2920,6 +2932,14 @@ out:
                        thread_ctx->thread_info.et_group_start,
                        thread_ctx->thread_info.et_group_end,
                        thread_ctx->thread_info.et_inode_number);
+
+#ifdef DEBUG_THREADS
+       pthread_mutex_lock(&thread_debug->etd_mutex);
+       thread_debug->etd_finished_threads++;
+       pthread_cond_broadcast(&thread_debug->etd_cond);
+       pthread_mutex_unlock(&thread_debug->etd_mutex);
+#endif
+
        return NULL;
 }
 
@@ -2933,6 +2953,12 @@ static int e2fsck_pass1_threads_start(struct e2fsck_thread_info **pinfo,
        struct e2fsck_thread_info       *tmp_pinfo;
        int                              i;
        e2fsck_t                         thread_ctx;
+#ifdef DEBUG_THREADS
+       struct e2fsck_thread_debug       thread_debug =
+               {PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0};
+
+       thread_debug.etd_finished_threads = 0;
+#endif
 
        retval = pthread_attr_init(&attr);
        if (retval) {
@@ -2953,6 +2979,9 @@ static int e2fsck_pass1_threads_start(struct e2fsck_thread_info **pinfo,
        for (i = 0; i < num_threads; i++) {
                tmp_pinfo = &infos[i];
                tmp_pinfo->eti_thread_index = i;
+#ifdef DEBUG_THREADS
+               tmp_pinfo->eti_debug = &thread_debug;
+#endif
                retval = e2fsck_pass1_thread_prepare(global_ctx, &thread_ctx,
                                                     i, num_threads);
                if (retval) {