From: Josef Bacik <josef@toxicpanda.com>
To: linux-btrfs@vger.kernel.org, kernel-team@fb.com
Subject: [PATCH v4 17/22] btrfs-progs: add a btrfs_delete_and_free_root helper
Date: Wed, 15 Dec 2021 14:59:43 -0500 [thread overview]
Message-ID: <d42290ff6cd2e211c492b663e7f0f3a5c97f7f16.1639598278.git.josef@toxicpanda.com> (raw)
In-Reply-To: <cover.1639598278.git.josef@toxicpanda.com>
The free space tree code already does this, but we need it for cleaning
up per block group roots. Abstract this code out into a helper so that
we can use it in multiple places in the future.
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
kernel-shared/disk-io.c | 25 +++++++++++++++++++++++++
kernel-shared/disk-io.h | 2 ++
kernel-shared/free-space-tree.c | 24 +++---------------------
3 files changed, 30 insertions(+), 21 deletions(-)
diff --git a/kernel-shared/disk-io.c b/kernel-shared/disk-io.c
index 38118e1d..83977cec 100644
--- a/kernel-shared/disk-io.c
+++ b/kernel-shared/disk-io.c
@@ -2368,6 +2368,31 @@ int btrfs_set_buffer_uptodate(struct extent_buffer *eb)
return set_extent_buffer_uptodate(eb);
}
+int btrfs_delete_and_free_root(struct btrfs_trans_handle *trans,
+ struct btrfs_root *root)
+{
+ struct btrfs_fs_info *fs_info = root->fs_info;
+ struct btrfs_root *tree_root = fs_info->tree_root;
+ int ret;
+
+ ret = btrfs_del_root(trans, tree_root, &root->root_key);
+ if (ret)
+ return ret;
+
+ list_del(&root->dirty_list);
+ ret = clean_tree_block(root->node);
+ if (ret)
+ return ret;
+ ret = btrfs_free_tree_block(trans, root, root->node, 0, 1);
+ if (ret)
+ return ret;
+ rb_erase(&root->rb_node, &fs_info->global_roots_tree);
+ free_extent_buffer(root->node);
+ free_extent_buffer(root->commit_root);
+ kfree(root);
+ return 0;
+}
+
struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,
struct btrfs_fs_info *fs_info,
u64 objectid)
diff --git a/kernel-shared/disk-io.h b/kernel-shared/disk-io.h
index 4f58cad1..6a64b620 100644
--- a/kernel-shared/disk-io.h
+++ b/kernel-shared/disk-io.h
@@ -214,6 +214,8 @@ int btrfs_fs_roots_compare_roots(struct rb_node *node1, struct rb_node *node2);
struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,
struct btrfs_fs_info *fs_info,
u64 objectid);
+int btrfs_delete_and_free_root(struct btrfs_trans_handle *trans,
+ struct btrfs_root *root);
struct btrfs_root *btrfs_csum_root(struct btrfs_fs_info *fs_info, u64 bytenr);
struct btrfs_root *btrfs_extent_root(struct btrfs_fs_info *fs_inf, u64 bytenr);
struct btrfs_root *btrfs_global_root(struct btrfs_fs_info *fs_info,
diff --git a/kernel-shared/free-space-tree.c b/kernel-shared/free-space-tree.c
index a82865d3..0a13b1d6 100644
--- a/kernel-shared/free-space-tree.c
+++ b/kernel-shared/free-space-tree.c
@@ -1257,27 +1257,9 @@ int btrfs_clear_free_space_tree(struct btrfs_fs_info *fs_info)
if (ret)
goto abort;
- ret = btrfs_del_root(trans, tree_root, &free_space_root->root_key);
- if (ret)
- goto abort;
-
- list_del(&free_space_root->dirty_list);
-
- ret = clean_tree_block(free_space_root->node);
- if (ret)
- goto abort;
- ret = btrfs_free_tree_block(trans, free_space_root,
- free_space_root->node, 0, 1);
- if (ret)
- goto abort;
-
- rb_erase(&free_space_root->rb_node, &fs_info->global_roots_tree);
- free_extent_buffer(free_space_root->node);
- free_extent_buffer(free_space_root->commit_root);
- kfree(free_space_root);
-
- ret = btrfs_commit_transaction(trans, tree_root);
-
+ ret = btrfs_delete_and_free_root(trans, free_space_root);
+ if (!ret)
+ ret = btrfs_commit_transaction(trans, tree_root);
abort:
return ret;
}
--
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 ` [PATCH v4 12/22] btrfs-progs: check: make free space tree validation extent tree v2 aware Josef Bacik
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 ` Josef Bacik [this message]
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=d42290ff6cd2e211c492b663e7f0f3a5c97f7f16.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).