linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Josef Bacik <josef@toxicpanda.com>
To: linux-btrfs@vger.kernel.org, kernel-team@fb.com
Subject: [PATCH v2 08/10] btrfs-progs: add add_block_group_free_space helper
Date: Mon, 23 Aug 2021 16:14:53 -0400	[thread overview]
Message-ID: <2baa0ddabfc39080848872a7ad4841482ef985e5.1629749291.git.josef@toxicpanda.com> (raw)
In-Reply-To: <cover.1629749291.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 7f589dfe..1e127e31 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


  parent reply	other threads:[~2021-08-23 20:15 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-23 20:14 [PATCH v2 00/10] btrfs-progs: mkfs fixes and prep work for extent tree v2 Josef Bacik
2021-08-23 20:14 ` [PATCH v2 01/10] btrfs-progs: mkfs: use an associative array for init blocks Josef Bacik
2021-08-23 20:14 ` [PATCH v2 02/10] btrfs-progs: mkfs: get rid of MKFS_SUPER_BLOCK Josef Bacik
2021-08-23 20:14 ` [PATCH v2 03/10] btrfs-progs: mkfs: use blocks_nr to determine the super used bytes Josef Bacik
2021-08-23 20:14 ` [PATCH v2 04/10] btrfs-progs: mkfs: set nritems based on root items written Josef Bacik
2021-08-23 20:14 ` [PATCH v2 05/10] btrfs-progs: mkfs: add helper for writing empty tree nodes Josef Bacik
2021-08-23 20:14 ` [PATCH v2 06/10] btrfs-progs: make sure track_dirty and ref_cows is set properly Josef Bacik
2021-08-23 20:14 ` [PATCH v2 07/10] btrfs-progs: mkfs: add the block group item in make_btrfs() Josef Bacik
2021-08-23 20:14 ` Josef Bacik [this message]
2021-08-23 20:14 ` [PATCH v2 09/10] btrfs-progs: mkfs: generate free space tree at make_btrfs() time Josef Bacik
2021-10-11  1:24   ` Qu Wenruo
2021-08-23 20:14 ` [PATCH v2 10/10] btrfs-progs: add the incompat flag for extent tree v2 Josef Bacik
2021-08-25 13:58 ` [PATCH v2 00/10] btrfs-progs: mkfs fixes and prep work " David Sterba
2021-09-03 13:53   ` David Sterba
2021-10-11 18:35   ` Goffredo Baroncelli
2021-10-11 18:47     ` David Sterba
2021-10-11 19:39       ` Goffredo Baroncelli

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=2baa0ddabfc39080848872a7ad4841482ef985e5.1629749291.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).