All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Cc: Lu Fengqi <lufq.fnst@cn.fujitsu.com>,
	Qu Wenruo <quwenruo@cn.fujitsu.com>
Subject: [PATCH 11/13] btrfs-progs: check: introduce low_memory mode fs_tree check
Date: Thu, 28 Jul 2016 15:08:23 +0800	[thread overview]
Message-ID: <1469689705-26836-12-git-send-email-lufq.fnst@cn.fujitsu.com> (raw)
In-Reply-To: <1469689705-26836-1-git-send-email-lufq.fnst@cn.fujitsu.com>

Introduce a new function check_fs_roots_v2() for check fs_tree in
low_memory mode. It call check_fs_root_v2() to check fs_root, and call
check_root_ref() to check root_ref.

Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 cmds-check.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 99 insertions(+), 6 deletions(-)

diff --git a/cmds-check.c b/cmds-check.c
index 4dc9345..e43dce1 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -4818,8 +4818,8 @@ static int check_root_ref(struct btrfs_root *root, struct btrfs_key *ref_key,
 	struct btrfs_key key;
 	struct btrfs_root_ref *ref;
 	struct btrfs_root_ref *backref;
-	char ref_name[BTRFS_NAME_LEN];
-	char backref_name[BTRFS_NAME_LEN];
+	char ref_name[BTRFS_NAME_LEN] = {0};
+	char backref_name[BTRFS_NAME_LEN] = {0};
 	u64 ref_dirid;
 	u64 ref_seq;
 	u32 ref_namelen;
@@ -4894,6 +4894,94 @@ out:
 	return err;
 }
 
+/*
+ * Check all fs/file tree in low_memory mode.
+ *
+ * 1. for fs tree root item, call check_fs_root_v2()
+ * 2. for fs tree root ref/backref, call check_root_ref()
+ *
+ * Return 0 if no error occurred.
+ */
+static int check_fs_roots_v2(struct btrfs_fs_info *fs_info)
+{
+	struct btrfs_root *tree_root = fs_info->tree_root;
+	struct btrfs_root *cur_root = NULL;
+	struct btrfs_path *path;
+	struct btrfs_key key;
+	struct extent_buffer *node;
+	unsigned int ext_ref;
+	int slot;
+	int ret;
+	int err = 0;
+
+	ext_ref = btrfs_fs_incompat(fs_info,
+				    BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF);
+
+	path = btrfs_alloc_path();
+	if (!path)
+		return -ENOMEM;
+
+	key.objectid = BTRFS_FS_TREE_OBJECTID;
+	key.offset = 0;
+	key.type = BTRFS_ROOT_ITEM_KEY;
+
+	ret = btrfs_search_slot(NULL, tree_root, &key, path, 0, 0);
+	if (ret < 0) {
+		err = ret;
+		goto out;
+	} else if (ret > 0) {
+		err = -ENOENT;
+		goto out;
+	}
+
+	while (1) {
+		node = path->nodes[0];
+		slot = path->slots[0];
+		btrfs_item_key_to_cpu(node, &key, slot);
+		if (key.objectid > BTRFS_LAST_FREE_OBJECTID)
+			goto out;
+		if (key.type == BTRFS_ROOT_ITEM_KEY &&
+		    fs_root_objectid(key.objectid)) {
+			if (key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
+				cur_root = btrfs_read_fs_root_no_cache(fs_info,
+								       &key);
+			} else {
+				key.offset = (u64)-1;
+				cur_root = btrfs_read_fs_root(fs_info, &key);
+			}
+
+			if (IS_ERR(cur_root)) {
+				error("Fail to read fs/subvol tree: %lld",
+				      key.objectid);
+				err = -EIO;
+				goto next;
+			}
+
+			ret = check_fs_root_v2(cur_root, ext_ref);
+			err |= ret;
+
+			if (key.objectid == BTRFS_TREE_RELOC_OBJECTID)
+				btrfs_free_fs_root(cur_root);
+		} else if (key.type == BTRFS_ROOT_REF_KEY ||
+				key.type == BTRFS_ROOT_BACKREF_KEY) {
+			ret = check_root_ref(tree_root, &key, node, slot);
+			err |= ret;
+		}
+next:
+		ret = btrfs_next_item(tree_root, path);
+		if (ret > 0)
+			goto out;
+		if (ret < 0) {
+			err = ret;
+			goto out;
+		}
+	}
+
+out:
+	btrfs_free_path(path);
+	return err;
+}
+
 static int all_backpointers_checked(struct extent_record *rec, int print_errs)
 {
 	struct rb_node *n;
@@ -12429,7 +12517,10 @@ int cmd_check(int argc, char **argv)
 				     BTRFS_FEATURE_INCOMPAT_NO_HOLES);
 	if (!ctx.progress_enabled)
 		fprintf(stderr, "checking fs roots\n");
