Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2470181imm; Mon, 28 May 2018 08:41:24 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqaUm4X84LZjaTQrr56wHBkrRyRPKTSbmidRV9nTshLjjLsdJ4B/hpYcWqYqk1ZnDa+1K74 X-Received: by 2002:a17:902:2924:: with SMTP id g33-v6mr14285088plb.26.1527522084490; Mon, 28 May 2018 08:41:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527522084; cv=none; d=google.com; s=arc-20160816; b=W/sTljpTHLRAUYACJwz9ZAeMDg2wtdkNZF3jRZ0J+7ocIecS6IN6Kn3j3PX+ms1PtJ dEqynv1/vp0EBcwIZhd3Oabl7GCk+3uz0mw5xzvZaCPkeDep757J8qqc5YgDBPEfLBvn tw4WXAFkzNqTu4lI4z4QPMwmXoqBcmf+aYp25GQ/LN8ax1DYw4WMlGgjTqWoX46zeiXd V0ntZt47uJqwmdbfpPmmGLqugUn0mLAj5BsPgSqrlEDSDpnUZilh/92rb8TC6x+fjV45 8cxQhZ1Xb/xNERZNXG3qs78MtfN+KVtKSrLpQWJcf1395dj+EMRun1puaom5XyxP+Jqe 8dTg== 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:dkim-signature :arc-authentication-results; bh=xWYHkWyUsFOtHz5r2E/1VB7w5JJCN3OlpgU1e0CKyTE=; b=ss8PystjmzLVePz148kR02gqqreGjhvwmYuAgfh5ksHg0sMOoJfCggxnKTxsZbUo3j hosuyQImVPqWOgRKXZUrxXkQIY76J63xrxH5P4EMNUHX83vDR0QK7Fk3epidRT3YXzr2 M1ovPuqa3bU+DmZrIJrlkI7+SjA5aDBps5AR93qOlf/pUaWYBElJLdce5cf2/TM/7Vrb VX0CefGTK/HYUVYDeVnWfPxQwrrb0LUJCiNi9PQgfX4hkxY8NIEI4Ewwr1dhIfpv7IJz Y9a+TAUA8Q+TZMQcHJgjA84zJlKePaWrnJW4cLLE9RwJJ9EnyvCnsR5P9vKQhG6yfNqI mH1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PDwcesmr; 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 71-v6si31011982plc.164.2018.05.28.08.41.09; Mon, 28 May 2018 08:41:24 -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; dkim=pass header.i=@kernel.org header.s=default header.b=PDwcesmr; 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 S1030704AbeE1KRp (ORCPT + 99 others); Mon, 28 May 2018 06:17:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:37724 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030302AbeE1KRf (ORCPT ); Mon, 28 May 2018 06:17:35 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (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 3D61520876; Mon, 28 May 2018 10:17:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527502654; bh=yhXcEknGgQj3pcaePUy1sojoanmFNSnJikXFu0a3HmM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PDwcesmrGaY5bi4Xnvq2eNzdabqgvvfST71KGjS+3xxKQv86FWOkF6hPWgvKeEbBo Oy+8jTj0T5Vc8R3RYw4lDdNZGntQoz4F8H0qliMUpwPqDGOTjmN0p8T8rCsGqXmeib czb8ZTfvP9BLKTRWLy23JfbXFJ2Qr20XOPsLdlLE= 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.4 048/268] ocfs2: return error when we attempt to access a dirty bh in jbd2 Date: Mon, 28 May 2018 12:00:22 +0200 Message-Id: <20180528100207.424717869@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100202.045206534@linuxfoundation.org> References: <20180528100202.045206534@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.4-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); }