diff mbox series

[RFC,v3,59/61] e2fsck: update mmp block race

Message ID 20201118153947.3394530-60-saranyamohan@google.com
State New
Headers show
Series Introduce parallel fsck to e2fsck pass1 | expand

Commit Message

Saranya Muruganandam Nov. 18, 2020, 3:39 p.m. UTC
From: Wang Shilong <wshilong@ddn.com>

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.

Signed-off-by: Wang Shilong <wshilong@ddn.com>
Signed-off-by: Saranya Muruganandam <saranyamohan@google.com>
---
 e2fsck/pass1.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c
index 8d4e2675..a51fe20f 100644
--- a/e2fsck/pass1.c
+++ b/e2fsck/pass1.c
@@ -1501,6 +1501,7 @@  void e2fsck_pass1_run(e2fsck_t ctx)
 	struct ea_quota	ea_ibody_quota;
 	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);
@@ -1652,14 +1653,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);
@@ -1667,8 +1665,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
@@ -2396,8 +2394,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
 }