1 From eee597ac931305eff3d3fd1d61d6aae553bc0984 Mon Sep 17 00:00:00 2001
2 From: Lukas Czerner <lczerner@redhat.com>
3 Date: Sun, 13 May 2018 19:28:35 -0400
4 Subject: ext4: update mtime in ext4_punch_hole even if no blocks are released
6 From: Lukas Czerner <lczerner@redhat.com>
8 commit eee597ac931305eff3d3fd1d61d6aae553bc0984 upstream.
10 Currently in ext4_punch_hole we're going to skip the mtime update if
11 there are no actual blocks to release. However we've actually modified
12 the file by zeroing the partial block so the mtime should be updated.
14 Moreover the sync and datasync handling is skipped as well, which is
17 Signed-off-by: Lukas Czerner <lczerner@redhat.com>
18 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
19 Reported-by: Joe Habermann <joe.habermann@quantum.com>
20 Cc: <stable@vger.kernel.org>
21 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
24 fs/ext4/inode.c | 40 ++++++++++++++++++++--------------------
25 1 file changed, 20 insertions(+), 20 deletions(-)
29 @@ -3531,28 +3531,28 @@ int ext4_punch_hole(struct inode *inode,
30 EXT4_BLOCK_SIZE_BITS(sb);
31 stop_block = (offset + length) >> EXT4_BLOCK_SIZE_BITS(sb);
33 - /* If there are no blocks to remove, return now */
34 - if (first_block >= stop_block)
37 - down_write(&EXT4_I(inode)->i_data_sem);
38 - ext4_discard_preallocations(inode);
40 - ret = ext4_es_remove_extent(inode, first_block,
41 - stop_block - first_block);
43 - up_write(&EXT4_I(inode)->i_data_sem);
46 + /* If there are blocks to remove, do it */
47 + if (stop_block > first_block) {
49 + down_write(&EXT4_I(inode)->i_data_sem);
50 + ext4_discard_preallocations(inode);
52 - if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
53 - ret = ext4_ext_remove_space(inode, first_block,
56 - ret = ext4_ind_remove_space(handle, inode, first_block,
58 + ret = ext4_es_remove_extent(inode, first_block,
59 + stop_block - first_block);
61 + up_write(&EXT4_I(inode)->i_data_sem);
65 + if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
66 + ret = ext4_ext_remove_space(inode, first_block,
69 + ret = ext4_ind_remove_space(handle, inode, first_block,
72 - up_write(&EXT4_I(inode)->i_data_sem);
73 + up_write(&EXT4_I(inode)->i_data_sem);
76 ext4_handle_sync(handle);