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 v2 04/30] btrfs-progs: check: make reinit work per found root item
Date: Wed, 10 Nov 2021 15:14:16 -0500	[thread overview]
Message-ID: <75eb2e354247aa6e9ab3b57083559bc6da131fd9.1636575146.git.josef@toxicpanda.com> (raw)
In-Reply-To: <cover.1636575146.git.josef@toxicpanda.com>

Instead of looking for the first extent root or csum root in memory,
scan through the tree root and re-init any root items that match the
given objectid.  This will allow reinit to work with both extent tree v1
and extent tree v2 global roots when using the --reinit option.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 check/main.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 49 insertions(+), 3 deletions(-)

diff --git a/check/main.c b/check/main.c
index e3e5a336..140cd427 100644
--- a/check/main.c
+++ b/check/main.c
@@ -9319,6 +9319,52 @@ out:
 	return ret;
 }
 
+static int reinit_global_roots(struct btrfs_trans_handle *trans, u64 objectid)
+{
+	struct btrfs_key key = {
+		.objectid = objectid,
+		.type = BTRFS_ROOT_ITEM_KEY,
+		.offset = 0,
+	};
+	struct btrfs_path path;
+	struct btrfs_root *tree_root = gfs_info->tree_root;
+	struct btrfs_root *root;
+	int ret;
+
+	btrfs_init_path(&path);
+	while (1) {
+		ret = btrfs_search_slot(NULL, tree_root, &key, &path, 0, 0);
+		if (ret) {
+			if (ret == 1) {
+				/* We should at least find the first one. */
+				if (key.offset == 0)
+					ret = -ENOENT;
+				else
+					ret = 0;
+			}
+			break;
+		}
+
+		btrfs_item_key_to_cpu(path.nodes[0], &key, path.slots[0]);
+		if (key.objectid != objectid)
+			break;
+		btrfs_release_path(&path);
+		root = btrfs_read_fs_root(gfs_info, &key);
+		if (IS_ERR(root)) {
+			error("Error reading global root [%llu %llu]",
+			      key.objectid, key.offset);
+			ret = PTR_ERR(root);
+			break;
+		}
+		ret = btrfs_fsck_reinit_root(trans, root);
+		if (ret)
+			break;
+		key.offset++;
+	}
+	btrfs_release_path(&path);
+	return ret;
+}
+
 static int reinit_extent_tree(struct btrfs_trans_handle *trans, bool pin)
 {
 	u64 start = 0;
@@ -9375,7 +9421,7 @@ again:
 	}
 
 	/* Ok we can allocate now, reinit the extent root */
