]> git.baikalelectronics.ru Git - kernel.git/commit
Btrfs: btrfs_defrag_file: Fix calculation of max_to_defrag.
authorchandan <chandan@linux.vnet.ibm.com>
Tue, 9 Jun 2015 05:05:11 +0000 (10:35 +0530)
committerChris Mason <clm@fb.com>
Wed, 10 Jun 2015 14:02:48 +0000 (07:02 -0700)
commit5d726598f6512c490ddf613796a529150dd8ae7e
tree146064f0c699fc69fdf0941014ea0916db600d9a
parent256dd290a48a1e0e31972c3028676a006272e956
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>
fs/btrfs/ioctl.c