linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Saranya Muruganandam <saranyamohan@google.com>
To: linux-ext4@vger.kernel.org, tytso@mit.edu
Cc: adilger.kernel@dilger.ca, Li Xi <lixi@ddn.com>,
	Wang Shilong <wshilong@ddn.com>,
	Saranya Muruganandam <saranyamohan@google.com>
Subject: [RFC PATCH v3 15/61] e2fsck: do not change global variables
Date: Wed, 18 Nov 2020 07:39:01 -0800	[thread overview]
Message-ID: <20201118153947.3394530-16-saranyamohan@google.com> (raw)
In-Reply-To: <20201118153947.3394530-1-saranyamohan@google.com>

From: Li Xi <lixi@ddn.com>

Global variables used in pass1 check are changed to local variables
in this patch. This will avoid conflict between threads.

Signed-off-by: Li Xi <lixi@ddn.com>
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Signed-off-by: Saranya Muruganandam <saranyamohan@google.com>
---
 e2fsck/pass1.c | 75 +++++++++++++++++++++++++++++++-------------------
 1 file changed, 47 insertions(+), 28 deletions(-)

diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c
index 9e4abad0..d4a2e707 100644
--- a/e2fsck/pass1.c
+++ b/e2fsck/pass1.c
@@ -86,7 +86,6 @@ static void alloc_bb_map(e2fsck_t ctx);
 static void alloc_imagic_map(e2fsck_t ctx);
 static void mark_inode_bad(e2fsck_t ctx, ino_t ino);
 static void handle_fs_bad_blocks(e2fsck_t ctx);
-static void process_inodes(e2fsck_t ctx, char *block_buf);
 static EXT2_QSORT_TYPE process_inode_cmp(const void *a, const void *b);
 static errcode_t scan_callback(ext2_filsys fs, ext2_inode_scan scan,
 				  dgrp_t group, void * priv_data);
@@ -121,15 +120,15 @@ struct process_inode_block {
 };
 
 struct scan_callback_struct {
-	e2fsck_t	ctx;
-	char		*block_buf;
+	e2fsck_t			 ctx;
+	char				*block_buf;
+	struct process_inode_block	*inodes_to_process;
+	int				*process_inode_count;
 };
 
-/*
- * For the inodes to process list.
- */
-static struct process_inode_block *inodes_to_process;
-static int process_inode_count;
+static void process_inodes(e2fsck_t ctx, char *block_buf,
+			   struct process_inode_block *inodes_to_process,
+			   int *process_inode_count);
 
 static __u64 ext2_max_sizes[EXT2_MAX_BLOCK_LOG_SIZE -
 			    EXT2_MIN_BLOCK_LOG_SIZE + 1];
@@ -1168,7 +1167,6 @@ static int e2fsck_should_abort(e2fsck_t ctx)
 void e2fsck_pass1_run(e2fsck_t ctx)
 {
 	int	i;
-	__u64	max_sizes;
 	ext2_filsys fs = ctx->fs;
 	ext2_ino_t	ino = 0;
 	struct ext2_inode *inode = NULL;
@@ -1191,6 +1189,8 @@ void e2fsck_pass1_run(e2fsck_t ctx)
 	ext2_ino_t	ino_threshold = 0;
 	dgrp_t		ra_group = 0;
 	struct ea_quota	ea_ibody_quota;
+	struct process_inode_block *inodes_to_process;
+	int		process_inode_count;
 
 	init_resource_track(&rtrack, ctx->fs->io);
 	clear_problem_context(&pctx);
@@ -1215,17 +1215,6 @@ void e2fsck_pass1_run(e2fsck_t ctx)
 	mtrace_print("Pass 1");
 #endif
 
-#define EXT2_BPP(bits) (1ULL << ((bits) - 2))
-
-	for (i = EXT2_MIN_BLOCK_LOG_SIZE; i <= EXT2_MAX_BLOCK_LOG_SIZE; i++) {
-		max_sizes = EXT2_NDIR_BLOCKS + EXT2_BPP(i);
-		max_sizes = max_sizes + EXT2_BPP(i) * EXT2_BPP(i);
-		max_sizes = max_sizes + EXT2_BPP(i) * EXT2_BPP(i) * EXT2_BPP(i);
-		max_sizes = (max_sizes * (1UL << i));
-		ext2_max_sizes[i - EXT2_MIN_BLOCK_LOG_SIZE] = max_sizes;
-	}
-#undef EXT2_BPP
-
 	imagic_fs = ext2fs_has_feature_imagic_inodes(sb);
 	extent_fs = ext2fs_has_feature_extents(sb);
 	inlinedata_fs = ext2fs_has_feature_inline_data(sb);
@@ -1349,6 +1338,8 @@ void e2fsck_pass1_run(e2fsck_t ctx)
 	ctx->stashed_inode = inode;
 	scan_struct.ctx = ctx;
 	scan_struct.block_buf = block_buf;
+	scan_struct.inodes_to_process = inodes_to_process;
+	scan_struct.process_inode_count = &process_inode_count;
 	ext2fs_set_inode_callback(scan, scan_callback, &scan_struct);
 	if (ctx->progress && ((ctx->progress)(ctx, 1, 0,
 					      ctx->fs->group_desc_count)))
@@ -1997,13 +1988,15 @@ void e2fsck_pass1_run(e2fsck_t ctx)
 			goto endit;
 
 		if (process_inode_count >= ctx->process_inode_size) {
-			process_inodes(ctx, block_buf);
+			process_inodes(ctx, block_buf, inodes_to_process,
+				       &process_inode_count);
 
 			if (e2fsck_should_abort(ctx))
 				goto endit;
 		}
 	}
