]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
Btrfs: fix wrong max_to_defrag in btrfs_defrag_file()
authorLi Zefan <lizf@cn.fujitsu.com>
Fri, 2 Sep 2011 07:56:55 +0000 (15:56 +0800)
committerChris Mason <chris.mason@oracle.com>
Wed, 16 Nov 2011 02:20:38 +0000 (21:20 -0500)
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>
(cherry picked from commit 5ca496604b5975d371bb669ee6c2394bcbea818f)

fs/btrfs/ioctl.c

index 817487162f1b7b77d7507b4e8d1c1b2c1fd87256..066280b7fb58eeb64ffcfc9c2bf9a01edb5d820e 100644 (file)
@@ -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