Btrfs: add missing inode version, ctime and mtime updates when punching hole [Linux 4.9.187]

This Linux kernel change "Btrfs: add missing inode version, ctime and mtime updates when punching hole" is included in the Linux 4.9.187 release. This change is authored by Filipe Manana <fdmanana [at] suse.com> on Wed Jun 19 13:05:50 2019 +0100. The commit for this change in Linux stable tree is d2db6cf (patch) which is from upstream commit 1790066. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream 1790066.

Btrfs: add missing inode version, ctime and mtime updates when punching hole

commit 179006688a7e888cbff39577189f2e034786d06a upstream.

If the range for which we are punching a hole covers only part of a page,
we end up updating the inode item but we skip the update of the inode's
iversion, mtime and ctime. Fix that by ensuring we update those properties
of the inode.

A patch for fstests test case generic/059 that tests this as been sent
along with this fix.

Fixes: 2aaa66558172b0 ("Btrfs: add hole punching")
Fixes: e8c1c76e804b18 ("Btrfs: add missing inode update when punching hole")
CC: stable@vger.kernel.org # 4.4+
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

There are 5 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 fs/btrfs/file.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index c77114c..6cdf273 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -2646,6 +2646,11 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
         * for detecting, at fsync time, if the inode isn't yet in the
         * log tree or it's there but not up to date.
         */
+       struct timespec now = current_time(inode);
+
+       inode_inc_iversion(inode);
+       inode->i_mtime = now;
+       inode->i_ctime = now;
        trans = btrfs_start_transaction(root, 1);
        if (IS_ERR(trans)) {
            err = PTR_ERR(trans);

Leave a Reply

Your email address will not be published. Required fields are marked *