Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp887412yba; Thu, 18 Apr 2019 11:13:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqwHPQHce/QsJUdTlVILebOTsUkW2r8IoxDnvtDjrIH4bq/ZiaqlQ1qIO/E2Q30IS93e0kWR X-Received: by 2002:aa7:8edd:: with SMTP id b29mr8055581pfr.241.1555611220644; Thu, 18 Apr 2019 11:13:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555611220; cv=none; d=google.com; s=arc-20160816; b=CGDuA/RzF7DZAuDDus+ok0KGI7/U7DtaXKR+R0Q8exwfk+v8Amkln9s9294uJmK/Gf DOn9YX8ozlyZVMqhG3sDF4Z/httR11uin7in6ag3JaIbtH1/B1P+AJOYwSBy0LpyJyni zMBtdequc00zX+a3h9jpRPW0EzMDOB3Z96qa5qhO+SJuKXQ0CV28mzkL+67oofcvn4mm N6L+k2yqUj31/B5cgnvFz6sG414fGGGVu9XD2lVDlIU5RB40Q0fhVPF3rZecDtJPXS4r dIrf8YkSeBZ6eMjIJeHXSIZABm7PeiAlHShaVf8iUBKFVMAmLuikAQPuzZ+/lLz1AkbR yy7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Eb96FFp+dhfmOOUYM6mSNrzoBdC/U6eQ3Dc8ZCACVVo=; b=S0+HS9XTF67tAM9pUri4dDllGNfbqpU1faikcdhpHZNoOlJuDLX+UEoM7oI8Y3bWoc bvWxyP3t8a9W8DmE9w9Gr6h7zG43rqSP7dVinYgrxIrswm0xisncDrvcZkHBAkr4aY2Z jIEIpQfpHwHydjQ1NpfLUAuyKtaIwaTCVpz6IIOLNmU577bq4+odj+dbIVe5N9UfT2US Bp7zJX2pU/5OfBpgK1yU7CV7tD6aCITzvpf2scUsMPEV9hlINQKnki7F4I5YRxHESrqS onHHhiPgZMyeRySMkinluL4kzyDldLpcRkycSnUphlyMeJxBi0IQ0KWesR0f2XxXgH21 m9tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UO0Dt4Iz; 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 k18si2517359pgb.351.2019.04.18.11.13.26; Thu, 18 Apr 2019 11:13:40 -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=UO0Dt4Iz; 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 S2404128AbfDRSKd (ORCPT + 99 others); Thu, 18 Apr 2019 14:10:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:42208 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391486AbfDRSK0 (ORCPT ); Thu, 18 Apr 2019 14:10:26 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 ADF6D20652; Thu, 18 Apr 2019 18:10:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555611026; bh=Ry/fhiyEgWF0AA1ikIdMjZpB+mjIFoMWeKf5AtmVcDs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UO0Dt4IzqD0tSvwXy44qr6gWJMjGaeoM80p6E2GFFV398/tRoDnUiFu2MoI09ZLbE XQ6rUQoq8MnUL5ufcW+aS+q1PKnYFdTfZEk3i/BD+KGLNK1EFgmq+eJeokBK6+R/67 +WIb0+bOsR0OZSnZI0af7FaEm0lpFThfoHm6L92E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jan Kara , Theodore Tso , Sasha Levin Subject: [PATCH 5.0 07/93] ext4: avoid panic during forced reboot Date: Thu, 18 Apr 2019 19:56:45 +0200 Message-Id: <20190418160437.771182786@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190418160436.781762249@linuxfoundation.org> References: <20190418160436.781762249@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 1dc1097ff60e4105216da7cd0aa99032b039a994 ] When admin calls "reboot -f" - i.e., does a hard system reboot by directly calling reboot(2) - ext4 filesystem mounted with errors=panic can panic the system. This happens because the underlying device gets disabled without unmounting the filesystem and thus some syscall running in parallel to reboot(2) can result in the filesystem getting IO errors. This is somewhat surprising to the users so try improve the behavior by switching to errors=remount-ro behavior when the system is running reboot(2). Signed-off-by: Jan Kara Signed-off-by: Theodore Ts'o Signed-off-by: Sasha Levin --- fs/ext4/super.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index fb12d3c17c1b..b9bca7298f96 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -430,6 +430,12 @@ static void ext4_journal_commit_callback(journal_t *journal, transaction_t *txn) spin_unlock(&sbi->s_md_lock); } +static bool system_going_down(void) +{ + return system_state == SYSTEM_HALT || system_state == SYSTEM_POWER_OFF + || system_state == SYSTEM_RESTART; +} + /* Deal with the reporting of failure conditions on a filesystem such as * inconsistencies detected or read IO failures. * @@ -460,7 +466,12 @@ static void ext4_handle_error(struct super_block *sb) if (journal) jbd2_journal_abort(journal, -EIO); } - if (test_opt(sb, ERRORS_RO)) { + /* + * We force ERRORS_RO behavior when system is rebooting. Otherwise we + * could panic during 'reboot -f' as the underlying device got already + * disabled. + */ + if (test_opt(sb, ERRORS_RO) || system_going_down()) { ext4_msg(sb, KERN_CRIT, "Remounting filesystem read-only"); /* * Make sure updated value of ->s_mount_flags will be visible @@ -468,8 +479,7 @@ static void ext4_handle_error(struct super_block *sb) */ smp_wmb(); sb->s_flags |= SB_RDONLY; - } - if (test_opt(sb, ERRORS_PANIC)) { + } else if (test_opt(sb, ERRORS_PANIC)) { if (EXT4_SB(sb)->s_journal && !(EXT4_SB(sb)->s_journal->j_flags & JBD2_REC_ERR)) return; -- 2.19.1