Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3489964pxj; Tue, 15 Jun 2021 01:58:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyf4PrfHQsTxVkjfannhykFRLczYrAJmsliPV/bCdj6RzjkFBiSs2B53FNihppUfTgIJ11+ X-Received: by 2002:a17:906:9512:: with SMTP id u18mr19991786ejx.61.1623747499912; Tue, 15 Jun 2021 01:58:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623747499; cv=none; d=google.com; s=arc-20160816; b=pg02z1XcobCgYXf/NsLhkXr05zXrk9BHvgPGBka90j/O6QT2V1hYbOV2C15oY69B8s oTnuih6C4AqM/DTC+64WKsUatsNoEHwzH2cwSpOqeezlIlTV61u2KDqPEqpfhjHGeVKk kUb7QRHSGz9eoNpG4G7FLhsCZgqpNHt2rdDMMEzwsnIl5w8OuWib+2olf2c2Gg3PTdTN d3HC2IQJ1O/mt1tsTKMJ/7bngcdHHwYlKnIDb0qZ59ccPkNw/aKf9vtLyPqhA4KQpu1O mHm/2BNbcEsdzW5DclIQTl8h6qpPz7bZoA+FSDtyePZgrT4cabuZrGBGPdNovZXeg5Oa 5G8A== 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 :message-id:date:subject:cc:to:from; bh=e7GttYbhh7JkCluqU7adC22uikA5wF+YqcxPAm2sfko=; b=kbSoPVPXqAG6dvjt9sJlanCnp4kkVNAW6mLkN506a6drfcWt6hnIhIPn/+hZKV0afz B8la2bP658KJ30lL+HmVK+SxvHy4MPDEFNtm61bqbz//A+oX2jNjWhjSsef8psHJJcw/ 52D7TojJbOHKopxyWoXfHu/1groH9TrQILRYuEe/DedN/mXwvjuG/nkBVI/tGOnKJhdG 1ffU6/aMqI7f1vRKIS/5Kmo8LMQRyeXUeekL16qOeFL/nS8iWPggg5VXmpjkbPcJxZuC 4j6bxYrsg+Lkb1IJPPExUSlaZqQgXYTBEuIKw7uH5I9afglGxvQQsnjozPPdMI939i4d WirQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s6si9010686edd.183.2021.06.15.01.57.52; Tue, 15 Jun 2021 01:58:19 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231298AbhFOI6p (ORCPT + 99 others); Tue, 15 Jun 2021 04:58:45 -0400 Received: from szxga08-in.huawei.com ([45.249.212.255]:7270 "EHLO szxga08-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231267AbhFOI6o (ORCPT ); Tue, 15 Jun 2021 04:58:44 -0400 Received: from dggeme754-chm.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4G429l16Fyz1BMJ8; Tue, 15 Jun 2021 16:51:39 +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.2176.2; Tue, 15 Jun 2021 16:56:38 +0800 From: Ye Bin To: , , , , CC: Ye Bin Subject: [PATCH RFC v2] ext4:fix warning in mark_buffer_dirty as IO error when mount with errors=continue Date: Tue, 15 Jun 2021 17:05:37 +0800 Message-ID: <20210615090537.3423231-1-yebin10@huawei.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) 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 We test with following step: 1. dmsetup create dust1 --table '0 2097152 dust /dev/sdc 0 4096' 2. mount /dev/mapper/dust1 /home/test 3. dmsetup message dust1 0 addbadblock 0 10 4. cd /home/test 5. echo "XXXXXXX" > t 6. wait a moment we got following warning: [ 80.654487] end_buffer_async_write: bh=0xffff88842f18bdd0 [ 80.656134] Buffer I/O error on dev dm-0, logical block 0, lost async page write [ 85.774450] EXT4-fs error (device dm-0): ext4_check_bdev_write_error:193: comm kworker/u16:8: Error while async write back metadata [ 91.415513] mark_buffer_dirty: bh=0xffff88842f18bdd0 [ 91.417038] ------------[ cut here ]------------ [ 91.418450] WARNING: CPU: 1 PID: 1944 at fs/buffer.c:1092 mark_buffer_dirty.cold+0x1c/0x5e [ 91.440322] Call Trace: [ 91.440652] __jbd2_journal_temp_unlink_buffer+0x135/0x220 [ 91.441354] __jbd2_journal_unfile_buffer+0x24/0x90 [ 91.441981] __jbd2_journal_refile_buffer+0x134/0x1d0 [ 91.442628] jbd2_journal_commit_transaction+0x249a/0x3240 [ 91.443336] ? put_prev_entity+0x2a/0x200 [ 91.443856] ? kjournald2+0x12e/0x510 [ 91.444324] kjournald2+0x12e/0x510 [ 91.444773] ? woken_wake_function+0x30/0x30 [ 91.445326] kthread+0x150/0x1b0 [ 91.445739] ? commit_timeout+0x20/0x20 [ 91.446258] ? kthread_flush_worker+0xb0/0xb0 [ 91.446818] ret_from_fork+0x1f/0x30 [ 91.447293] ---[ end trace 66f0b6bf3d1abade ]--- If super block write back with IO error, then will call clear_buffer_uptodate clear uptodate flag. But there is no chance to set buffer uptodate again. So call set_buffer_uptodate before call jbd2_journal_dirty_metadata to make sure that buffer is uptodate when buffer is jbddirty. Signed-off-by: Ye Bin --- fs/ext4/ext4_jbd2.c | 2 +- fs/ext4/super.c | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/fs/ext4/ext4_jbd2.c b/fs/ext4/ext4_jbd2.c index be799040a415..b96ecba91899 100644 --- a/fs/ext4/ext4_jbd2.c +++ b/fs/ext4/ext4_jbd2.c @@ -327,6 +327,7 @@ int __ext4_handle_dirty_metadata(const char *where, unsigned int line, set_buffer_meta(bh); set_buffer_prio(bh); + set_buffer_uptodate(bh); if (ext4_handle_valid(handle)) { err = jbd2_journal_dirty_metadata(handle, bh); /* Errors can only happen due to aborted journal or a nasty bug */ @@ -355,7 +356,6 @@ int __ext4_handle_dirty_metadata(const char *where, unsigned int line, err); } } else { - set_buffer_uptodate(bh); if (inode) mark_buffer_dirty_inode(bh, inode); else diff --git a/fs/ext4/super.c b/fs/ext4/super.c index d29f6aa7d96e..67a92c11a45c 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -705,15 +705,23 @@ static void flush_stashed_error_work(struct work_struct *work) * ext4 error handling code during handling of previous errors. */ if (!sb_rdonly(sbi->s_sb) && journal) { + struct buffer_head *sbh = sbi->s_sbh; handle = jbd2_journal_start(journal, 1); if (IS_ERR(handle)) goto write_directly; - if (jbd2_journal_get_write_access(handle, sbi->s_sbh)) { + if (jbd2_journal_get_write_access(handle, sbh)) { jbd2_journal_stop(handle); goto write_directly; } ext4_update_super(sbi->s_sb); - if (jbd2_journal_dirty_metadata(handle, sbi->s_sbh)) { + if (buffer_write_io_error(sbh) || !buffer_uptodate(sbh)) { + ext4_msg(sbi->s_sb, KERN_ERR, "previous I/O error to " + "superblock detected"); + clear_buffer_write_io_error(sbh); + set_buffer_uptodate(sbh); + } + + if (jbd2_journal_dirty_metadata(handle, sbh)) { jbd2_journal_stop(handle); goto write_directly; } -- 2.31.1