btrfs: defrag: introduce helper to defrag a range
authorQu Wenruo <wqu@suse.com>
Fri, 6 Aug 2021 08:12:38 +0000 (16:12 +0800)
committerDavid Sterba <dsterba@suse.com>
Tue, 26 Oct 2021 17:07:57 +0000 (19:07 +0200)
commite9eec72151e215c9bc58431c1a7e00e759c6c391
tree43b01bc01bf198945c3ba8e7ab956e163a8c91e1
parent22b398eeeed43d51e85b1008e51bf9663ac1f491
btrfs: defrag: introduce helper to defrag a range

A new helper, defrag_one_range(), is introduced to defrag one range.

This function will mostly prepare the needed pages and extent status for
defrag_one_locked_target().

As we can only have a consistent view of extent map with page and extent
bits locked, we need to re-check the range passed in to get a real
target list for defrag_one_locked_target().

Since defrag_collect_targets() will call defrag_lookup_extent() and lock
extent range, we also need to teach those two functions to skip extent
lock.  Thus new parameter, @locked, is introduced to skip extent lock if
the caller has already locked the range.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/ioctl.c