add patch fix-ocfs2-corrupt-when-updating-journal-superblock-fails
[ext4-patch-queue.git] / wait-for-existing-dio-workers-in-ext4_alloc_file_blocks
blobb65e808d68cace3f0f57e2c03ad1c2168a92ec82
1 ext4: wait for existing dio workers in ext4_alloc_file_blocks()
3 From: Lukas Czerner <lczerner@redhat.com>
5 Currently existing dio workers can jump in and potentially increase
6 extent tree depth while we're allocating blocks in
7 ext4_alloc_file_blocks().  This may cause us to underestimate the
8 number of credits needed for the transaction because the extent tree
9 depth can change after our estimation.
11 Fix this by waiting for all the existing dio workers in the same way
12 as we do it in ext4_punch_hole.  We've seen errors caused by this in
13 xfstest generic/299, however it's really hard to reproduce.
15 Signed-off-by: Lukas Czerner <lczerner@redhat.com>
16 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
17 ---
18  fs/ext4/extents.c | 6 ++++++
19  1 file changed, 6 insertions(+)
21 diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
22 index 13c5ebf..a5f7322 100644
23 --- a/fs/ext4/extents.c
24 +++ b/fs/ext4/extents.c
25 @@ -4678,6 +4678,10 @@ static int ext4_alloc_file_blocks(struct file *file, ext4_lblk_t offset,
26         if (len <= EXT_UNWRITTEN_MAX_LEN)
27                 flags |= EXT4_GET_BLOCKS_NO_NORMALIZE;
29 +       /* Wait all existing dio workers, newcomers will block on i_mutex */
30 +       ext4_inode_block_unlocked_dio(inode);
31 +       inode_dio_wait(inode);
33         /*
34          * credits to insert 1 extent into extent tree
35          */
36 @@ -4741,6 +4745,8 @@ retry:
37                 goto retry;
38         }
40 +       ext4_inode_resume_unlocked_dio(inode);
42         return ret > 0 ? ret2 : ret;
43  }
45 -- 
46 1.8.3.1
49 To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
50 the body of a message to majordomo@vger.kernel.org
51 More majordomo info at  http://vger.kernel.org/majordomo-info.html