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 2/4] btrfs-progs: Continue repair even some extent reference can't be repaired and report result to user.
Date: Tue, 13 Jan 2015 10:04:45 +0800	[thread overview]
Message-ID: <1421114687-6084-3-git-send-email-quwenruo@cn.fujitsu.com> (raw)
In-Reply-To: <1421114687-6084-1-git-send-email-quwenruo@cn.fujitsu.com>

Before this patch, btrfsck will exit repairing if some extent reference
can't be repaired.
This is somewhat overkilled.

This patch will report number of all errors and fixed/recorded one, and
continue in repair mode.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 cmds-check.c | 56 +++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 33 insertions(+), 23 deletions(-)

diff --git a/cmds-check.c b/cmds-check.c
index 500207e..b275b39 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -7279,6 +7279,9 @@ static int check_extent_refs(struct btrfs_trans_handle *trans,
 	int fixed = 0;
 	int had_dups = 0;
 	int recorded = 0;
+	u64 nr_fixed = 0;
+	u64 nr_recorded = 0;
+	u64 nr_err = 0;
 
 	if (repair) {
 		/*
@@ -7340,12 +7343,12 @@ static int check_extent_refs(struct btrfs_trans_handle *trans,
 	if (had_dups)
 		return -EAGAIN;
 
-	while(1) {
+	cache = first_cache_extent(extent_cache);
+	while(cache) {
+		err = 0;
 		fixed = 0;
 		recorded = 0;
-		cache = search_cache_extent(extent_cache, 0);
-		if (!cache)
-			break;
+
 		rec = container_of(cache, struct extent_record, cache);
 		if (rec->num_duplicates) {
 			fprintf(stderr, "extent item %llu has multiple extent "
@@ -7360,9 +7363,10 @@ static int check_extent_refs(struct btrfs_trans_handle *trans,
 			fprintf(stderr, "extent item %llu, found %llu\n",
 				(unsigned long long)rec->extent_item_refs,
 				(unsigned long long)rec->refs);
+			err = 1;
 			ret = record_orphan_data_extents(root->fs_info, rec);
 			if (ret < 0)
-				goto repair_abort;
+				goto next;
 			if (ret == 0) {
 				recorded = 1;
 			} else {
@@ -7375,11 +7379,10 @@ static int check_extent_refs(struct btrfs_trans_handle *trans,
 							root->fs_info,
 							extent_cache, rec);
 					if (ret)
-						goto repair_abort;
+						goto next;
 					fixed = 1;
 				}
 			}
-			err = 1;
 
 		}
 		if (all_backpointers_checked(rec, 1)) {
@@ -7387,48 +7390,55 @@ static int check_extent_refs(struct btrfs_trans_handle *trans,
 				(unsigned long long)rec->start,
 				(unsigned long long)rec->nr);
 
+			err = 1;
 			if (!fixed && !recorded && repair) {
 				ret = fixup_extent_refs(trans, root->fs_info,
 							extent_cache, rec);
 				if (ret)
-					goto repair_abort;
+					goto next;
 				fixed = 1;
 			}
-			err = 1;
 		}
 		if (!rec->owner_ref_checked) {
 			fprintf(stderr, "owner ref check failed [%llu %llu]\n",
 				(unsigned long long)rec->start,
 				(unsigned long long)rec->nr);
+			err = 1;
 			if (!fixed && !recorded && repair) {
 				ret = fixup_extent_refs(trans, root->fs_info,
 							extent_cache, rec);
 				if (ret)
-					goto repair_abort;
+					goto next;
 				fixed = 1;
 			}
-			err = 1;
 		}
-		if (err && !fixed)
-			mark_root_corrupted(root->fs_info, rec);
-
 		remove_cache_extent(extent_cache, cache);
 		free_all_extent_backrefs(rec);
 		free(rec);
+next:
+		if (err && !fixed)
+			mark_root_corrupted(root->fs_info, rec);
+
+		nr_err += err;
+		nr_fixed += fixed;
+		nr_recorded += recorded;
+		cache = next_cache_extent(cache);
 	}
-repair_abort:
+
 	if (repair) {
-		if (ret && ret != -EAGAIN) {
-			fprintf(stderr, "failed to repair damaged filesystem, aborting\n");
-			exit(1);
-		} else if (!ret) {
+		if (!ret)
 			btrfs_fix_block_accounting(trans, root);
-		}
-		if (err)
-			fprintf(stderr, "repaired damaged extent references\n");
+		printf("Found %llu errors, fixed %llu, recorded %llu\n",
+		       nr_err, nr_fixed, nr_recorded);
+		if (nr_fixed == nr_err)
+			printf("repaired all damaged extent references\n");
+		else if (nr_fixed + nr_recorded == nr_err)
+			printf("all damaged extent references repaired or recorded for later repair\n");
+		else
+			printf("some extent referenced can't be repaired\n");
 		return ret;
 	}
-	return err;
+	return nr_err;
 }
 
 u64 calc_stripe_length(u64 type, u64 length, int num_stripes)
-- 
2.2.1


  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 ` Qu Wenruo [this message]
2015-01-13  2:04 ` [PATCH 3/4] btrfs-progs: Automatically rebuild csum/extent tree if no other tree has corrupted/missing extent Qu Wenruo
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-3-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).