summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2011-10-13 08:20:40 +0200
committerLinus Torvalds <torvalds@linux-foundation.org>2011-10-13 08:20:40 +0200
commitb2f9452bd5234d573898bbda52a410b154f8f510 (patch)
treeb2599fdd3247befb52f9b5c64b99aed6f6db195e
parentMerge git://git.samba.org/sfrench/cifs-2.6 (diff)
parentBtrfs: make sure not to defrag extents past i_size (diff)
downloadlinux-b2f9452bd5234d573898bbda52a410b154f8f510.tar.xz
linux-b2f9452bd5234d573898bbda52a410b154f8f510.zip
Merge branch 'btrfs-3.0' of git://github.com/chrismason/linux
* 'btrfs-3.0' of git://github.com/chrismason/linux: Btrfs: make sure not to defrag extents past i_size Btrfs: fix recursive auto-defrag
-rw-r--r--fs/btrfs/ioctl.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 538f65a79ec5..dae5dfe41ba5 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -1047,7 +1047,16 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
if (!max_to_defrag)
max_to_defrag = last_index - 1;
- while (i <= last_index && defrag_count < max_to_defrag) {
+ /*
+ * make writeback starts from i, so the defrag range can be
+ * written sequentially.
+ */
+ if (i < inode->i_mapping->writeback_index)
+ inode->i_mapping->writeback_index = i;
+
+ while (i <= last_index && defrag_count < max_to_defrag &&
+ (i < (i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
+ PAGE_CACHE_SHIFT)) {
/*
* make sure we stop running if someone unmounts
* the FS