1 ext4: move ext4_update_i_disksize() into mpage_map_and_submit_extent()
3 The function ext4_update_i_disksize() is used in only one place, in
4 the function mpage_map_and_submit_extent(). Move there to simplify
5 the code paths, and also move the call to ext4_mark_inode_dirty() into
6 the i_data_sem's critical region, to be consistent with all of the
7 other places where we update i_disksize. That way, we also keep the
8 raw_inode's i_disksize protected.
10 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
11 Cc: stable@vger.kernel.org
13 fs/ext4/ext4.h | 17 -----------------
14 fs/ext4/inode.c | 16 +++++++++++++---
15 2 files changed, 13 insertions(+), 20 deletions(-)
17 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
18 index f1c65dc..66946aa 100644
21 @@ -2466,23 +2466,6 @@ static inline void ext4_update_i_disksize(struct inode *inode, loff_t newsize)
22 up_write(&EXT4_I(inode)->i_data_sem);
26 - * Update i_disksize after writeback has been started. Races with truncate
27 - * are avoided by checking i_size under i_data_sem.
29 -static inline void ext4_wb_update_i_disksize(struct inode *inode, loff_t newsize)
33 - down_write(&EXT4_I(inode)->i_data_sem);
34 - i_size = i_size_read(inode);
35 - if (newsize > i_size)
37 - if (newsize > EXT4_I(inode)->i_disksize)
38 - EXT4_I(inode)->i_disksize = newsize;
39 - up_write(&EXT4_I(inode)->i_data_sem);
42 struct ext4_group_info {
43 unsigned long bb_state;
44 struct rb_root bb_free_root;
45 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
46 index 7b93df9..f023f0c 100644
49 @@ -2247,13 +2247,23 @@ static int mpage_map_and_submit_extent(handle_t *handle,
53 - /* Update on-disk size after IO is submitted */
55 + * Update on-disk size after IO is submitted. Races with
56 + * truncate are avoided by checking i_size under i_data_sem.
58 disksize = ((loff_t)mpd->first_page) << PAGE_CACHE_SHIFT;
59 if (disksize > EXT4_I(inode)->i_disksize) {
62 - ext4_wb_update_i_disksize(inode, disksize);
65 + down_write(&EXT4_I(inode)->i_data_sem);
66 + i_size = i_size_read(inode);
67 + if (disksize > i_size)
69 + if (disksize > EXT4_I(inode)->i_disksize)
70 + EXT4_I(inode)->i_disksize = disksize;
71 err2 = ext4_mark_inode_dirty(handle, inode);
72 + up_write(&EXT4_I(inode)->i_data_sem);
74 ext4_error(inode->i_sb,
75 "Failed to mark inode %lu dirty",