diff options
Diffstat (limited to 'fs/ext4/inode.c')
-rw-r--r-- | fs/ext4/inode.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 38f430119fef..fc4051eb4e0f 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c | |||
@@ -2237,12 +2237,10 @@ static int mpage_map_and_submit_extent(handle_t *handle, | |||
2237 | 2237 | ||
2238 | /* Update on-disk size after IO is submitted */ | 2238 | /* Update on-disk size after IO is submitted */ |
2239 | disksize = ((loff_t)mpd->first_page) << PAGE_CACHE_SHIFT; | 2239 | disksize = ((loff_t)mpd->first_page) << PAGE_CACHE_SHIFT; |
2240 | if (disksize > i_size_read(inode)) | ||
2241 | disksize = i_size_read(inode); | ||
2242 | if (disksize > EXT4_I(inode)->i_disksize) { | 2240 | if (disksize > EXT4_I(inode)->i_disksize) { |
2243 | int err2; | 2241 | int err2; |
2244 | 2242 | ||
2245 | ext4_update_i_disksize(inode, disksize); | 2243 | ext4_wb_update_i_disksize(inode, disksize); |
2246 | err2 = ext4_mark_inode_dirty(handle, inode); | 2244 | err2 = ext4_mark_inode_dirty(handle, inode); |
2247 | if (err2) | 2245 | if (err2) |
2248 | ext4_error(inode->i_sb, | 2246 | ext4_error(inode->i_sb, |
@@ -4627,18 +4625,27 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr) | |||
4627 | error = ext4_orphan_add(handle, inode); | 4625 | error = ext4_orphan_add(handle, inode); |
4628 | orphan = 1; | 4626 | orphan = 1; |
4629 | } | 4627 | } |
4628 | down_write(&EXT4_I(inode)->i_data_sem); | ||
4630 | EXT4_I(inode)->i_disksize = attr->ia_size; | 4629 | EXT4_I(inode)->i_disksize = attr->ia_size; |
4631 | rc = ext4_mark_inode_dirty(handle, inode); | 4630 | rc = ext4_mark_inode_dirty(handle, inode); |
4632 | if (!error) | 4631 | if (!error) |
4633 | error = rc; | 4632 | error = rc; |
4633 | /* | ||
4634 | * We have to update i_size under i_data_sem together | ||
4635 | * with i_disksize to avoid races with writeback code | ||
4636 | * running ext4_wb_update_i_disksize(). | ||
4637 | */ | ||
4638 | if (!error) | ||
4639 | i_size_write(inode, attr->ia_size); | ||
4640 | up_write(&EXT4_I(inode)->i_data_sem); | ||
4634 | ext4_journal_stop(handle); | 4641 | ext4_journal_stop(handle); |
4635 | if (error) { | 4642 | if (error) { |
4636 | ext4_orphan_del(NULL, inode); | 4643 | ext4_orphan_del(NULL, inode); |
4637 | goto err_out; | 4644 | goto err_out; |
4638 | } | 4645 | } |
4639 | } | 4646 | } else |
4647 | i_size_write(inode, attr->ia_size); | ||
4640 | 4648 | ||
4641 | i_size_write(inode, attr->ia_size); | ||
4642 | /* | 4649 | /* |
4643 | * Blocks are going to be removed from the inode. Wait | 4650 | * Blocks are going to be removed from the inode. Wait |
4644 | * for dio in flight. Temporarily disable | 4651 | * for dio in flight. Temporarily disable |