From: Wang Shilong <wshilong@xxxxxxx> Signed-off-by: Wang Shilong <wshilong@xxxxxxx> --- e2fsck/pass1.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c index f1bb1fc5..e8c0618b 100644 --- a/e2fsck/pass1.c +++ b/e2fsck/pass1.c @@ -2508,6 +2508,65 @@ static int e2fsck_pass1_merge_fs(ext2_filsys dest, ext2_filsys src) return retval; } +static void e2fsck_pass1_copy_invalid_bitmaps(e2fsck_t global_ctx, + e2fsck_t thread_ctx) +{ + int i, j; + int grp_start = thread_ctx->thread_info.et_group_start; + int grp_end = thread_ctx->thread_info.et_group_end; + int total = grp_end - grp_start; + + thread_ctx->invalid_inode_bitmap_flag = e2fsck_allocate_memory(global_ctx, + sizeof(int) * total, "invalid_inode_bitmap"); + thread_ctx->invalid_block_bitmap_flag = e2fsck_allocate_memory(global_ctx, + sizeof(int) * total, "invalid_block_bitmap"); + thread_ctx->invalid_inode_table_flag = e2fsck_allocate_memory(global_ctx, + sizeof(int) * total, "invalid_inode_table"); + thread_ctx->invalid_bitmaps = 0; + + for (i = grp_start, j = 0; i < grp_end; i++, j++) { + thread_ctx->invalid_block_bitmap_flag[j] = + global_ctx->invalid_block_bitmap_flag[i]; + thread_ctx->invalid_inode_bitmap_flag[j] = + global_ctx->invalid_inode_bitmap_flag[i]; + thread_ctx->invalid_inode_table_flag[j] = + global_ctx->invalid_inode_table_flag[i]; + if (thread_ctx->invalid_block_bitmap_flag[j]) + thread_ctx->invalid_bitmaps++; + if (thread_ctx->invalid_inode_bitmap_flag[j]) + thread_ctx->invalid_bitmaps++; + if (thread_ctx->invalid_inode_table_flag[j]) + thread_ctx->invalid_bitmaps++; + + } +} + +static void e2fsck_pass1_merge_invalid_bitmaps(e2fsck_t global_ctx, + e2fsck_t thread_ctx) +{ + int i, j; + int grp_start = thread_ctx->thread_info.et_group_start; + int grp_end = thread_ctx->thread_info.et_group_end; + + for (i = grp_start, j = 0; i < grp_end; i++, j++) { + global_ctx->invalid_block_bitmap_flag[i] = + thread_ctx->invalid_block_bitmap_flag[j]; + global_ctx->invalid_inode_bitmap_flag[i] = + thread_ctx->invalid_inode_bitmap_flag[j]; + global_ctx->invalid_inode_table_flag[i] = + thread_ctx->invalid_inode_table_flag[j]; + if (thread_ctx->invalid_block_bitmap_flag[j]) + global_ctx->invalid_bitmaps++; + if (thread_ctx->invalid_inode_bitmap_flag[j]) + global_ctx->invalid_bitmaps++; + if (thread_ctx->invalid_inode_table_flag[j]) + global_ctx->invalid_bitmaps++; + } + ext2fs_free_mem(&thread_ctx->invalid_block_bitmap_flag); + ext2fs_free_mem(&thread_ctx->invalid_inode_bitmap_flag); + ext2fs_free_mem(&thread_ctx->invalid_inode_table_flag); +} + static errcode_t e2fsck_pass1_thread_prepare(e2fsck_t global_ctx, e2fsck_t *thread_ctx, int thread_index, @@ -2584,6 +2643,7 @@ static errcode_t e2fsck_pass1_thread_prepare(e2fsck_t global_ctx, goto out_fs; } *thread_ctx = thread_context; + e2fsck_pass1_copy_invalid_bitmaps(global_ctx, thread_context); return 0; out_fs: ext2fs_free_mem(&thread_fs); @@ -2724,6 +2784,10 @@ static int e2fsck_pass1_thread_join_one(e2fsck_t global_ctx, e2fsck_t thread_ctx int dx_dir_info_count = global_ctx->dx_dir_info_count; ext2_u32_list dirs_to_hash = global_ctx->dirs_to_hash; quota_ctx_t qctx = global_ctx->qctx; + int *invalid_block_bitmap_flag = global_ctx->invalid_block_bitmap_flag; + int *invalid_inode_bitmap_flag = global_ctx->invalid_inode_bitmap_flag; + int *invalid_inode_table_flag = global_ctx->invalid_inode_table_flag; + int invalid_bitmaps = global_ctx->invalid_bitmaps; #ifdef HAVE_SETJMP_H jmp_buf old_jmp; @@ -2795,6 +2859,11 @@ static int e2fsck_pass1_thread_join_one(e2fsck_t global_ctx, e2fsck_t thread_ctx } global_ctx->qctx = qctx; e2fsck_pass1_merge_quota_ctx(global_ctx, thread_ctx); + global_ctx->invalid_block_bitmap_flag = invalid_block_bitmap_flag; + global_ctx->invalid_inode_bitmap_flag = invalid_inode_bitmap_flag; + global_ctx->invalid_inode_table_flag = invalid_inode_table_flag; + global_ctx->invalid_bitmaps = invalid_bitmaps; + e2fsck_pass1_merge_invalid_bitmaps(global_ctx, thread_ctx); /* * PASS1_COPY_CTX_BITMAP might return directly from this function, @@ -2846,6 +2915,8 @@ static int e2fsck_pass1_threads_join(struct e2fsck_thread_info *infos, int i; struct e2fsck_thread_info *pinfo; + /* merge invalid bitmaps will recalculate it */ + global_ctx->invalid_bitmaps = 0; for (i = 0; i < num_threads; i++) { pinfo = &infos[i]; -- 2.25.4