From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH v4 01/11] btrfs-progs: check/lowmem: Lookup block group item in a seperate function
Date: Tue, 5 May 2020 08:02:20 +0800 [thread overview]
Message-ID: <20200505000230.4454-2-wqu@suse.com> (raw)
In-Reply-To: <20200505000230.4454-1-wqu@suse.com>
In check_chunk_item() we search extent tree for block group item.
Refactor this part into a separate function, find_block_group_item(),
so that later skinny-bg-tree feature can reuse it.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
check/mode-lowmem.c | 74 ++++++++++++++++++++++++++++-----------------
1 file changed, 47 insertions(+), 27 deletions(-)
diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c
index 821ebc57c8ed..dbb90895127d 100644
--- a/check/mode-lowmem.c
+++ b/check/mode-lowmem.c
@@ -4499,6 +4499,50 @@ next:
return 0;
}
+/*
+ * Find the block group item with @bytenr, @len and @type
+ *
+ * Return 0 if found.
+ * Return -ENOENT if not found.
+ * Return <0 for fatal error.
+ */
+static int find_block_group_item(struct btrfs_fs_info *fs_info,
+ struct btrfs_path *path, u64 bytenr, u64 len,
+ u64 type)
+{
+ struct btrfs_block_group_item bgi;
+ struct btrfs_key key;
+ int ret;
+
+ key.objectid = bytenr;
+ key.type = BTRFS_BLOCK_GROUP_ITEM_KEY;
+ key.offset = len;
+
+ ret = btrfs_search_slot(NULL, fs_info->extent_root, &key, path, 0, 0);
+ if (ret < 0)
+ return ret;
+ if (ret > 0) {
+ ret = -ENOENT;
+ error("chunk [%llu %llu) doesn't have related block group item",
+ bytenr, bytenr + len);
+ goto out;
+ }
+ read_extent_buffer(path->nodes[0], &bgi,
+ btrfs_item_ptr_offset(path->nodes[0], path->slots[0]),
+ sizeof(bgi));
+ if (btrfs_stack_block_group_flags(&bgi) != type) {
+ error(
+"chunk [%llu %llu) type mismatch with block group, block group has 0x%llx chunk has %llx",
+ bytenr, bytenr + len, btrfs_stack_block_group_flags(&bgi),
+ type);
+ ret = -EUCLEAN;
+ }
+
+out:
+ btrfs_release_path(path);
+ return ret;
+}
+
/*
* Check a chunk item.
* Including checking all referred dev_extents and block group
@@ -4506,16 +4550,12 @@ next:
static int check_chunk_item(struct btrfs_fs_info *fs_info,
struct extent_buffer *eb, int slot)
{
- struct btrfs_root *extent_root = fs_info->extent_root;
struct btrfs_root *dev_root = fs_info->dev_root;
struct btrfs_path path;
struct btrfs_key chunk_key;
- struct btrfs_key bg_key;
struct btrfs_key devext_key;
struct btrfs_chunk *chunk;
struct extent_buffer *leaf;
- struct btrfs_block_group_item *bi;
- struct btrfs_block_group_item bg_item;
struct btrfs_dev_extent *ptr;
u64 length;
u64 chunk_end;
@@ -4542,31 +4582,11 @@ static int check_chunk_item(struct btrfs_fs_info *fs_info,
}
type = btrfs_chunk_type(eb, chunk);
- bg_key.objectid = chunk_key.offset;
- bg_key.type = BTRFS_BLOCK_GROUP_ITEM_KEY;
- bg_key.offset = length;
-
btrfs_init_path(&path);
- ret = btrfs_search_slot(NULL, extent_root, &bg_key, &path, 0, 0);
- if (ret) {
- error(
- "chunk[%llu %llu) did not find the related block group item",
- chunk_key.offset, chunk_end);
+ ret = find_block_group_item(fs_info, &path, chunk_key.offset, length,
+ type);
+ if (ret < 0)
err |= REFERENCER_MISSING;
- } else{
- leaf = path.nodes[0];
- bi = btrfs_item_ptr(leaf, path.slots[0],
- struct btrfs_block_group_item);
- read_extent_buffer(leaf, &bg_item, (unsigned long)bi,
- sizeof(bg_item));
- if (btrfs_stack_block_group_flags(&bg_item) != type) {
- error(
-"chunk[%llu %llu) related block group item flags mismatch, wanted: %llu, have: %llu",
- chunk_key.offset, chunk_end, type,
- btrfs_stack_block_group_flags(&bg_item));
- err |= REFERENCER_MISSING;
- }
- }
num_stripes = btrfs_chunk_num_stripes(eb, chunk);
stripe_len = btrfs_stripe_length(fs_info, eb, chunk);
--
2.26.2
next prev parent reply other threads:[~2020-05-05 0:02 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-05 0:02 [PATCH v4 00/11] btrfs-progs: Support for SKINNY_BG_TREE feature Qu Wenruo
2020-05-05 0:02 ` Qu Wenruo [this message]
2020-05-06 17:24 ` [PATCH v4 01/11] btrfs-progs: check/lowmem: Lookup block group item in a seperate function Johannes Thumshirn
2020-05-05 0:02 ` [PATCH v4 02/11] btrfs-progs: block-group: Refactor how we read one block group item Qu Wenruo
2020-05-06 17:27 ` Johannes Thumshirn
2020-05-06 22:52 ` Qu Wenruo
2020-05-07 7:41 ` Johannes Thumshirn
2020-05-05 0:02 ` [PATCH v4 03/11] btrfs-progs: Rename btrfs_remove_block_group() and free_block_group_item() Qu Wenruo
2020-05-07 11:05 ` Johannes Thumshirn
2020-05-05 0:02 ` [PATCH v4 04/11] btrfs-progs: block-group: Refactor how we insert a block group item Qu Wenruo
2020-05-08 14:23 ` Johannes Thumshirn
2020-05-05 0:02 ` [PATCH v4 05/11] btrfs-progs: block-group: Rename write_one_cahce_group() Qu Wenruo
2020-05-08 14:24 ` Johannes Thumshirn
2020-05-05 0:02 ` [PATCH v4 06/11] btrfs-progs: Introduce rw support for skinny_bg_tree Qu Wenruo
2020-05-05 0:02 ` [PATCH v4 07/11] btrfs-progs: mkfs: Introduce -O skinny-bg-tree Qu Wenruo
2020-05-05 0:02 ` [PATCH v4 08/11] btrfs-progs: dump-tree/dump-super: Introduce support for skinny bg tree Qu Wenruo
2020-05-05 0:02 ` [PATCH v4 09/11] btrfs-progs: check: Introduce support for bg-tree feature Qu Wenruo
2020-05-05 0:02 ` [PATCH v4 10/11] btrfs-progs: btrfstune: Allow to enable bg-tree feature offline Qu Wenruo
2020-05-05 0:02 ` [PATCH v4 11/11] btrfs-progs: btrfstune: Allow user to rollback to regular extent tree Qu Wenruo
2020-05-11 18:58 ` [PATCH v4 00/11] btrfs-progs: Support for SKINNY_BG_TREE feature David Sterba
2020-05-12 0:26 ` Qu Wenruo
2020-05-12 2:30 ` Qu Wenruo
2020-05-12 8:21 ` Nikolay Borisov
2020-05-12 8:44 ` 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=20200505000230.4454-2-wqu@suse.com \
--to=wqu@suse.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).