-	ret = check_fs_roots(root, &root_cache);
+	if (low_memory)
+		ret = check_fs_roots_v2(root->fs_info);
+	else
+		ret = check_fs_roots(root, &root_cache);
 	if (ret)
 		goto out;
 
@@ -12439,9 +12530,11 @@ int cmd_check(int argc, char **argv)
 		goto out;
 
 	fprintf(stderr, "checking root refs\n");
-	ret = check_root_refs(root, &root_cache);
-	if (ret)
-		goto out;
+	if (!low_memory) {
+		ret = check_root_refs(root, &root_cache);
+		if (ret)
+			goto out;
+	}
 
 	while (repair && !list_empty(&root->fs_info->recow_ebs)) {
 		struct extent_buffer *eb;
-- 
2.7.4




  parent reply	other threads:[~2016-07-28  7:09 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-28  7:08 [PATCH 00/13] btrfs-progs: check: check fs roots in low_memory mode Lu Fengqi
2016-07-28  7:08 ` [PATCH 01/13] btrfs-progs: move btrfs_extref_hash() to hash.h Lu Fengqi
2016-07-28  7:08 ` [PATCH 02/13] btrfs-progs: check: introduce function to find dir_item Lu Fengqi
2016-09-06 15:08   ` David Sterba
2016-07-28  7:08 ` [PATCH 03/13] btrfs-progs: check: introduce function to check inode_ref Lu Fengqi
2016-07-28  7:08 ` [PATCH 04/13] btrfs-progs: check: introduce function to check inode_extref Lu Fengqi
2016-07-28  7:08 ` [PATCH 05/13] btrfs-progs: check: introduce function to find inode_ref Lu Fengqi
2016-07-28  7:08 ` [PATCH 06/13] btrfs-progs: check: introduce a function to check dir_item Lu Fengqi
2016-07-28  7:08 ` [PATCH 07/13] btrfs-progs: check: introduce function to check file extent Lu Fengqi
2016-07-28  7:08 ` [PATCH 08/13] btrfs-progs: check: introduce function to check inode item Lu Fengqi
2016-07-28  7:08 ` [PATCH 09/13] btrfs-progs: check: introduce function to check fs root Lu Fengqi
2016-07-28  7:08 ` [PATCH 10/13] btrfs-progs: check: introduce function to check root ref Lu Fengqi
2016-07-28  7:08 ` Lu Fengqi [this message]
2016-07-28  7:08 ` [PATCH 12/13] btrfs-progs: check: fix the return value bug of cmd_check() Lu Fengqi
2016-07-28  7:08 ` [PATCH 13/13] btrfs-progs: check: fix false warning for check_extent_item() Lu Fengqi
2016-08-17 17:00 ` [PATCH 00/13] btrfs-progs: check: check fs roots in low_memory mode David Sterba
2016-08-19  9:57   ` Wang Xiaoguang
2016-08-19 10:31     ` David Sterba

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=1469689705-26836-12-git-send-email-lufq.fnst@cn.fujitsu.com \
    --to=lufq.fnst@cn.fujitsu.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=quwenruo@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.