Fix defrag patches so they build.
[ext4-patch-queue.git] / take-read-lock-during-overwrite-case.patch
blob7d1da9da2d1e4c95a1462c952611eb9df8729d5c
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>
9 ---
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
17 --- a/fs/ext4/inode.c
18 +++ b/fs/ext4/inode.c
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)
22 int retval;
23 - if (create) {
24 - down_write((&EXT4_I(inode)->i_data_sem));
25 + /*
26 + * Try to see if we can get the block without requesting
27 + * for new file system block.
28 + */
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,
32 + bh, 0, 0);
33 } else {
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))
40 + return retval;
42 + /*
43 + * We need to allocate new blocks which will result
44 + * in i_data update
45 + */
46 + down_write((&EXT4_I(inode)->i_data_sem));
47 + /*
48 + * We need to check for EXT4 here because migrate
49 + * could have changed the inode type in between
50 + */
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);
58 - if (create) {
59 - up_write((&EXT4_I(inode)->i_data_sem));
60 - } else {
61 - up_read((&EXT4_I(inode)->i_data_sem));
62 - }
63 + up_write((&EXT4_I(inode)->i_data_sem));
64 return retval;