From: Wang Shilong Date: Thu, 17 Sep 2020 02:58:56 +0000 (+0800) Subject: e2fsck: clear icache when using multi-thread fsck X-Git-Tag: v1.46.6-wc1~89 X-Git-Url: https://git.whamcloud.com/tools/e2fsprogs.git/?a=commitdiff_plain;h=204522eb1a1714e2a312e09dfb97d98aa8508276;p=tools%2Fe2fsprogs.git e2fsck: clear icache when using multi-thread fsck icache of fs will be rebuilt when needed, so after copying fs, icache can be inited to NULL. E2fsprogs-commit: 5d4f09fa148e41b4e0ea01fc364de5bbedf02ecf Change-Id: I21c58b3f126fd85008d6c732da71b298b2a8b4ff Signed-off-by: Li Xi Signed-off-by: Wang Shilong Reviewed-by: Andreas Dilger Signed-off-by: Theodore Ts'o --- diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c index d35abbe..cd70fe1 100644 --- a/e2fsck/pass1.c +++ b/e2fsck/pass1.c @@ -2123,8 +2123,10 @@ endit: ctx->invalid_bitmaps++; } -static void e2fsck_pass1_copy_fs(ext2_filsys dest, ext2_filsys src) +static errcode_t e2fsck_pass1_copy_fs(ext2_filsys dest, ext2_filsys src) { + errcode_t retval; + memcpy(dest, src, sizeof(struct struct_ext2_filsys)); if (dest->dblist) dest->dblist->fs = dest; @@ -2132,6 +2134,29 @@ static void e2fsck_pass1_copy_fs(ext2_filsys dest, ext2_filsys src) dest->inode_map->fs = dest; if (dest->block_map) dest->block_map->fs = dest; + + /* icache will be rebuilt if needed, so do not copy from @src */ + src->icache = NULL; + return 0; +} + +static void e2fsck_pass1_merge_fs(ext2_filsys dest, ext2_filsys src) +{ + struct ext2_inode_cache *icache = dest->icache; + + 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; + dest->icache = icache; + + if (src->icache) { + ext2fs_free_inode_cache(src->icache); + src->icache = NULL; + } } static errcode_t e2fsck_pass1_thread_prepare(e2fsck_t global_ctx, e2fsck_t *thread_ctx) @@ -2155,12 +2180,18 @@ static errcode_t e2fsck_pass1_thread_prepare(e2fsck_t global_ctx, e2fsck_t *thre goto out_context; } - e2fsck_pass1_copy_fs(thread_fs, global_fs); + retval = e2fsck_pass1_copy_fs(thread_fs, global_fs); + if (retval) { + com_err(global_ctx->program_name, retval, "while copying fs"); + goto out_fs; + } thread_fs->priv_data = thread_context; thread_context->fs = thread_fs; *thread_ctx = thread_context; return 0; +out_fs: + ext2fs_free_mem(&thread_fs); out_context: ext2fs_free_mem(&thread_context); return retval; @@ -2184,7 +2215,7 @@ 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); - e2fsck_pass1_copy_fs(global_fs, thread_fs); + e2fsck_pass1_merge_fs(global_fs, thread_fs); global_fs->priv_data = global_ctx; global_ctx->fs = global_fs;