FAILED: patch "[PATCH] Btrfs: fix assertion on fsync of regular file when using" failed to apply to 4.9-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 4.9-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
Quoted 1 line
From
7ed586d0a8241e81d58c656c5b315f781fa6fc97Mon Sep 17 00:00:00 2001
From: Filipe Manana <[email protected]>
Date: Mon, 15 Oct 2018 09:51:00 +0100
Subject: [PATCH] Btrfs: fix assertion on fsync of regular file when using
no-holes feature
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.
fs/btrfs/tree-log.c +2 -1
@@ -4652,7 +4652,8 @@ static int btrfs_log_trailing_hole(struct btrfs_trans_handle *trans,ASSERT (len == i_size || (len == fs_info->sectorsize &&btrfs_file_extent_compression (leaf, extent) != -BTRFS_COMPRESS_NONE )); +BTRFS_COMPRESS_NONE ) || + (len < i_size && i_size < fs_info->sectorsize));return 0 ; }