From patchwork Tue Sep 1 15:10:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 310574 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 405E4C433E6 for ; Tue, 1 Sep 2020 15:13:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0711820FC3 for ; Tue, 1 Sep 2020 15:13:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598973181; bh=k1wBZkuFVL8dW5d4JlcUY7U1TYR+0F01BvfIZJpQIPo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=evOWCrFBQcxFgHi3tqNFeSP3Xs1cDfKWRriS9+CkMqGMeEIAp5yJT7EygLuAA+8IE ykH6lh/UzMG4IXGstPBNl5+PyVglJHOgKjS+9He7R/FY4vMjxhz4P7WhVGq3h0uuvb RSZDgVbB9R/i2XW6E3CPIYxgXc2Do7AYwx4bW6+g= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728822AbgIAPMx (ORCPT ); Tue, 1 Sep 2020 11:12:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:55450 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728814AbgIAPMv (ORCPT ); Tue, 1 Sep 2020 11:12:51 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C0FD8206FA; Tue, 1 Sep 2020 15:12:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598973170; bh=k1wBZkuFVL8dW5d4JlcUY7U1TYR+0F01BvfIZJpQIPo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZQh+LLSmvQF+Wo/GRw5n62khdo57OscQRdIKRCHBJYHQUDvAQQBwJVNT1Dl83FCxy UDsPyFc96jS3W7BPaoFg7UAGcX6UIh09TOnQCgj8GLzQRXAgM2Aa0TAFm9+NNnSdlg QAfFNi2VQCEpVHr4BVMD21vzsWuLz2yiX9wiiZk8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "zhangyi (F)" , Theodore Tso , Sasha Levin Subject: [PATCH 4.4 35/62] jbd2: abort journal if free a async write error metadata buffer Date: Tue, 1 Sep 2020 17:10:18 +0200 Message-Id: <20200901150922.485242933@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200901150920.697676718@linuxfoundation.org> References: <20200901150920.697676718@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: zhangyi (F) [ Upstream commit c044f3d8360d2ecf831ba2cc9f08cf9fb2c699fb ] If we free a metadata buffer which has been failed to async write out in the background, the jbd2 checkpoint procedure will not detect this failure in jbd2_log_do_checkpoint(), so it may lead to filesystem inconsistency after cleanup journal tail. This patch abort the journal if free a buffer has write_io_error flag to prevent potential further inconsistency. Signed-off-by: zhangyi (F) Link: https://lore.kernel.org/r/20200620025427.1756360-5-yi.zhang@huawei.com Signed-off-by: Theodore Ts'o Signed-off-by: Sasha Levin --- fs/jbd2/transaction.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c index 622610934c9ad..ce2bf9d74224c 100644 --- a/fs/jbd2/transaction.c +++ b/fs/jbd2/transaction.c @@ -2000,6 +2000,7 @@ int jbd2_journal_try_to_free_buffers(journal_t *journal, { struct buffer_head *head; struct buffer_head *bh; + bool has_write_io_error = false; int ret = 0; J_ASSERT(PageLocked(page)); @@ -2024,11 +2025,26 @@ int jbd2_journal_try_to_free_buffers(journal_t *journal, jbd_unlock_bh_state(bh); if (buffer_jbd(bh)) goto busy; + + /* + * If we free a metadata buffer which has been failed to + * write out, the jbd2 checkpoint procedure will not detect + * this failure and may lead to filesystem inconsistency + * after cleanup journal tail. + */ + if (buffer_write_io_error(bh)) { + pr_err("JBD2: Error while async write back metadata bh %llu.", + (unsigned long long)bh->b_blocknr); + has_write_io_error = true; + } } while ((bh = bh->b_this_page) != head); ret = try_to_free_buffers(page); busy: + if (has_write_io_error) + jbd2_journal_abort(journal, -EIO); + return ret; }