ext2: add wait flag support to sync_fs
PATCH 2/2 ext2: add wait flag support to sync_fs
In reply to a message not in the archiveMake 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_bloext2_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 ();
PATCH 1/2 ext2: clear uptodate flag on super block I/O error (v2)
In reply to a message not in the archiveThis 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 sustatic 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 ; }
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).Signed-off-by Stephen Hemminger <[email protected]>
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 sustatic 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
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.
Signed-off-by Stephen Hemminger <[email protected]>
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_bloext2_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
Re: [PATCH 1/2] ext2: clear uptodate flag on super block I/O error (v2)
In reply to Jan KaraQuoted 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 inmark_buffer_dirty(). So I'd just silentlyset_buffer_uptodateand 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?
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 inmark_buffer_dirty(). So I'd just silentlyset_buffer_uptodateand 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
Quoted 3 lines · Jan Kara
BTW: Christoph, why did you choose to call
ext2_sync_fswith wait == 1
fromext2_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.
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_fswith wait == 1
fromext2_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?
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_fswith wait == 1
fromext2_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