From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Josef Bacik <josef@toxicpanda.com>,
linux-btrfs@vger.kernel.org, kernel-team@fb.com
Subject: Re: [PATCH 10/20] btrfs-progs: check: abstract out the used marking helpers
Date: Sat, 6 Nov 2021 08:37:45 +0800 [thread overview]
Message-ID: <12fb0839-eef0-ce6d-db1c-ae747414cde2@gmx.com> (raw)
In-Reply-To: <c82b4edc2e8619a4359ae3933e821e66db80beb3.1636143924.git.josef@toxicpanda.com>
On 2021/11/6 04:28, Josef Bacik wrote:
> We will walk all referenced tree blocks during check in order to avoid
> writing over any referenced blocks during fsck. However in the future
> we're going to need to do this for things like fixing block group
> accounting with extent tree v2. This is because extent tree v2 will not
> refer to all of the allocated blocks in the extent tree. Refactor the
> code some to allow us to send down an arbitrary extent_io_tree so we can
> use this helper for any case where we need to figure out where all the
> used space is on an extent tree v2 file system.
I guess in that case @tree parameter will be an per-block-group io-tree
then?
Then the refactor may be more suitable for the extent-tree-v2 patchset.
>
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>
> ---
> check/mode-common.c | 57 ++++++++++++++++++++-------------------------
> 1 file changed, 25 insertions(+), 32 deletions(-)
>
> diff --git a/check/mode-common.c b/check/mode-common.c
> index 0c3bd38b..a4a09714 100644
> --- a/check/mode-common.c
> +++ b/check/mode-common.c
> @@ -599,23 +599,21 @@ void reset_cached_block_groups()
> }
> }
>
> -static int traverse_tree_blocks(struct extent_buffer *eb, int tree_root, int pin)
> +static int traverse_tree_blocks(struct btrfs_fs_info *fs_info,
fs_info can be extracted from eb->fs_info directly.
Thanks,
Qu
> + 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;
> - struct extent_io_tree *tree;
> 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 (pin)
> - tree = &gfs_info->pinned_extents;
> - else
> - tree = gfs_info->excluded_extents;
> /*
> * If we have pinned/excluded this block before, don't do it again.
> * This can not only avoid forever loop with broken filesystem
> @@ -625,7 +623,7 @@ static int traverse_tree_blocks(struct extent_buffer *eb, int tree_root, int pin
> return 0;
>
> if (pin)
> - btrfs_pin_extent(gfs_info, eb->start, eb->len);
> + btrfs_pin_extent(fs_info, eb->start, eb->len);
> else
> set_extent_dirty(tree, eb->start, end - 1);
>
> @@ -654,12 +652,12 @@ static int traverse_tree_blocks(struct extent_buffer *eb, int tree_root, int pin
> * in, but for now this doesn't actually use the root so
> * just pass in extent_root.
> */
> - tmp = read_tree_block(gfs_info, bytenr, 0);
> + 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(tmp, 0, pin);
> + ret = traverse_tree_blocks(fs_info, tree, tmp, 0);
> free_extent_buffer(tmp);
> if (ret)
> return ret;
> @@ -669,20 +667,21 @@ static int traverse_tree_blocks(struct extent_buffer *eb, int tree_root, int pin
> /* If we aren't the tree root don't read the block */
> if (level == 1 && !tree_root) {
> if (pin)
> - btrfs_pin_extent(gfs_info, bytenr,
> - gfs_info->nodesize);
> + btrfs_pin_extent(fs_info, bytenr,
> + fs_info->nodesize);
> else
> set_extent_dirty(tree, bytenr,
> - gfs_info->nodesize);
> + fs_info->nodesize);
> continue;
> }
>
> - tmp = read_tree_block(gfs_info, bytenr, 0);
> + 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(tmp, tree_root, pin);
> + ret = traverse_tree_blocks(fs_info, tree, tmp,
> + tree_root);
> free_extent_buffer(tmp);
> if (ret)
> return ret;
> @@ -692,30 +691,27 @@ static int traverse_tree_blocks(struct extent_buffer *eb, int tree_root, int pin
> return 0;
> }
>
> -static int pin_down_tree_blocks(struct extent_buffer *eb, int tree_root)
> -{
> - return traverse_tree_blocks(eb, tree_root, 1);
> -}
> -
> -int pin_metadata_blocks(void)
> +int btrfs_mark_used_tree_blocks(struct btrfs_fs_info *fs_info,
> + struct extent_io_tree *tree)
> {
> int ret;
>
> - ret = pin_down_tree_blocks(gfs_info->chunk_root->node, 0);
> - if (ret)
> - return ret;
> -
> - return pin_down_tree_blocks(gfs_info->tree_root->node, 1);
> + 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;
> }
>
> -static int exclude_tree_blocks(struct extent_buffer *eb, int tree_root)
> +int pin_metadata_blocks(void)
> {
> - return traverse_tree_blocks(eb, tree_root, 0);
> + return btrfs_mark_used_tree_blocks(gfs_info,
> + &gfs_info->pinned_extents);
> }
>
> int exclude_metadata_blocks(void)
> {
> - int ret;
> struct extent_io_tree *excluded_extents;
>
> excluded_extents = malloc(sizeof(*excluded_extents));
> @@ -724,10 +720,7 @@ int exclude_metadata_blocks(void)
> extent_io_tree_init(excluded_extents);
> gfs_info->excluded_extents = excluded_extents;
>
> - ret = exclude_tree_blocks(gfs_info->chunk_root->node, 0);
> - if (ret)
> - return ret;
> - return exclude_tree_blocks(gfs_info->tree_root->node, 1);
> + return btrfs_mark_used_tree_blocks(gfs_info, excluded_extents);
> }
>
> void cleanup_excluded_extents(void)
>
next prev parent reply other threads:[~2021-11-06 0:37 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 [this message]
2021-11-05 20:28 ` [PATCH 11/20] btrfs-progs: check: move btrfs_mark_used_tree_blocks to common Josef Bacik
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=12fb0839-eef0-ce6d-db1c-ae747414cde2@gmx.com \
--to=quwenruo.btrfs@gmx.com \
--cc=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