From patchwork Mon Sep 6 14:47:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "yebin (H)" X-Patchwork-Id: 1524977 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4H39x26sQfz9sW5 for ; Tue, 7 Sep 2021 00:37:58 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243565AbhIFOjC (ORCPT ); Mon, 6 Sep 2021 10:39:02 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:15298 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243437AbhIFOi5 (ORCPT ); Mon, 6 Sep 2021 10:38:57 -0400 Received: from dggeme754-chm.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4H39wL1BSbz8spw; Mon, 6 Sep 2021 22:37:22 +0800 (CST) Received: from huawei.com (10.175.127.227) by dggeme754-chm.china.huawei.com (10.3.19.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.8; Mon, 6 Sep 2021 22:37:49 +0800 From: Ye Bin To: , , CC: , , Ye Bin Subject: [PATCH -next 1/6] ext4: init seq with random value in kmmpd Date: Mon, 6 Sep 2021 22:47:49 +0800 Message-ID: <20210906144754.2601607-2-yebin10@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210906144754.2601607-1-yebin10@huawei.com> References: <20210906144754.2601607-1-yebin10@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggeme754-chm.china.huawei.com (10.3.19.100) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org If two host has the same nodename, and seq start from 0, May cause the detection mechanism to fail. So init seq with random value to accelerate conflict detection. Signed-off-by: Ye Bin --- fs/ext4/mmp.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c index cebea4270817..12af6dc8457b 100644 --- a/fs/ext4/mmp.c +++ b/fs/ext4/mmp.c @@ -122,6 +122,21 @@ void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp, (int)sizeof(mmp->mmp_bdevname), mmp->mmp_bdevname); } +/* + * Get a random new sequence number but make sure it is not greater than + * EXT4_MMP_SEQ_MAX. + */ +static unsigned int mmp_new_seq(void) +{ + u32 new_seq; + + do { + new_seq = prandom_u32(); + } while (new_seq > EXT4_MMP_SEQ_MAX); + + return new_seq; +} + /* * kmmpd will update the MMP sequence every s_mmp_update_interval seconds */ @@ -132,7 +147,7 @@ static int kmmpd(void *data) struct buffer_head *bh = EXT4_SB(sb)->s_mmp_bh; struct mmp_struct *mmp; ext4_fsblk_t mmp_block; - u32 seq = 0; + u32 seq = mmp_new_seq(); unsigned long failed_writes = 0; int mmp_update_interval = le16_to_cpu(es->s_mmp_update_interval); unsigned mmp_check_interval; @@ -258,21 +273,6 @@ void ext4_stop_mmpd(struct ext4_sb_info *sbi) } } -/* - * Get a random new sequence number but make sure it is not greater than - * EXT4_MMP_SEQ_MAX. - */ -static unsigned int mmp_new_seq(void) -{ - u32 new_seq; - - do { - new_seq = prandom_u32(); - } while (new_seq > EXT4_MMP_SEQ_MAX); - - return new_seq; -} - /* * Protect the filesystem from being mounted more than once. */ From patchwork Mon Sep 6 14:47:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "yebin (H)" X-Patchwork-Id: 1524978 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4H39x42Wm4z9sRN for ; Tue, 7 Sep 2021 00:38:00 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243556AbhIFOjD (ORCPT ); Mon, 6 Sep 2021 10:39:03 -0400 Received: from szxga08-in.huawei.com ([45.249.212.255]:15242 "EHLO szxga08-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243450AbhIFOi6 (ORCPT ); Mon, 6 Sep 2021 10:38:58 -0400 Received: from dggeme754-chm.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4H39vx2HwNz1DGhl; Mon, 6 Sep 2021 22:37:01 +0800 (CST) Received: from huawei.com (10.175.127.227) by dggeme754-chm.china.huawei.com (10.3.19.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.8; Mon, 6 Sep 2021 22:37:50 +0800 From: Ye Bin To: , , CC: , , Ye Bin Subject: [PATCH -next 2/6] ext4: introduce last_check_time record previous check time Date: Mon, 6 Sep 2021 22:47:50 +0800 Message-ID: <20210906144754.2601607-3-yebin10@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210906144754.2601607-1-yebin10@huawei.com> References: <20210906144754.2601607-1-yebin10@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggeme754-chm.china.huawei.com (10.3.19.100) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org kmmpd: ... diff = jiffies - last_update_time; if (diff > mmp_check_interval * HZ) { ... As "mmp_check_interval = 2 * mmp_update_interval", 'diff' always little than 'mmp_update_interval', so there will never trigger detection. Introduce last_check_time record previous check time. Signed-off-by: Ye Bin --- fs/ext4/mmp.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c index 12af6dc8457b..89797f12a815 100644 --- a/fs/ext4/mmp.c +++ b/fs/ext4/mmp.c @@ -152,6 +152,7 @@ static int kmmpd(void *data) int mmp_update_interval = le16_to_cpu(es->s_mmp_update_interval); unsigned mmp_check_interval; unsigned long last_update_time; + unsigned long last_check_time; unsigned long diff; int retval = 0; @@ -170,6 +171,7 @@ static int kmmpd(void *data) memcpy(mmp->mmp_nodename, init_utsname()->nodename, sizeof(mmp->mmp_nodename)); + last_update_time = jiffies; while (!kthread_should_stop() && !sb_rdonly(sb)) { if (!ext4_has_feature_mmp(sb)) { @@ -198,17 +200,18 @@ static int kmmpd(void *data) } diff = jiffies - last_update_time; - if (diff < mmp_update_interval * HZ) + if (diff < mmp_update_interval * HZ) { schedule_timeout_interruptible(mmp_update_interval * HZ - diff); + diff = jiffies - last_update_time; + } /* * We need to make sure that more than mmp_check_interval - * seconds have not passed since writing. If that has happened - * we need to check if the MMP block is as we left it. + * seconds have not passed since check. If that has happened + * we need to check if the MMP block is as we write it. */ - diff = jiffies - last_update_time; - if (diff > mmp_check_interval * HZ) { + if (jiffies - last_check_time > mmp_check_interval * HZ) { struct buffer_head *bh_check = NULL; struct mmp_struct *mmp_check; @@ -234,6 +237,7 @@ static int kmmpd(void *data) goto wait_to_exit; } put_bh(bh_check); + last_check_time = jiffies; } /* From patchwork Mon Sep 6 14:47:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "yebin (H)" X-Patchwork-Id: 1524979 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4H39x45nd7z9sXN for ; Tue, 7 Sep 2021 00:38:00 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243326AbhIFOjD (ORCPT ); Mon, 6 Sep 2021 10:39:03 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:19012 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243432AbhIFOi6 (ORCPT ); Mon, 6 Sep 2021 10:38:58 -0400 Received: from dggeme754-chm.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4H39rH3HrRzbmG0; Mon, 6 Sep 2021 22:33:51 +0800 (CST) Received: from huawei.com (10.175.127.227) by dggeme754-chm.china.huawei.com (10.3.19.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.8; Mon, 6 Sep 2021 22:37:50 +0800 From: Ye Bin To: , , CC: , , Ye Bin Subject: [PATCH -next 3/6] ext4: compare to local seq and nodename when check conflict Date: Mon, 6 Sep 2021 22:47:51 +0800 Message-ID: <20210906144754.2601607-4-yebin10@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210906144754.2601607-1-yebin10@huawei.com> References: <20210906144754.2601607-1-yebin10@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggeme754-chm.china.huawei.com (10.3.19.100) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org As mmp and check_mmp is point to the same data, so there will never detect conflict. To solve this issue just compare to local data. Signed-off-by: Ye Bin --- fs/ext4/mmp.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c index 89797f12a815..0fe7b9ac9db6 100644 --- a/fs/ext4/mmp.c +++ b/fs/ext4/mmp.c @@ -154,6 +154,7 @@ static int kmmpd(void *data) unsigned long last_update_time; unsigned long last_check_time; unsigned long diff; + char nodename[64]; int retval = 0; mmp_block = le64_to_cpu(es->s_mmp_block); @@ -169,8 +170,8 @@ static int kmmpd(void *data) BUILD_BUG_ON(sizeof(mmp->mmp_bdevname) < BDEVNAME_SIZE); bdevname(bh->b_bdev, mmp->mmp_bdevname); - memcpy(mmp->mmp_nodename, init_utsname()->nodename, - sizeof(mmp->mmp_nodename)); + memcpy(nodename, init_utsname()->nodename, sizeof(nodename)); + memcpy(mmp->mmp_nodename, nodename, sizeof(mmp->mmp_nodename)); last_update_time = jiffies; while (!kthread_should_stop() && !sb_rdonly(sb)) { @@ -224,8 +225,8 @@ static int kmmpd(void *data) } mmp_check = (struct mmp_struct *)(bh_check->b_data); - if (mmp->mmp_seq != mmp_check->mmp_seq || - memcmp(mmp->mmp_nodename, mmp_check->mmp_nodename, + if (seq != mmp_check->mmp_seq || + memcmp(nodename, mmp_check->mmp_nodename, sizeof(mmp->mmp_nodename))) { dump_mmp_msg(sb, mmp_check, "Error while updating MMP info. " From patchwork Mon Sep 6 14:47:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "yebin (H)" X-Patchwork-Id: 1524981 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4H39x61Vc2z9sXk for ; Tue, 7 Sep 2021 00:38:02 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243599AbhIFOjF (ORCPT ); Mon, 6 Sep 2021 10:39:05 -0400 Received: from szxga08-in.huawei.com ([45.249.212.255]:15243 "EHLO szxga08-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243553AbhIFOjA (ORCPT ); Mon, 6 Sep 2021 10:39:00 -0400 Received: from dggeme754-chm.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4H39vy0yv8z1DGjk; Mon, 6 Sep 2021 22:37:02 +0800 (CST) Received: from huawei.com (10.175.127.227) by dggeme754-chm.china.huawei.com (10.3.19.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.8; Mon, 6 Sep 2021 22:37:50 +0800 From: Ye Bin To: , , CC: , , Ye Bin Subject: [PATCH -next 4/6] ext4: avoid to re-read mmp check data get from page cache Date: Mon, 6 Sep 2021 22:47:52 +0800 Message-ID: <20210906144754.2601607-5-yebin10@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210906144754.2601607-1-yebin10@huawei.com> References: <20210906144754.2601607-1-yebin10@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggeme754-chm.china.huawei.com (10.3.19.100) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org As call read_mmp_block pass bh_check which value is NULL, then call sb_getblk to get buffer_head. But mmp_block's buffer_head is already exist which also is uptodate. Lead to compare the same data. Signed-off-by: Ye Bin --- fs/ext4/mmp.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c index 0fe7b9ac9db6..2a1473e4a9de 100644 --- a/fs/ext4/mmp.c +++ b/fs/ext4/mmp.c @@ -213,10 +213,7 @@ static int kmmpd(void *data) * we need to check if the MMP block is as we write it. */ if (jiffies - last_check_time > mmp_check_interval * HZ) { - struct buffer_head *bh_check = NULL; - struct mmp_struct *mmp_check; - - retval = read_mmp_block(sb, &bh_check, mmp_block); + retval = read_mmp_block(sb, &bh, mmp_block); if (retval) { ext4_error_err(sb, -retval, "error reading MMP data: %d", @@ -224,20 +221,18 @@ static int kmmpd(void *data) goto wait_to_exit; } - mmp_check = (struct mmp_struct *)(bh_check->b_data); - if (seq != mmp_check->mmp_seq || - memcmp(nodename, mmp_check->mmp_nodename, - sizeof(mmp->mmp_nodename))) { - dump_mmp_msg(sb, mmp_check, + mmp = (struct mmp_struct *)(bh->b_data); + if (seq != le32_to_cpu(mmp->mmp_seq) || + memcmp(nodename, mmp->mmp_nodename, + sizeof(nodename))) { + dump_mmp_msg(sb, mmp, "Error while updating MMP info. " "The filesystem seems to have been" " multiply mounted."); ext4_error_err(sb, EBUSY, "abort"); - put_bh(bh_check); retval = -EBUSY; goto wait_to_exit; } - put_bh(bh_check); last_check_time = jiffies; } From patchwork Mon Sep 6 14:47:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "yebin (H)" X-Patchwork-Id: 1524982 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4H39xD4Xwkz9sXN for ; Tue, 7 Sep 2021 00:38:08 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243608AbhIFOjF (ORCPT ); Mon, 6 Sep 2021 10:39:05 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:15299 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243494AbhIFOi6 (ORCPT ); Mon, 6 Sep 2021 10:38:58 -0400 Received: from dggeme754-chm.china.huawei.com (unknown [172.30.72.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4H39wM5Rd5z8stB; Mon, 6 Sep 2021 22:37:23 +0800 (CST) Received: from huawei.com (10.175.127.227) by dggeme754-chm.china.huawei.com (10.3.19.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.8; Mon, 6 Sep 2021 22:37:51 +0800 From: Ye Bin To: , , CC: , , Ye Bin Subject: [PATCH -next 5/6] ext4: avoid to double free s_mmp_bh Date: Mon, 6 Sep 2021 22:47:53 +0800 Message-ID: <20210906144754.2601607-6-yebin10@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210906144754.2601607-1-yebin10@huawei.com> References: <20210906144754.2601607-1-yebin10@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggeme754-chm.china.huawei.com (10.3.19.100) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org If call read_mmp_block failed then s_mmp_bh will be freed in read_mmp_block. Kmmpd wait to be killed, ext4_stop_mmpd stop kmmpd and also release s_mmp_bh. To avoid double free, just set EXT4_SB(sb)->s_mmp_bh with NULL. Signed-off-by: Ye Bin --- fs/ext4/mmp.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c index 2a1473e4a9de..eed854bb6194 100644 --- a/fs/ext4/mmp.c +++ b/fs/ext4/mmp.c @@ -218,6 +218,7 @@ static int kmmpd(void *data) ext4_error_err(sb, -retval, "error reading MMP data: %d", retval); + EXT4_SB(sb)->s_mmp_bh = NULL; goto wait_to_exit; } From patchwork Mon Sep 6 14:47:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "yebin (H)" X-Patchwork-Id: 1524980 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4H39x53T1nz9sRN for ; Tue, 7 Sep 2021 00:38:01 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243594AbhIFOjE (ORCPT ); Mon, 6 Sep 2021 10:39:04 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:19013 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243551AbhIFOi6 (ORCPT ); Mon, 6 Sep 2021 10:38:58 -0400 Received: from dggeme754-chm.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4H39rJ4zg3zbmG5; Mon, 6 Sep 2021 22:33:52 +0800 (CST) Received: from huawei.com (10.175.127.227) by dggeme754-chm.china.huawei.com (10.3.19.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.8; Mon, 6 Sep 2021 22:37:51 +0800 From: Ye Bin To: , , CC: , , Ye Bin Subject: [PATCH -next 6/6] ext4: fix possible store wrong check interval value in disk when umount Date: Mon, 6 Sep 2021 22:47:54 +0800 Message-ID: <20210906144754.2601607-7-yebin10@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210906144754.2601607-1-yebin10@huawei.com> References: <20210906144754.2601607-1-yebin10@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggeme754-chm.china.huawei.com (10.3.19.100) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Test follow steps: 1. mkfs.ext4 /dev/sda -O mmp 2. mount /dev/sda /mnt 3. wait for about 1 minute 4. umount mnt 5. debugfs /dev/sda 6. dump_mmp 7. fsck.ext4 /dev/sda I found 'check_interval' is range in [5, 10]. And sometime run fsck print "MMP interval is 10 seconds and total wait time is 42 seconds. Please wait...". kmmpd: ... if (diff < mmp_update_interval * HZ) schedule_timeout_interruptible(mmp_update_interval * HZ - diff); diff = jiffies - last_update_time; ... mmp_check_interval = max(min(EXT4_MMP_CHECK_MULT * diff / HZ, EXT4_MMP_MAX_CHECK_INTERVAL), EXT4_MMP_MIN_CHECK_INTERVAL); mmp->mmp_check_interval = cpu_to_le16(mmp_check_interval); ... We will call ext4_stop_mmpd to stop kmmpd kthread when umount, and schedule_timeout_interruptible will be interrupted, so 'diff' maybe little than mmp_update_interval. Then mmp_check_interval will range in [EXT4_MMP_MAX_CHECK_INTERVAL, EXT4_MMP_CHECK_MULT * diff / HZ]. To solve this issue, if 'diff' little then mmp_update_interval * HZ just break loop, don't update check interval. Signed-off-by: Ye Bin --- fs/ext4/mmp.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c index eed854bb6194..41c0a03019db 100644 --- a/fs/ext4/mmp.c +++ b/fs/ext4/mmp.c @@ -205,6 +205,14 @@ static int kmmpd(void *data) schedule_timeout_interruptible(mmp_update_interval * HZ - diff); diff = jiffies - last_update_time; + /* If 'diff' little 'than mmp_update_interval * HZ', it + * means someone call ext4_stop_mmpd to stop kmmpd + * kthread. We don't need to update mmp_check_interval + * any more, as 'diff' is not exact value. + */ + if (unlikely(diff < mmp_update_interval * HZ && + kthread_should_stop())) + break; } /*