From: Li Zefan Date: Fri, 2 Sep 2011 07:56:55 +0000 (+0800) Subject: Btrfs: fix wrong max_to_defrag in btrfs_defrag_file() X-Git-Tag: v2.6.39-400.9.0~845^2~51 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=75ecf653881b72b623a827022050b3f2d5b939a9;p=users%2Fjedix%2Flinux-maple.git Btrfs: fix wrong max_to_defrag in btrfs_defrag_file() 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 (cherry picked from commit 5ca496604b5975d371bb669ee6c2394bcbea818f) --- diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 817487162f1b..066280b7fb58 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -1061,7 +1061,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; /* * make writeback starts from i, so the defrag range can be