Skip to content

Commit

Permalink
Btrfs: fix wrong max_to_defrag in btrfs_defrag_file()
Browse files Browse the repository at this point in the history
It's off-by-one, and thus we may skip the last page while defragmenting.

An example case:

  # create /mnt/file with 2 4K file extents
  # btrfs fi defrag /mnt/file
  # sync
  # filefrag /mnt/file
  /mnt/file: 2 extents found

So it's not defragmented.

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
  • Loading branch information
Li Zefan authored and David Sterba committed Oct 20, 2011
1 parent 151a31b commit 5ca4966
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion fs/btrfs/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
i = range->start >> PAGE_CACHE_SHIFT;
}
if (!max_to_defrag)
max_to_defrag = last_index - 1;
max_to_defrag = last_index;

while (i <= last_index && defrag_count < max_to_defrag) {
/*
Expand Down

0 comments on commit 5ca4966

Please sign in to comment.