From: Li Xi Date: Tue, 6 Aug 2019 03:19:15 +0000 (+0800) Subject: LU-8465 e2fsck: copy fs when using multi-thread fsck X-Git-Tag: v1.45.6.wc2~61 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=7432f421b844b5cc6c84db05454d7cfdba1d449f;p=tools%2Fe2fsprogs.git LU-8465 e2fsck: copy fs when using multi-thread fsck This patch only copy the fs to a new one when -m is enabled. It doesn't actually start any thread. When pass1 test finishes, the new fs is copied back to the original context. This patch handles the fs fields in dblist, inode_map and block_map properly. Change-Id: I1cc80bb1d762692a6bde3a57d1498d2842884c41 Signed-off-by: Li Xi Signed-off-by: Wang Shilong Reviewed-on: https://review.whamcloud.com/35696 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger --- diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c index 0a476e0..c601b6d 100644 --- a/e2fsck/pass1.c +++ b/e2fsck/pass1.c @@ -50,6 +50,8 @@ #include "e2fsck.h" #include +/* todo remove this finally */ +#include #include #include "problem.h" @@ -2342,10 +2344,23 @@ endit: ctx->invalid_bitmaps++; } +static void e2fsck_pass1_copy_fs(ext2_filsys dest, ext2_filsys src) +{ + memcpy(dest, src, sizeof(struct struct_ext2_filsys)); + if (dest->dblist) + dest->dblist->fs = dest; + if (dest->inode_map) + dest->inode_map->fs = dest; + if (dest->block_map) + dest->block_map->fs = dest; +} + static errcode_t e2fsck_pass1_thread_prepare(e2fsck_t global_ctx, e2fsck_t *thread_ctx) { errcode_t retval; e2fsck_t thread_context; + ext2_filsys thread_fs; + ext2_filsys global_fs = global_ctx->fs; retval = ext2fs_get_mem(sizeof(struct e2fsck_struct), &thread_context); if (retval) { @@ -2353,18 +2368,32 @@ static errcode_t e2fsck_pass1_thread_prepare(e2fsck_t global_ctx, e2fsck_t *thre return retval; } memcpy(thread_context, global_ctx, sizeof(struct e2fsck_struct)); - thread_context->fs->priv_data = thread_context; thread_context->global_ctx = global_ctx; + retval = ext2fs_get_mem(sizeof(struct struct_ext2_filsys), &thread_fs); + if (retval) { + com_err(global_ctx->program_name, retval, "while allocating memory"); + goto out_context; + } + + e2fsck_pass1_copy_fs(thread_fs, global_fs); + thread_fs->priv_data = thread_context; + + thread_context->fs = thread_fs; *thread_ctx = thread_context; return 0; +out_context: + ext2fs_free_mem(&thread_context); + return retval; } static int e2fsck_pass1_thread_join(e2fsck_t global_ctx, e2fsck_t thread_ctx) { - int flags = global_ctx->flags; + int flags = global_ctx->flags; + ext2_filsys thread_fs = thread_ctx->fs; + ext2_filsys global_fs = global_ctx->fs; #ifdef HAVE_SETJMP_H - jmp_buf old_jmp; + jmp_buf old_jmp; memcpy(old_jmp, global_ctx->abort_loc, sizeof(jmp_buf)); #endif @@ -2376,7 +2405,11 @@ static int e2fsck_pass1_thread_join(e2fsck_t global_ctx, e2fsck_t thread_ctx) global_ctx->flags |= (flags & E2F_FLAG_SIGNAL_MASK) | (global_ctx->flags & E2F_FLAG_SIGNAL_MASK); - global_ctx->fs->priv_data = global_ctx; + e2fsck_pass1_copy_fs(global_fs, thread_fs); + global_fs->priv_data = global_ctx; + global_ctx->fs = global_fs; + + ext2fs_free_mem(&thread_ctx->fs); ext2fs_free_mem(&thread_ctx); return 0; }