Commit 9d0792a7 authored by Stone Wang's avatar Stone Wang Committed by Linus Torvalds

[PATCH] ext2/ext3: block allocator startup fix

We found strange blocks layout in our mail server, after careful study, we
got the reason and tried to fix it.

On the very fist attempt to allocate a block to the newly-initialised inode,
if we are trying to add a block at logical file offset "1" then
ext2_find_goal() will incorrectly assume that this was a next_alloc_block
cache hit (because we think the previously-allocated block was at offset
zero).

Net result: why trying to extend a freshly-opened one-block file we end up
deciding to place the second file block at disk block "1", rather than going
off and calling ext2_find_near().

Fix it by checking that we actually do have something valid cached in
next_alloc_goal.
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 6a64d979
...@@ -354,7 +354,7 @@ static inline int ext2_find_goal(struct inode *inode, ...@@ -354,7 +354,7 @@ static inline int ext2_find_goal(struct inode *inode,
{ {
struct ext2_inode_info *ei = EXT2_I(inode); struct ext2_inode_info *ei = EXT2_I(inode);
write_lock(&ei->i_meta_lock); write_lock(&ei->i_meta_lock);
if (block == ei->i_next_alloc_block + 1) { if ((block == ei->i_next_alloc_block + 1) && ei->i_next_alloc_goal) {
ei->i_next_alloc_block++; ei->i_next_alloc_block++;
ei->i_next_alloc_goal++; ei->i_next_alloc_goal++;
} }
......
...@@ -464,7 +464,7 @@ static int ext3_find_goal(struct inode *inode, long block, Indirect chain[4], ...@@ -464,7 +464,7 @@ static int ext3_find_goal(struct inode *inode, long block, Indirect chain[4],
{ {
struct ext3_inode_info *ei = EXT3_I(inode); struct ext3_inode_info *ei = EXT3_I(inode);
/* Writer: ->i_next_alloc* */ /* Writer: ->i_next_alloc* */
if (block == ei->i_next_alloc_block + 1) { if ((block == ei->i_next_alloc_block + 1)&& ei->i_next_alloc_goal) {
ei->i_next_alloc_block++; ei->i_next_alloc_block++;
ei->i_next_alloc_goal++; ei->i_next_alloc_goal++;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment