Skip to content

Commit 4fdb688

Browse files
fdmananakdave
authored andcommitted
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 <[email protected]> Fixes: 9ddc959 ("btrfs: use the file extent tree infrastructure") Tested-by: Johannes Hirte <[email protected]> Signed-off-by: Filipe Manana <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 4d4225f commit 4fdb688

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

fs/btrfs/reflink.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ static int clone_copy_inline_extent(struct inode *dst,
264264
size);
265265
inode_add_bytes(dst, datal);
266266
set_bit(BTRFS_INODE_NEEDS_FULL_SYNC, &BTRFS_I(dst)->runtime_flags);
267+
ret = btrfs_inode_set_file_extent_range(BTRFS_I(dst), 0, aligned_end);
267268
out:
268269
if (!ret && !trans) {
269270
/*

0 commit comments

Comments
 (0)