From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH RFC 09/10] btrfs-progs: mkfs/sprout: introduce a helper to remove empty system chunks from seed device
Date: Wed, 20 Apr 2022 08:19:58 +0800 [thread overview]
Message-ID: <0bfae2b54049cb076c1443fd58ec065a9e84c1f2.1650413308.git.wqu@suse.com> (raw)
In-Reply-To: <cover.1650413308.git.wqu@suse.com>
Even if an empty system chunk is still in sys_chunk_array, kernel will
reject the mount.
So here we introduce the helper to do the removal, by iterating through
all block groups, and remove the block group if it's a system chunk and
contains stripe which points to the seed device.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
mkfs/sprout.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
diff --git a/mkfs/sprout.c b/mkfs/sprout.c
index 38d80d789084..049098872d3e 100644
--- a/mkfs/sprout.c
+++ b/mkfs/sprout.c
@@ -241,3 +241,56 @@ static int sprout_relocate_chunk_tree(struct btrfs_trans_handle *trans)
btrfs_release_path(&path);
return ret;
}
+
+static int sprout_remove_seed_sys_chunk(struct btrfs_trans_handle *trans)
+{
+ struct btrfs_fs_info *fs_info = trans->fs_info;
+ struct btrfs_block_group *bg;
+ struct btrfs_device *seed_dev;
+ int ret;
+
+ /* We should have exacly one seed device */
+ ASSERT(fs_info->fs_devices->seed);
+ ASSERT(fs_info->fs_devices->seed->devices.next ==
+ fs_info->fs_devices->seed->devices.prev);
+ seed_dev = list_entry(fs_info->fs_devices->seed->devices.next,
+ struct btrfs_device, dev_list);
+ bg = btrfs_lookup_first_block_group(fs_info, 0);
+ while (bg) {
+ const u64 cur = bg->start + bg->length;
+
+ struct cache_extent *ce;
+ struct map_lookup *map;
+ bool delete = false;
+ int i;
+
+ if (!(bg->flags & BTRFS_BLOCK_GROUP_SYSTEM))
+ goto next;
+
+ ce = search_cache_extent(&fs_info->mapping_tree.cache_tree,
+ bg->start);
+ if (!ce) {
+ /* No chunk map for an bg, a big problem */
+ error("no chunk map for block group at %llu", bg->start);
+ return -EUCLEAN;
+ }
+ map = container_of(ce, struct map_lookup, ce);
+
+ for (i = 0; i < map->num_stripes; i++) {
+ if (map->stripes[i].dev == seed_dev) {
+ delete = true;
+ break;
+ }
+ }
+ if (!delete)
+ goto next;
+
+ ret = btrfs_remove_block_group(trans, bg->start, bg->length);
+ if (ret < 0)
+ return ret;
+next:
+ /* Has to using @cur, as the current bg may has been deleted */
+ bg = btrfs_lookup_first_block_group(fs_info, cur);
+ }
+ return 0;
+}
--
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 ` [PATCH RFC 07/10] btrfs-progs: mkfs/sprout: introduce helper to force allocating a chunk Qu Wenruo
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 ` Qu Wenruo [this message]
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=0bfae2b54049cb076c1443fd58ec065a9e84c1f2.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