Skip to content

Commit e17af96

Browse files
fdmananagregkh
authored andcommitted
Btrfs: fix assertion on fsync of regular file when using no-holes feature
commit 7ed586d upstream. When using the NO_HOLES feature and logging a regular file, we were expecting that if we find an inline extent, that either its size in RAM (uncompressed and unenconded) matches the size of the file or if it does not, that it matches the sector size and it represents compressed data. This assertion does not cover a case where the length of the inline extent is smaller than the sector size and also smaller the file's size, such case is possible through fallocate. Example: $ mkfs.btrfs -f -O no-holes /dev/sdb $ mount /dev/sdb /mnt $ xfs_io -f -c "pwrite -S 0xb60 0 21" /mnt/foobar $ xfs_io -c "falloc 40 40" /mnt/foobar $ xfs_io -c "fsync" /mnt/foobar In the above example we trigger the assertion because the inline extent's length is 21 bytes while the file size is 80 bytes. The fallocate() call merely updated the file's size and did not touch the existing inline extent, as expected. So fix this by adjusting the assertion so that an inline extent length smaller than the file size is valid if the file size is smaller than the filesystem's sector size. A test case for fstests follows soon. Reported-by: Anatoly Trosinenko <[email protected]> Fixes: a89ca6f ("Btrfs: fix fsync after truncate when no_holes feature is enabled") CC: [email protected] # 4.14+ Link: https://lore.kernel.org/linux-btrfs/CAE5jQCfRSBC7n4pUTFJcmHh109=gwyT9mFkCOL+NKfzswmR=_Q@mail.gmail.com/ Signed-off-by: Filipe Manana <[email protected]> Signed-off-by: David Sterba <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 85c5f24 commit e17af96

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

fs/btrfs/tree-log.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4655,7 +4655,8 @@ static int btrfs_log_trailing_hole(struct btrfs_trans_handle *trans,
46554655
ASSERT(len == i_size ||
46564656
(len == fs_info->sectorsize &&
46574657
btrfs_file_extent_compression(leaf, extent) !=
4658-
BTRFS_COMPRESS_NONE));
4658+
BTRFS_COMPRESS_NONE) ||
4659+
(len < i_size && i_size < fs_info->sectorsize));
46594660
return 0;
46604661
}
46614662

0 commit comments

Comments
 (0)