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>
Subject: [PATCH 3/7] btrfs-progs: Allow btrfs_read_fs_root() to re-read the tree node.
Date: Wed, 4 Feb 2015 15:16:47 +0800	[thread overview]
Message-ID: <1423034213-14018-4-git-send-email-quwenruo@cn.fujitsu.com> (raw)
In-Reply-To: <1423034213-14018-1-git-send-email-quwenruo@cn.fujitsu.com>

With this patch, btrfs_read_fs_root() will try to re-read the tree node
if it's not up to date.

This will help for the tree block csum resetting function.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 disk-io.c | 51 +++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 39 insertions(+), 12 deletions(-)

diff --git a/disk-io.c b/disk-io.c
index cb18002..747ef15 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -713,20 +713,47 @@ struct btrfs_root *btrfs_read_fs_root(struct btrfs_fs_info *fs_info,
 	struct btrfs_root *root;
 	struct rb_node *node;
 	int ret;
+	int found = 0;
 	u64 objectid = location->objectid;
 
-	if (location->objectid == BTRFS_ROOT_TREE_OBJECTID)
-		return fs_info->tree_root;
-	if (location->objectid == BTRFS_EXTENT_TREE_OBJECTID)
-		return fs_info->extent_root;
-	if (location->objectid == BTRFS_CHUNK_TREE_OBJECTID)
-		return fs_info->chunk_root;
-	if (location->objectid == BTRFS_DEV_TREE_OBJECTID)
-		return fs_info->dev_root;
-	if (location->objectid == BTRFS_CSUM_TREE_OBJECTID)
-		return fs_info->csum_root;
-	if (location->objectid == BTRFS_QUOTA_TREE_OBJECTID)
-		return fs_info->quota_root;
+	if (location->objectid == BTRFS_ROOT_TREE_OBJECTID) {
+		root = fs_info->tree_root;
+		found = 1;
+	}
+	if (location->objectid == BTRFS_EXTENT_TREE_OBJECTID) {
+		root = fs_info->extent_root;
+		found = 1;
+	}
+	if (location->objectid == BTRFS_CHUNK_TREE_OBJECTID) {
+		root = fs_info->chunk_root;
+		found = 1;
+	}
+	if (location->objectid == BTRFS_DEV_TREE_OBJECTID) {
+		root = fs_info->dev_root;
+		found = 1;
+	}
+	if (location->objectid == BTRFS_CSUM_TREE_OBJECTID) {
+		root = fs_info->csum_root;
+		found = 1;
+	}
+	if (location->objectid == BTRFS_QUOTA_TREE_OBJECTID) {
+		root = fs_info->quota_root;
+		found = 1;
+	}
+	/*
+	 * The specified root has corruption. We should try to reread
+	 * it since its treeblock csum may be reseted.
+	 */
+	if (found && !extent_buffer_uptodate(root->node)) {
+		u64 bytenr = btrfs_root_bytenr(&root->root_item);
+
+		root->node = read_tree_block(root, bytenr, root->nodesize, 0);
+		if (!extent_buffer_uptodate(root->node)) {
+			if (IS_ERR(root->node))
+				return ERR_PTR(PTR_ERR(root->node));
+			return ERR_PTR(-EIO);
+		}
+	}
 
 	BUG_ON(location->objectid == BTRFS_TREE_RELOC_OBJECTID ||
 	       location->offset != (u64)-1);
-- 
2.2.2


  parent reply	other threads:[~2015-02-04  7:19 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-04  7:16 [PATCH 0/7] Allow btrfsck to reset csum of all tree blocks, AKA dangerous mode Qu Wenruo
2015-02-04  7:16 ` [PATCH 1/7] btrfs-progs: Add btrfs_(prev/next)_tree_block() to keep search result in the same level of path->lowest_level Qu Wenruo
2015-02-04  7:16 ` [PATCH 2/7] btrfs-progs: Introduce btrfs_next_slot() function to iterate to next slot in given level Qu Wenruo
2015-02-04  7:16 ` Qu Wenruo [this message]
2015-02-04  7:16 ` [PATCH 4/7] btrfs-progs: Export write_tree_block() and allow it to do nocow write Qu Wenruo
2015-02-04  7:16 ` [PATCH 4/5] btrfs-progs: Introduce new function reset_tree_block_csum() for later tree block csum reset Qu Wenruo
2015-02-04  7:16 ` [PATCH 5/5] btrfs-progs: Introduce new function reset_(one_root/roots)_csum() to reset one/all tree's csum in tree root Qu Wenruo
2015-02-04  7:16 ` [PATCH 5/7] btrfs-progs: Introduce new function reset_tree_block_csum() for later tree block csum reset Qu Wenruo
2015-02-04  7:16 ` [PATCH 6/7] btrfs-progs: Introduce new function reset_(one_root/roots)_csum() to reset one/all tree's csum in tree root Qu Wenruo
2015-02-04  7:16 ` [PATCH 7/7] btrfs-progs: Introduce "--dangerous" option to reset all tree block csum Qu Wenruo
2015-02-04  9:16 ` [PATCH 0/7] Allow btrfsck to reset csum of all tree blocks, AKA dangerous mode Martin Steigerwald
2015-02-04 10:07   ` Paul Jones
2015-02-05  1:43     ` Qu Wenruo
2015-02-05  1:35   ` Qu Wenruo
2015-02-05  8:31     ` Martin Steigerwald
2015-02-05  8:45       ` Qu Wenruo
2015-02-05  8:59         ` BTRFS wiki: page about recovery (was: Re: [PATCH 0/7] Allow btrfsck to reset csum of all tree blocks, AKA dangerous mode.) Martin Steigerwald
2015-04-22  5:55 ` [PATCH 0/7] Allow btrfsck to reset csum of all tree blocks, AKA dangerous mode Qu Wenruo

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=1423034213-14018-4-git-send-email-quwenruo@cn.fujitsu.com \
    --to=quwenruo@cn.fujitsu.com \
    --cc=linux-btrfs@vger.kernel.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).