]> git.baikalelectronics.ru Git - kernel.git/commit
btrfs: fix lost i_size update after cloning inline extent
authorFilipe Manana <fdmanana@suse.com>
Sat, 4 Apr 2020 20:20:22 +0000 (21:20 +0100)
committerDavid Sterba <dsterba@suse.com>
Wed, 8 Apr 2020 17:10:34 +0000 (19:10 +0200)
commitf737dd60dfe288b118101a5a293c51283948866e
tree71d551436072247eb11b9923b311eeb29e372706
parentf8652c4cda4d2edae9c031f8e9ddeb11a7ba2b93
btrfs: fix lost i_size update after cloning inline extent

When not using the NO_HOLES feature we were not marking the destination's
file range as written after cloning an inline extent into it. This can
lead to a data loss if the current destination file size is smaller than
the source file's size.

Example:

  $ mkfs.btrfs -f -O ^no-holes /dev/sdc
  $ mount /mnt/sdc /mnt

  $ echo "hello world" > /mnt/foo
  $ cp --reflink=always /mnt/foo /mnt/bar
  $ rm -f /mnt/foo
  $ umount /mnt

  $ mount /mnt/sdc /mnt
  $ cat /mnt/bar
  $
  $ stat -c %s /mnt/bar
  0

  # -> the file is empty, since we deleted foo, the data lost is forever

Fix that by calling btrfs_inode_set_file_extent_range() after cloning an
inline extent.

A test case for fstests will follow soon.

Link: https://lore.kernel.org/linux-btrfs/20200404193846.GA432065@latitude/
Reported-by: Johannes Hirte <johannes.hirte@datenkhaos.de>
Fixes: 1503497a6777b ("btrfs: use the file extent tree infrastructure")
Tested-by: Johannes Hirte <johannes.hirte@datenkhaos.de>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/reflink.c