1 ext4: Take read lock during overwrite case.
3 From: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
5 When we are overwriting a file and not actually allocating new file system
6 blocks we need to take only the read lock on i_data_sem.
8 Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
11 fs/ext4/inode.c | 32 ++++++++++++++++++++++++--------
12 1 files changed, 24 insertions(+), 8 deletions(-)
15 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
16 index a7eb8bb..89cd353 100644
19 @@ -901,11 +901,31 @@ int ext4_get_blocks_wrap(handle_t *handle, struct inode *inode, sector_t block,
20 int create, int extend_disksize)
24 - down_write((&EXT4_I(inode)->i_data_sem));
26 + * Try to see if we can get the block without requesting
27 + * for new file system block.
29 + down_read((&EXT4_I(inode)->i_data_sem));
30 + if (EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL) {
31 + retval = ext4_ext_get_blocks(handle, inode, block, max_blocks,
34 - down_read((&EXT4_I(inode)->i_data_sem));
35 + retval = ext4_get_blocks_handle(handle,
36 + inode, block, max_blocks, bh, 0, 0);
38 + up_read((&EXT4_I(inode)->i_data_sem));
39 + if (!create || (retval > 0))
43 + * We need to allocate new blocks which will result
46 + down_write((&EXT4_I(inode)->i_data_sem));
48 + * We need to check for EXT4 here because migrate
49 + * could have changed the inode type in between
51 if (EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL) {
52 retval = ext4_ext_get_blocks(handle, inode, block, max_blocks,
53 bh, create, extend_disksize);
54 @@ -913,11 +933,7 @@ int ext4_get_blocks_wrap(handle_t *handle, struct inode *inode, sector_t block,
55 retval = ext4_get_blocks_handle(handle, inode, block,
56 max_blocks, bh, create, extend_disksize);
59 - up_write((&EXT4_I(inode)->i_data_sem));
61 - up_read((&EXT4_I(inode)->i_data_sem));
63 + up_write((&EXT4_I(inode)->i_data_sem));