]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commit
Btrfs: fix wrong ctime and mtime of a directory after log replay
authorFilipe Manana <fdmanana@suse.com>
Wed, 15 May 2019 15:02:47 +0000 (16:02 +0100)
committerDavid Sterba <dsterba@suse.com>
Tue, 28 May 2019 17:16:16 +0000 (19:16 +0200)
commit5338e43abbab13791144d37fd8846847062351c6
tree4b23bb648971ea713dcf04ca7e3251f3bbb3159d
parent60d9f50308e5df19bc18c2fefab0eba4a843900a
Btrfs: fix wrong ctime and mtime of a directory after log replay

When replaying a log that contains a new file or directory name that needs
to be added to its parent directory, we end up updating the mtime and the
ctime of the parent directory to the current time after we have set their
values to the correct ones (set at fsync time), efectivelly losing them.

Sample reproducer:

  $ mkfs.btrfs -f /dev/sdb
  $ mount /dev/sdb /mnt

  $ mkdir /mnt/dir
  $ touch /mnt/dir/file

  # fsync of the directory is optional, not needed
  $ xfs_io -c fsync /mnt/dir
  $ xfs_io -c fsync /mnt/dir/file

  $ stat -c %Y /mnt/dir
  1557856079

  <power failure>

  $ sleep 3
  $ mount /dev/sdb /mnt
  $ stat -c %Y /mnt/dir
  1557856082

    --> should have been 1557856079, the mtime is updated to the current
        time when replaying the log

Fix this by not updating the mtime and ctime to the current time at
btrfs_add_link() when we are replaying a log tree.

This could be triggered by my recent fsync fuzz tester for fstests, for
which an fstests patch exists titled "fstests: generic, fsync fuzz tester
with fsstress".

Fixes: e02119d5a7b43 ("Btrfs: Add a write ahead tree log to optimize synchronous operations")
CC: stable@vger.kernel.org # 4.4+
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/inode.c