Skip to contentSkip to conversation

ext2: Avoid WARN() messages when failing to write to the superblock

PATCH In review Theodore Ts'o 2 participants 4 messages Oct 20, 2009 – Oct 26, 2009 ext2 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext2: Avoid WARN() messages when failing to write to the superblock

This fixes a common warning reported by kerneloops.org

[Kernel summit hacking hour]
---
 fs/ext2/super.c |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)
fs/ext2/super.c +22 -0
index 1a9ffee..7b3b6cd 100644
@@ -1089,9 +1089,30 @@ failed_sbi:
 	return ret;
 }
 
+static void ext2_clear_super_error(struct super_block * sb)
+{
+	struct buffer_head *sbh = EXT2_SB(sb)->s_sbh;
+
+	if (buffer_write_io_error(sbh)) {
+		/*
+		 * Oh, dear.  A previous attempt to write the
+		 * superblock failed.  This could happen because the
+		 * USB device was yanked out.  Or it could happen to
+		 * be a transient write error and maybe the block will
+		 * be remapped.  Nothing we can do but to retry the
+		 * write and hope for the best.
+		 */
+		printk(KERN_ERR "EXT2-fs: %s previous I/O error to "
+		       "superblock detected", sb->s_id);
+		clear_buffer_write_io_error(sbh);
+		set_buffer_uptodate(sbh);
+	}
+}
+
 static void ext2_commit_super (struct super_block * sb,
 			       struct ext2_super_block * es)
 {
+	ext2_clear_super_error(sb);
 	es->s_wtime = cpu_to_le32(get_seconds());
 	mark_buffer_dirty(EXT2_SB(sb)->s_sbh);
 	sb->s_dirt = 0;
@@ -1099,6 +1120,7 @@ static void ext2_commit_super (struct super_block * sb,
 
 static void ext2_sync_super(struct super_block *sb, struct ext2_super_block *es)
 {
+	ext2_clear_super_error(sb);
 	es->s_free_blocks_count = cpu_to_le32(ext2_count_free_blocks(sb));
 	es->s_free_inodes_count = cpu_to_le32(ext2_count_free_inodes(sb));
 	es->s_wtime = cpu_to_le32(get_seconds());
Signature · 1 line
1.6.5.104.g2567b.dirty
#1 lore raw
Quoted 8 lines · Theodore Ts'o

This fixes a common warning reported by kerneloops.org

fs/ext2/super.c +5 -0
+static void ext2_clear_super_error(struct super_block * sb)
+{
+	struct buffer_head *sbh = EXT2_SB(sb)->s_sbh;
+
+	if (buffer_write_io_error(sbh)) {

fs/ext2/super.c failed_sbi: · line 1106

Quoted 10 lines
fs/ext2/super.c +10 -0
+		/*
+		 * Oh, dear.  A previous attempt to write the
+		 * superblock failed.  This could happen because the
+		 * USB device was yanked out.  Or it could happen to
+		 * be a transient write error and maybe the block will
+		 * be remapped.  Nothing we can do but to retry the
+		 * write and hope for the best.
+		 */
+		printk(KERN_ERR "EXT2-fs: %s previous I/O error to "
+		       "superblock detected", sb->s_id);

KERN_ALERT/KERN_CRITICAL?
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#2 lore raw
Quoted 5 lines · Pavel Machek
Quoted 5 lines
fs/ext2/super.c +5 -0
+	if (buffer_write_io_error(sbh)) {
+		/*
+		 * Oh, dear.  A previous attempt to write the
+		 * superblock failed.  This could happen because the
+		 * USB device was yanked out.  Or it could happen to
Quoted 8 lines

fs/ext2/super.c failed_sbi: · line 1106

Quoted 6 lines
fs/ext2/super.c +6 -0
+		 * be a transient write error and maybe the block will
+		 * be remapped.  Nothing we can do but to retry the
+		 * write and hope for the best.
+		 */
+		printk(KERN_ERR "EXT2-fs: %s previous I/O error to "
+		       "superblock detected", sb->s_id);

KERN_ALERT/KERN_CRITICAL?

Based on kerneloops.org logs, it's apparently very frequent that clueless lusers rip out USB drives without bothering to unmount them first. (Or people by crappy laptops where the SD cards sticks out slightly and is easily jostled.) It's not clear we really want to be issueing KERN_ALERT or KERN_CRITICAL messages when this very common event happens.

- TRed

#3 lore raw
Quoted 15 lines · Theodore Tso
Quoted 5 lines · Pavel Machek
Quoted 5 lines
fs/ext2/super.c +5 -0
+	if (buffer_write_io_error(sbh)) {
+		/*
+		 * Oh, dear.  A previous attempt to write the
+		 * superblock failed.  This could happen because the
+		 * USB device was yanked out.  Or it could happen to
Quoted 8 lines

fs/ext2/super.c failed_sbi: · line 1106

Quoted 6 lines
fs/ext2/super.c +6 -0
+		 * be a transient write error and maybe the block will
+		 * be remapped.  Nothing we can do but to retry the
+		 * write and hope for the best.
+		 */
+		printk(KERN_ERR "EXT2-fs: %s previous I/O error to "
+		       "superblock detected", sb->s_id);

KERN_ALERT/KERN_CRITICAL?

Quoted 6 lines

Based on kerneloops.org logs, it's apparently very frequent that clueless lusers rip out USB drives without bothering to unmount them first. (Or people by crappy laptops where the SD cards sticks out slightly and is easily jostled.) It's not clear we really want to be issueing KERN_ALERT or KERN_CRITICAL messages when this very common event happens.

I'd say that frequency of the message should not determine the priority. (If this happens on your root filesystem you are in deep trouble, and it _should_ be broadcast on all consoles).

OTOH filesystem should be handle device unplug just fine, so not issuing this in that case would be nice...
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html