-	ret = btrfs_fsck_reinit_root(trans, btrfs_extent_root(gfs_info, 0));
+	ret = reinit_global_roots(trans, BTRFS_EXTENT_TREE_OBJECTID);
 	if (ret) {
 		fprintf(stderr, "extent root initialization failed\n");
 		/*
@@ -10699,8 +10745,8 @@ static int cmd_check(const struct cmd_struct *cmd, int argc, char **argv)
 
 		if (init_csum_tree) {
 			printf("Reinitialize checksum tree\n");
-			ret = btrfs_fsck_reinit_root(trans,
-						btrfs_csum_root(gfs_info, 0));
+			ret = reinit_global_roots(trans,
+						  BTRFS_CSUM_TREE_OBJECTID);
 			if (ret) {
 				error("checksum tree initialization failed: %d",
 						ret);
-- 
2.26.3


  parent reply	other threads:[~2021-11-10 20:14 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-10 20:14 [PATCH v2 00/30] btrfs-progs: extent tree v2 support, global roots Josef Bacik
2021-11-10 20:14 ` [PATCH v2 01/30] btrfs-progs: stop accessing ->extent_root directly Josef Bacik
2021-11-10 20:14 ` [PATCH v2 02/30] btrfs-progs: stop accessing ->free_space_root directly Josef Bacik
2021-11-10 20:14 ` [PATCH v2 03/30] btrfs-progs: track csum, extent, and free space trees in a rb tree Josef Bacik
2021-11-10 20:14 ` Josef Bacik [this message]
2021-11-10 20:14 ` [PATCH v2 05/30] btrfs-progs: check: check the global roots for uptodate root nodes Josef Bacik
2021-11-10 20:14 ` [PATCH v2 06/30] btrfs-progs: check: check all of the csum roots Josef Bacik
2021-11-10 20:14 ` [PATCH v2 07/30] btrfs-progs: check: fill csum root from all extent roots Josef Bacik
2021-11-10 20:14 ` [PATCH v2 08/30] btrfs-progs: common: search all extent roots for marking used space Josef Bacik
2021-11-10 20:14 ` [PATCH v2 09/30] btrfs-progs: common: allow users to select extent-tree-v2 option Josef Bacik
2021-11-10 20:14 ` [PATCH v2 10/30] btrfs-progs: add definitions for the block group tree Josef Bacik
2021-11-10 20:14 ` [PATCH v2 11/30] btrfs-progs: add on disk pointers to global tree ids Josef Bacik
2021-11-10 20:14 ` [PATCH v2 12/30] btrfs-progs: add support for loading the block group root Josef Bacik
2021-11-10 20:14 ` [PATCH v2 13/30] btrfs-progs: add print support for the block group tree Josef Bacik
2021-11-10 20:14 ` [PATCH v2 14/30] btrfs-progs: mkfs: use the btrfs_block_group_root helper Josef Bacik
2021-11-10 20:14 ` [PATCH v2 15/30] btrfs-progs: check-lowmem: " Josef Bacik
2021-11-10 20:14 ` [PATCH v2 16/30] btrfs-progs: handle no bg item in extent tree for free space tree Josef Bacik
2021-11-10 20:14 ` [PATCH v2 17/30] btrfs-progs: mkfs: add support for the block group tree Josef Bacik
2021-11-10 20:14 ` [PATCH v2 18/30] btrfs-progs: check: add block group tree support Josef Bacik
2021-11-10 20:14 ` [PATCH v2 19/30] btrfs-progs: qgroup-verify: scan extents based on block groups Josef Bacik
2021-11-10 20:14 ` [PATCH v2 20/30] btrfs-progs: check: make free space tree validation extent tree v2 aware Josef Bacik
2021-11-10 20:14 ` [PATCH v2 21/30] btrfs-progs: check: add helper to reinit the root based on a key Josef Bacik
2021-11-10 20:14 ` [PATCH v2 22/30] btrfs-progs: check: handle the block group tree properly Josef Bacik
2021-11-10 20:14 ` [PATCH v2 23/30] btrfs-progs: load the number of global roots into the fs_info Josef Bacik
2021-11-10 20:14 ` [PATCH v2 24/30] btrfs-progs: handle the per-block group global root id Josef Bacik
2021-11-10 20:14 ` [PATCH v2 25/30] btrfs-progs: add a btrfs_delete_and_free_root helper Josef Bacik
2021-11-10 20:14 ` [PATCH v2 26/30] btrfs-progs: make btrfs_clear_free_space_tree extent tree v2 aware Josef Bacik
2021-11-10 20:14 ` [PATCH v2 27/30] btrfs-progs: make btrfs_create_tree take a key for the root key Josef Bacik
2021-11-10 20:14 ` [PATCH v2 28/30] btrfs-progs: mkfs: set chunk_item_objectid properly for extent tree v2 Josef Bacik
2021-11-10 20:14 ` [PATCH v2 29/30] btrfs-progs: mkfs: create the global root's Josef Bacik
2021-11-15 20:51   ` David Sterba
2021-11-16 14:45     ` [PATCH v3] " Josef Bacik
2021-11-10 20:14 ` [PATCH v2 30/30] btrfs-progs: check: don't do the root item check for extent tree v2 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=75eb2e354247aa6e9ab3b57083559bc6da131fd9.1636575146.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.