@@ -1901,8 +1901,13 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
* start and finish before we start logging the inode, so that
* all extents are persisted and the respective file extent
* items are in the fs/subvol btree.
+ *
+ * We also need to do the whole range, we set FULL_SYNC if we
+ * truncated, and we could have some previous version of the
+ * inode in the log, so we need to write and log all the things.
*/
- ret = btrfs_wait_ordered_range(inode, start, end - start + 1);
+ end = (u64)-1;
+ ret = btrfs_wait_ordered_range(inode, start, end);
} else {
/*
* Start any new ordered operations before starting to log the
My log writes test uncovered a corruption that could happen with fsx'es mmap write. It does an msync(MS_SYNC) after every mmap write, which turns into a vfs_fsync_range() for the range we wrote. However if we've truncated before this we will set FULL_SYNC on the inode, so if we've truncated up and then only log up to the range we've inlcluded then fsck complains because i_size is > the last extent in the flie. Fix this by making sure we log the entire file and not just the range requested. With this patch we now pass the log writes test. Thanks, Signed-off-by: Josef Bacik <jbacik@fb.com> --- fs/btrfs/file.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)