Skip to content

Commit

Permalink
ext4: wait for existing dio workers in ext4_alloc_file_blocks()
Browse files Browse the repository at this point in the history
Currently existing dio workers can jump in and potentially increase
extent tree depth while we're allocating blocks in
ext4_alloc_file_blocks().  This may cause us to underestimate the
number of credits needed for the transaction because the extent tree
depth can change after our estimation.

Fix this by waiting for all the existing dio workers in the same way
as we do it in ext4_punch_hole.  We've seen errors caused by this in
xfstest generic/299, however it's really hard to reproduce.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
  • Loading branch information
Lukas Czerner authored and Theodore Ts'o committed Jun 15, 2015
1 parent 4134f5c commit 0d306dc
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions fs/ext4/extents.c
Original file line number Diff line number Diff line change
Expand Up @@ -4678,6 +4678,10 @@ static int ext4_alloc_file_blocks(struct file *file, ext4_lblk_t offset,
if (len <= EXT_UNWRITTEN_MAX_LEN)
flags |= EXT4_GET_BLOCKS_NO_NORMALIZE;

/* Wait all existing dio workers, newcomers will block on i_mutex */
ext4_inode_block_unlocked_dio(inode);
inode_dio_wait(inode);

/*
* credits to insert 1 extent into extent tree
*/
Expand Down Expand Up @@ -4741,6 +4745,8 @@ static int ext4_alloc_file_blocks(struct file *file, ext4_lblk_t offset,
goto retry;
}

ext4_inode_resume_unlocked_dio(inode);

return ret > 0 ? ret2 : ret;
}

Expand Down

0 comments on commit 0d306dc

Please sign in to comment.