linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Cc: <marc@merlins.org>
Subject: [PATCH 2/2] btrfs-progs: find-root: Fix a bug that will cause wrong result
Date: Tue, 25 Aug 2015 10:44:57 +0800	[thread overview]
Message-ID: <1440470697-21177-2-git-send-email-quwenruo@cn.fujitsu.com> (raw)
In-Reply-To: <1440470697-21177-1-git-send-email-quwenruo@cn.fujitsu.com>

[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


  reply	other threads:[~2015-08-25  2:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2015-08-25 17:18   ` [PATCH 2/2] btrfs-progs: find-root: Fix a bug that will cause wrong result David Sterba
2015-08-25 17:16 ` [PATCH 1/2] btrfs-progs: find-root: Output matched root when searching all roots David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1440470697-21177-2-git-send-email-quwenruo@cn.fujitsu.com \
    --to=quwenruo@cn.fujitsu.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=marc@merlins.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).