Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1666462rwb; Mon, 7 Nov 2022 04:31:21 -0800 (PST) X-Google-Smtp-Source: AMsMyM5NOlA6TPuIIEpRRj/vlZ8xDIzJRWoVd3B2Tj61hTH3/gZ67F1Y0TtHHYIlL6vEcq6XCZsz X-Received: by 2002:a17:90a:4745:b0:214:100a:65c8 with SMTP id y5-20020a17090a474500b00214100a65c8mr34185697pjg.105.1667824280727; Mon, 07 Nov 2022 04:31:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667824280; cv=none; d=google.com; s=arc-20160816; b=UUQ54xvz636oeTh2VsrFddKHWpyi0xQzqcf51NfVG7rFsjFxPTo7rqKuSxn6Hzb/C8 b4a096irrtH42PvG4CxVdToKSIt7SzSii37xzuwMs/aGjSLBqvBxiLMDp9+Xpw+1uLtC 8IM+jIRHhLGaLUntc7eRSVK5qX7gy1Goc/F2SAGfohaw+I4WTtQ2GtOqL2bhxaByJVJ7 vpodO6ZqJ4sYtWvLHpAUmW1UKC3sARVNozXp1A+ZsqBHCtD6bZEdiJFuj9rV8TLWmuLU 61Y7zGqVcWBvmQBsSCvq0xZhS4/q8sKsPHtf9/3oceRWEmya0Vmt0QzEe/8nVoCRevTt L/IQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7mCTw1xNENoPySQjpxJulxZ+cgE3/DtDrhwZ00hou64=; b=vC3YjG99Tn59WPo3uh8o4m1zCKgGny4/PbT0ZMj3xj8x5cRaqF0UM+ovNvXoCRgkbY DqgO5d/NqUY/z8tnXk74dnN/C9L1u4/LkjF6A4FWIaNBPNRpZ43hZfdIOztKpNVUlugt GspDfOI+j7UBluX4vAadNlVs4Rzc7CiJz/kJEiXPRwgirMs/ZKPs+AVGafYLKYcv+vg9 BHxH/c5gMk/j2l1ZuPR0c7GRHyvnV4xyV1+Fw4e/AmQc0510I+7cBu3Zp5sDRXx1VPqz pezLKIS/QfvOVJZOC3TOZ9tj6MP7czHFRAt4GJP4EpOL7Q3JcQDGUAI15c5rRcYSakQ3 EfbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Z5a0TsZ6; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r14-20020a63440e000000b0046f45ab031esi8631459pga.600.2022.11.07.04.31.07; Mon, 07 Nov 2022 04:31:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Z5a0TsZ6; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232095AbiKGMay (ORCPT + 99 others); Mon, 7 Nov 2022 07:30:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231935AbiKGMag (ORCPT ); Mon, 7 Nov 2022 07:30:36 -0500 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 661371B9D2 for ; Mon, 7 Nov 2022 04:29:31 -0800 (PST) Received: by mail-pj1-x1030.google.com with SMTP id v4-20020a17090a088400b00212cb0ed97eso10125795pjc.5 for ; Mon, 07 Nov 2022 04:29:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7mCTw1xNENoPySQjpxJulxZ+cgE3/DtDrhwZ00hou64=; b=Z5a0TsZ6akgVS5InsU+efI070jXFge2KncXT0iqgNNdAvRawfnCumcq52lAe793gWR 81MiIJctZ7WyoIBRzQxsaCdoL+Ct93pXL/qDoBST60CfwPyrPn0zvIWmD87L6Z7ZyUKY em/0x2yaDxmq/1BHUC9ZiMUEjqvi8IPJDisjpE2xBBLdi6HilMcnvSRjNEX07Yi/Wp3p y7KNkG/NOMB+F52TDZFVRoMGz78xEGAnIGdLTs3E5jd0ODvjiqakS0VixeyVrmVrc9fN vvC677Hh1WfYe9tjN4XCUQnoo3Gqjszui7FuVzHwQ43awyTLLDfTuaIure+i+yZ/YVoO 4iTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7mCTw1xNENoPySQjpxJulxZ+cgE3/DtDrhwZ00hou64=; b=7FDKHtWnqYRvDqR0oGPQI9mlGSAdiz3Mpo3G6UPPjb4VCsY083u2DUIgTgBcEbZoe6 pqp1arGLBj3nKS/FvTPgdW5Qnb4Gb3ZstmmXVXu/GVBtG2xxyAXpIYhA4vrnKZ/Q+40H ik9IJ6FGf52nrMpNetl9xcO5t36rdM6yT1xMj9bRf6N+dbEczVnu2v1DPcQZ/flBke5E ZEd9NrVwqKHN1SJAONMrnobPqstIAF++LMDDMYKup3FWAqNWpr8fDrMHEWHWF9D7+Au9 OkMf0QEA3f2k0QjEEWJNG2cJxBMHDvnU1+KGPfT9X7Fec3aSIGZ7hr4DeHnPjwLdiG8u OG+g== X-Gm-Message-State: ACrzQf0yBbg+drtCgrY+LH2jMTVmxP+FyDY7MWTh3tayFwsMSGfzXLuM us+Y346gjbrr08Hh+683mEz6N7f2ZtM= X-Received: by 2002:a17:90a:a415:b0:20a:f813:83a3 with SMTP id y21-20020a17090aa41500b0020af81383a3mr51751288pjp.238.1667824170932; Mon, 07 Nov 2022 04:29:30 -0800 (PST) Received: from localhost ([2406:7400:63:f20b:312d:45b2:85c1:c486]) by smtp.gmail.com with ESMTPSA id o22-20020a170902779600b0018668bee7cdsm4877440pll.77.2022.11.07.04.29.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 04:29:30 -0800 (PST) From: "Ritesh Harjani (IBM)" To: Theodore Ts'o Cc: linux-ext4@vger.kernel.org, Harshad Shirwadkar , Wang Shilong , Andreas Dilger , Li Xi , "Ritesh Harjani (IBM)" Subject: [RFCv1 70/72] e2fsck: Fix and simplify update_mmp in case of pfsck Date: Mon, 7 Nov 2022 17:51:58 +0530 Message-Id: <846558b5f837ed2d32246a072d3b97f584573c7d.1667822612.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org This adds pass1_update_mmp_enter() & pass1_update_mmp_exit() routines to update mmp block. This also fixes a data race reported by threadsan because of reading and writing to mmp_update_thread variable. Signed-off-by: Ritesh Harjani (IBM) --- e2fsck/pass1.c | 97 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 63 insertions(+), 34 deletions(-) diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c index 4168a45d..2ff83fcb 100644 --- a/e2fsck/pass1.c +++ b/e2fsck/pass1.c @@ -1097,6 +1097,66 @@ out: return 0; } +static void pass1_update_mmp_enter(e2fsck_t ctx, ext2_ino_t ino) +{ + ext2_filsys fs = ctx->fs; + e2fsck_t global_ctx = ctx->global_ctx ? ctx->global_ctx : ctx; + int check_mmp = 0; + int set_mmp = 0; + +#ifdef HAVE_PTHREAD + /* only one active thread could update mmp block. */ + e2fsck_pass1_block_map_r_lock(ctx); + if (!global_ctx->mmp_update_thread) + set_mmp = 1; + if (global_ctx->mmp_update_thread == ctx->thread_info.et_thread_index + 1) + check_mmp = 1; + e2fsck_pass1_block_map_r_unlock(ctx); + + if (!check_mmp && !set_mmp) + return; + + if (set_mmp) { + e2fsck_pass1_block_map_w_lock(ctx); + if (!global_ctx->mmp_update_thread) { + global_ctx->mmp_update_thread = + ctx->thread_info.et_thread_index + 1; + check_mmp = 1; + } + e2fsck_pass1_block_map_w_unlock(ctx); + } +#else + check_mmp = 1; +#endif + + if (check_mmp && (ino % (fs->super->s_inodes_per_group * 4) == 1)) { + if (e2fsck_mmp_update(fs)) + fatal_error(ctx, 0); + } +} + +static void pass1_update_mmp_exit(e2fsck_t ctx) +{ + ext2_filsys fs = ctx->fs; + e2fsck_t global_ctx = ctx->global_ctx ? ctx->global_ctx : ctx; + int set_mmp = 0; + +#ifdef HAVE_PTHREAD + e2fsck_pass1_block_map_r_lock(ctx); + if (global_ctx->mmp_update_thread == ctx->thread_info.et_thread_index + 1) + set_mmp = 1; + e2fsck_pass1_block_map_r_unlock(ctx); + + if (!set_mmp) + return; + + /* reset update_thread after this thread exit */ + e2fsck_pass1_block_map_w_lock(ctx); + global_ctx->mmp_update_thread = 0; + e2fsck_pass1_block_map_w_unlock(ctx); +#endif +} + static void pass1_readahead(e2fsck_t ctx, dgrp_t *group, ext2_ino_t *next_ino) { ext2_ino_t inodes_in_group = 0, inodes_per_block, inodes_per_buffer; @@ -1511,7 +1571,7 @@ void e2fsck_pass1_run(e2fsck_t ctx) dgrp_t ra_group = 0; struct ea_quota ea_ibody_quota; struct process_inode_block *inodes_to_process; - int process_inode_count, check_mmp; + int process_inode_count; e2fsck_t global_ctx = ctx->global_ctx ? ctx->global_ctx : ctx; init_resource_track(&rtrack, ctx->fs->io); @@ -1675,33 +1735,8 @@ void e2fsck_pass1_run(e2fsck_t ctx) #endif while (1) { - check_mmp = 0; e2fsck_pass1_check_lock(ctx); -#ifdef HAVE_PTHREAD - if (!global_ctx->mmp_update_thread) { - e2fsck_pass1_block_map_w_lock(ctx); - if (!global_ctx->mmp_update_thread) { - global_ctx->mmp_update_thread = - ctx->thread_info.et_thread_index + 1; - check_mmp = 1; - } - e2fsck_pass1_block_map_w_unlock(ctx); - } - - /* only one active thread could update mmp block. */ - e2fsck_pass1_block_map_r_lock(ctx); - if (global_ctx->mmp_update_thread == - ctx->thread_info.et_thread_index + 1) - check_mmp = 1; - e2fsck_pass1_block_map_r_unlock(ctx); -#else - check_mmp = 1; -#endif - - if (check_mmp && (ino % (fs->super->s_inodes_per_group * 4) == 1)) { - if (e2fsck_mmp_update(fs)) - fatal_error(ctx, 0); - } + pass1_update_mmp_enter(ctx, ino); old_op = ehandler_operation(eop_next_inode); pctx.errcode = ext2fs_get_next_inode_full(scan, &ino, inode, inode_size); @@ -2458,13 +2493,7 @@ endit: print_resource_track(ctx, _("Pass 1"), &rtrack, ctx->fs->io); else ctx->invalid_bitmaps++; -#ifdef HAVE_PTHREAD - /* reset update_thread after this thread exit */ - e2fsck_pass1_block_map_w_lock(ctx); - if (check_mmp) - global_ctx->mmp_update_thread = 0; - e2fsck_pass1_block_map_w_unlock(ctx); -#endif + pass1_update_mmp_exit(ctx); } #ifdef HAVE_PTHREAD -- 2.37.3