]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/3.18.114/ext4-update-mtime-in-ext4_punch_hole-even-if-no-blocks-are-released.patch
4.14-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 3.18.114 / ext4-update-mtime-in-ext4_punch_hole-even-if-no-blocks-are-released.patch
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
5
6 From: Lukas Czerner <lczerner@redhat.com>
7
8 commit eee597ac931305eff3d3fd1d61d6aae553bc0984 upstream.
9
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.
13
14 Moreover the sync and datasync handling is skipped as well, which is
15 also wrong. Fix it.
16
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>
22
23 ---
24 fs/ext4/inode.c | 40 ++++++++++++++++++++--------------------
25 1 file changed, 20 insertions(+), 20 deletions(-)
26
27 --- a/fs/ext4/inode.c
28 +++ b/fs/ext4/inode.c
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);
32
33 - /* If there are no blocks to remove, return now */
34 - if (first_block >= stop_block)
35 - goto out_stop;
36 -
37 - down_write(&EXT4_I(inode)->i_data_sem);
38 - ext4_discard_preallocations(inode);
39 -
40 - ret = ext4_es_remove_extent(inode, first_block,
41 - stop_block - first_block);
42 - if (ret) {
43 - up_write(&EXT4_I(inode)->i_data_sem);
44 - goto out_stop;
45 - }
46 + /* If there are blocks to remove, do it */
47 + if (stop_block > first_block) {
48 +
49 + down_write(&EXT4_I(inode)->i_data_sem);
50 + ext4_discard_preallocations(inode);
51
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 + ret = ext4_es_remove_extent(inode, first_block,
59 + stop_block - first_block);
60 + if (ret) {
61 + up_write(&EXT4_I(inode)->i_data_sem);
62 + goto out_stop;
63 + }
64 +
65 + if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
66 + ret = ext4_ext_remove_space(inode, first_block,
67 + stop_block - 1);
68 + else
69 + ret = ext4_ind_remove_space(handle, inode, first_block,
70 + stop_block);
71
72 - up_write(&EXT4_I(inode)->i_data_sem);
73 + up_write(&EXT4_I(inode)->i_data_sem);
74 + }
75 if (IS_SYNC(inode))
76 ext4_handle_sync(handle);
77