Jan Kara f92b2d
From e86807862e6880809f191c4cea7f88a489f0ed34 Mon Sep 17 00:00:00 2001
Jan Kara f92b2d
From: Theodore Ts'o <tytso@mit.edu>
Jan Kara f92b2d
Date: Sun, 30 Dec 2018 23:20:39 -0500
Jan Kara f92b2d
Subject: [PATCH] ext4: avoid kernel warning when writing the superblock to a
Jan Kara f92b2d
 dead device
Jan Kara f92b2d
Git-commit: e86807862e6880809f191c4cea7f88a489f0ed34
Jan Kara f92b2d
Patch-mainline: v5.0-rc1
Jan Kara f92b2d
References: bsc#1124981
Jan Kara f92b2d
Jan Kara f92b2d
The xfstests generic/475 test switches the underlying device with
Jan Kara f92b2d
dm-error while running a stress test.  This results in a large number
Jan Kara f92b2d
of file system errors, and since we can't lock the buffer head when
Jan Kara f92b2d
marking the superblock dirty in the ext4_grp_locked_error() case, it's
Jan Kara f92b2d
possible the superblock to be !buffer_uptodate() without
Jan Kara f92b2d
buffer_write_io_error() being true.
Jan Kara f92b2d
Jan Kara f92b2d
We need to set buffer_uptodate() before we call mark_buffer_dirty() or
Jan Kara f92b2d
this will trigger a WARN_ON.  It's safe to do this since the
Jan Kara f92b2d
superblock must have been properly read into memory or the mount would
Jan Kara f92b2d
have been successful.  So if buffer_uptodate() is not set, we can
Jan Kara f92b2d
safely assume that this happened due to a failed attempt to write the
Jan Kara f92b2d
superblock.
Jan Kara f92b2d
Jan Kara f92b2d
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Jan Kara f92b2d
Cc: stable@vger.kernel.org
Jan Kara f92b2d
Acked-by: Jan Kara <jack@suse.cz>
Jan Kara f92b2d
Jan Kara f92b2d
---
Jan Kara f92b2d
 fs/ext4/super.c | 2 +-
Jan Kara f92b2d
 1 file changed, 1 insertion(+), 1 deletion(-)
Jan Kara f92b2d
Jan Kara f92b2d
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
Jan Kara f92b2d
index d6c142d73d99..fb12d3c17c1b 100644
Jan Kara f92b2d
--- a/fs/ext4/super.c
Jan Kara f92b2d
+++ b/fs/ext4/super.c
Jan Kara f92b2d
@@ -4902,7 +4902,7 @@ static int ext4_commit_super(struct super_block *sb, int sync)
Jan Kara f92b2d
 	ext4_superblock_csum_set(sb);
Jan Kara f92b2d
 	if (sync)
Jan Kara f92b2d
 		lock_buffer(sbh);
Jan Kara f92b2d
-	if (buffer_write_io_error(sbh)) {
Jan Kara f92b2d
+	if (buffer_write_io_error(sbh) || !buffer_uptodate(sbh)) {
Jan Kara f92b2d
 		/*
Jan Kara f92b2d
 		 * Oh, dear.  A previous attempt to write the
Jan Kara f92b2d
 		 * superblock failed.  This could happen because the
Jan Kara f92b2d
-- 
Jan Kara f92b2d
2.16.4
Jan Kara f92b2d