-	process_inodes(ctx, block_buf);
+	process_inodes(ctx, block_buf, inodes_to_process,
+		       &process_inode_count);
 	ext2fs_close_inode_scan(scan);
 	scan = NULL;
 
@@ -2113,6 +2106,27 @@ endit:
 		ctx->invalid_bitmaps++;
 }
 
+static void init_ext2_max_sizes()
+{
+	int	i;
+	__u64	max_sizes;
+
+	/*
+	 * Init ext2_max_sizes which will be immutable and shared between
+	 * threads
+	 */
+#define EXT2_BPP(bits) (1ULL << ((bits) - 2))
+
+	for (i = EXT2_MIN_BLOCK_LOG_SIZE; i <= EXT2_MAX_BLOCK_LOG_SIZE; i++) {
+		max_sizes = EXT2_NDIR_BLOCKS + EXT2_BPP(i);
+		max_sizes = max_sizes + EXT2_BPP(i) * EXT2_BPP(i);
+		max_sizes = max_sizes + EXT2_BPP(i) * EXT2_BPP(i) * EXT2_BPP(i);
+		max_sizes = (max_sizes * (1UL << i));
+		ext2_max_sizes[i - EXT2_MIN_BLOCK_LOG_SIZE] = max_sizes;
+	}
+#undef EXT2_BPP
+}
+
 #ifdef CONFIG_PFSCK
 static errcode_t e2fsck_pass1_copy_bitmap(ext2_filsys fs, ext2fs_generic_bitmap *src,
 					  ext2fs_generic_bitmap *dest)
