summaryrefslogtreecommitdiffstats
path: root/fs/btrfs/ioctl.c
diff options
context:
space:
mode:
authorchandan <chandan@linux.vnet.ibm.com>2015-06-09 01:05:11 -0400
committerChris Mason <clm@fb.com>2015-06-10 10:02:48 -0400
commit070034bdf98544b23a7fcf500618fd31dec06ab2 (patch)
tree146064f0c699fc69fdf0941014ea0916db600d9a /fs/btrfs/ioctl.c
parente4826a5b2430f23ad4ec7823efcd413fce9f2d64 (diff)
Btrfs: btrfs_defrag_file: Fix calculation of max_to_defrag.
max_to_defrag represents the number of pages to defrag rather than the last page of the file range to be defragged. Consider a file having 10 4k blocks (i.e. blocks in the range [0 - 9]). If the defrag ioctl was invoked for the block range [3 - 6], then max_to_defrag should actually have the value 4. Instead in the current code we end up setting it to 6. Now, this does not (yet) cause an issue since the first part of the while loop condition in btrfs_defrag_file() (i.e. "i <= last_index") causes the control to flow out of the while loop before any buggy behavior is actually caused. So the patch just makes sure that max_to_defrag ends up having the right value rather than fixing a bug. I did run the xfstests suite to make sure that the code does not regress. Changelog: v1->v2: Provide a much descriptive commit message. Signed-off-by: Chandan Rajendra <chandan@linux.vnet.ibm.com> Signed-off-by: Chris Mason <clm@fb.com>
Diffstat (limited to 'fs/btrfs/ioctl.c')
-rw-r--r--fs/btrfs/ioctl.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 25c422b11bdb..9041f154cc32 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -1318,7 +1318,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
1318 i = range->start >> PAGE_CACHE_SHIFT; 1318 i = range->start >> PAGE_CACHE_SHIFT;
1319 } 1319 }
1320 if (!max_to_defrag) 1320 if (!max_to_defrag)
1321 max_to_defrag = last_index + 1; 1321 max_to_defrag = last_index - i + 1;
1322 1322
1323 /* 1323 /*
1324 * make writeback starts from i, so the defrag range can be 1324 * make writeback starts from i, so the defrag range can be