Received: by 10.192.165.148 with SMTP id m20csp539116imm; Wed, 25 Apr 2018 03:56:56 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/C2zhLHJMdds2xesI5gfbSI+eyTFW4TjvhUX+AyrEy6Nr4Id0h25PCzqTbRJaYBVIadNa6 X-Received: by 2002:a17:902:8546:: with SMTP id d6-v6mr29869097plo.106.1524653816230; Wed, 25 Apr 2018 03:56:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524653816; cv=none; d=google.com; s=arc-20160816; b=NklzwihRyyBoFaFm8yK/PPzCIqcht5xuyFc3FxM1dPpCMD93grJ65ERC+4PgeUPkZD prLuKab87rB9tCV8bqcKqtoibsq8hQAUYugSyx8gY68c8QrJ5Ty77pTDOcCY2ihjekDz aLRad+k/cnf7maXZM1T9cP8DI9tQb4pq5wnxsevnkGwGO+snslDitpqkyFWg68JfQR+U icSAqktqMhC/k9WgV67fj1OtvkUdFfu04CunE+BCjuy9lZZgXr5cJF2roJzbmqffB97w EtF5s4hnBwi7CnEYsbzio1H0HZBuA+Bf1FzgMZx2bViQOyFAvwFeuLsj/I+R2XtxiXCp pb1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=uNaqFertqxW0m1cW5TsLLju5wySsjuwPIT0Z1HvymTo=; b=wlaISWTE9QRL4LKLtKY2F/eYk/vjy7aGgHQKOu0ymrQTTonkBef9NJquDTQDcS3L8c p/Rh8ftAjh1rlshF7oGSpiwmD3bax4uZGJuwFa/plpzNgf4cvn1iWwoDw0sAxIU6GA/v 2c8Df9YuXsPhQl9U+xMYPjbdYl8oz2flv6lq2hRARrZmBgXP2ZgMmEZ4Nw0YUG49r1Eu DLEQk2R3dasllB5UteSWmUi3dYYzuADu08CzVCddV6NJo/ND+mmZFPvSFaqF5sqXDefD WSqpEjp6s2rFLQ3MqTxx9dDDvfkpZHMrRV1FDI3lwDjrHxCID+OtsdTYcuf1qyrxCUun sJcA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k185si13478140pgk.2.2018.04.25.03.56.41; Wed, 25 Apr 2018 03:56:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754255AbeDYKzj (ORCPT + 99 others); Wed, 25 Apr 2018 06:55:39 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:52920 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753858AbeDYKnQ (ORCPT ); Wed, 25 Apr 2018 06:43:16 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id DE951480; Wed, 25 Apr 2018 10:43:15 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jun Piao , Yiwen Jiang , Changwei Ge , Mark Fasheh , Joel Becker , Junxiao Bi , Joseph Qi , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 4.14 110/183] ocfs2: return error when we attempt to access a dirty bh in jbd2 Date: Wed, 25 Apr 2018 12:35:30 +0200 Message-Id: <20180425103246.874406810@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180425103242.532713678@linuxfoundation.org> References: <20180425103242.532713678@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: piaojun [ Upstream commit d984187e3a1ad7d12447a7ab2c43ce3717a2b5b3 ] We should not reuse the dirty bh in jbd2 directly due to the following situation: 1. When removing extent rec, we will dirty the bhs of extent rec and truncate log at the same time, and hand them over to jbd2. 2. The bhs are submitted to jbd2 area successfully. 3. The write-back thread of device help flush the bhs to disk but encounter write error due to abnormal storage link. 4. After a while the storage link become normal. Truncate log flush worker triggered by the next space reclaiming found the dirty bh of truncate log and clear its 'BH_Write_EIO' and then set it uptodate in __ocfs2_journal_access(): ocfs2_truncate_log_worker ocfs2_flush_truncate_log __ocfs2_flush_truncate_log ocfs2_replay_truncate_records ocfs2_journal_access_di __ocfs2_journal_access // here we clear io_error and set 'tl_bh' uptodata. 5. Then jbd2 will flush the bh of truncate log to disk, but the bh of extent rec is still in error state, and unfortunately nobody will take care of it. 6. At last the space of extent rec was not reduced, but truncate log flush worker have given it back to globalalloc. That will cause duplicate cluster problem which could be identified by fsck.ocfs2. Sadly we can hardly revert this but set fs read-only in case of ruining atomicity and consistency of space reclaim. Link: http://lkml.kernel.org/r/5A6E8092.8090701@huawei.com Fixes: acf8fdbe6afb ("ocfs2: do not BUG if buffer not uptodate in __ocfs2_journal_access") Signed-off-by: Jun Piao Reviewed-by: Yiwen Jiang Reviewed-by: Changwei Ge Cc: Mark Fasheh Cc: Joel Becker Cc: Junxiao Bi Cc: Joseph Qi Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/ocfs2/journal.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) --- a/fs/ocfs2/journal.c +++ b/fs/ocfs2/journal.c @@ -666,23 +666,24 @@ static int __ocfs2_journal_access(handle /* we can safely remove this assertion after testing. */ if (!buffer_uptodate(bh)) { mlog(ML_ERROR, "giving me a buffer that's not uptodate!\n"); - mlog(ML_ERROR, "b_blocknr=%llu\n", - (unsigned long long)bh->b_blocknr); + mlog(ML_ERROR, "b_blocknr=%llu, b_state=0x%lx\n", + (unsigned long long)bh->b_blocknr, bh->b_state); lock_buffer(bh); /* - * A previous attempt to write this buffer head failed. - * Nothing we can do but to retry the write and hope for - * the best. + * A previous transaction with a couple of buffer heads fail + * to checkpoint, so all the bhs are marked as BH_Write_EIO. + * For current transaction, the bh is just among those error + * bhs which previous transaction handle. We can't just clear + * its BH_Write_EIO and reuse directly, since other bhs are + * not written to disk yet and that will cause metadata + * inconsistency. So we should set fs read-only to avoid + * further damage. */ if (buffer_write_io_error(bh) && !buffer_uptodate(bh)) { - clear_buffer_write_io_error(bh); - set_buffer_uptodate(bh); - } - - if (!buffer_uptodate(bh)) { unlock_buffer(bh); - return -EIO; + return ocfs2_error(osb->sb, "A previous attempt to " + "write this buffer head failed\n"); } unlock_buffer(bh); }