Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp413036pxb; Wed, 18 Nov 2020 07:41:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJw5Wvocrl4qeJNeY3lwvnN70J9p3kpTIuwDg3Jp6e/B/XTK9T1ZC5IOSGnHwaeW4GKuNbMB X-Received: by 2002:aa7:db8a:: with SMTP id u10mr26885966edt.204.1605714069151; Wed, 18 Nov 2020 07:41:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605714069; cv=none; d=google.com; s=arc-20160816; b=O8pi+Q3nxEz07Urj9ZDIx7JnjFAkakBAoA9YoUGOU+GMJuX1UY2P0ZTJpBiTwig/Ul lmwXaGndmqDhTQ3tuWa7ihr8Nni8H5WnKEguAyFl2LpcfdT3H2CiSMYZZhS7UcH6TSa2 XRlDPDu9HNl3JpPR0Bh96HrYOyVhvqh23so7QhFFFxw+Qfsy1/ZXYXEX/BC/3crtdWGP znRctGVbE2sZ45SC33hDhCXPmcbetF0JOyRR8a1ffx8koz03V5v9NagOlZ+0PrVzYHvS 8LMixS35JXbi/8bwzS+wOwqClf7KIGzmPbvFeofDXm+RgxMZpsIYBXynzVWfqubZJYVp YsZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:sender:dkim-signature; bh=BUnSJiCRb7gKUFWssFlD1/YSL9ijQFMd0Y48Ctas5M4=; b=MEc5kGG6P3A5a+LR0AcjHMPdVxKcwaj/vypOLRWWadQb173GSUXhyKcLWmp5FrmB/v fsdlCKYCH+giiR93c3mLAfCL393t9DnqPKKz18KKYFOZcP2tB2fYYrrraRikvjK9pA42 wNb+dDvKGBQmOhclZHQckSB7T0uESGXFBzPahzx2dLnmoGf7dixAISFqHBkJNGxrZXpV uXTaf5LamD+GWtcSM8JoOhUOhERoHeUangIjgtKm5YIsL0CXOE+t7n2s2rRIwql51d0X o83fKtZCOnuhuN5AN95zapZOVs20XqmxqkFT8ir2xtK/0MYoEYt4ATM5fgdh3RAmBnAE uYrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=t8m018Og; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w29si3522019edi.534.2020.11.18.07.40.45; Wed, 18 Nov 2020 07:41:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=t8m018Og; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727363AbgKRPke (ORCPT + 99 others); Wed, 18 Nov 2020 10:40:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726574AbgKRPkd (ORCPT ); Wed, 18 Nov 2020 10:40:33 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F71BC0613D6 for ; Wed, 18 Nov 2020 07:40:32 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id n186so2891256ybg.17 for ; Wed, 18 Nov 2020 07:40:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=BUnSJiCRb7gKUFWssFlD1/YSL9ijQFMd0Y48Ctas5M4=; b=t8m018OgOok81vplOE4kgh6U8br+MQcy+WXVd4f8X9eGwHbzah3DN/UuKfnZxp2GH2 6SJopazwnAZkjBi0q0lc6u7ZpayPEAjbKe8OeMuwvCQ3kvucRpeR3+hE4vg3vEMBa86x i/OuH08attkNNHAxRTlue5Pp79027MiQzOBwo+lQTp35zIr0Az7c9j5xtVBKHM7Lxidy gyUGRmxQ66GyGyYN23jHAupR6uXewwqFeXVrI71/luGwdp5C1eidQ2b0RvKcvQh26PMp zugKSHHcLoH9jbL7M/vCtj7FtdYFeO20doLH2VyyR1T4LKBfEZAmM8DmTDW9YEUvdbA/ TTnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=BUnSJiCRb7gKUFWssFlD1/YSL9ijQFMd0Y48Ctas5M4=; b=LXPKzGGIuHEIOumoObIqj+vtHCQYyCwBU13Ebzqoa0melxVtKiGMz48ZA5whDO714t Yyr/Pdqv/E4hLp14fl8CwqnHk1t+sm/sCNMgFL0YwKVUdEOx7KNiWVSExqZZOFFCvUkW /HaX0maihZirama+Txu8HqKyIHW6v9VG/pdzKrwdFB7HNTcHoJunJtkANrg7VzZUy/BA e22GOj6n4xSGQjWxQgjU3C8qgoCkRpirSLvbgdcR6lejk4vxgcfc0e5hLFm1+rXU1NG4 GjfPeBkykppvWyMP5ipyc/SintLCL0cJ5K6erDoKVNDD4fnffTsmCXf3jkyfK/rBYtgt s64A== X-Gm-Message-State: AOAM533SXTyqJe9vqOpecxwe88pzoghlJfTxa5O+ZttliKVLz2Zp2V3V IMlhCOy1mWHyJwS3B1f23Q8zlyOeeqjJjIf+0kBmNxjLFkvvty3BccssYoFYDNoc6bOSAMvi4ES ftN4o0fnWe1M78tyrZKgxxXIgz0bwCzXvy4pwzxMKtQmWQ6vIDsABCiqmK1Q3wLS6dM82HcuIZj hqef18bco= Sender: "saranyamohan via sendgmr" X-Received: from saranyamohan.svl.corp.google.com ([100.116.76.178]) (user=saranyamohan job=sendgmr) by 2002:a5b:74f:: with SMTP id s15mr7411466ybq.11.1605714031240; Wed, 18 Nov 2020 07:40:31 -0800 (PST) Date: Wed, 18 Nov 2020 07:38:49 -0800 In-Reply-To: <20201118153947.3394530-1-saranyamohan@google.com> Message-Id: <20201118153947.3394530-4-saranyamohan@google.com> Mime-Version: 1.0 References: <20201118153947.3394530-1-saranyamohan@google.com> X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog Subject: [RFC PATCH v3 03/61] e2fsck: copy fs when using multi-thread fsck From: Saranya Muruganandam To: linux-ext4@vger.kernel.org, tytso@mit.edu Cc: adilger.kernel@dilger.ca, Li Xi , Wang Shilong , Saranya Muruganandam Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Li Xi 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. Signed-off-by: Li Xi Signed-off-by: Wang Shilong Signed-off-by: Saranya Muruganandam --- e2fsck/pass1.c | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c index 64d237d3..5b4947b0 100644 --- a/e2fsck/pass1.c +++ b/e2fsck/pass1.c @@ -49,6 +49,8 @@ #include "e2fsck.h" #include +/* todo remove this finally */ +#include #include #include "problem.h" @@ -2084,10 +2086,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) { @@ -2095,18 +2110,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 @@ -2118,7 +2147,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; } -- 2.29.2.299.gdc1121823c-goog