add patch ext4-remove-NULL-check-before-calling-kmem-cache-destroy
[ext4-patch-queue.git] / update-mtime-in-ext4_punch_hole-even-if-no-blocks-removed
blob668afc87de0e88446cb42f64fe787be09fa36e18
1 ext4: update mtime in ext4_punch_hole even if no blocks are released
3 From: Lukas Czerner <lczerner@redhat.com>
5 Currently in ext4_punch_hole we're going to skip the mtime update if
6 there are no actual blocks to release. However we've actually modified
7 the file by zeroing the partial block so the mtime should be updated.
9 Moreover the sync and datasync handling is skipped as well, which is
10 also wrong. Fix it.
12 Signed-off-by: Lukas Czerner <lczerner@redhat.com>
13 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
14 Reported-by: Joe Habermann <joe.habermann@quantum.com>
15 Cc: <stable@vger.kernel.org>
16 ---
17  fs/ext4/inode.c | 36 ++++++++++++++++++------------------
18  1 file changed, 18 insertions(+), 18 deletions(-)
20 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
21 index 1e50c5e..6b4c5c0 100644
22 --- a/fs/ext4/inode.c
23 +++ b/fs/ext4/inode.c
24 @@ -4298,28 +4298,28 @@ int ext4_punch_hole(struct inode *inode, loff_t offset, loff_t length)
25                 EXT4_BLOCK_SIZE_BITS(sb);
26         stop_block = (offset + length) >> EXT4_BLOCK_SIZE_BITS(sb);
28 -       /* If there are no blocks to remove, return now */
29 -       if (first_block >= stop_block)
30 -               goto out_stop;
31 +       /* If there are blocks to remove, do it */
32 +       if (stop_block > first_block) {
34 -       down_write(&EXT4_I(inode)->i_data_sem);
35 -       ext4_discard_preallocations(inode);
36 +               down_write(&EXT4_I(inode)->i_data_sem);
37 +               ext4_discard_preallocations(inode);
39 -       ret = ext4_es_remove_extent(inode, first_block,
40 -                                   stop_block - first_block);
41 -       if (ret) {
42 -               up_write(&EXT4_I(inode)->i_data_sem);
43 -               goto out_stop;
44 -       }
45 +               ret = ext4_es_remove_extent(inode, first_block,
46 +                                           stop_block - first_block);
47 +               if (ret) {
48 +                       up_write(&EXT4_I(inode)->i_data_sem);
49 +                       goto out_stop;
50 +               }
52 -       if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
53 -               ret = ext4_ext_remove_space(inode, first_block,
54 -                                           stop_block - 1);
55 -       else
56 -               ret = ext4_ind_remove_space(handle, inode, first_block,
57 -                                           stop_block);
58 +               if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
59 +                       ret = ext4_ext_remove_space(inode, first_block,
60 +                                                   stop_block - 1);
61 +               else
62 +                       ret = ext4_ind_remove_space(handle, inode, first_block,
63 +                                                   stop_block);
65 -       up_write(&EXT4_I(inode)->i_data_sem);
66 +               up_write(&EXT4_I(inode)->i_data_sem);
67 +       }
68         if (IS_SYNC(inode))
69                 ext4_handle_sync(handle);
71 -- 
72 2.7.5