diff mbox

[3/3] btrfs-progs: check: record last checked root_item in original mode

Message ID 20171121101524.2014-3-suy.fnst@cn.fujitsu.com (mailing list archive)
State New, archived
Headers show

Commit Message

Su Yue Nov. 21, 2017, 10:15 a.m. UTC
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:

Comments

David Sterba Jan. 8, 2018, 7:03 p.m. UTC | #1
On Tue, Nov 21, 2017 at 06:15:24PM +0800, Su Yue wrote:
> 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.

Patch looks good to me, do you have a test image?
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Su Yue Jan. 9, 2018, 7:27 a.m. UTC | #2
On 01/09/2018 03:03 AM, David Sterba wrote:
> On Tue, Nov 21, 2017 at 06:15:24PM +0800, Su Yue wrote:
>> 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.
> 
> Patch looks good to me, do you have a test image?
> 
fuzz-tests/images/bko-161811.raw there is.
Or do I need to add an another case to fsck-tests?

Thanks,
Su

> 


--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

=============================
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)