Skip to contentSkip to conversation

ext2: add wait flag support to sync_fs

PATCH In review Stephen Hemminger 3 participants 9 messages Nov 17, 2009 – Nov 20, 2009 1 message not in the archive ext2 file system

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/2 ext2: clear uptodate flag on super block I/O error (v2)

This fixes a WARN backtrace in mark_buffer_dirty() that occurs during unmount when a USB or floppy device is removed.
The super block update from a previous operation has marked the buffer as in error, and the flag has to be cleared before doing the update. (Similar code already exists in ext4).

---
Patch against 2.6.32-rc7
Revised to handle both sync_fs and put_super updating superblock.

fs/ext2/super.c +15 -2
@@ -1099,11 +1099,24 @@ static void ext2_commit_super (struct su
 
 static void ext2_sync_super(struct super_block *sb, struct ext2_super_block *es)
 {
+	struct buffer_head *sbh = EXT2_SB(sb)->s_sbh;
+
+	if (buffer_write_io_error(sbh)) {
+		/*
+		 * This happens if USB or floppy device is yanked out.
+		 * Maybe user put device back in so warn and update again.
+		 */
+		printk(KERN_ERR
+		       "EXT2-fs: previous I/O error to superblock detected\n");
+		clear_buffer_write_io_error(sbh);
+		set_buffer_uptodate(sbh);
+	}
+
 	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());
-	mark_buffer_dirty(EXT2_SB(sb)->s_sbh);
-	sync_dirty_buffer(EXT2_SB(sb)->s_sbh);
+	mark_buffer_dirty(sbh);
+	sync_dirty_buffer(sbh);
 	sb->s_dirt = 0;
 }
 
#2 lore raw

Re: [PATCH 1/2] ext2: clear uptodate flag on super block I/O error (v2)

Quoted 7 lines

This fixes a WARN backtrace in mark_buffer_dirty() that occurs during unmount when a USB or floppy device is removed.
The super block update from a previous operation has marked the buffer as in error, and the flag has to be cleared before doing the update. (Similar code already exists in ext4).

Although I agree with Nick that ultimate solution would be to stop
clearing the uptodate flag, I think the change is fine in principle as a workaround for warning that only scares people.

