Thread (17 messages) 17 messages, 5 authors, 2021-10-11
STALE1716d

[PATCH v2 02/10] btrfs-progs: mkfs: get rid of MKFS_SUPER_BLOCK

From: Josef Bacik <josef@toxicpanda.com>
Date: 2021-08-23 20:15:02
Subsystem: the rest · Maintainer: Linus Torvalds

We use these block's in order to keep track of which blocks need to be
added to the extent tree and where their roots need to be written.
However we skip MKFS_SUPER_BLOCK for all of these helpers, and we don't
actually need to keep track of the specific block we allocated because
it is always BTRFS_SUPER_INFO_OFFSET.  Remove this enum as we don't need
it.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 mkfs/common.c | 17 ++++++-----------
 mkfs/common.h |  2 --
 2 files changed, 6 insertions(+), 13 deletions(-)
diff --git a/mkfs/common.c b/mkfs/common.c
index 35ee4bff..ee9ad390 100644
--- a/mkfs/common.c
+++ b/mkfs/common.c
@@ -76,8 +76,7 @@ static int btrfs_create_tree_root(int fd, struct btrfs_mkfs_config *cfg,
 
 	for (i = 0; i < blocks_nr; i++) {
 		blk = blocks[i];
-		if (blk == MKFS_SUPER_BLOCK || blk == MKFS_ROOT_TREE
-		    || blk == MKFS_CHUNK_TREE)
+		if (blk == MKFS_ROOT_TREE || blk == MKFS_CHUNK_TREE)
 			continue;
 
 		btrfs_set_root_bytenr(&root_item, cfg->blocks[blk]);
@@ -201,15 +200,12 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)
 	uuid_generate(super.dev_item.uuid);
 	uuid_generate(chunk_tree_uuid);
 
-	cfg->blocks[MKFS_SUPER_BLOCK] = BTRFS_SUPER_INFO_OFFSET;
 	for (i = 0; i < blocks_nr; i++) {
 		blk = blocks[i];
-		if (blk == MKFS_SUPER_BLOCK)
-			continue;
-		cfg->blocks[i] = system_group_offset + cfg->nodesize * (i - 1);
+		cfg->blocks[blk] = system_group_offset + cfg->nodesize * i;
 	}
 
-	btrfs_set_super_bytenr(&super, cfg->blocks[MKFS_SUPER_BLOCK]);
+	btrfs_set_super_bytenr(&super, BTRFS_SUPER_INFO_OFFSET);
 	btrfs_set_super_num_devices(&super, 1);
 	btrfs_set_super_magic(&super, BTRFS_MAGIC_TEMPORARY);
 	btrfs_set_super_generation(&super, 1);
@@ -257,8 +253,7 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)
 	itemoff = __BTRFS_LEAF_DATA_SIZE(cfg->nodesize);
 	for (i = 0; i < blocks_nr; i++) {
 		blk = blocks[i];
-		if (blk == MKFS_SUPER_BLOCK)
-			continue;
+
 		item_size = sizeof(struct btrfs_extent_item);
 		if (!skinny_metadata)
 			item_size += sizeof(struct btrfs_tree_block_info);
@@ -270,7 +265,7 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)
 			ret = -EINVAL;
 			goto out;
 		}
-		if (cfg->blocks[blk] < cfg->blocks[blocks[i - 1]]) {
+		if (i && cfg->blocks[blk] < cfg->blocks[blocks[i - 1]]) {
 			error("blocks %d and %d in reverse order: %llu < %llu",
 				blk, blocks[i - 1],
 				(unsigned long long)cfg->blocks[blk],
@@ -487,7 +482,7 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)
 	buf->len = BTRFS_SUPER_INFO_SIZE;
 	csum_tree_block_size(buf, btrfs_csum_type_size(cfg->csum_type), 0,
 			     cfg->csum_type);
-	ret = sbwrite(fd, buf->data, cfg->blocks[MKFS_SUPER_BLOCK]);
+	ret = sbwrite(fd, buf->data, BTRFS_SUPER_INFO_OFFSET);
 	if (ret != BTRFS_SUPER_INFO_SIZE) {
 		ret = (ret < 0 ? -errno : -EIO);
 		goto out;
diff --git a/mkfs/common.h b/mkfs/common.h
index 378da6bd..f2d28057 100644
--- a/mkfs/common.h
+++ b/mkfs/common.h
@@ -45,7 +45,6 @@ struct btrfs_root;
  * Tree root blocks created during mkfs
  */
 enum btrfs_mkfs_block {
-	MKFS_SUPER_BLOCK = 0,
 	MKFS_ROOT_TREE,
 	MKFS_EXTENT_TREE,
 	MKFS_CHUNK_TREE,
@@ -56,7 +55,6 @@ enum btrfs_mkfs_block {
 };
 
 static const enum btrfs_mkfs_block extent_tree_v1_blocks[] = {
-	MKFS_SUPER_BLOCK,
 	MKFS_ROOT_TREE,
 	MKFS_EXTENT_TREE,
 	MKFS_CHUNK_TREE,
-- 
2.26.3
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help