diff options
author | Filipe Manana <fdmanana@suse.com> | 2018-01-18 12:34:20 +0100 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2018-01-22 16:08:20 +0100 |
commit | 9f13ce743b1bd4e764193980e6311bfcdf424bb2 (patch) | |
tree | d553c925b456564ff2e265b66c6498125dda0679 /fs/btrfs/file.c | |
parent | Btrfs: use cached state when dirtying pages during buffered write (diff) | |
download | linux-9f13ce743b1bd4e764193980e6311bfcdf424bb2.tar.xz linux-9f13ce743b1bd4e764193980e6311bfcdf424bb2.zip |
Btrfs: fix missing inode i_size update after zero range operation
For a fallocate's zero range operation that targets a range with an end
that is not aligned to the sector size, we can end up not updating the
inode's i_size. This happens when the last page of the range maps to an
unwritten (prealloc) extent and before that last page we have either a
hole or a written extent. This is because in this scenario we relied
on a call to btrfs_prealloc_file_range() to update the inode's i_size,
however it can only update the i_size to the "down aligned" end of the
range.
Example:
$ mkfs.btrfs -f /dev/sdc
$ mount /dev/sdc /mnt
$ xfs_io -f -c "pwrite -S 0xff 0 428K" /mnt/foobar
$ xfs_io -c "falloc -k 428K 4K" /mnt/foobar
$ xfs_io -c "fzero 0 430K" /mnt/foobar
$ du --bytes /mnt/foobar
438272 /mnt/foobar
The inode's i_size was left as 428Kb (438272 bytes) when it should have
been updated to 430Kb (440320 bytes).
Fix this by always updating the inode's i_size explicitly after zeroing
the range.
Fixes: ba6d5887946ff86d93dc ("Btrfs: add support for fallocate's zero range operation")
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs/file.c')
-rw-r--r-- | fs/btrfs/file.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index cba2ac371ce0..baad81c1f9a3 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -3026,9 +3026,12 @@ reserve_space: unlock_extent_cached(&BTRFS_I(inode)->io_tree, lockstart, lockend, &cached_state); /* btrfs_prealloc_file_range releases reserved space on error */ - if (ret) + if (ret) { space_reserved = false; + goto out; + } } + ret = btrfs_fallocate_update_isize(inode, offset + len, mode); out: if (ret && space_reserved) btrfs_free_reserved_data_space(inode, data_reserved, |