* [PATCH 1/2] btrfs-progs: find-root: Output matched root when searching all roots
@ 2015-08-25 2:44 Qu Wenruo
2015-08-25 2:44 ` [PATCH 2/2] btrfs-progs: find-root: Fix a bug that will cause wrong result Qu Wenruo
2015-08-25 17:16 ` [PATCH 1/2] btrfs-progs: find-root: Output matched root when searching all roots David Sterba
0 siblings, 2 replies; 4+ messages in thread
From: Qu Wenruo @ 2015-08-25 2:44 UTC (permalink / raw)
To: linux-btrfs; +Cc: marc
[Bug]
When given '-a' option, btrfs-find-root will output all possible tree
roots but the exact matched one.
[Reason]
Result printing skipes the exact match one, as it will normally be shown
before the alternative ones.
But when '-a' is given, that's not the case.
[Fix]
Just show the exact match one for search all case.
Reported-by: Marc Merlin <marc@merlins.org>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
btrfs-find-root.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/btrfs-find-root.c b/btrfs-find-root.c
index 1cb3085..01b3603 100644
--- a/btrfs-find-root.c
+++ b/btrfs-find-root.c
@@ -109,6 +109,9 @@ static void print_one_result(struct cache_extent *tree_block,
tree_block->start, generation, level);
if (unsure)
printf("but we are unsure about the correct generation/level\n");
+ else if (level == filter->match_level &&
+ generation == filter->match_gen)
+ printf("and it matches superblock\n");
else
printf("but generation/level doesn't match, want gen: %llu level: %u\n",
filter->match_gen, filter->match_level);
@@ -129,8 +132,10 @@ static void print_find_root_result(struct cache_tree *result,
struct btrfs_find_root_gen_cache, cache);
level = gen_cache->highest_level;
generation = cache->start;
+ /* For exact found one, skip it as it's output before */
if (level == filter->match_level &&
- generation == filter->match_gen)
+ generation == filter->match_gen &&
+ !filter->search_all)
continue;
for (tree_block = last_cache_extent(&gen_cache->eb_tree);
tree_block; tree_block = prev_cache_extent(tree_block))
--
2.5.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] btrfs-progs: find-root: Fix a bug that will cause wrong result
2015-08-25 2:44 [PATCH 1/2] btrfs-progs: find-root: Output matched root when searching all roots Qu Wenruo
@ 2015-08-25 2:44 ` Qu Wenruo
2015-08-25 17:18 ` David Sterba
2015-08-25 17:16 ` [PATCH 1/2] btrfs-progs: find-root: Output matched root when searching all roots David Sterba
1 sibling, 1 reply; 4+ messages in thread
From: Qu Wenruo @ 2015-08-25 2:44 UTC (permalink / raw)
To: linux-btrfs; +Cc: marc
[BUG]
btrfs-find-root may not output desire result, as due to
search_extent_cache() may return result which 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 judgment to make sure the search_extent_cache() is returning
desired result.
Reported-by: Marc Merlin <marc@merlins.org>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
find-root.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/find-root.c b/find-root.c
index 1af37b5..0eca0ab 100644
--- a/find-root.c
+++ b/find-root.c
@@ -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 doesn't cover
+ * the range. So need extra judgement to make sure it's a match.
+ */
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;
--
2.5.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] btrfs-progs: find-root: Output matched root when searching all roots
2015-08-25 2:44 [PATCH 1/2] btrfs-progs: find-root: Output matched root when searching all roots Qu Wenruo
2015-08-25 2:44 ` [PATCH 2/2] btrfs-progs: find-root: Fix a bug that will cause wrong result Qu Wenruo
@ 2015-08-25 17:16 ` David Sterba
1 sibling, 0 replies; 4+ messages in thread
From: David Sterba @ 2015-08-25 17:16 UTC (permalink / raw)
To: Qu Wenruo; +Cc: linux-btrfs, marc
On Tue, Aug 25, 2015 at 10:44:56AM +0800, Qu Wenruo wrote:
> [Bug]
> When given '-a' option, btrfs-find-root will output all possible tree
> roots but the exact matched one.
>
> [Reason]
> Result printing skipes the exact match one, as it will normally be shown
> before the alternative ones.
> But when '-a' is given, that's not the case.
>
> [Fix]
> Just show the exact match one for search all case.
>
> Reported-by: Marc Merlin <marc@merlins.org>
> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Applied, thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] btrfs-progs: find-root: Fix a bug that will cause wrong result
2015-08-25 2:44 ` [PATCH 2/2] btrfs-progs: find-root: Fix a bug that will cause wrong result Qu Wenruo
@ 2015-08-25 17:18 ` David Sterba
0 siblings, 0 replies; 4+ messages in thread
From: David Sterba @ 2015-08-25 17:18 UTC (permalink / raw)
To: Qu Wenruo; +Cc: linux-btrfs, marc
On Tue, Aug 25, 2015 at 10:44:57AM +0800, Qu Wenruo wrote:
> [BUG]
> btrfs-find-root may not output desire result, as due to
> search_extent_cache() may return result which 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 judgment to make sure the search_extent_cache() is returning
> desired result.
>
> Reported-by: Marc Merlin <marc@merlins.org>
> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Applied, thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-08-25 17:19 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-25 2:44 [PATCH 1/2] btrfs-progs: find-root: Output matched root when searching all roots Qu Wenruo
2015-08-25 2:44 ` [PATCH 2/2] btrfs-progs: find-root: Fix a bug that will cause wrong result Qu Wenruo
2015-08-25 17:18 ` David Sterba
2015-08-25 17:16 ` [PATCH 1/2] btrfs-progs: find-root: Output matched root when searching all roots David Sterba
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).