All of lore.kernel.org
 help / color / mirror / Atom feed
From: Josef Bacik <josef@toxicpanda.com>
To: linux-btrfs@vger.kernel.org, kernel-team@fb.com
Subject: [PATCH 11/20] btrfs-progs: check: move btrfs_mark_used_tree_blocks to common
Date: Fri,  5 Nov 2021 16:28:36 -0400	[thread overview]
Message-ID: <df67538393e5d71fc33ddebbd479f7ad450ec30d.1636143924.git.josef@toxicpanda.com> (raw)
In-Reply-To: <cover.1636143924.git.josef@toxicpanda.com>

This is going to be used for the extent tree v2 stuff more commonly, so
move it out so that it is accessible from everywhere that we need it.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 check/mode-common.c | 105 -------------------------------------------
 common/repair.c     | 106 ++++++++++++++++++++++++++++++++++++++++++++
 common/repair.h     |   2 +
 3 files changed, 108 insertions(+), 105 deletions(-)

diff --git a/check/mode-common.c b/check/mode-common.c
index a4a09714..56377840 100644
--- a/check/mode-common.c
+++ b/check/mode-common.c
@@ -599,111 +599,6 @@ void reset_cached_block_groups()
 	}
 }
 
-static int traverse_tree_blocks(struct btrfs_fs_info *fs_info,
-				struct extent_io_tree *tree,
-				struct extent_buffer *eb, int tree_root)
-{
-	struct extent_buffer *tmp;
-	struct btrfs_root_item *ri;
-	struct btrfs_key key;
-	u64 bytenr;
-	int level = btrfs_header_level(eb);
-	int nritems;
-	int ret;
-	int i;
-	u64 end = eb->start + eb->len;
-	bool pin = tree == &fs_info->pinned_extents;
-
-	/*
-	 * If we have pinned/excluded this block before, don't do it again.
-	 * This can not only avoid forever loop with broken filesystem
-	 * but also give us some speedups.
-	 */
-	if (test_range_bit(tree, eb->start, end - 1, EXTENT_DIRTY, 0))
-		return 0;
-
-	if (pin)
-		btrfs_pin_extent(fs_info, eb->start, eb->len);
-	else
-		set_extent_dirty(tree, eb->start, end - 1);
-
-	nritems = btrfs_header_nritems(eb);
-	for (i = 0; i < nritems; i++) {
-		if (level == 0) {
-			bool is_extent_root;
-			btrfs_item_key_to_cpu(eb, &key, i);
-			if (key.type != BTRFS_ROOT_ITEM_KEY)
-				continue;
-			/* Skip the extent root and reloc roots */
-			if (key.objectid == BTRFS_TREE_RELOC_OBJECTID ||
-			    key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID)
-				continue;
-			is_extent_root =
-				key.objectid == BTRFS_EXTENT_TREE_OBJECTID;
-			/* If pin, skip the extent root */
-			if (pin && is_extent_root)
-				continue;
-			ri = btrfs_item_ptr(eb, i, struct btrfs_root_item);
-			bytenr = btrfs_disk_root_bytenr(eb, ri);
-
-			/*
-			 * If at any point we start needing the real root we
-			 * will have to build a stump root for the root we are
-			 * in, but for now this doesn't actually use the root so
-			 * just pass in extent_root.
-			 */
-			tmp = read_tree_block(fs_info, bytenr, 0);
-			if (!extent_buffer_uptodate(tmp)) {
-				fprintf(stderr, "Error reading root block\n");
-				return -EIO;
-			}
-			ret = traverse_tree_blocks(fs_info, tree, tmp, 0);
-			free_extent_buffer(tmp);
-			if (ret)
-				return ret;
-		} else {
-			bytenr = btrfs_node_blockptr(eb, i);
-
-			/* If we aren't the tree root don't read the block */
-			if (level == 1 && !tree_root) {
-				if (pin)
-					btrfs_pin_extent(fs_info, bytenr,
-							 fs_info->nodesize);
-				else
-					set_extent_dirty(tree, bytenr,
-							 fs_info->nodesize);
-				continue;
-			}
-
-			tmp = read_tree_block(fs_info, bytenr, 0);
-			if (!extent_buffer_uptodate(tmp)) {
-				fprintf(stderr, "Error reading tree block\n");
-				return -EIO;
-			}
-			ret = traverse_tree_blocks(fs_info, tree, tmp,
-						   tree_root);
-			free_extent_buffer(tmp);
-			if (ret)
-				return ret;
-		}
-	}
-
-	return 0;
-}
-
-int btrfs_mark_used_tree_blocks(struct btrfs_fs_info *fs_info,
-				struct extent_io_tree *tree)
-{
-	int ret;
-
-	ret = traverse_tree_blocks(fs_info, tree,
-				   fs_info->chunk_root->node, 0);
-	if (!ret)
-		ret = traverse_tree_blocks(fs_info, tree,
-					   fs_info->tree_root->node, 1);
-	return ret;
-}
-
 int pin_metadata_blocks(void)
 {
 	return btrfs_mark_used_tree_blocks(gfs_info,
diff --git a/common/repair.c b/common/repair.c
index a5ba43e2..79519140 100644
--- a/common/repair.c
+++ b/common/repair.c
@@ -18,6 +18,7 @@
 
 #include "kernel-shared/ctree.h"
 #include "kernel-shared/transaction.h"
+#include "kernel-shared/disk-io.h"
 #include "common/extent-cache.h"
 #include "common/utils.h"
 #include "common/repair.h"
@@ -51,6 +52,111 @@ int btrfs_add_corrupt_extent_record(struct btrfs_fs_info *info,
 	return ret;
 }
 
+static int traverse_tree_blocks(struct btrfs_fs_info *fs_info,
+				struct extent_io_tree *tree,
+				struct extent_buffer *eb, int tree_root)
+{
+	struct extent_buffer *tmp;
+	struct btrfs_root_item *ri;
+	struct btrfs_key key;
+	u64 bytenr;
+	int level = btrfs_header_level(eb);
+	int nritems;
+	int ret;
+	int i;
+	u64 end = eb->start + eb->len;
+	bool pin = tree == &fs_info->pinned_extents;
+
+	/*
+	 * If we have pinned/excluded this block before, don't do it again.
+	 * This can not only avoid forever loop with broken filesystem
+	 * but also give us some speedups.
+	 */
+	if (test_range_bit(tree, eb->start, end - 1, EXTENT_DIRTY, 0))
+		return 0;
+
+	if (pin)
+		btrfs_pin_extent(fs_info, eb->start, eb->len);
+	else
+		set_extent_dirty(tree, eb->start, end - 1);
+
+	nritems = btrfs_header_nritems(eb);
+	for (i = 0; i < nritems; i++) {
+		if (level == 0) {
+			bool is_extent_root;
+			btrfs_item_key_to_cpu(eb, &key, i);
+			if (key.type != BTRFS_ROOT_ITEM_KEY)
+				continue;
+			/* Skip the extent root and reloc roots */
+			if (key.objectid == BTRFS_TREE_RELOC_OBJECTID ||
+			    key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID)
+				continue;
+			is_extent_root =
+				key.objectid == BTRFS_EXTENT_TREE_OBJECTID;
+			/* If pin, skip the extent root */
+			if (pin && is_extent_root)
+				continue;
+			ri = btrfs_item_ptr(eb, i, struct btrfs_root_item);
+			bytenr = btrfs_disk_root_bytenr(eb, ri);
+
+			/*
+			 * If at any point we start needing the real root we
+			 * will have to build a stump root for the root we are
+			 * in, but for now this doesn't actually use the root so
+			 * just pass in extent_root.
+			 */
+			tmp = read_tree_block(fs_info, bytenr, 0);
+			if (!extent_buffer_uptodate(tmp)) {
+				fprintf(stderr, "Error reading root block\n");
+				return -EIO;
+			}
+			ret = traverse_tree_blocks(fs_info, tree, tmp, 0);
+			free_extent_buffer(tmp);
+			if (ret)
+				return ret;
+		} else {
+			bytenr = btrfs_node_blockptr(eb, i);
+
+			/* If we aren't the tree root don't read the block */
+			if (level == 1 && !tree_root) {
+				if (pin)
+					btrfs_pin_extent(fs_info, bytenr,
+							 fs_info->nodesize);
+				else
+					set_extent_dirty(tree, bytenr,
+							 fs_info->nodesize);
+				continue;
+			}
+
+			tmp = read_tree_block(fs_info, bytenr, 0);
+			if (!extent_buffer_uptodate(tmp)) {
+				fprintf(stderr, "Error reading tree block\n");
+				return -EIO;
+			}
+			ret = traverse_tree_blocks(fs_info, tree, tmp,
+						   tree_root);
+			free_extent_buffer(tmp);
+			if (ret)
+				return ret;
+		}
+	}
+
+	return 0;
+}
+
+int btrfs_mark_used_tree_blocks(struct btrfs_fs_info *fs_info,
+				struct extent_io_tree *tree)
+{
+	int ret;
+
+	ret = traverse_tree_blocks(fs_info, tree,
+				   fs_info->chunk_root->node, 0);
+	if (!ret)
+		ret = traverse_tree_blocks(fs_info, tree,
+					   fs_info->tree_root->node, 1);
+	return ret;
+}
+
 /*
  * Fixup block accounting. The initial block accounting created by
  * make_block_groups isn't accuracy in this case.
diff --git a/common/repair.h b/common/repair.h
index 4e1fa3e7..793ebcd2 100644
--- a/common/repair.h
+++ b/common/repair.h
@@ -33,5 +33,7 @@ int btrfs_add_corrupt_extent_record(struct btrfs_fs_info *info,
 				    struct btrfs_key *first_key,
 				    u64 start, u64 len, int level);
 int btrfs_fix_block_accounting(struct btrfs_trans_handle *trans);
+int btrfs_mark_used_tree_blocks(struct btrfs_fs_info *fs_info,
+				struct extent_io_tree *tree);
 
 #endif
-- 
2.26.3


  parent reply	other threads:[~2021-11-05 20:29 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-05 20:28 [PATCH 00/20] btrfs-progs: extent tree v2 global root support prep work Josef Bacik
2021-11-05 20:28 ` [PATCH 01/20] btrfs-progs: simplify btrfs_make_block_group Josef Bacik
2021-11-06  0:14   ` Qu Wenruo
2021-11-08 10:13   ` Anand Jain
2021-11-05 20:28 ` [PATCH 02/20] btrfs-progs: check: don't walk down non fs-trees for qgroup check Josef Bacik
2021-11-06  0:14   ` Qu Wenruo
2021-11-05 20:28 ` [PATCH 03/20] btrfs-progs: filesystem-show: close ctree once we're done Josef Bacik
2021-11-08 10:23   ` Anand Jain
2021-11-05 20:28 ` [PATCH 04/20] btrfs-progs: add a helper for setting up a root node Josef Bacik
2021-11-06  0:18   ` Qu Wenruo
2021-11-05 20:28 ` [PATCH 05/20] btrfs-progs: btrfs-shared: stop passing root to csum related functions Josef Bacik
2021-11-06  0:20   ` Qu Wenruo
2021-11-05 20:28 ` [PATCH 06/20] btrfs-progs: check: stop passing csum root around Josef Bacik
2021-11-06  0:21   ` Qu Wenruo
2021-11-05 20:28 ` [PATCH 07/20] btrfs-progs: stop accessing ->csum_root directly Josef Bacik
2021-11-06  0:23   ` Qu Wenruo
2021-11-08 19:19     ` Josef Bacik
2021-11-09  0:56       ` Qu Wenruo
2021-11-09 15:12       ` David Sterba
2021-11-05 20:28 ` [PATCH 08/20] btrfs-progs: image: keep track of seen blocks when walking trees Josef Bacik
2021-11-06  0:26   ` Qu Wenruo
2021-11-05 20:28 ` [PATCH 09/20] btrfs-progs: common: move btrfs_fix_block_accounting to repair.c Josef Bacik
2021-11-06  0:30   ` Qu Wenruo
2021-11-05 20:28 ` [PATCH 10/20] btrfs-progs: check: abstract out the used marking helpers Josef Bacik
2021-11-06  0:37   ` Qu Wenruo
2021-11-05 20:28 ` Josef Bacik [this message]
2021-11-05 20:28 ` [PATCH 12/20] btrfs-progs: mark reloc roots as used Josef Bacik
2021-11-06  0:39   ` Qu Wenruo
2021-11-08 19:14     ` Josef Bacik
2021-11-09  0:57       ` Qu Wenruo
2021-11-05 20:28 ` [PATCH 13/20] btrfs-progs: stop accessing ->extent_root directly Josef Bacik
2021-11-06  0:41   ` Qu Wenruo
2021-11-05 20:28 ` [PATCH 14/20] btrfs-progs: stop accessing ->free_space_root directly Josef Bacik
2021-11-06  0:44   ` Qu Wenruo
2021-11-05 20:28 ` [PATCH 15/20] btrfs-progs: track csum, extent, and free space trees in a rb tree Josef Bacik
2021-11-05 20:28 ` [PATCH 16/20] btrfs-progs: check: make reinit work per found root item Josef Bacik
2021-11-05 20:28 ` [PATCH 17/20] btrfs-progs: check: check the global roots for uptodate root nodes Josef Bacik
2021-11-05 20:28 ` [PATCH 18/20] btrfs-progs: check: check all of the csum roots Josef Bacik
2021-11-05 20:28 ` [PATCH 19/20] btrfs-progs: check: fill csum root from all extent roots Josef Bacik
2021-11-05 20:28 ` [PATCH 20/20] btrfs-progs: common: search all extent roots for marking used space Josef Bacik
2021-11-06  0:55 ` [PATCH 00/20] btrfs-progs: extent tree v2 global root support prep work Qu Wenruo
2021-11-06 20:17   ` Josef Bacik

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=df67538393e5d71fc33ddebbd479f7ad450ec30d.1636143924.git.josef@toxicpanda.com \
    --to=josef@toxicpanda.com \
    --cc=kernel-team@fb.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 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.