diff mbox series

[2/9] btrfs-progs: use blocks_nr to determine the super used bytes

Message ID 1d73b314e14e03f4fe7a70475822f534fd5914e4.1629486429.git.josef@toxicpanda.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: mkfs fixes and enhancements for extent tree v2 | expand

Commit Message

Josef Bacik Aug. 20, 2021, 7:11 p.m. UTC
We were setting the superblock's used bytes to a static number.  However
the number of blocks we have to write has the correct used size, so just
add up the total number of blocks we're allocating as we determine their
offsets.  This value will be used later which is why I'm calculating it
this way instead of doing the math to set the bytes_super specifically.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 mkfs/common.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Qu Wenruo Aug. 23, 2021, 8:43 a.m. UTC | #1
On 2021/8/21 上午3:11, Josef Bacik wrote:
> We were setting the superblock's used bytes to a static number.  However
> the number of blocks we have to write has the correct used size, so just
> add up the total number of blocks we're allocating as we determine their
> offsets.  This value will be used later which is why I'm calculating it
> this way instead of doing the math to set the bytes_super specifically.
>
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Getting rid of an hardcoded immediate number is always a good thing.

Thanks,
Qu
> ---
>   mkfs/common.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/mkfs/common.c b/mkfs/common.c
> index e9ff529a..8902d39e 100644
> --- a/mkfs/common.c
> +++ b/mkfs/common.c
> @@ -162,6 +162,7 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)
>   	u64 ref_root;
>   	u32 array_size;
>   	u32 item_size;
> +	u64 total_used = 0;
>   	int skinny_metadata = !!(cfg->features &
>   				 BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA);
>   	u64 num_bytes;
> @@ -207,6 +208,7 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)
>   		if (blk == MKFS_SUPER_BLOCK)
>   			continue;
>   		cfg->blocks[blk] = system_group_offset + cfg->nodesize * i;
> +		total_used += cfg->nodesize;
>   	}
>
>   	btrfs_set_super_bytenr(&super, cfg->blocks[MKFS_SUPER_BLOCK]);
> @@ -216,7 +218,7 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)
>   	btrfs_set_super_root(&super, cfg->blocks[MKFS_ROOT_TREE]);
>   	btrfs_set_super_chunk_root(&super, cfg->blocks[MKFS_CHUNK_TREE]);
>   	btrfs_set_super_total_bytes(&super, num_bytes);
> -	btrfs_set_super_bytes_used(&super, 6 * cfg->nodesize);
> +	btrfs_set_super_bytes_used(&super, total_used);
>   	btrfs_set_super_sectorsize(&super, cfg->sectorsize);
>   	super.__unused_leafsize = cpu_to_le32(cfg->nodesize);
>   	btrfs_set_super_nodesize(&super, cfg->nodesize);
>
diff mbox series

Patch

diff --git a/mkfs/common.c b/mkfs/common.c
index e9ff529a..8902d39e 100644
--- a/mkfs/common.c
+++ b/mkfs/common.c
@@ -162,6 +162,7 @@  int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)
 	u64 ref_root;
 	u32 array_size;
 	u32 item_size;
+	u64 total_used = 0;
 	int skinny_metadata = !!(cfg->features &
 				 BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA);
 	u64 num_bytes;
@@ -207,6 +208,7 @@  int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)
 		if (blk == MKFS_SUPER_BLOCK)
 			continue;
 		cfg->blocks[blk] = system_group_offset + cfg->nodesize * i;
+		total_used += cfg->nodesize;
 	}
 
 	btrfs_set_super_bytenr(&super, cfg->blocks[MKFS_SUPER_BLOCK]);
@@ -216,7 +218,7 @@  int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)
 	btrfs_set_super_root(&super, cfg->blocks[MKFS_ROOT_TREE]);
 	btrfs_set_super_chunk_root(&super, cfg->blocks[MKFS_CHUNK_TREE]);
 	btrfs_set_super_total_bytes(&super, num_bytes);
-	btrfs_set_super_bytes_used(&super, 6 * cfg->nodesize);
+	btrfs_set_super_bytes_used(&super, total_used);
 	btrfs_set_super_sectorsize(&super, cfg->sectorsize);
 	super.__unused_leafsize = cpu_to_le32(cfg->nodesize);
 	btrfs_set_super_nodesize(&super, cfg->nodesize);