Whamcloud - gitweb
LU-14126 e2fsck: update mmp block race 72/40572/2
authorWang Shilong <wshilong@ddn.com>
Sun, 8 Nov 2020 09:19:06 +0000 (17:19 +0800)
committerWang Shilong <wshilong@whamcloud.com>
Mon, 23 Nov 2020 02:31:36 +0000 (02:31 +0000)
Update mmp block is only expected in one thread, @mmp_update_thread
is used to get/set active thread number, however this should
be set globally shared with different threads rather than be private
per thread.

Fixes: 7284939c57618 ("LU-8465 e2fsck: update mmp block in one thread")
Change-Id: Id3c4ed80003cf9caecb8814ac7b03fabeb83c8bd
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-on: https://review.whamcloud.com/40572
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Wang Shilong <wshilong@whamcloud.com>
e2fsck/pass1.c

index b98b2f6..4e8d099 100644 (file)
@@ -1706,6 +1706,7 @@ void e2fsck_pass1_run(e2fsck_t ctx)
        int             inode_exp = 0;
        struct process_inode_block *inodes_to_process;
        int             process_inode_count, check_mmp;
+       e2fsck_t        global_ctx = ctx->global_ctx ? ctx->global_ctx : ctx;
 
        init_resource_track(&rtrack, ctx->fs->io);
        clear_problem_context(&pctx);
@@ -1857,14 +1858,11 @@ void e2fsck_pass1_run(e2fsck_t ctx)
                check_mmp = 0;
                e2fsck_pass1_check_lock(ctx);
 #ifdef CONFIG_PFSCK
-               if (!ctx->mmp_update_thread) {
+               if (!global_ctx->mmp_update_thread) {
                        e2fsck_pass1_block_map_w_lock(ctx);
-                       if (!ctx->mmp_update_thread) {
-                               if (ctx->global_ctx)
-                                       ctx->mmp_update_thread =
-                                               ctx->thread_info.et_thread_index + 1;
-                               else
-                                       ctx->mmp_update_thread = 1;
+                       if (!global_ctx->mmp_update_thread) {
+                               global_ctx->mmp_update_thread =
+                                       ctx->thread_info.et_thread_index + 1;
                                check_mmp = 1;
                        }
                        e2fsck_pass1_block_map_w_unlock(ctx);
@@ -1872,8 +1870,8 @@ void e2fsck_pass1_run(e2fsck_t ctx)
 
                /* only one active thread could update mmp block. */
                e2fsck_pass1_block_map_r_lock(ctx);
-               if (!ctx->global_ctx || ctx->mmp_update_thread ==
-                       (ctx->thread_info.et_thread_index + 1))
+               if (global_ctx->mmp_update_thread ==
+                   ctx->thread_info.et_thread_index + 1)
                        check_mmp = 1;
                e2fsck_pass1_block_map_r_unlock(ctx);
 #else
@@ -2632,8 +2630,8 @@ endit:
 #ifdef CONFIG_PFSCK
        /* reset update_thread after this thread exit */
        e2fsck_pass1_block_map_w_lock(ctx);
-       if (ctx->mmp_update_thread)
-               ctx->mmp_update_thread = 0;
+       if (check_mmp)
+               global_ctx->mmp_update_thread = 0;
        e2fsck_pass1_block_map_w_unlock(ctx);
 #endif
 }