2.6.11-rc2/ext3 quota allocation bug on error path ...
looking at ext3_xattr_block_set() [fs/ext3/xattr.c] ... I see that
error = -EDQUOT;
if (DQUOT_ALLOC_BLOCK(inode, 1))
goto cleanup;allocates a quota block, but right after that several error echecks happen ...
if (error)
goto cleanup;and I don't see any DQUOT_FREE_BLOCK() in the errorpath
cleanup:
if (ce)
mb_cache_entry_release(ce);
brelse(new_bh);
if (!(bs->bh && s->base == bs->bh->b_data))
kfree(s->base);
return error;I'd suggest the attached fix (agains 2.6.11-rc2), comments?
best,
Herbert
fs/ext3/xattr.c renamed from fs/ext3/xattr.c.orig +6 -2
@@ -773,7 +773,7 @@ inserted: error =ext3_journal_get_write_access (handle, new_bh);if (error) - goto cleanup; + goto cleanup_dquot;lock_buffer (new_bh);BHDR (new_bh)->h_refcount =cpu_to_le32 (1 +le32_to_cpu (BHDR (new_bh)->h_refcount));
@@ -783,7 +783,7 @@ inserted: error =ext3_journal_dirty_metadata (handle, new_bh);if (error) - goto cleanup; + goto cleanup_dquot; }mb_cache_entry_release (ce); ce =NULL ;
@@ -844,6 +844,10 @@ cleanup:return error; +cleanup_dquot: +DQUOT_FREE_BLOCK (inode,1 ); + goto cleanup; + bad_block: ext3_error(inode->i_sb, __FUNCTION__, "inode %ld: bad block %d", inode->i_ino,
Quoted 25 lines
looking at
ext3_xattr_block_set()[fs/ext3/xattr.c] ... I see thaterror = -EDQUOT; if (DQUOT_ALLOC_BLOCK(inode, 1)) goto cleanup;allocates a quota block, but right after that several error echecks happen ...
if (error) goto cleanup;and I don't see any
DQUOT_FREE_BLOCK()in the errorpathcleanup:
if (ce) mb_cache_entry_release(ce); brelse(new_bh); if (!(bs->bh && s->base == bs->bh->b_data)) kfree(s->base); return error;
Quoted 1 line
I'd suggest the attached fix (agains 2.6.11-rc2), comments?
Yes, the patch looks right. Please apply it, Andrew. BTW ext2 needs a
similar fix - will submit in the next mail.
Honza
Quoted 32 lines
fs/ext3/xattr.c renamed from fs/ext3/xattr.c.orig +6
-2@@ -773,7 +773,7 @@ inserted: error =ext3_journal_get_write_access (handle, new_bh);if (error) - goto cleanup; + goto cleanup_dquot;lock_buffer (new_bh);BHDR (new_bh)->h_refcount =cpu_to_le32 (1 +le32_to_cpu (BHDR (new_bh)->h_refcount));@@ -783,7 +783,7 @@ inserted: error =ext3_journal_dirty_metadata (handle, new_bh);if (error) - goto cleanup; + goto cleanup_dquot; }mb_cache_entry_release (ce); ce =NULL ;@@ -844,6 +844,10 @@ cleanup:return error; +cleanup_dquot: +DQUOT_FREE_BLOCK (inode,1 ); + goto cleanup; + bad_block: ext3_error(inode->i_sb, __FUNCTION__, "inode %ld: bad block %d", inode->i_ino,
Signature · 2 lines
Jan Kara <[email protected]> SuSE CR Labs
Hello,
Quoted 21 lines · Herbert Poetzl
fs/ext3/xattr.c renamed from fs/ext3/xattr.c.orig +2
-2@@ -773,7 +773,7 @@ inserted: error =ext3_journal_get_write_access (handle, new_bh);if (error) - goto cleanup; + goto cleanup_dquot;lock_buffer (new_bh);BHDR (new_bh)->h_refcount =cpu_to_le32 (1 +le32_to_cpu (BHDR (new_bh)->h_refcount));@@ -783,7 +783,7 @@ inserted: error =ext3_journal_dirty_metadata (handle, new_bh);if (error) - goto cleanup; + goto cleanup_dquot; }mb_cache_entry_release (ce); ce =NULL ;
fs/ext3/xattr.c cleanup: · line 853
Quoted 10 lines
fs/ext3/xattr.c renamed from fs/ext3/xattr.c.orig +4
-0@@ -844,6 +844,10 @@ cleanup:return error; +cleanup_dquot: +DQUOT_FREE_BLOCK (inode,1 ); + goto cleanup; + bad_block: ext3_error(inode->i_sb, __FUNCTION__, "inode %ld: bad block %d", inode->i_ino,
looks good. Can this please be added?
THanks,
Signature · 2 lines
Andreas Gruenbacher <[email protected]> SUSE Labs, SUSE LINUX GMBH
Quoted 10 lines · Andreas Gruenbacher
fs/ext3/xattr.c cleanup: · line 853
Quoted 8 lines
fs/ext3/xattr.c renamed from fs/ext3/xattr.c.orig +4
-0+cleanup_dquot: +DQUOT_FREE_BLOCK (inode,1 ); + goto cleanup; + bad_block: ext3_error(inode->i_sb, __FUNCTION__, "inode %ld: bad block %d", inode->i_ino,looks good. Can this please be added?
Yup. But nobody has sent the equivalent ext2 fix yet?
Quoted 10 lines · Andrew Morton
Quoted 9 lines · Andreas Gruenbacher
Quoted 8 lines
(quoted diff) +4
-0+cleanup_dquot: + DQUOT_FREE_BLOCK(inode, 1); + goto cleanup; + bad_block: ext3_error(inode->i_sb, __FUNCTION__, "inode %ld: bad block %d", inode->i_ino,
Quoted 3 lines
Quoted 1 line
looks good. Can this please be added?
Yup. But nobody has sent the equivalent ext2 fix yet?
hmm, what about this one?
fs/ext2/xattr.c +4 -2
@@ -706,8 +706,11 @@ ext2_xattr_set2(struct inode *inode, str inode->i_ctime =CURRENT_TIME_SEC ;if (IS_SYNC (inode)) { error =ext2_sync_inode (inode); -if (error) +if (error) { +if (new_bh && new_bh != old_bh) +DQUOT_FREE_BLOCK (inode,1 ); goto cleanup; + } }else mark_inode_dirty (inode);
@@ -748,7 +751,6 @@ ext2_xattr_set2(struct inode *inode, str cleanup:brelse (new_bh); -return error; }
and here the ext3 fix again:
fs/ext3/xattr.c +6 -2
@@ -773,7 +773,7 @@ inserted: error =ext3_journal_get_write_access (handle, new_bh);if (error) - goto cleanup; + goto cleanup_dquot;lock_buffer (new_bh);BHDR (new_bh)->h_refcount =cpu_to_le32 (1 +le32_to_cpu (BHDR (new_bh)->h_refcount));
@@ -783,7 +783,7 @@ inserted: error =ext3_journal_dirty_metadata (handle, new_bh);if (error) - goto cleanup; + goto cleanup_dquot; }mb_cache_entry_release (ce); ce =NULL ;
@@ -844,6 +844,10 @@ cleanup:return error; +cleanup_dquot: +DQUOT_FREE_BLOCK (inode,1 ); + goto cleanup; + bad_block: ext3_error(inode->i_sb, __FUNCTION__, "inode %ld: bad block %d", inode->i_ino,
best,
Herbert
Quoted 11 lines · Andrew Morton
Quoted 10 lines
Quoted 9 lines · Andreas Gruenbacher
Quoted 8 lines
fs/ext3/xattr.c +4
-0+cleanup_dquot: +DQUOT_FREE_BLOCK (inode,1 ); + goto cleanup; + bad_block: ext3_error(inode->i_sb, __FUNCTION__, "inode %ld: bad block %d", inode->i_ino,
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
looks good. Can this please be added?
Yup. But nobody has sent the equivalent ext2 fix yet?
hmm, what about this one?
I have already made a fix and sent it to Andreas and linux-fsdevel.
For ext2 it's actually a bit more complicated because ext2_sync_inode() can return with ENOSPC (because do_writepages() need not be able to write the dirty data of the inode) but inode would be written and hence in that case we should not release the quota (and we should release the old xattr block properly). Andreas proposed to just call write_inode() instead of ext2_sync_inode() to avoid the ENOSPC case but then we might end up with inconsistency between inode metadata and indirect blocks for SYNC inode (though the only way I see how this can happen is that we race against file write and the short time inconsistency might be bearable...).
I send a combination of mine and Herbert's patch.
Honza
Signature · 26 lines
Jan Kara <[email protected]> SuSE CR Labs Fix a subtle bug in error handling of ext2 xattrs. When ext2_sync_inode() fails because of ENOSPC (it could not write inode's dirty data) we want to keep xattrs in a consistent state and release the old block properly. Signed-off-by: Jan Kara <[email protected]> --- linux/fs/ext2/xattr.c 2005-01-27 12:56:25.782729816 +0100 +++ linux/fs/ext2/xattr.c 2005-01-27 13:14:21.196242112 +0100 @@ -706,8 +706,14 @@ inode->i_ctime = CURRENT_TIME_SEC; if (IS_SYNC(inode)) { error = ext2_sync_inode (inode); - if (error) + /* In case sync failed due to ENOSPC the inode was actually + * written (only some dirty data were not) so we just proceed + * as if nothing happened and cleanup the unused block */ + if (error && error != ENOSPC) { + if (new_bh && new_bh != old_bh) + DQUOT_FREE_BLOCK(inode, 1); goto cleanup; + } } else mark_inode_dirty(inode);