mirror of
https://github.com/kdave/btrfs-progs
synced 2025-01-18 11:40:56 +00:00
btrfs-progs: find-root: fix a bug that will cause wrong result
[BUG] btrfs-find-root may not output desire result, as due to search_extent_cache() may return a result that doesn't cover the desired range, generation cache can be screwed up if higher generation tree root is found before lower generation tree root. For example: ======= ./btrfs-find-root /dev/sda6 -a Superblock thinks the generation is 8 Superblock thinks the level is 0 adding bytenr: 4194304, gen: 8 <<< Debug output adding bytenr: 24715264, gen: 7 <<< gen is 7 at read_tree_block time Well block 4194304(gen: 8 level: 0) seems good, and it matches superblock Well block 24715264(gen: 8 level: 0) seems good, and it matches superblock <<< But its gen is wrong at result output time ======= [Fix] Add a new check to make sure the search_extent_cache() is returning the desired result. Reported-by: Marc Merlin <marc@merlins.org> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
3eb8836424
commit
004eabb1ad
@ -46,9 +46,14 @@ static int add_eb_to_result(struct extent_buffer *eb,
|
||||
generation < filter->generation)
|
||||
return ret;
|
||||
|
||||
/* Get the generation cache or create one */
|
||||
/*
|
||||
* Get the generation cache or create one
|
||||
*
|
||||
* NOTE: search_cache_extent() may return cache that doesn't cover
|
||||
* the range. So we need an extra check to make sure it's the right one.
|
||||
*/
|
||||
cache = search_cache_extent(result, generation);
|
||||
if (!cache) {
|
||||
if (!cache || cache->start != generation) {
|
||||
gen_cache = malloc(sizeof(*gen_cache));
|
||||
BUG_ON(!gen_cache);
|
||||
cache = &gen_cache->cache;
|
||||
|
Loading…
Reference in New Issue
Block a user