From: Josef Bacik <josef@toxicpanda.com>
To: linux-btrfs@vger.kernel.org, kernel-team@fb.com
Subject: [PATCH 7/9] btrfs-progs: add add_block_group_free_space helper
Date: Fri, 20 Aug 2021 15:11:55 -0400 [thread overview]
Message-ID: <cdabc5351f55f70e9fe1096b4718c6b700157e6a.1629486429.git.josef@toxicpanda.com> (raw)
In-Reply-To: <cover.1629486429.git.josef@toxicpanda.com>
This exists in the kernel free-space-tree.c but not in progs. We need
it to generate the free space items for new block groups, which is
needed when we start creating the free space tree in make_btrfs().
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
kernel-shared/extent-tree.c | 2 ++
kernel-shared/free-space-tree.c | 26 ++++++++++++++++++++++++++
kernel-shared/free-space-tree.h | 2 ++
3 files changed, 30 insertions(+)
diff --git a/kernel-shared/extent-tree.c b/kernel-shared/extent-tree.c
index 056a9256..b5b43c10 100644
--- a/kernel-shared/extent-tree.c
+++ b/kernel-shared/extent-tree.c
@@ -2816,6 +2816,8 @@ int btrfs_make_block_group(struct btrfs_trans_handle *trans,
ret = btrfs_insert_item(trans, extent_root, &key, &bgi, sizeof(bgi));
BUG_ON(ret);
+ add_block_group_free_space(trans, cache);
+
return 0;
}
diff --git a/kernel-shared/free-space-tree.c b/kernel-shared/free-space-tree.c
index 2edc7fc7..397311c0 100644
--- a/kernel-shared/free-space-tree.c
+++ b/kernel-shared/free-space-tree.c
@@ -986,6 +986,32 @@ out:
return ret;
}
+int add_block_group_free_space(struct btrfs_trans_handle *trans,
+ struct btrfs_block_group *block_group)
+{
+ struct btrfs_path *path;
+ int ret;
+
+ if (!btrfs_fs_compat_ro(trans->fs_info, FREE_SPACE_TREE))
+ return 0;
+
+ path = btrfs_alloc_path();
+ if (!path)
+ return -ENOMEM;
+
+ ret = add_new_free_space_info(trans, block_group, path);
+ if (ret)
+ goto out;
+ ret = __add_to_free_space_tree(trans, block_group, path,
+ block_group->start,
+ block_group->length);
+out:
+ btrfs_free_path(path);
+ if (ret)
+ btrfs_abort_transaction(trans, ret);
+ return ret;
+}
+
int populate_free_space_tree(struct btrfs_trans_handle *trans,
struct btrfs_block_group *block_group)
{
diff --git a/kernel-shared/free-space-tree.h b/kernel-shared/free-space-tree.h
index 3d32e167..4f6aa5fc 100644
--- a/kernel-shared/free-space-tree.h
+++ b/kernel-shared/free-space-tree.h
@@ -34,5 +34,7 @@ int add_to_free_space_tree(struct btrfs_trans_handle *trans, u64 start,
int remove_from_free_space_tree(struct btrfs_trans_handle *trans, u64 start,
u64 size);
int btrfs_create_free_space_tree(struct btrfs_fs_info *info);
+int add_block_group_free_space(struct btrfs_trans_handle *trans,
+ struct btrfs_block_group *block_group);
#endif
--
2.26.3
next prev parent reply other threads:[~2021-08-20 19:12 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-20 19:11 [PATCH 0/9] btrfs-progs: mkfs fixes and enhancements for extent tree v2 Josef Bacik
2021-08-20 19:11 ` [PATCH 1/9] btrfs-progs: use an associative array for init mkfs blocks Josef Bacik
2021-08-23 8:42 ` Qu Wenruo
2021-08-23 16:10 ` David Sterba
2021-10-09 6:34 ` Wang Yugui
2021-10-11 10:19 ` David Sterba
2021-08-20 19:11 ` [PATCH 2/9] btrfs-progs: use blocks_nr to determine the super used bytes Josef Bacik
2021-08-23 8:43 ` Qu Wenruo
2021-08-20 19:11 ` [PATCH 3/9] btrfs-progs: allocate blocks from the start of the temp system chunk Josef Bacik
2021-08-23 8:45 ` Qu Wenruo
2021-08-20 19:11 ` [PATCH 4/9] btrfs-progs: set nritems based on root items written Josef Bacik
2021-08-23 8:46 ` Qu Wenruo
2021-08-20 19:11 ` [PATCH 5/9] btrfs-progs: add helper for writing empty tree nodes Josef Bacik
2021-08-23 8:49 ` Qu Wenruo
2021-08-20 19:11 ` [PATCH 6/9] btrfs-progs: add the block group item in make_btrfs() Josef Bacik
2021-08-23 9:00 ` Qu Wenruo
2021-08-23 20:04 ` Josef Bacik
2021-08-23 23:37 ` Qu Wenruo
2021-08-23 23:47 ` Josef Bacik
2021-08-24 0:01 ` Qu Wenruo
2021-08-20 19:11 ` Josef Bacik [this message]
2021-08-20 19:11 ` [PATCH 8/9] btrfs-progs: generate free space tree at make_btrfs() time Josef Bacik
2021-08-20 19:11 ` [PATCH 9/9] btrfs-progs: add the incompat flag 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=cdabc5351f55f70e9fe1096b4718c6b700157e6a.1629486429.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).