From: Josef Bacik <josef@toxicpanda.com>
To: linux-btrfs@vger.kernel.org, kernel-team@fb.com
Subject: [PATCH v4 12/22] btrfs-progs: check: make free space tree validation extent tree v2 aware
Date: Wed, 15 Dec 2021 14:59:38 -0500 [thread overview]
Message-ID: <70c2664edea4585775c8a3c4ba64a6949f4cee09.1639598278.git.josef@toxicpanda.com> (raw)
In-Reply-To: <cover.1639598278.git.josef@toxicpanda.com>
The free space tree needs to be validated against all referenced blocks
in the file system, so use the btrfs_mark_used_blocks() helper to check
the free space tree and free space cache against. This will do the
right thing for both extent tree v1 and extent tree v2.
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
check/main.c | 90 ++++++++++++++++++----------------------------------
1 file changed, 31 insertions(+), 59 deletions(-)
diff --git a/check/main.c b/check/main.c
index da66735b..3eea186f 100644
--- a/check/main.c
+++ b/check/main.c
@@ -5624,72 +5624,38 @@ static int check_cache_range(struct btrfs_root *root,
}
static int verify_space_cache(struct btrfs_root *root,
- struct btrfs_block_group *cache)
+ struct btrfs_block_group *cache,
+ struct extent_io_tree *used)
{
- struct btrfs_path path;
- struct extent_buffer *leaf;
- struct btrfs_key key;
- u64 last;
+ u64 start, end, last_end, bg_end;
int ret = 0;
- root = btrfs_extent_root(root->fs_info, cache->start);
+ start = cache->start;
+ bg_end = cache->start + cache->length;
+ last_end = start;
- last = max_t(u64, cache->start, BTRFS_SUPER_INFO_OFFSET);
-
- btrfs_init_path(&path);
- key.objectid = last;
- key.offset = 0;
- key.type = BTRFS_EXTENT_ITEM_KEY;
- ret = btrfs_search_slot(NULL, root, &key, &path, 0, 0);
- if (ret < 0)
- goto out;
- ret = 0;
- while (1) {
- if (path.slots[0] >= btrfs_header_nritems(path.nodes[0])) {
- ret = btrfs_next_leaf(root, &path);
- if (ret < 0)
- goto out;
- if (ret > 0) {
- ret = 0;
- break;
- }
- }
- leaf = path.nodes[0];
- btrfs_item_key_to_cpu(leaf, &key, path.slots[0]);
- if (key.objectid >= cache->start + cache->length)
+ while (start < bg_end) {
+ ret = find_first_extent_bit(used, cache->start, &start, &end,
+ EXTENT_DIRTY);
+ if (ret || start >= bg_end) {
+ ret = 0;
break;
- if (key.type != BTRFS_EXTENT_ITEM_KEY &&
- key.type != BTRFS_METADATA_ITEM_KEY) {
- path.slots[0]++;
- continue;
}
-
- if (last == key.objectid) {
- if (key.type == BTRFS_EXTENT_ITEM_KEY)
- last = key.objectid + key.offset;
- else
- last = key.objectid + gfs_info->nodesize;
- path.slots[0]++;
- continue;
+ if (last_end < start) {
+ ret = check_cache_range(root, cache, last_end,
+ start - last_end);
+ if (ret)
+ return ret;
}
-
- ret = check_cache_range(root, cache, last,
- key.objectid - last);
- if (ret)
- break;
- if (key.type == BTRFS_EXTENT_ITEM_KEY)
- last = key.objectid + key.offset;
- else
- last = key.objectid + gfs_info->nodesize;
- path.slots[0]++;
+ end = min(end, bg_end - 1);
+ clear_extent_dirty(used, start, end);
+ start = end + 1;
+ last_end = start;
}
- if (last < cache->start + cache->length)
- ret = check_cache_range(root, cache, last,
- cache->start + cache->length - last);
-
-out:
- btrfs_release_path(&path);
+ if (last_end < bg_end)
+ ret = check_cache_range(root, cache, last_end,
+ bg_end - last_end);
if (!ret &&
!RB_EMPTY_ROOT(&cache->free_space_ctl->free_space_offset)) {
@@ -5703,11 +5669,17 @@ out:
static int check_space_cache(struct btrfs_root *root)
{
+ struct extent_io_tree used;
struct btrfs_block_group *cache;
u64 start = BTRFS_SUPER_INFO_OFFSET + BTRFS_SUPER_INFO_SIZE;
int ret;
int error = 0;
+ extent_io_tree_init(&used);
+ ret = btrfs_mark_used_blocks(gfs_info, &used);
+ if (ret)
+ return ret;
+
while (1) {
ctx.item_count++;
cache = btrfs_lookup_first_block_group(gfs_info, start);
@@ -5752,14 +5724,14 @@ static int check_space_cache(struct btrfs_root *root)
continue;
}
- ret = verify_space_cache(root, cache);
+ ret = verify_space_cache(root, cache, &used);
if (ret) {
fprintf(stderr, "cache appears valid but isn't %llu\n",
cache->start);
error++;
}
}
-
+ extent_io_tree_cleanup(&used);
return error ? -EINVAL : 0;
}
--
2.26.3
next prev parent reply other threads:[~2021-12-15 20:00 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-15 19:59 [PATCH v4 00/22] btrfs-progs: extent tree v2 support, global roots Josef Bacik
2021-12-15 19:59 ` [PATCH v4 01/22] btrfs-progs: common: allow users to select extent-tree-v2 option Josef Bacik
2021-12-15 19:59 ` [PATCH v4 02/22] btrfs-progs: add definitions for the block group tree Josef Bacik
2021-12-15 19:59 ` [PATCH v4 03/22] btrfs-progs: add on disk pointers to global tree ids Josef Bacik
2021-12-15 19:59 ` [PATCH v4 04/22] btrfs-progs: add support for loading the block group root Josef Bacik
2021-12-15 19:59 ` [PATCH v4 05/22] btrfs-progs: add print support for the block group tree Josef Bacik
2021-12-15 19:59 ` [PATCH v4 06/22] btrfs-progs: mkfs: use the btrfs_block_group_root helper Josef Bacik
2021-12-15 19:59 ` [PATCH v4 07/22] btrfs-progs: check-lowmem: " Josef Bacik
2021-12-15 19:59 ` [PATCH v4 08/22] btrfs-progs: handle no bg item in extent tree for free space tree Josef Bacik
2021-12-15 19:59 ` [PATCH v4 09/22] btrfs-progs: mkfs: add support for the block group tree Josef Bacik
2021-12-15 19:59 ` [PATCH v4 10/22] btrfs-progs: check: add block group tree support Josef Bacik
2021-12-15 19:59 ` [PATCH v4 11/22] btrfs-progs: qgroup-verify: scan extents based on block groups Josef Bacik
2021-12-15 19:59 ` Josef Bacik [this message]
2021-12-15 19:59 ` [PATCH v4 13/22] btrfs-progs: check: add helper to reinit the root based on a key Josef Bacik
2021-12-15 19:59 ` [PATCH v4 14/22] btrfs-progs: check: handle the block group tree properly Josef Bacik
2021-12-15 19:59 ` [PATCH v4 15/22] btrfs-progs: load the number of global roots into the fs_info Josef Bacik
2021-12-15 19:59 ` [PATCH v4 16/22] btrfs-progs: handle the per-block group global root id Josef Bacik
2021-12-15 19:59 ` [PATCH v4 17/22] btrfs-progs: add a btrfs_delete_and_free_root helper Josef Bacik
2021-12-15 19:59 ` [PATCH v4 18/22] btrfs-progs: make btrfs_clear_free_space_tree extent tree v2 aware Josef Bacik
2021-12-15 19:59 ` [PATCH v4 19/22] btrfs-progs: make btrfs_create_tree take a key for the root key Josef Bacik
2021-12-15 19:59 ` [PATCH v4 20/22] btrfs-progs: mkfs: set chunk_item_objectid properly for extent tree v2 Josef Bacik
2021-12-15 19:59 ` [PATCH v4 21/22] btrfs-progs: mkfs: create the global root's Josef Bacik
2021-12-15 19:59 ` [PATCH v4 22/22] 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=70c2664edea4585775c8a3c4ba64a6949f4cee09.1639598278.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).