All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: jbacik@fb.com, linux-btrfs@vger.kernel.org
Cc: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Subject: [PATCH RFC v2 05/16] btrfs-progs: fsck: Introduce function to check shared block ref
Date: Fri, 29 Apr 2016 15:18:59 +0800	[thread overview]
Message-ID: <1461914350-19875-6-git-send-email-quwenruo@cn.fujitsu.com> (raw)
In-Reply-To: <1461914350-19875-1-git-send-email-quwenruo@cn.fujitsu.com>

From: Lu Fengqi <lufq.fnst@cn.fujitsu.com>

Introduce function check_shared_block_backref() to check shared block
ref.

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

diff --git a/cmds-check.c b/cmds-check.c
index fae4c26..de3c2e1 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -8889,6 +8889,48 @@ out:
 	return err;
 }
 
+/*
+ * Check referencer for shared block backref
+ * If level == -1, this function will resolve the level.
+ */
+static int check_shared_block_backref(struct btrfs_fs_info *fs_info,
+				     u64 parent, u64 bytenr, int level)
+{
+	struct extent_buffer *eb;
+	u32 nodesize = btrfs_super_nodesize(fs_info->super_copy);
+	u32 nr;
+	int found_parent = 0;
+	int i;
+
+	eb = read_tree_block_fs_info(fs_info, parent, nodesize, 0);
+	if (!extent_buffer_uptodate(eb))
+		goto out;
+
+	if (level == -1)
+		level = query_tree_block_level(fs_info, bytenr);
+	if (level < 0)
+		goto out;
+
+	if (level + 1 != btrfs_header_level(eb))
+		goto out;
+
+	nr = btrfs_header_nritems(eb);
+	for (i = 0; i < nr; i++) {
+		if (bytenr == btrfs_node_blockptr(eb, i)) {
+			found_parent = 1;
+			break;
+		}
+	}
+out:
+	free_extent_buffer(eb);
+	if (!found_parent) {
+		error("Shared extent[%llu %u] lost its parent(parent: %llu, level: %u)",
+		      bytenr, nodesize, parent, level);
+		return REFERENCER_MISSING;
+	}
+	return 0;
+}
+
 static int btrfs_fsck_reinit_root(struct btrfs_trans_handle *trans,
 			   struct btrfs_root *root, int overwrite)
 {
-- 
2.8.0




  parent reply	other threads:[~2016-04-29  7:20 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-29  7:18 [PATCH RFC v2 00/16] Introduce low memory usage btrfsck mode Qu Wenruo
2016-04-29  7:18 ` [PATCH RFC v2 01/16] btrfs-progs: fsck: Introduce function to check tree block backref in extent tree Qu Wenruo
2016-04-29  7:18 ` [PATCH RFC v2 02/16] btrfs-progs: fsck: Introduce function to check data " Qu Wenruo
2016-04-29  7:18 ` [PATCH RFC v2 03/16] btrfs-progs: fsck: Introduce function to query tree block level Qu Wenruo
2016-04-29  7:18 ` [PATCH RFC v2 04/16] btrfs-progs: fsck: Introduce function to check referencer of a backref Qu Wenruo
2016-04-29  7:18 ` Qu Wenruo [this message]
2016-04-29  7:19 ` [PATCH RFC v2 06/16] btrfs-progs: fsck: Introduce function to check referencer for data backref Qu Wenruo
2016-04-29  7:19 ` [PATCH RFC v2 07/16] btrfs-progs: fsck: Introduce function to check shared " Qu Wenruo
2016-04-29  7:19 ` [PATCH RFC v2 08/16] btrfs-progs: fsck: Introduce function to check an extent Qu Wenruo
2016-04-29  7:19 ` [PATCH RFC v2 09/16] btrfs-progs: fsck: Introduce function to check dev extent item Qu Wenruo
2016-04-29  7:19 ` [PATCH RFC v2 10/16] btrfs-progs: fsck: Introduce function to check dev used space Qu Wenruo
2016-04-29  7:19 ` [PATCH RFC v2 11/16] btrfs-progs: fsck: Introduce function to check block group item Qu Wenruo
2016-04-29  7:19 ` [PATCH RFC v2 12/16] btrfs-progs: fsck: Introduce function to check chunk item Qu Wenruo
2016-04-29  7:19 ` [PATCH RFC v2 13/16] btrfs-progs: fsck: Introduce hub function for later fsck Qu Wenruo
2016-04-29  7:19 ` [PATCH RFC v2 14/16] btrfs-progs: fsck: Introduce function to speed up fs tree check Qu Wenruo
2016-04-29  7:19 ` [PATCH RFC v2 15/16] btrfs-progs: fsck: Introduce traversal function for fsck Qu Wenruo
2016-04-29  7:19 ` [PATCH RFC v2 16/16] btrfs-progs: fsck: Introduce low memory mode Qu Wenruo
2016-04-29  7:27 ` [PATCH RFC v2 00/16] Introduce low memory usage btrfsck mode Qu Wenruo
2016-04-29 13:54   ` Josef Bacik
2016-05-10 12:44 ` David Sterba
2016-05-11  1:17   ` 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=1461914350-19875-6-git-send-email-quwenruo@cn.fujitsu.com \
    --to=quwenruo@cn.fujitsu.com \
    --cc=jbacik@fb.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=lufq.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.