add patch use_GFP_NOFS_in_jbd2_cleanup_journal_tail
[ext4-patch-queue.git] / only-call-ext4_truncate-when-size-le-isize
blob4d66998810579aa014c3a6c79570d8829b9ef88f
1 ext4: only call ext4_truncate when size <= isize
3 From: Josef Bacik <jbacik@fb.com>
5 At LSF we decided that if we truncate up from isize we shouldn't trim
6 fallocated blocks that were fallocated with KEEP_SIZE and are past the
7 new i_size.  This patch fixes ext4 to do this.  Thanks,
9 Signed-off-by: Josef Bacik <jbacik@fb.com>
10 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
11 Reviewed-by: Lukas Czerner <lczerner@redhat.com>
12 ---
13  fs/ext4/inode.c | 5 ++---
14  1 file changed, 2 insertions(+), 3 deletions(-)
16 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
17 index 0554b0b..92174dd 100644
18 --- a/fs/ext4/inode.c
19 +++ b/fs/ext4/inode.c
20 @@ -4640,6 +4640,7 @@ static void ext4_wait_for_tail_page_commit(struct inode *inode)
21  int ext4_setattr(struct dentry *dentry, struct iattr *attr)
22  {
23         struct inode *inode = d_inode(dentry);
24 +       loff_t oldsize = inode->i_size;
25         int error, rc = 0;
26         int orphan = 0;
27         const unsigned int ia_valid = attr->ia_valid;
28 @@ -4727,8 +4728,6 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
29                                 goto err_out;
30                         }
31                 } else {
32 -                       loff_t oldsize = inode->i_size;
34                         i_size_write(inode, attr->ia_size);
35                         pagecache_isize_extended(inode, oldsize, inode->i_size);
36                 }
37 @@ -4756,7 +4755,7 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
38          * We want to call ext4_truncate() even if attr->ia_size ==
39          * inode->i_size for cases like truncation of fallocated space
40          */
41 -       if (attr->ia_valid & ATTR_SIZE)
42 +       if (attr->ia_valid & ATTR_SIZE && attr->ia_size <= oldsize)
43                 ext4_truncate(inode);
45         if (!rc) {
46 -- 
47 1.8.3.1
50 To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
51 the body of a message to majordomo@vger.kernel.org
52 More majordomo info at  http://vger.kernel.org/majordomo-info.html