@@ -2656,6 +2670,7 @@ out_abort:
 void e2fsck_pass1(e2fsck_t ctx)
 {
 
+	init_ext2_max_sizes();
 #ifdef CONFIG_PFSCK
 	e2fsck_pass1_multithread(ctx);
 #else
@@ -2680,7 +2695,9 @@ static errcode_t scan_callback(ext2_filsys fs,
 	scan_struct = (struct scan_callback_struct *) priv_data;
 	ctx = scan_struct->ctx;
 
-	process_inodes((e2fsck_t) fs->priv_data, scan_struct->block_buf);
+	process_inodes((e2fsck_t) fs->priv_data, scan_struct->block_buf,
+		       scan_struct->inodes_to_process,
+		       scan_struct->process_inode_count);
 
 	if (ctx->progress)
 		if ((ctx->progress)(ctx, 1, group+1,
@@ -2706,7 +2723,9 @@ static errcode_t scan_callback(ext2_filsys fs,
 /*
  * Process the inodes in the "inodes to process" list.
  */
-static void process_inodes(e2fsck_t ctx, char *block_buf)
+static void process_inodes(e2fsck_t ctx, char *block_buf,
+			   struct process_inode_block *inodes_to_process,
+			   int *process_inode_count)
 {
 	int			i;
 	struct ext2_inode	*old_stashed_inode;
@@ -2718,15 +2737,15 @@ static void process_inodes(e2fsck_t ctx, char *block_buf)
 #if 0
 	printf("begin process_inodes: ");
 #endif
-	if (process_inode_count == 0)
+	if (*process_inode_count == 0)
 		return;
 	old_operation = ehandler_operation(0);
 	old_stashed_inode = ctx->stashed_inode;
 	old_stashed_ino = ctx->stashed_ino;
-	qsort(inodes_to_process, process_inode_count,
+	qsort(inodes_to_process, *process_inode_count,
 		      sizeof(struct process_inode_block), process_inode_cmp);
 	clear_problem_context(&pctx);
-	for (i=0; i < process_inode_count; i++) {
+	for (i=0; i < *process_inode_count; i++) {
 		pctx.inode = ctx->stashed_inode =
 			(struct ext2_inode *) &inodes_to_process[i].inode;
 		pctx.ino = ctx->stashed_ino = inodes_to_process[i].ino;
@@ -2744,7 +2763,7 @@ static void process_inodes(e2fsck_t ctx, char *block_buf)
 	}
 	ctx->stashed_inode = old_stashed_inode;
 	ctx->stashed_ino = old_stashed_ino;
-	process_inode_count = 0;
+	*process_inode_count = 0;
 #if 0
 	printf("end process inodes\n");
 #endif
-- 
2.29.2.299.gdc1121823c-goog


  parent reply	other threads:[~2020-11-18 15:40 UTC|newest]

Thread overview: 84+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-18 15:38 [RFC PATCH v3 00/61] Introduce parallel fsck to e2fsck pass1 Saranya Muruganandam
2020-11-18 15:38 ` [RFC PATCH v3 01/61] e2fsck: add -m option for multithread Saranya Muruganandam
2020-11-23 19:53   ` harshad shirwadkar
2020-11-23 21:28   ` Theodore Y. Ts'o
2020-11-18 15:38 ` [RFC PATCH v3 02/61] e2fsck: copy context when using multi-thread fsck Saranya Muruganandam
2020-11-23 19:55   ` harshad shirwadkar
2020-11-23 21:38   ` Theodore Y. Ts'o
2020-12-17 23:56   ` Darrick J. Wong
2020-12-18  1:13     ` Wang Shilong
2020-12-18  1:27       ` Darrick J. Wong
2020-11-18 15:38 ` [RFC PATCH v3 03/61] e2fsck: copy fs " Saranya Muruganandam
2020-11-23 22:12   ` Theodore Y. Ts'o
2020-11-18 15:38 ` [RFC PATCH v3 04/61] e2fsck: clear icache " Saranya Muruganandam
2020-11-23 22:27   ` Theodore Y. Ts'o
2020-11-18 15:38 ` [RFC PATCH v3 05/61] e2fsck: add assert when copying context Saranya Muruganandam
2020-11-18 15:38 ` [RFC PATCH v3 06/61] e2fsck: copy bitmaps " Saranya Muruganandam
2020-11-18 15:38 ` [RFC PATCH v3 07/61] e2fsck: copy badblocks when copying fs Saranya Muruganandam
2020-11-18 15:38 ` [RFC PATCH v3 08/61] e2fsck: open io-channel " Saranya Muruganandam
2020-11-23 22:38   ` Theodore Y. Ts'o
2020-11-24 14:17     ` Theodore Y. Ts'o
2020-11-18 15:38 ` [RFC PATCH v3 09/61] e2fsck: create logs for mult-threads Saranya Muruganandam
2020-11-23 23:05   ` Theodore Y. Ts'o
2020-11-18 15:38 ` [RFC PATCH v3 10/61] e2fsck: optionally configure one pfsck thread Saranya Muruganandam
2020-11-23 23:16   ` Theodore Y. Ts'o
2020-11-18 15:38 ` [RFC PATCH v3 11/61] e2fsck: add start/end group for thread Saranya Muruganandam
2020-11-18 15:38 ` [RFC PATCH v3 12/61] e2fsck: split groups to different threads Saranya Muruganandam
2020-11-18 15:38 ` [RFC PATCH v3 13/61] e2fsck: print thread log properly Saranya Muruganandam
2020-11-23 23:40   ` Theodore Y. Ts'o
2020-11-18 15:39 ` [RFC PATCH v3 14/61] e2fsck: merge bitmaps after thread completes Saranya Muruganandam
2020-11-24  2:00   ` Theodore Y. Ts'o
2020-11-18 15:39 ` Saranya Muruganandam [this message]
2020-11-18 15:39 ` [RFC PATCH v3 16/61] e2fsck: optimize the inserting of dir_info_db Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 17/61] e2fsck: merge dir_info after thread finishes Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 18/61] e2fsck: rbtree bitmap for dir Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 19/61] e2fsck: merge badblocks after thread finishes Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 20/61] e2fsck: merge icounts " Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 21/61] e2fsck: merge dblist " Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 22/61] e2fsck: add debug codes for multiple threads Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 23/61] e2fsck: merge counts after threads finish Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 24/61] e2fsck: merge fs flags when " Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 25/61] e2fsck: merge dx_dir_info after " Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 26/61] e2fsck: merge dirs_to_hash when " Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 27/61] e2fsck: merge context flags properly Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 28/61] e2fsck: merge quota context after threads finish Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 29/61] e2fsck: serialize fix operations Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 30/61] e2fsck: move some fixes out of parallel pthreads Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 31/61] e2fsck: split and merge invalid bitmaps Saranya Muruganandam
2020-12-18  0:05   ` Darrick J. Wong
2020-12-18  1:19     ` Wang Shilong
2020-11-18 15:39 ` [RFC PATCH v3 32/61] e2fsck: merge EA blocks properly Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 33/61] e2fsck: kickoff mutex lock for block found map Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 34/61] e2fsck: allow admin specify number of threads Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 35/61] e2fsck: adjust " Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 36/61] e2fsck: fix readahead for pfsck of pass1 Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 37/61] e2fsck: merge options after threads finish Saranya Muruganandam
2020-12-17 23:30   ` Darrick J. Wong
2020-11-18 15:39 ` [RFC PATCH v3 38/61] e2fsck: reset lost_and_found " Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 39/61] e2fsck: merge extent depth count " Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 40/61] e2fsck: simplify e2fsck context merging codes Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 41/61] e2fsck: set E2F_FLAG_ALLOC_OK after threads Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 42/61] e2fsck: wait fix thread finish before checking Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 43/61] e2fsck: cleanup e2fsck_pass1_thread_join() Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 44/61] e2fsck: avoid too much memory allocation for pfsck Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 45/61] e2fsck: make default smallest RA size to 1M Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 46/61] ext2fs: parallel bitmap loading Saranya Muruganandam
2020-11-24  2:44   ` Theodore Y. Ts'o
2020-11-18 15:39 ` [RFC PATCH v3 47/61] e2fsck: update mmp block in one thread Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 48/61] e2fsck: reset @inodes_to_rebuild if restart Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 49/61] e2fsck: fix build for make rpm Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 50/61] e2fsck: move ext2fs_get_avg_group to rw_bitmaps.c Saranya Muruganandam
2020-11-24  2:12   ` Theodore Y. Ts'o
2020-11-18 15:39 ` [RFC PATCH v3 51/61] configure: enable pfsck by default Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 53/61] e2fsck: fix f_multithread_ok test Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 54/61] e2fsck: fix race in ext2fs_read_bitmaps() Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 55/61] e2fsck: fix readahead for pass1 without pfsck Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 56/61] e2fsck: fix memory leaks with pfsck enabled Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 57/61] ext2fs: fix to set tail flags " Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 58/61] e2fsck: misc cleanups for pfsck Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 59/61] e2fsck: update mmp block race Saranya Muruganandam
2020-11-18 15:39 ` [RFC PATCH v3 60/61] e2fsck: propagate number of threads Saranya Muruganandam
2020-11-24  3:56   ` Theodore Y. Ts'o
2020-11-18 15:39 ` [RFC PATCH v3 61/61] e2fsck: Annotating fields in e2fsck_struct Saranya Muruganandam
2020-11-19 15:58 ` [RFC PATCH v3 00/61] Introduce parallel fsck to e2fsck pass1 Theodore Y. Ts'o
2020-11-23 21:25 ` Theodore Y. Ts'o

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201118153947.3394530-16-saranyamohan@google.com \
    --to=saranyamohan@google.com \
    --cc=adilger.kernel@dilger.ca \
    --cc=linux-ext4@vger.kernel.org \
    --cc=lixi@ddn.com \
    --cc=tytso@mit.edu \
    --cc=wshilong@ddn.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).