]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-5.0/ext4-avoid-panic-during-forced-reboot.patch
autosel patches for 5.0
[thirdparty/kernel/stable-queue.git] / queue-5.0 / ext4-avoid-panic-during-forced-reboot.patch
1 From dbec735b02040c15e86558f7aef51d9f0179de2f Mon Sep 17 00:00:00 2001
2 From: Jan Kara <jack@suse.cz>
3 Date: Thu, 14 Mar 2019 23:46:05 -0400
4 Subject: ext4: avoid panic during forced reboot
5
6 [ Upstream commit 1dc1097ff60e4105216da7cd0aa99032b039a994 ]
7
8 When admin calls "reboot -f" - i.e., does a hard system reboot by
9 directly calling reboot(2) - ext4 filesystem mounted with errors=panic
10 can panic the system. This happens because the underlying device gets
11 disabled without unmounting the filesystem and thus some syscall running
12 in parallel to reboot(2) can result in the filesystem getting IO errors.
13
14 This is somewhat surprising to the users so try improve the behavior by
15 switching to errors=remount-ro behavior when the system is running
16 reboot(2).
17
18 Signed-off-by: Jan Kara <jack@suse.cz>
19 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 Signed-off-by: Sasha Levin <sashal@kernel.org>
21 ---
22 fs/ext4/super.c | 16 +++++++++++++---
23 1 file changed, 13 insertions(+), 3 deletions(-)
24
25 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
26 index fb12d3c17c1b..b9bca7298f96 100644
27 --- a/fs/ext4/super.c
28 +++ b/fs/ext4/super.c
29 @@ -430,6 +430,12 @@ static void ext4_journal_commit_callback(journal_t *journal, transaction_t *txn)
30 spin_unlock(&sbi->s_md_lock);
31 }
32
33 +static bool system_going_down(void)
34 +{
35 + return system_state == SYSTEM_HALT || system_state == SYSTEM_POWER_OFF
36 + || system_state == SYSTEM_RESTART;
37 +}
38 +
39 /* Deal with the reporting of failure conditions on a filesystem such as
40 * inconsistencies detected or read IO failures.
41 *
42 @@ -460,7 +466,12 @@ static void ext4_handle_error(struct super_block *sb)
43 if (journal)
44 jbd2_journal_abort(journal, -EIO);
45 }
46 - if (test_opt(sb, ERRORS_RO)) {
47 + /*
48 + * We force ERRORS_RO behavior when system is rebooting. Otherwise we
49 + * could panic during 'reboot -f' as the underlying device got already
50 + * disabled.
51 + */
52 + if (test_opt(sb, ERRORS_RO) || system_going_down()) {
53 ext4_msg(sb, KERN_CRIT, "Remounting filesystem read-only");
54 /*
55 * Make sure updated value of ->s_mount_flags will be visible
56 @@ -468,8 +479,7 @@ static void ext4_handle_error(struct super_block *sb)
57 */
58 smp_wmb();
59 sb->s_flags |= SB_RDONLY;
60 - }
61 - if (test_opt(sb, ERRORS_PANIC)) {
62 + } else if (test_opt(sb, ERRORS_PANIC)) {
63 if (EXT4_SB(sb)->s_journal &&
64 !(EXT4_SB(sb)->s_journal->j_flags & JBD2_REC_ERR))
65 return;
66 --
67 2.19.1
68