Quoted 7 lines
fs/ext2/super.c +1 -0
@@ -1099,11 +1099,24 @@ static void ext2_commit_super (struct su
 
 static void ext2_sync_super(struct super_block *sb, struct ext2_super_block *es)
 {
+	struct buffer_head *sbh = EXT2_SB(sb)->s_sbh;

fs/ext2/super.c static void ext2_commit_super (struct su · line 1112

Quoted 10 lines
fs/ext2/super.c +10 -0
+
+	if (buffer_write_io_error(sbh)) {
+		/*
+		 * This happens if USB or floppy device is yanked out.
+		 * Maybe user put device back in so warn and update again.
+		 */
+		printk(KERN_ERR
+		       "EXT2-fs: previous I/O error to superblock detected\n");
+		clear_buffer_write_io_error(sbh);
+		set_buffer_uptodate(sbh);

It's not much about puting the device back. It's really just about
avoiding the warning in mark_buffer_dirty(). So I'd just silently set_buffer_uptodate and be done with it. For superblock we are darn sure that in memory copy is the one that has the latest data :)

fs/ext2/super.c static void ext2_commit_super (struct su · line 1121

Quoted 11 lines
fs/ext2/super.c +4 -2
+	}
+
 	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());
-	mark_buffer_dirty(EXT2_SB(sb)->s_sbh);
-	sync_dirty_buffer(EXT2_SB(sb)->s_sbh);
+	mark_buffer_dirty(sbh);
+	sync_dirty_buffer(sbh);
 	sb->s_dirt = 0;
 }

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SuSE CR Labs
#3 lore raw

Re: [PATCH 1/2] ext2: clear uptodate flag on super block I/O error (v2)

Quoted 5 lines · On Thu, 19 Nov 2009 16:19:53 +0100 Jan Kara <[email protected]> wrote:
Quoted 5 lines
fs/ext2/super.c +5 -0
+	if (buffer_write_io_error(sbh)) {
+		/*
+		 * This happens if USB or floppy device is yanked out.
+		 * Maybe user put device back in so warn and update again.
+		 */
Quoted 8 lines

fs/ext2/super.c static void ext2_commit_super (struct su · line 1112

Quoted 4 lines
fs/ext2/super.c +4 -0
+		printk(KERN_ERR
+		       "EXT2-fs: previous I/O error to superblock detected\n");
+		clear_buffer_write_io_error(sbh);
+		set_buffer_uptodate(sbh);  

It's not much about puting the device back. It's really just about
avoiding the warning in mark_buffer_dirty(). So I'd just silently set_buffer_uptodate and be done with it. For superblock we are darn sure that in memory copy is the one that has the latest data :)

This code mirrors ext4_commit_super, why should ext2 be any different?

#4 lore raw

Re: [PATCH 1/2] ext2: clear uptodate flag on super block I/O error (v2)

Quoted 17 lines · Stephen Hemminger
Quoted 5 lines · On Thu, 19 Nov 2009 16:19:53 +0100 Jan Kara <[email protected]> wrote:
Quoted 5 lines
fs/ext2/super.c +5 -0
+	if (buffer_write_io_error(sbh)) {
+		/*
+		 * This happens if USB or floppy device is yanked out.
+		 * Maybe user put device back in so warn and update again.
+		 */
Quoted 8 lines

fs/ext2/super.c static void ext2_commit_super (struct su · line 1112

Quoted 4 lines
fs/ext2/super.c +4 -0
+		printk(KERN_ERR
+		       "EXT2-fs: previous I/O error to superblock detected\n");
+		clear_buffer_write_io_error(sbh);
+		set_buffer_uptodate(sbh);  

It's not much about puting the device back. It's really just about
avoiding the warning in mark_buffer_dirty(). So I'd just silently set_buffer_uptodate and be done with it. For superblock we are darn sure that in memory copy is the one that has the latest data :)

Quoted 1 line

This code mirrors ext4_commit_super, why should ext2 be any different?

OK, my remark was mostly about the comment which is different in ext4 ;).
I'll just fixup the comment and merge the patch. Thanks.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#5 lore raw

PATCH 2/2 ext2: add wait flag support to sync_fs

In reply to a message not in the archive

Make ext2 safer against accidental data loss during removal by adding support for waiting for super block update on sync. Don't know why this wasn't done originally, all the other file systems have it.

fs/ext2/super.c +2 -0
@@ -1147,6 +1147,8 @@ static int ext2_sync_fs(struct super_blo
 		ext2_sync_super(sb, es);
 	} else {
 		ext2_commit_super(sb, es);
+		if (wait)
+			sync_dirty_buffer(EXT2_SB(sb)->s_sbh);
 	}
 	sb->s_dirt = 0;
 	unlock_kernel();
#6 lore raw
Quoted 10 lines

Make ext2 safer against accidental data loss during removal by adding support for waiting for super block update on sync. Don't know why this wasn't done originally, all the other file systems have it.

fs/ext2/super.c static int ext2_sync_fs(struct super_blo · line 1154

Quoted 8 lines
fs/ext2/super.c +2 -0
@@ -1147,6 +1147,8 @@ static int ext2_sync_fs(struct super_blo
 		ext2_sync_super(sb, es);
 	} else {
 		ext2_commit_super(sb, es);
+		if (wait)
+			sync_dirty_buffer(EXT2_SB(sb)->s_sbh);
 	}
 	sb->s_dirt = 0;
 	unlock_kernel();

Looking at the code it just looks strange. Part of it is because
of Christoph's conversion of ext2_write_super to ext2_sync_fs (40f31dd47e7c3d15af1f9845eda0fa0c4c33f32f) but the VALID_FS handling oddness seems to be even older. IMHO we should just clear the VALID_FS flag on mount and in write_super() and sync_fs() just update block and inode counters. wait == 1 case should then really wait for superblock buffer, wait == 0 should not wait.
BTW: Christoph, why did you choose to call ext2_sync_fs with wait == 1
from ext2_write_super()? I'd think (and looking into callsites seem to confirm that) that ->write_super() was meant to be asynchronous...
I've added this to my todo...

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SuSE CR Labs
#7 lore raw
Quoted 3 lines · Jan Kara

BTW: Christoph, why did you choose to call ext2_sync_fs with wait == 1
from ext2_write_super()? I'd think (and looking into callsites seem to confirm that) that ->write_super() was meant to be asynchronous...

No particular reason - the argument wasn't and still isn't used in ext2. And yes, now that ->sync_fs is mandatory ->write_super should be asynchronous.

#8 lore raw
Quoted 9 lines · On Fri, 20 Nov 2009 05:36:22 -0500 Christoph Hellwig <[email protected]> wrote:
Quoted 3 lines · Jan Kara

BTW: Christoph, why did you choose to call ext2_sync_fs with wait == 1
from ext2_write_super()? I'd think (and looking into callsites seem to confirm that) that ->write_super() was meant to be asynchronous...

No particular reason - the argument wasn't and still isn't used in ext2. And yes, now that ->sync_fs is mandatory ->write_super should be asynchronous.

Shouldn't super block (and all other) updates be synchronous if ext2 is mounted with SYNC and DIRSYNC?

#9 lore raw
Quoted 8 lines · Stephen Hemminger
Quoted 5 lines · On Fri, 20 Nov 2009 05:36:22 -0500 Christoph Hellwig <[email protected]> wrote:
Quoted 3 lines · Jan Kara

BTW: Christoph, why did you choose to call ext2_sync_fs with wait == 1
from ext2_write_super()? I'd think (and looking into callsites seem to confirm that) that ->write_super() was meant to be asynchronous...

Quoted 6 lines
Quoted 3 lines

No particular reason - the argument wasn't and still isn't used in ext2. And yes, now that ->sync_fs is mandatory ->write_super should be asynchronous.

Shouldn't super block (and all other) updates be synchronous if ext2 is mounted with SYNC and DIRSYNC?

Well, looking at the code, we don't seem to do that ;) Maybe we should
but would it really bring anything? The only thing which will go wrong are counters of free blocks and inodes and those will be recomputed by fsck anyway. And note that SYNC does not guarantee you that you don't need fsck if you just pull the device out without umount. It just limits the damage...

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR