From: Wang Shilong <wshilong@xxxxxxx> 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 <wshilong@xxxxxxx> Signed-off-by: Saranya Muruganandam <saranyamohan@xxxxxxxxxx> --- 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 a66772c1..1469c3e1 100644 --- a/e2fsck/e2fsck.h +++ b/e2fsck/e2fsck.h @@ -451,6 +451,7 @@ struct e2fsck_struct { char *undo_file; #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 60f70111..e98cda9f 100644 --- a/e2fsck/pass1.c +++ b/e2fsck/pass1.c @@ -1497,7 +1497,7 @@ void e2fsck_pass1_run(e2fsck_t ctx) dgrp_t ra_group = 0; struct ea_quota ea_ibody_quota; 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); @@ -1646,8 +1646,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); } @@ -2365,6 +2390,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 -- 2.29.2.299.gdc1121823c-goog