btrfs-progs: convert: properly handle reserved ranges while iterating files
authorJeff Mahoney <jeffm@suse.com>
Tue, 25 Jul 2017 20:54:41 +0000 (16:54 -0400)
committerDavid Sterba <dsterba@suse.com>
Thu, 24 Aug 2017 17:07:18 +0000 (19:07 +0200)
commit77083770759166dd42f1cc17f173148b51ae7d28
treec944240f2e5ebaf2b43aa933024145c64bb9db47
parent960870cc57999d6b432a214d771edf440eb81f3d
btrfs-progs: convert: properly handle reserved ranges while iterating files

Commit 522ef705e38 (btrfs-progs: convert: Introduce function to calculate
the available space) changed how we handle migrating file data so that
we never have btrfs space associated with the reserved ranges.  This
works pretty well and when we iterate over the file blocks, the
associations are redirected to the migrated locations.

This commit missed the case in block_iterate_proc where we just check
for intersection with a superblock location before looking up a block
group.  intersect_with_sb checks to see if the range intersects with
a stripe containing a superblock but, in fact, we've reserved the
full 0-1MB range at the start of the disk.  So a file block located
at e.g. 160kB will fall in the reserved region but won't be excepted
in block_iterate_block.  We ultimately hit a BUG_ON when we fail
to look up the block group for that location.

This is reproducible using convert-tests/003-ext4-basic.

The fix is to have intersect_with_sb and block_iterate_proc understand
the full size of the reserved ranges.  Since we use the range to
determine the boundary for the block iterator, let's just return the
boundary.  0 isn't a valid boundary and means that we proceed normally
with block group lookup.

Cc: Qu Wenruo <quwenruo.btrfs@gmx.com>
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Reviewed-by: Qu Wenruo <quwenruo.btrfs@gmx.com>
Signed-off-by: David Sterba <dsterba@suse.com>
convert/source-fs.c