From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH RFC 07/10] btrfs-progs: mkfs/sprout: introduce helper to force allocating a chunk
Date: Wed, 20 Apr 2022 08:19:56 +0800 [thread overview]
Message-ID: <81ddaed32542e58aaa9c338e91438cf2926add19.1650413308.git.wqu@suse.com> (raw)
In-Reply-To: <cover.1650413308.git.wqu@suse.com>
The new helper, sprout_alloc_one_chunk(), will force allocating a chunk,
mostly using the profile from the seed device.
With the delayed chunk allocation, we really only need to grab the
target profile, and call btrfs_alloc_chunk() followed by
btrfs_make_block_group().
For mixed block group, we need btrfs_space_info to determine if a
profile needs extra types, so here we expoert btrfs_find_space_info().
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
kernel-shared/ctree.h | 2 ++
kernel-shared/extent-tree.c | 16 ++++++++--------
mkfs/sprout.c | 38 +++++++++++++++++++++++++++++++++++++
3 files changed, 48 insertions(+), 8 deletions(-)
diff --git a/kernel-shared/ctree.h b/kernel-shared/ctree.h
index 68943ff294cc..99ed81a9790a 100644
--- a/kernel-shared/ctree.h
+++ b/kernel-shared/ctree.h
@@ -2614,6 +2614,8 @@ u64 btrfs_name_hash(const char *name, int len);
u64 btrfs_extref_hash(u64 parent_objectid, const char *name, int len);
/* extent-tree.c */
+struct btrfs_space_info *btrfs_find_space_info(struct btrfs_fs_info *info,
+ u64 flags);
int btrfs_reserve_extent(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
u64 num_bytes, u64 empty_size,
diff --git a/kernel-shared/extent-tree.c b/kernel-shared/extent-tree.c
index da801b1d9926..63ace7cea681 100644
--- a/kernel-shared/extent-tree.c
+++ b/kernel-shared/extent-tree.c
@@ -1592,8 +1592,8 @@ int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans)
return ret;
}
-static struct btrfs_space_info *__find_space_info(struct btrfs_fs_info *info,
- u64 flags)
+struct btrfs_space_info *btrfs_find_space_info(struct btrfs_fs_info *info,
+ u64 flags)
{
struct btrfs_space_info *found;
@@ -1617,7 +1617,7 @@ static int free_space_info(struct btrfs_fs_info *fs_info, u64 flags,
if (bytes_used)
return -ENOTEMPTY;
- found = __find_space_info(fs_info, flags);
+ found = btrfs_find_space_info(fs_info, flags);
if (!found)
return -ENOENT;
if (found->total_bytes < total_bytes) {
@@ -1638,7 +1638,7 @@ int update_space_info(struct btrfs_fs_info *info, u64 flags,
{
struct btrfs_space_info *found;
- found = __find_space_info(info, flags);
+ found = btrfs_find_space_info(info, flags);
if (found) {
found->total_bytes += total_bytes;
found->bytes_used += bytes_used;
@@ -1694,7 +1694,7 @@ static int do_chunk_alloc(struct btrfs_trans_handle *trans,
u64 num_bytes;
int ret;
- space_info = __find_space_info(fs_info, flags);
+ space_info = btrfs_find_space_info(fs_info, flags);
if (!space_info) {
ret = update_space_info(fs_info, flags, 0, 0, &space_info);
BUG_ON(ret);
@@ -2381,7 +2381,7 @@ static int alloc_reserved_tree_block(struct btrfs_trans_handle *trans,
u64 start, end;
int ret;
- sinfo = __find_space_info(fs_info, BTRFS_BLOCK_GROUP_METADATA);
+ sinfo = btrfs_find_space_info(fs_info, BTRFS_BLOCK_GROUP_METADATA);
ASSERT(sinfo);
ins.objectid = node->bytenr;
@@ -2478,7 +2478,7 @@ static int alloc_tree_block(struct btrfs_trans_handle *trans,
if (!extent_op)
return -ENOMEM;
- sinfo = __find_space_info(fs_info, BTRFS_BLOCK_GROUP_METADATA);
+ sinfo = btrfs_find_space_info(fs_info, BTRFS_BLOCK_GROUP_METADATA);
if (!sinfo) {
error("Corrupted fs, no valid METADATA block group found");
return -EUCLEAN;
@@ -3657,7 +3657,7 @@ int cleanup_ref_head(struct btrfs_trans_handle *trans,
if (!head->is_data) {
struct btrfs_space_info *sinfo;
- sinfo = __find_space_info(trans->fs_info,
+ sinfo = btrfs_find_space_info(trans->fs_info,
BTRFS_BLOCK_GROUP_METADATA);
ASSERT(sinfo);
sinfo->bytes_reserved -= head->num_bytes;
diff --git a/mkfs/sprout.c b/mkfs/sprout.c
index 5977a73644f5..66119bbe975f 100644
--- a/mkfs/sprout.c
+++ b/mkfs/sprout.c
@@ -149,3 +149,41 @@ static int update_seed_dev_geneartion(struct btrfs_trans_handle *trans)
return ret;
}
+static int sprout_alloc_one_chunk(struct btrfs_trans_handle *trans, u64 type)
+{
+ struct btrfs_fs_info *fs_info = trans->fs_info;
+ struct btrfs_space_info *space_info;
+ u64 chunk_start;
+ u64 chunk_size;
+ u64 chunk_flags;
+ int ret;
+
+ space_info = btrfs_find_space_info(fs_info, type);
+ if (!space_info)
+ return -ENOENT;
+
+ if (type & BTRFS_BLOCK_GROUP_METADATA)
+ chunk_flags = fs_info->avail_metadata_alloc_bits &
+ fs_info->metadata_alloc_profile;
+ if (type & BTRFS_BLOCK_GROUP_SYSTEM)
+ chunk_flags = fs_info->avail_system_alloc_bits &
+ fs_info->system_alloc_profile;
+ if (type & BTRFS_BLOCK_GROUP_DATA)
+ chunk_flags = fs_info->avail_data_alloc_bits &
+ fs_info->data_alloc_profile;
+ /* This is for mixed profile */
+ chunk_flags |= space_info->flags;
+
+ ret = btrfs_alloc_chunk(trans, fs_info, &chunk_start, &chunk_size,
+ chunk_flags);
+ if (ret < 0)
+ goto error;
+ ret = btrfs_make_block_group(trans, fs_info, 0, chunk_flags,
+ chunk_start, chunk_size);
+ if (ret < 0)
+ goto error;
+ return ret;
+error:
+ btrfs_abort_transaction(trans, ret);
+ return ret;
+}
--
2.35.1
next prev parent reply other threads:[~2022-04-20 0:20 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-20 0:19 [PATCH RFC 00/10] btrfs-progs: mkfs: add --seed option to sprout a seed device at mkfs time Qu Wenruo
2022-04-20 0:19 ` [PATCH RFC 01/10] btrfs-progs: refactor find_free_dev_extent_start() for later expansion Qu Wenruo
2022-04-20 0:19 ` [PATCH RFC 02/10] btrfs-progs: delay chunk and device extent items insertion Qu Wenruo
2022-04-20 0:19 ` [PATCH RFC 03/10] btrfs-progs: mkfs: introduce helper to set seed flag Qu Wenruo
2022-04-20 0:19 ` [PATCH RFC 04/10] btrfs-progs: mkfs: avoid error out if some trees exist Qu Wenruo
2022-04-20 0:19 ` [PATCH RFC 05/10] btrfs-progs: extract btrfs_fs_devices structure allocation into a helper Qu Wenruo
2022-04-20 0:19 ` [PATCH RFC 06/10] btrfs-progs: mkfs/sprout: add a helper to update generation for seed device Qu Wenruo
2022-04-20 0:19 ` Qu Wenruo [this message]
2022-04-20 0:19 ` [PATCH RFC 08/10] btrfs-progs: mkfs/sprout: introduce a helper to relocate system chunks Qu Wenruo
2022-04-20 0:19 ` [PATCH RFC 09/10] btrfs-progs: mkfs/sprout: introduce a helper to remove empty system chunks from seed device Qu Wenruo
2022-04-20 0:19 ` [PATCH RFC 10/10] btrfs-progs: mkfs: add support for seed sprout 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=81ddaed32542e58aaa9c338e91438cf2926add19.1650413308.git.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