diff mbox

Btrfs: log entire range for FULL_SYNC

Message ID 1429122801-3096-1-git-send-email-jbacik@fb.com (mailing list archive)
State New, archived
Headers show

Commit Message

Josef Bacik April 15, 2015, 6:33 p.m. UTC
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.

Signed-off-by: Josef Bacik <jbacik@fb.com>
 fs/btrfs/file.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
diff mbox


diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 23b6e03..46c7227 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -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