From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Subject: [PATCH 3/4] btrfs-progs: Automatically rebuild csum/extent tree if no other tree has corrupted/missing extent.
Date: Tue, 13 Jan 2015 10:04:46 +0800 [thread overview]
Message-ID: <1421114687-6084-4-git-send-email-quwenruo@cn.fujitsu.com> (raw)
In-Reply-To: <1421114687-6084-1-git-send-email-quwenruo@cn.fujitsu.com>
If we find other tree has no corrupted/missing extent, we should be
safely to rebuild csum/extent tree.
This patch will automatically do it using the report_root_corrtuped()
result.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
cmds-check.c | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/cmds-check.c b/cmds-check.c
index b275b39..7d8d9d1 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -9030,6 +9030,8 @@ int cmd_check(int argc, char **argv)
int init_csum_tree = 0;
int qgroup_report = 0;
enum btrfs_open_ctree_flags ctree_flags = OPEN_CTREE_EXCLUSIVE;
+ u16 root_corrupted = 0;
+ int in_recheck = 0;
while(1) {
int c;
@@ -9075,12 +9077,14 @@ int cmd_check(int argc, char **argv)
printf("Creating a new CRC tree\n");
init_csum_tree = 1;
repair = 1;
+ in_recheck = 1;
ctree_flags |= OPEN_CTREE_WRITES;
} else if (option_index == 3) {
init_extent_tree = 1;
ctree_flags |= (OPEN_CTREE_WRITES |
OPEN_CTREE_NO_BLOCK_GROUPS);
repair = 1;
+ in_recheck = 1;
} else if (option_index == 4) {
check_data_csum = 1;
}
@@ -9106,6 +9110,7 @@ int cmd_check(int argc, char **argv)
if (repair)
ctree_flags |= OPEN_CTREE_PARTIAL;
+again:
info = open_ctree_fs_info(argv[optind], bytenr, tree_root_bytenr,
ctree_flags);
if (!info) {
@@ -9218,7 +9223,21 @@ int cmd_check(int argc, char **argv)
* chunk and extent tree check has iterates all the extents,
* so know we have a brief view on which trees are damaged.
*/
- report_root_corrupted(info, "\t");
+ root_corrupted = report_root_corrupted(info, "\t");
+ if (repair && !in_recheck && (root_corrupted == CORRUPTED_CSUM ||
+ root_corrupted == CORRUPTED_EXTENT)) {
+ in_recheck = 1;
+ if (root_corrupted == CORRUPTED_CSUM) {
+ init_csum_tree = 1;
+ printf("Only csum tree is corrupted, rebuild it\n");
+ }
+ if (root_corrupted == CORRUPTED_EXTENT) {
+ init_extent_tree = 1;
+ printf("Only extent tree is corrupted, rebuild it\n");
+ }
+ close_ctree(root);
+ goto again;
+ }
ret = repair_root_items(info);
if (ret < 0)
goto close_out;
--
2.2.1
next prev parent reply other threads:[~2015-01-13 2:04 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-13 2:04 [PATCH 0/4] Better btrfsck tree corruption report and automatic csum tree rebuild Qu Wenruo
2015-01-13 2:04 ` [PATCH 1/4] btrfs-progs: Report corrupted trees after check_chunks_and_extents() Qu Wenruo
2015-01-13 2:04 ` [PATCH 2/4] btrfs-progs: Continue repair even some extent reference can't be repaired and report result to user Qu Wenruo
2015-01-13 2:04 ` Qu Wenruo [this message]
2015-01-13 2:04 ` [PATCH 4/4] btrfs-progs: Remove all csum extents for init_csum Qu Wenruo
2015-01-28 18:27 ` [PATCH 0/4] Better btrfsck tree corruption report and automatic csum tree rebuild David Sterba
2015-01-29 0:51 ` 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=1421114687-6084-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).