From: Saranya Muruganandam <saranyamohan@google.com>
To: linux-ext4@vger.kernel.org, tytso@mit.edu
Cc: adilger.kernel@dilger.ca, Wang Shilong <wshilong@ddn.com>,
Saranya Muruganandam <saranyamohan@google.com>
Subject: [RFC PATCH v3 30/61] e2fsck: move some fixes out of parallel pthreads
Date: Wed, 18 Nov 2020 07:39:16 -0800 [thread overview]
Message-ID: <20201118153947.3394530-31-saranyamohan@google.com> (raw)
In-Reply-To: <20201118153947.3394530-1-saranyamohan@google.com>
From: Wang Shilong <wshilong@ddn.com>
We could only use @found_map_block to find free blocks
after we have collectd all used blocks, so something like
handle_fs_bad_blocks(), ext2fs_create_resize_inode(),
e2fsck_pass1_dupblocks() really should be handled after
all threads has been finished.
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Signed-off-by: Saranya Muruganandam <saranyamohan@google.com>
---
e2fsck/e2fsck.h | 4 +
e2fsck/pass1.c | 306 ++++++++++++++++-----------
e2fsck/util.c | 36 +++-
tests/f_multithread/expect.1 | 2 +-
tests/f_multithread_logfile/expect.1 | 2 +-
tests/f_multithread_no/expect.1 | 2 +-
6 files changed, 216 insertions(+), 136 deletions(-)
diff --git a/e2fsck/e2fsck.h b/e2fsck/e2fsck.h
index 777d8b96..fecc8bbf 100644
--- a/e2fsck/e2fsck.h
+++ b/e2fsck/e2fsck.h
@@ -450,6 +450,8 @@ struct e2fsck_struct {
#ifdef CONFIG_PFSCK
/* serialize fix operation for multiple threads */
pthread_mutex_t fs_fix_mutex;
+ /* protect block_found_map, block_dup_map */
+ pthread_mutex_t fs_block_map_mutex;
#endif
};
@@ -750,6 +752,8 @@ extern errcode_t e2fsck_allocate_subcluster_bitmap(ext2_filsys fs,
unsigned long long get_memory_size(void);
extern void e2fsck_pass1_fix_lock(e2fsck_t ctx);
extern void e2fsck_pass1_fix_unlock(e2fsck_t ctx);
+extern void e2fsck_pass1_block_map_lock(e2fsck_t ctx);
+extern void e2fsck_pass1_block_map_unlock(e2fsck_t ctx);
/* unix.c */
extern void e2fsck_clear_progbar(e2fsck_t ctx);
diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c
index 594571a7..49bdba21 100644
--- a/e2fsck/pass1.c
+++ b/e2fsck/pass1.c
@@ -750,11 +750,15 @@ static void check_is_really_dir(e2fsck_t ctx, struct problem_context *pctx,
if (i >= 4)
not_device++;
+ e2fsck_pass1_block_map_lock(ctx);
if (blk < ctx->fs->super->s_first_data_block ||
blk >= ext2fs_blocks_count(ctx->fs->super) ||
ext2fs_fast_test_block_bitmap2(ctx->block_found_map,
- blk))
+ blk)) {
+ e2fsck_pass1_block_map_unlock(ctx);
return; /* Invalid block, can't be dir */
+ }
+ e2fsck_pass1_block_map_unlock(ctx);
}
blk = inode->i_block[0];
}
@@ -888,19 +892,15 @@ static void reserve_block_for_root_repair(e2fsck_t ctx)
errcode_t err;
ext2_filsys fs = ctx->fs;
- e2fsck_pass1_fix_lock(ctx);
ctx->root_repair_block = 0;
if (ext2fs_test_inode_bitmap2(ctx->inode_used_map, EXT2_ROOT_INO))
- goto out;
+ return;
err = ext2fs_new_block2(fs, 0, ctx->block_found_map, &blk);
if (err)
- goto out;
+ return;
ext2fs_mark_block_bitmap2(ctx->block_found_map, blk);
ctx->root_repair_block = blk;
-out:
- e2fsck_pass1_fix_unlock(ctx);
- return;
}
static void reserve_block_for_lnf_repair(e2fsck_t ctx)
@@ -911,18 +911,15 @@ static void reserve_block_for_lnf_repair(e2fsck_t ctx)
static const char name[] = "lost+found";
ext2_ino_t ino;
- e2fsck_pass1_fix_lock(ctx);
ctx->lnf_repair_block = 0;
if (!ext2fs_lookup(fs, EXT2_ROOT_INO, name, sizeof(name)-1, 0, &ino))
- goto out;
+ return;
err = ext2fs_new_block2(fs, 0, ctx->block_found_map, &blk);
if (err)
- goto out;
+ return;
ext2fs_mark_block_bitmap2(ctx->block_found_map, blk);
ctx->lnf_repair_block = blk;
-out:
- e2fsck_pass1_fix_unlock(ctx);
return;
}
@@ -1177,6 +1174,118 @@ static int e2fsck_should_abort(e2fsck_t ctx)
return 0;
}
+/*
+ * We need call mark_table_blocks() before multiple
+ * thread start, since all known system blocks should be
+ * marked and checked later.
+ */
+static errcode_t e2fsck_pass1_prepare(e2fsck_t ctx)
+{
+ struct problem_context pctx;
+ ext2_filsys fs = ctx->fs;
+
+ clear_problem_context(&pctx);
+ if (!(ctx->options & E2F_OPT_PREEN))
+ fix_problem(ctx, PR_1_PASS_HEADER, &pctx);
+
+ pctx.errcode = e2fsck_allocate_subcluster_bitmap(ctx->fs,
+ _("in-use block map"), EXT2FS_BMAP64_RBTREE,
+ "block_found_map", &ctx->block_found_map);
+ if (pctx.errcode) {
+ pctx.num = 1;
+ fix_problem(ctx, PR_1_ALLOCATE_BBITMAP_ERROR, &pctx);
+ ctx->flags |= E2F_FLAG_ABORT;
+ return pctx.errcode;
+ }
+ pctx.errcode = e2fsck_allocate_block_bitmap(ctx->fs,
+ _("metadata block map"), EXT2FS_BMAP64_RBTREE,
+ "block_metadata_map", &ctx->block_metadata_map);
+ if (pctx.errcode) {
+ pctx.num = 1;
+ fix_problem(ctx, PR_1_ALLOCATE_BBITMAP_ERROR, &pctx);
+ ctx->flags |= E2F_FLAG_ABORT;
+ return pctx.errcode;
+ }
+
+ mark_table_blocks(ctx);
+ pctx.errcode = ext2fs_convert_subcluster_bitmap(ctx->fs,
+ &ctx->block_found_map);
+ if (pctx.errcode) {
+ fix_problem(ctx, PR_1_CONVERT_SUBCLUSTER, &pctx);
+ ctx->flags |= E2F_FLAG_ABORT;
+ return pctx.errcode;
+ }
+
+ if (ext2fs_has_feature_mmp(fs->super) &&
+ fs->super->s_mmp_block > fs->super->s_first_data_block &&
+ fs->super->s_mmp_block < ext2fs_blocks_count(fs->super))
+ ext2fs_mark_block_bitmap2(ctx->block_found_map,
+ fs->super->s_mmp_block);
+
+ return 0;
+}
+
+static void e2fsck_pass1_post(e2fsck_t ctx)
+{
+ struct problem_context pctx;
+ ext2_filsys fs = ctx->fs;
+ char *block_buf;
+
+ reserve_block_for_root_repair(ctx);
+ reserve_block_for_lnf_repair(ctx);
+
+ if (ctx->invalid_bitmaps)
+ handle_fs_bad_blocks(ctx);
+
+ if (ctx->flags & E2F_FLAG_RESIZE_INODE) {
+ struct ext2_inode *inode;
+ int inode_size = EXT2_INODE_SIZE(fs->super);
+ inode = e2fsck_allocate_memory(ctx, inode_size,
+ "scratch inode");
+
+ clear_problem_context(&pctx);
+ pctx.errcode = ext2fs_create_resize_inode(fs);
+ if (pctx.errcode) {
+ if (!fix_problem(ctx, PR_1_RESIZE_INODE_CREATE,
+ &pctx)) {
+ ctx->flags |= E2F_FLAG_ABORT;
+ ext2fs_free_mem(&inode);
+ ext2fs_free_mem(&block_buf);
+ return;
+ }
+ pctx.errcode = 0;
+ }
+ if (!pctx.errcode) {
+ e2fsck_read_inode(ctx, EXT2_RESIZE_INO, inode,
+ "recreate inode");
+ inode->i_mtime = ctx->now;
+ e2fsck_write_inode(ctx, EXT2_RESIZE_INO, inode,
+ "recreate inode");
+ }
+ ctx->flags &= ~E2F_FLAG_RESIZE_INODE;
+ ext2fs_free_mem(&inode);
+ }
+
+ if (ctx->flags & E2F_FLAG_RESTART) {
+ ext2fs_free_mem(&block_buf);
+ return;
+ }
+
+ if (ctx->block_dup_map) {
+ if (ctx->options & E2F_OPT_PREEN) {
+ clear_problem_context(&pctx);
+ fix_problem(ctx, PR_1_DUP_BLOCKS_PREENSTOP, &pctx);
+ }
+ block_buf =
+ (char *)e2fsck_allocate_memory(ctx,
+ ctx->fs->blocksize * 3,
+ "block interate buffer");
+ e2fsck_pass1_dupblocks(ctx, block_buf);
+ ext2fs_free_mem(&block_buf);
+ }
+}
+
+
void e2fsck_pass1_run(e2fsck_t ctx)
{
int i;
@@ -1215,9 +1324,6 @@ void e2fsck_pass1_run(e2fsck_t ctx)
ctx->readahead_kb = e2fsck_guess_readahead(ctx->fs);
pass1_readahead(ctx, &ra_group, &ino_threshold);
- if (!(ctx->options & E2F_OPT_PREEN))
- fix_problem(ctx, PR_1_PASS_HEADER, &pctx);
-
if (ext2fs_has_feature_dir_index(fs->super) &&
!(ctx->options & E2F_OPT_NO)) {
if (ext2fs_u32_list_create(&ctx->dirs_to_hash, 50))
@@ -1266,24 +1372,6 @@ void e2fsck_pass1_run(e2fsck_t ctx)
ctx->flags |= E2F_FLAG_ABORT;
return;
}
- pctx.errcode = e2fsck_allocate_subcluster_bitmap(fs,
- _("in-use block map"), EXT2FS_BMAP64_RBTREE,
- "block_found_map", &ctx->block_found_map);
- if (pctx.errcode) {
- pctx.num = 1;
- fix_problem(ctx, PR_1_ALLOCATE_BBITMAP_ERROR, &pctx);
- ctx->flags |= E2F_FLAG_ABORT;
- return;
- }
- pctx.errcode = e2fsck_allocate_block_bitmap(fs,
- _("metadata block map"), EXT2FS_BMAP64_RBTREE,
- "block_metadata_map", &ctx->block_metadata_map);
- if (pctx.errcode) {
- pctx.num = 1;
- fix_problem(ctx, PR_1_ALLOCATE_BBITMAP_ERROR, &pctx);
- ctx->flags |= E2F_FLAG_ABORT;
- return;
- }
pctx.errcode = e2fsck_setup_icount(ctx, "inode_link_info", 0, NULL,
&ctx->inode_link_info);
if (pctx.errcode) {
@@ -1325,14 +1413,6 @@ void e2fsck_pass1_run(e2fsck_t ctx)
}
}
- mark_table_blocks(ctx);
- pctx.errcode = ext2fs_convert_subcluster_bitmap(fs,
- &ctx->block_found_map);
- if (pctx.errcode) {
- fix_problem(ctx, PR_1_CONVERT_SUBCLUSTER, &pctx);
- ctx->flags |= E2F_FLAG_ABORT;
- goto endit;
- }
block_buf = (char *) e2fsck_allocate_memory(ctx, fs->blocksize * 3,
"block interate buffer");
if (EXT2_INODE_SIZE(fs->super) == EXT2_GOOD_OLD_INODE_SIZE)
@@ -1366,12 +1446,6 @@ void e2fsck_pass1_run(e2fsck_t ctx)
fs->super->s_mkfs_time < fs->super->s_inodes_count))
low_dtime_check = 0;
- if (ext2fs_has_feature_mmp(fs->super) &&
- fs->super->s_mmp_block > fs->super->s_first_data_block &&
- fs->super->s_mmp_block < ext2fs_blocks_count(fs->super))
- ext2fs_mark_block_bitmap2(ctx->block_found_map,
- fs->super->s_mmp_block);
-
/* Set up ctx->lost_and_found if possible */
(void) e2fsck_get_lost_and_found(ctx, 0);
@@ -1701,8 +1775,10 @@ void e2fsck_pass1_run(e2fsck_t ctx)
failed_csum = 0;
}
+ e2fsck_pass1_block_map_lock(ctx);
pctx.errcode = ext2fs_copy_bitmap(ctx->block_found_map,
&pb.fs_meta_blocks);
+ e2fsck_pass1_block_map_unlock(ctx);
if (pctx.errcode) {
pctx.num = 4;
fix_problem(ctx, PR_1_ALLOCATE_BBITMAP_ERROR, &pctx);
@@ -2018,9 +2094,6 @@ void e2fsck_pass1_run(e2fsck_t ctx)
ext2fs_close_inode_scan(scan);
scan = NULL;
- reserve_block_for_root_repair(ctx);
- reserve_block_for_lnf_repair(ctx);
-
/*
* If any extended attribute blocks' reference counts need to
* be adjusted, either up (ctx->refcount_extra), or down
@@ -2048,11 +2121,6 @@ void e2fsck_pass1_run(e2fsck_t ctx)
ctx->ea_block_quota_inodes = 0;
}
- if (ctx->invalid_bitmaps) {
- e2fsck_pass1_fix_lock(ctx);
- handle_fs_bad_blocks(ctx);
- e2fsck_pass1_fix_unlock(ctx);
- }
/* We don't need the block_ea_map any more */
if (ctx->block_ea_map) {
@@ -2063,29 +2131,6 @@ void e2fsck_pass1_run(e2fsck_t ctx)
/* We don't need the encryption policy => ID map any more */
destroy_encryption_policy_map(ctx);
- if (ctx->flags & E2F_FLAG_RESIZE_INODE) {
- clear_problem_context(&pctx);
- e2fsck_pass1_fix_lock(ctx);
- pctx.errcode = ext2fs_create_resize_inode(fs);
- e2fsck_pass1_fix_unlock(ctx);
- if (pctx.errcode) {
- if (!fix_problem(ctx, PR_1_RESIZE_INODE_CREATE,
- &pctx)) {
- ctx->flags |= E2F_FLAG_ABORT;
- goto endit;
- }
- pctx.errcode = 0;
- }
- if (!pctx.errcode) {
- e2fsck_read_inode(ctx, EXT2_RESIZE_INO, inode,
- "recreate inode");
- inode->i_mtime = ctx->now;
- e2fsck_write_inode(ctx, EXT2_RESIZE_INO, inode,
- "recreate inode");
- }
- ctx->flags &= ~E2F_FLAG_RESIZE_INODE;
- }
-
if (ctx->flags & E2F_FLAG_RESTART) {
/*
* Only the master copy of the superblock and block
@@ -2097,13 +2142,6 @@ void e2fsck_pass1_run(e2fsck_t ctx)
goto endit;
}
- if (ctx->block_dup_map) {
- if (ctx->options & E2F_OPT_PREEN) {
- clear_problem_context(&pctx);
- fix_problem(ctx, PR_1_DUP_BLOCKS_PREENSTOP, &pctx);
- }
- e2fsck_pass1_dupblocks(ctx, block_buf);
- }
ctx->flags |= E2F_FLAG_ALLOC_OK;
endit:
e2fsck_use_inode_shortcuts(ctx, 0);
@@ -2358,10 +2396,10 @@ static errcode_t e2fsck_pass1_thread_prepare(e2fsck_t global_ctx, e2fsck_t *thre
assert(global_ctx->inode_reg_map == NULL);
assert(global_ctx->inodes_to_rebuild == NULL);
- assert(global_ctx->block_found_map == NULL);
+ assert(global_ctx->block_found_map != NULL);
+ assert(global_ctx->block_metadata_map != NULL);
assert(global_ctx->block_dup_map == NULL);
assert(global_ctx->block_ea_map == NULL);
- assert(global_ctx->block_metadata_map == NULL);
assert(global_ctx->fs->dblist == NULL);
retval = ext2fs_get_mem(sizeof(struct e2fsck_struct), &thread_context);
@@ -2525,10 +2563,8 @@ static int e2fsck_pass1_thread_join_one(e2fsck_t global_ctx, e2fsck_t thread_ctx
ext2fs_inode_bitmap inode_bb_map = global_ctx->inode_bb_map;
ext2fs_inode_bitmap inode_imagic_map = global_ctx->inode_imagic_map;
ext2fs_inode_bitmap inode_reg_map = global_ctx->inode_reg_map;
- ext2fs_block_bitmap block_found_map = global_ctx->block_found_map;
ext2fs_block_bitmap block_dup_map = global_ctx->block_dup_map;
ext2fs_block_bitmap block_ea_map = global_ctx->block_ea_map;
- ext2fs_block_bitmap block_metadata_map = global_ctx->block_metadata_map;
ext2fs_block_bitmap inodes_to_rebuild = global_ctx->inodes_to_rebuild;
ext2_icount_t inode_count = global_ctx->inode_count;
ext2_icount_t inode_link_info = global_ctx->inode_link_info;
@@ -2571,10 +2607,8 @@ static int e2fsck_pass1_thread_join_one(e2fsck_t global_ctx, e2fsck_t thread_ctx
global_ctx->inode_imagic_map = inode_imagic_map;
global_ctx->inodes_to_rebuild = inodes_to_rebuild;
global_ctx->inode_reg_map = inode_reg_map;
- global_ctx->block_found_map = block_found_map;
- global_ctx->block_dup_map = block_dup_map;
global_ctx->block_ea_map = block_ea_map;
- global_ctx->block_metadata_map = block_metadata_map;
+ global_ctx->block_dup_map = block_dup_map;
global_ctx->dir_info = dir_info;
e2fsck_pass1_merge_dir_info(global_ctx, thread_ctx);
global_ctx->dx_dir_info = dx_dir_info;
@@ -2670,26 +2704,11 @@ static int e2fsck_pass1_thread_join_one(e2fsck_t global_ctx, e2fsck_t thread_ctx
&global_ctx->inodes_to_rebuild);
if (retval)
return retval;
- retval = e2fsck_pass1_merge_bitmap(global_fs,
- &thread_ctx->block_found_map,
- &global_ctx->block_found_map);
- if (retval)
- return retval;
- retval = e2fsck_pass1_merge_bitmap(global_fs,
- &thread_ctx->block_dup_map,
- &global_ctx->block_dup_map);
- if (retval)
- return retval;
retval = e2fsck_pass1_merge_bitmap(global_fs,
&thread_ctx->block_ea_map,
&global_ctx->block_ea_map);
if (retval)
return retval;
- retval = e2fsck_pass1_merge_bitmap(global_fs,
- &thread_ctx->block_metadata_map,
- &global_ctx->block_metadata_map);
- if (retval)
- return retval;
return 0;
}
@@ -2713,10 +2732,7 @@ static int e2fsck_pass1_thread_join(e2fsck_t global_ctx, e2fsck_t thread_ctx)
e2fsck_pass1_free_bitmap(&thread_ctx->inode_imagic_map);
e2fsck_pass1_free_bitmap(&thread_ctx->inode_reg_map);
e2fsck_pass1_free_bitmap(&thread_ctx->inodes_to_rebuild);
- e2fsck_pass1_free_bitmap(&thread_ctx->block_found_map);
- e2fsck_pass1_free_bitmap(&thread_ctx->block_dup_map);
e2fsck_pass1_free_bitmap(&thread_ctx->block_ea_map);
- e2fsck_pass1_free_bitmap(&thread_ctx->block_metadata_map);
e2fsck_free_dir_info(thread_ctx);
ext2fs_free_icount(thread_ctx->inode_count);
ext2fs_free_icount(thread_ctx->inode_link_info);
@@ -2897,6 +2913,7 @@ static void e2fsck_pass1_multithread(e2fsck_t global_ctx)
errcode_t retval;
pthread_mutex_init(&global_ctx->fs_fix_mutex, NULL);
+ pthread_mutex_init(&global_ctx->fs_block_map_mutex, NULL);
retval = e2fsck_pass1_threads_start(&infos, num_threads, global_ctx);
if (retval) {
com_err(global_ctx->program_name, retval,
@@ -2948,17 +2965,25 @@ static int multiple_threads_supported(e2fsck_t ctx)
void e2fsck_pass1(e2fsck_t ctx)
{
+ errcode_t retval;
+ int multiple = 0;
init_ext2_max_sizes();
+ retval = e2fsck_pass1_prepare(ctx);
+ if (retval)
+ return;
#ifdef CONFIG_PFSCK
if (multiple_threads_supported(ctx)) {
+ multiple = 1;
e2fsck_pass1_multithread(ctx);
- return;
+ } else {
+ fprintf(stderr, "Fall through single thread for pass1 "
+ "because tdb could not handle properly\n");
}
- fprintf(stderr, "Fall through single thread for pass1 "
- "because tdb could not handle properly\n");
#endif
- e2fsck_pass1_run(ctx);
+ if (!multiple)
+ e2fsck_pass1_run(ctx);
+ e2fsck_pass1_post(ctx);
}
#undef FINISH_INODE_LOOP
@@ -3147,9 +3172,14 @@ static void alloc_imagic_map(e2fsck_t ctx)
* WARNING: Assumes checks have already been done to make sure block
* is valid. This is true in both process_block and process_bad_block.
*/
-static _INLINE_ void mark_block_used(e2fsck_t ctx, blk64_t block)
+static _INLINE_ void mark_block_used_unlocked(e2fsck_t ctx, blk64_t block)
{
- struct problem_context pctx;
+ struct problem_context pctx;
+ e2fsck_t global_ctx;
+
+ global_ctx = ctx->global_ctx;
+ if (!global_ctx)
+ global_ctx = ctx;
clear_problem_context(&pctx);
@@ -3158,11 +3188,15 @@ static _INLINE_ void mark_block_used(e2fsck_t ctx, blk64_t block)
!(ctx->options & E2F_OPT_UNSHARE_BLOCKS)) {
return;
}
- if (!ctx->block_dup_map) {
+ /**
+ * this should be safe because this operation has
+ * been serialized by mutex.
+ */
+ if (!global_ctx->block_dup_map) {
pctx.errcode = e2fsck_allocate_block_bitmap(ctx->fs,
_("multiply claimed block map"),
EXT2FS_BMAP64_RBTREE, "block_dup_map",
- &ctx->block_dup_map);
+ &global_ctx->block_dup_map);
if (pctx.errcode) {
pctx.num = 3;
fix_problem(ctx, PR_1_ALLOCATE_BBITMAP_ERROR,
@@ -3172,12 +3206,20 @@ static _INLINE_ void mark_block_used(e2fsck_t ctx, blk64_t block)
return;
}
}
- ext2fs_fast_mark_block_bitmap2(ctx->block_dup_map, block);
+ ext2fs_fast_mark_block_bitmap2(global_ctx->block_dup_map, block);
} else {
ext2fs_fast_mark_block_bitmap2(ctx->block_found_map, block);
}
}
+static _INLINE_ void mark_block_used(e2fsck_t ctx, blk64_t block)
+{
+ e2fsck_pass1_block_map_lock(ctx);
+ mark_block_used_unlocked(ctx, block);
+ e2fsck_pass1_block_map_unlock(ctx);
+
+}
+
/*
* When cluster size is greater than one block, it is caller's responsibility
* to make sure block parameter starts at a cluster boundary.
@@ -3185,14 +3227,16 @@ static _INLINE_ void mark_block_used(e2fsck_t ctx, blk64_t block)
static _INLINE_ void mark_blocks_used(e2fsck_t ctx, blk64_t block,
unsigned int num)
{
- if (ext2fs_test_block_bitmap_range2(ctx->block_found_map, block, num))
+ e2fsck_pass1_block_map_lock(ctx);
+ if (ext2fs_test_block_bitmap_range2(ctx->block_found_map, block, num)) {
ext2fs_mark_block_bitmap_range2(ctx->block_found_map, block, num);
- else {
+ } else {
unsigned int i;
for (i = 0; i < num; i += EXT2FS_CLUSTER_RATIO(ctx->fs))
- mark_block_used(ctx, block + i);
+ mark_block_used_unlocked(ctx, block + i);
}
+ e2fsck_pass1_block_map_unlock(ctx);
}
static errcode_t _INLINE_ e2fsck_write_ext_attr3(e2fsck_t ctx, blk64_t block,
@@ -4759,10 +4803,12 @@ static int process_bad_block(ext2_filsys fs,
}
if (blockcnt < 0) {
+ e2fsck_pass1_block_map_lock(ctx);
if (ext2fs_test_block_bitmap2(p->fs_meta_blocks, blk)) {
p->bbcheck = 1;
if (fix_problem(ctx, PR_1_BB_FS_BLOCK, pctx)) {
*block_nr = 0;
+ e2fsck_pass1_block_map_unlock(ctx);
return BLOCK_CHANGED;
}
} else if (ext2fs_test_block_bitmap2(ctx->block_found_map,
@@ -4771,12 +4817,17 @@ static int process_bad_block(ext2_filsys fs,
if (fix_problem(ctx, PR_1_BBINODE_BAD_METABLOCK,
pctx)) {
*block_nr = 0;
+ e2fsck_pass1_block_map_unlock(ctx);
return BLOCK_CHANGED;
}
- if (e2fsck_should_abort(ctx))
+ if (e2fsck_should_abort(ctx)) {
+ e2fsck_pass1_block_map_unlock(ctx);
return BLOCK_ABORT;
- } else
- mark_block_used(ctx, blk);
+ }
+ } else {
+ mark_block_used_unlocked(ctx, blk);
+ }
+ e2fsck_pass1_block_map_unlock(ctx);
return 0;
}
#if 0
@@ -4789,10 +4840,13 @@ static int process_bad_block(ext2_filsys fs,
* there's an overlap between the filesystem table blocks
* (bitmaps and inode table) and the bad block list.
*/
+ e2fsck_pass1_block_map_lock(ctx);
if (!ext2fs_test_block_bitmap2(ctx->block_found_map, blk)) {
ext2fs_mark_block_bitmap2(ctx->block_found_map, blk);
+ e2fsck_pass1_block_map_unlock(ctx);
return 0;
}
+ e2fsck_pass1_block_map_unlock(ctx);
/*
* Try to find the where the filesystem block was used...
*/
@@ -4947,6 +5001,7 @@ static void new_table_block(e2fsck_t ctx, blk64_t first_block, dgrp_t group,
fix_problem(ctx, (old_block ? PR_1_RELOC_FROM_TO :
PR_1_RELOC_TO), &pctx);
pctx.blk2 = 0;
+ e2fsck_pass1_block_map_lock(ctx);
for (i = 0; i < num; i++) {
pctx.blk = i;
ext2fs_mark_block_bitmap2(ctx->block_found_map, (*new_block)+i);
@@ -4967,6 +5022,7 @@ static void new_table_block(e2fsck_t ctx, blk64_t first_block, dgrp_t group,
if (pctx.errcode)
fix_problem(ctx, PR_1_RELOC_WRITE_ERR, &pctx);
}
+ e2fsck_pass1_block_map_unlock(ctx);
ext2fs_free_mem(&buf);
}
diff --git a/e2fsck/util.c b/e2fsck/util.c
index 8eec477c..3dcfa86a 100644
--- a/e2fsck/util.c
+++ b/e2fsck/util.c
@@ -570,23 +570,34 @@ void e2fsck_read_inode_full(e2fsck_t ctx, unsigned long ino,
}
#ifdef CONFIG_PFSCK
+#define e2fsck_get_lock_context(ctx) \
+ e2fsck_t global_ctx = ctx->global_ctx; \
+ if (!global_ctx) \
+ global_ctx = ctx; \
+
void e2fsck_pass1_fix_lock(e2fsck_t ctx)
{
- e2fsck_t global_ctx = ctx->global_ctx;
- if (!global_ctx)
- global_ctx = ctx;
-
+ e2fsck_get_lock_context(ctx);
pthread_mutex_lock(&global_ctx->fs_fix_mutex);
}
void e2fsck_pass1_fix_unlock(e2fsck_t ctx)
{
- e2fsck_t global_ctx = ctx->global_ctx;
- if (!global_ctx)
- global_ctx = ctx;
-
+ e2fsck_get_lock_context(ctx);
pthread_mutex_unlock(&global_ctx->fs_fix_mutex);
}
+
+void e2fsck_pass1_block_map_lock(e2fsck_t ctx)
+{
+ e2fsck_get_lock_context(ctx);
+ pthread_mutex_lock(&global_ctx->fs_block_map_mutex);
+}
+
+void e2fsck_pass1_block_map_unlock(e2fsck_t ctx)
+{
+ e2fsck_get_lock_context(ctx);
+ pthread_mutex_unlock(&global_ctx->fs_block_map_mutex);
+}
#else
void e2fsck_pass1_fix_lock(e2fsck_t ctx)
{
@@ -596,6 +607,15 @@ void e2fsck_pass1_fix_lock(e2fsck_t ctx)
void e2fsck_pass1_fix_unlock(e2fsck_t ctx)
{
+}
+
+void e2fsck_pass1_block_map_lock(e2fsck_t ctx)
+{
+
+}
+
+void e2fsck_pass1_block_map_unlock(e2fsck_t ctx)
+{
}
#endif
diff --git a/tests/f_multithread/expect.1 b/tests/f_multithread/expect.1
index 8d2acd2b..4db68d9e 100644
--- a/tests/f_multithread/expect.1
+++ b/tests/f_multithread/expect.1
@@ -1,7 +1,7 @@
ext2fs_open2: Bad magic number in super-block
../e2fsck/e2fsck: Superblock invalid, trying backup blocks...
+Pass 1: Checking inodes, blocks, and sizes
[Thread 0] Scan group range [0, 2)
-[Thread 0] Pass 1: Checking inodes, blocks, and sizes
[Thread 0] Scanned group range [0, 2), inodes 3008
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
diff --git a/tests/f_multithread_logfile/expect.1 b/tests/f_multithread_logfile/expect.1
index 8d2acd2b..4db68d9e 100644
--- a/tests/f_multithread_logfile/expect.1
+++ b/tests/f_multithread_logfile/expect.1
@@ -1,7 +1,7 @@
ext2fs_open2: Bad magic number in super-block
../e2fsck/e2fsck: Superblock invalid, trying backup blocks...
+Pass 1: Checking inodes, blocks, and sizes
[Thread 0] Scan group range [0, 2)
-[Thread 0] Pass 1: Checking inodes, blocks, and sizes
[Thread 0] Scanned group range [0, 2), inodes 3008
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
diff --git a/tests/f_multithread_no/expect.1 b/tests/f_multithread_no/expect.1
index f85a3382..eda2fcac 100644
--- a/tests/f_multithread_no/expect.1
+++ b/tests/f_multithread_no/expect.1
@@ -1,7 +1,7 @@
ext2fs_open2: Bad magic number in super-block
../e2fsck/e2fsck: Superblock invalid, trying backup blocks...
+Pass 1: Checking inodes, blocks, and sizes
[Thread 0] Scan group range [0, 2)
-[Thread 0] Pass 1: Checking inodes, blocks, and sizes
[Thread 0] Scanned group range [0, 2), inodes 3008
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
--
2.29.2.299.gdc1121823c-goog
next prev parent reply other threads:[~2020-11-18 15:41 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 ` [RFC PATCH v3 15/61] e2fsck: do not change global variables Saranya Muruganandam
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 ` Saranya Muruganandam [this message]
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-31-saranyamohan@google.com \
--to=saranyamohan@google.com \
--cc=adilger.kernel@dilger.ca \
--cc=linux-ext4@vger.kernel.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.