btrfs-progs: convert: use search_cache_extent in migrate_one_reserved_range
authorJeff Mahoney <jeffm@suse.com>
Thu, 27 Jul 2017 15:47:21 +0000 (11:47 -0400)
committerDavid Sterba <dsterba@suse.com>
Thu, 24 Aug 2017 17:07:29 +0000 (19:07 +0200)
commitf2c14eb282a87d7e622538f76dfbc356cb73c1d4
tree0fa6d8a2d57a3af08754fcef870723a23216318a
parent10726f7423e9179d367fb6eb9e37d8ffd91a7f66
btrfs-progs: convert: use search_cache_extent in migrate_one_reserved_range

When we are looking for extents in migrate_one_reserved_range, it's likely
that there will be multiple extents that fall into the 0-1MB range.

If lookup_cache_extent is called with a range that covers multiple cache
entries, it will return the first entry it encounters while searching
from the top of the tree that happens to fall in that range.  That
means that we can end up skipping regions within that range, resulting
in a file system image that can't be rolled back since it wasn't
all migrated properly.

This is reproducible using convert-tests/008-readonly-image.  There was
a range from 0-160kB, but the only entry that was returned began at
~ 280kB.

The fix is to use search_cache_extent to iterate through multiple regions
within that range.

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/main.c