All of lore.kernel.org
 help / color / mirror / Atom feed
From: damenly.su@gmail.com
To: linux-btrfs@vger.kernel.org
Cc: suy.fnst@cn.fujitsu.com
Subject: [PATCH v2 4/7] btrfs-progs: lowmem: search key of root again after check_fs_root() under repair
Date: Wed, 12 Sep 2018 20:49:21 +0000	[thread overview]
Message-ID: <20180912204924.10089-5-suy.fnst@cn.fujitsu.com> (raw)
In-Reply-To: <20180912204924.10089-1-suy.fnst@cn.fujitsu.com>

From: Su Yue <suy.fnst@cn.fujitsu.com>

In check_fs_roots_lowmem(), we do search and follow the resulted path
to call check_fs_root(), then call btrfs_next_item() to check next
root.
However, if repair is enabled, the root tree can be cowed, the
existed path can cause strange errors.

Solution:
  If repair, save the key before calling check_fs_root,
  search the saved key again before checking next root.

Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
---
 check/mode-lowmem.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c
index 89a304bbdd69..8fc9edab1d66 100644
--- a/check/mode-lowmem.c
+++ b/check/mode-lowmem.c
@@ -4967,9 +4967,13 @@ int check_fs_roots_lowmem(struct btrfs_fs_info *fs_info)
 	}
 
 	while (1) {
+		struct btrfs_key saved_key;
+
 		node = path.nodes[0];
 		slot = path.slots[0];
 		btrfs_item_key_to_cpu(node, &key, slot);
+		if (repair)
+			saved_key = key;
 		if (key.objectid > BTRFS_LAST_FREE_OBJECTID)
 			goto out;
 		if (key.type == BTRFS_ROOT_ITEM_KEY &&
@@ -5000,6 +5004,17 @@ int check_fs_roots_lowmem(struct btrfs_fs_info *fs_info)
 			err |= ret;
 		}
 next:
+		/*
+		 * Since root tree can be cowed during repair,
+		 * here search the saved key again.
+		 */
+		if (repair) {
+			btrfs_release_path(&path);
+			ret = btrfs_search_slot(NULL, fs_info->tree_root,
+						&saved_key, &path, 0, 0);
+			/* Repair never deletes trees, search must succeed. */
+			BUG_ON(ret);
+		}
 		ret = btrfs_next_item(tree_root, &path);
 		if (ret > 0)
 			goto out;
-- 
2.18.0

  parent reply	other threads:[~2018-09-12 17:54 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-12 20:49 [PATCH v2 0/7] btrfs-progs: lowmem: bug fixes and inode_extref repair damenly.su
2018-09-12 20:49 ` [PATCH v2 1/7] btrfs-progs: adjust arguments of btrfs_lookup_inode_extref() damenly.su
2018-09-13 23:26   ` Qu Wenruo
2018-09-12 20:49 ` [PATCH v2 2/7] btrfs-progs: make btrfs_unlink() lookup inode_extref damenly.su
2018-09-13 23:30   ` Qu Wenruo
2018-09-12 20:49 ` [PATCH v2 3/7] btrfs-progs: lowmem check: find dir_item by di_key in check_dir_item() damenly.su
2018-09-13 23:33   ` Qu Wenruo
2018-09-14  0:57     ` Su Yue
2018-09-12 20:49 ` damenly.su [this message]
2018-09-13 23:37   ` [PATCH v2 4/7] btrfs-progs: lowmem: search key of root again after check_fs_root() under repair Qu Wenruo
2018-09-14  0:58     ` Su Yue
2018-09-14  6:27       ` Nikolay Borisov
2018-09-14  7:13         ` Su Yue
2018-09-12 20:49 ` [PATCH v2 5/7] btrfs-progs: lowmem: continue to check item in last slot while checking inodes damenly.su
2018-09-13 23:43   ` Qu Wenruo
2018-09-14  1:22     ` Su Yue
2018-09-12 20:49 ` [PATCH v2 6/7] btrfs-progs: lowmem: improve check_inode_extref() damenly.su
2018-09-13 23:50   ` Qu Wenruo
2018-09-12 20:49 ` [PATCH v2 7/7] btrfs-progs: fsck-tests: add test case inode_extref without dir_item and dir_index damenly.su
2018-09-13 23:55   ` 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=20180912204924.10089-5-suy.fnst@cn.fujitsu.com \
    --to=damenly.su@gmail.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=suy.fnst@cn.fujitsu.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.