linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Su Yue <suy.fnst@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Subject: [PATCH 3/3] btrfs-progs: check: record last checked root_item in original mode
Date: Tue, 21 Nov 2017 18:15:24 +0800	[thread overview]
Message-ID: <20171121101524.2014-3-suy.fnst@cn.fujitsu.com> (raw)
In-Reply-To: <20171121101524.2014-1-suy.fnst@cn.fujitsu.com>

check_fs_roots() will check all fs trees again if fs_info->tree_root
have been cowed.
It is inefficient if there are many subvolumes in filesystem.

And it also causes dead loop while repairing
fuzz-tests/images/bko-161811.raw:
=============================
ERROR: DIR_ITEM[256 1167283096] name  namelen 32 filetype 1 mismatch with its hash, wanted 1167283096 have 709597396
invalid location in dir item 0
root 5 root dir 256 error
root 5 inode 256 errors 10, odd dir item
Failed to reset nlink for inode 18446744073709551361: No such file or directory
        unresolved ref dir 256 index 0 namelen 32 name  filetype 1 errors 106, no dir index, no inode ref, name too long
ERROR: DIR_ITEM[256 1167283096] name  namelen 32 filetype 1 mismatch with its hash, wanted 1167283096 have 709597396
invalid location in dir item 0
root 5 root dir 256 error
root 5 inode 256 errors 10, odd dir item
Failed to reset nlink for inode 18446744073709551361: No such file or directory
        unresolved ref dir 256 index 0 namelen 32 name  filetype 1 errors 106, no dir index, no inode ref, name too long
ERROR: DIR_ITEM[256 1167283096] name  namelen 32 filetype 1 mismatch with its hash, wanted 1167283
...
==============================

Process of the dead loop:
1) check_fs_root() failed to repair the inode.
2) btrfs_commit_transaction() did cow of the fs_info->tree_root
3) check_fs_roots() restarted to check fs tree.
4) goto 1).

Introduce a variable @prev_key to record last checked root_item.
If check_fs_root() failed, go to check the next fs_tree instead of
trying it again and again.

Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
---
 cmds-check.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/cmds-check.c b/cmds-check.c
index 68348ae94c8b..d149608acde2 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -4587,6 +4587,7 @@ static int check_fs_roots(struct btrfs_fs_info *fs_info,
 {
 	struct btrfs_path path;
 	struct btrfs_key key;
+	struct btrfs_key prev_key;
 	struct walk_control wc;
 	struct extent_buffer *leaf, *tree_node;
 	struct btrfs_root *tmp_root;
@@ -4609,19 +4610,21 @@ static int check_fs_roots(struct btrfs_fs_info *fs_info,
 	cache_tree_init(&wc.shared);
 	btrfs_init_path(&path);
 
+	prev_key.offset = 0;
+	prev_key.objectid = 0;
+	prev_key.type = BTRFS_ROOT_ITEM_KEY;
 again:
-	key.offset = 0;
-	key.objectid = 0;
-	key.type = BTRFS_ROOT_ITEM_KEY;
+	key = prev_key;
 	ret = btrfs_search_slot(NULL, tree_root, &key, &path, 0, 0);
 	if (ret < 0) {
 		err = 1;
 		goto out;
 	}
+	if (!ret)
+		path.slots[0]++;
 	tree_node = tree_root->node;
 	while (1) {
 		if (tree_node != tree_root->node) {
-			free_root_recs_tree(root_cache);
 			btrfs_release_path(&path);
 			goto again;
 		}
@@ -4636,6 +4639,9 @@ again:
 			leaf = path.nodes[0];
 		}
 		btrfs_item_key_to_cpu(leaf, &key, path.slots[0]);
+		/* save key */
+		prev_key = key;
+
 		if (key.type == BTRFS_ROOT_ITEM_KEY &&
 		    fs_root_objectid(key.objectid)) {
 			if (key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
@@ -4654,6 +4660,8 @@ again:
 			if (ret == -EAGAIN) {
 				free_root_recs_tree(root_cache);
 				btrfs_release_path(&path);
+				prev_key.objectid = 0;
+				prev_key.offset = 0;
 				goto again;
 			}
 			if (ret)
-- 
2.15.0




  parent reply	other threads:[~2017-11-21 10:11 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-21 10:15 [PATCH 1/3] btrfs-progs: check: report more specific info about invalid location Su Yue
2017-11-21 10:15 ` [PATCH 2/3] btrfs-progs: check: do not reset ret after try_repair_inode Su Yue
2018-01-08 19:00   ` David Sterba
2017-11-21 10:15 ` Su Yue [this message]
2018-01-08 19:03   ` [PATCH 3/3] btrfs-progs: check: record last checked root_item in original mode David Sterba
2018-01-09  7:27     ` Su Yue
2017-11-21 11:46 ` [PATCH 1/3] btrfs-progs: check: report more specific info about invalid location Nikolay Borisov
2017-11-22  1:48   ` Su Yue
2017-11-22  2:17 ` [PATCH v2 " Su Yue
2017-11-22  7:06   ` Nikolay Borisov
2018-01-08 19:04     ` David Sterba
2018-01-09  7:52 ` [PATCH 2/3 v2] btrfs-progs: check: do not reset ret after try_repair_inode Su Yue

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=20171121101524.2014-3-suy.fnst@cn.fujitsu.com \
    --to=suy.fnst@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).