Skip to content

Commit

Permalink
Btrfs: fix defragmentation regression
Browse files Browse the repository at this point in the history
There's an off-by-one bug:

  # create a file with lots of 4K file extents
  # btrfs fi defrag /mnt/file
  # sync
  # filefrag -v /mnt/file
  Filesystem type is: 9123683e
  File size of /mnt/file is 1228800 (300 blocks, blocksize 4096)
   ext logical physical expected length flags
     0       0     3372              64
     1      64     3136     3435      1
     2      65     3436     3136     64
     3     129     3201     3499      1
     4     130     3500     3201     64
     5     194     3266     3563      1
     6     195     3564     3266     64
     7     259     3331     3627      1
     8     260     3628     3331     40 eof

After this patch:

  ...
  # filefrag -v /mnt/file
  Filesystem type is: 9123683e
  File size of /mnt/file is 1228800 (300 blocks, blocksize 4096)
   ext logical physical expected length flags
     0       0     3372             300 eof
  /mnt/file: 1 extent found

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
  • Loading branch information
Li Zefan authored and David Sterba committed Oct 20, 2011
1 parent 60ccf82 commit cbcc832
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions fs/btrfs/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,6 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,

defrag_count += ret;
balance_dirty_pages_ratelimited_nr(inode->i_mapping, ret);
i += ret;

if (newer_than) {
if (newer_off == (u64)-1)
Expand All @@ -1107,7 +1106,10 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
break;
}
} else {
i++;
if (ret > 0)
i += ret;
else
i++;
}
}

Expand Down

0 comments on commit cbcc832

Please sign in to comment.