From 7284939c5761844ef0da56b4853650010683f828 Mon Sep 17 00:00:00 2001 From: Wang Shilong Date: Wed, 23 Sep 2020 22:36:41 +0800 Subject: [PATCH] LU-8465 e2fsck: update mmp block in one thread For multiple threads, different threads will try to update mmp block at the same time, only allow one thread to update it. Signed-off-by: Wang Shilong Change-Id: Iee824dc7473b8af79f4c385204e109644fcc738c Reviewed-on: https://review.whamcloud.com/39874 Reviewed-by: Andreas Dilger Tested-by: Andreas Dilger --- e2fsck/e2fsck.h | 1 + e2fsck/pass1.c | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/e2fsck/e2fsck.h b/e2fsck/e2fsck.h index 2680780..31c7fa4 100644 --- a/e2fsck/e2fsck.h +++ b/e2fsck/e2fsck.h @@ -499,6 +499,7 @@ struct e2fsck_struct { __u32 extent_depth_count[MAX_EXTENT_DEPTH_COUNT]; #ifdef CONFIG_PFSCK __u32 fs_num_threads; + __u32 mmp_update_thread; int fs_need_locking; /* serialize fix operation for multiple threads */ pthread_rwlock_t fs_fix_rwlock; diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c index 4a49a60..1402b5d 100644 --- a/e2fsck/pass1.c +++ b/e2fsck/pass1.c @@ -1702,7 +1702,7 @@ void e2fsck_pass1_run(e2fsck_t ctx) struct ea_quota ea_ibody_quota; int inode_exp = 0; struct process_inode_block *inodes_to_process; - int process_inode_count; + int process_inode_count, check_mmp; init_resource_track(&rtrack, ctx->fs->io); clear_problem_context(&pctx); @@ -1851,8 +1851,33 @@ void e2fsck_pass1_run(e2fsck_t ctx) #endif while (1) { + check_mmp = 0; e2fsck_pass1_check_lock(ctx); - if (ino % (fs->super->s_inodes_per_group * 4) == 1) { +#ifdef CONFIG_PFSCK + if (!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; + check_mmp = 1; + } + e2fsck_pass1_block_map_w_unlock(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)) + check_mmp = 1; + e2fsck_pass1_block_map_r_unlock(ctx); +#else + check_mmp = 1; +#endif + + if (check_mmp && (ino % (fs->super->s_inodes_per_group * 4) == 1)) { if (e2fsck_mmp_update(fs)) fatal_error(ctx, 0); } @@ -2601,6 +2626,13 @@ endit: print_resource_track(ctx, _("Pass 1"), &rtrack, ctx->fs->io); else ctx->invalid_bitmaps++; +#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; + e2fsck_pass1_block_map_w_unlock(ctx); +#endif } #ifdef CONFIG_PFSCK -- 1.8.3.1