Message ID | 2677d6c2568dcdc4eef9ef89e6d0a8d0a45960a8.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 |
On 2021/8/21 上午3:11, Josef Bacik wrote: > During mkfs we skip allocating a block for the super block, however > because we're using the blocks array iterator to determine the offset of > our block we're leaving a hole at the beginning of the temporary chunk. > This isn't a problem per-se, but I'm going to start generating the free > space tree at make_btrfs() time and having this hole makes the free > space tree creation slightly more complicated. > > Instead keep track of which block we're on so that we start from the > actual offset of the system chunk. Can't we just get rid the extra block for superblock? As the superblock is always located at a fixed location, we don't really need to put it into the blocks[] array. Thanks, Qu > > Signed-off-by: Josef Bacik <josef@toxicpanda.com> > --- > mkfs/common.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/mkfs/common.c b/mkfs/common.c > index 8902d39e..0e747301 100644 > --- a/mkfs/common.c > +++ b/mkfs/common.c > @@ -153,6 +153,7 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg) > u8 chunk_tree_uuid[BTRFS_UUID_SIZE]; > u8 *ptr; > int i; > + int cnt; > int ret; > int blocks_nr = ARRAY_SIZE(extent_tree_v1_blocks); > int blk; > @@ -203,11 +204,11 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg) > uuid_generate(chunk_tree_uuid); > > cfg->blocks[MKFS_SUPER_BLOCK] = BTRFS_SUPER_INFO_OFFSET; > - for (i = 0; i < blocks_nr; i++) { > + for (cnt = 0, i = 0; i < blocks_nr; i++) { > blk = blocks[i]; > if (blk == MKFS_SUPER_BLOCK) > continue; > - cfg->blocks[blk] = system_group_offset + cfg->nodesize * i; > + cfg->blocks[blk] = system_group_offset + cfg->nodesize * cnt++; > total_used += cfg->nodesize; > } > >
diff --git a/mkfs/common.c b/mkfs/common.c index 8902d39e..0e747301 100644 --- a/mkfs/common.c +++ b/mkfs/common.c @@ -153,6 +153,7 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg) u8 chunk_tree_uuid[BTRFS_UUID_SIZE]; u8 *ptr; int i; + int cnt; int ret; int blocks_nr = ARRAY_SIZE(extent_tree_v1_blocks); int blk; @@ -203,11 +204,11 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg) uuid_generate(chunk_tree_uuid); cfg->blocks[MKFS_SUPER_BLOCK] = BTRFS_SUPER_INFO_OFFSET; - for (i = 0; i < blocks_nr; i++) { + for (cnt = 0, i = 0; i < blocks_nr; i++) { blk = blocks[i]; if (blk == MKFS_SUPER_BLOCK) continue; - cfg->blocks[blk] = system_group_offset + cfg->nodesize * i; + cfg->blocks[blk] = system_group_offset + cfg->nodesize * cnt++; total_used += cfg->nodesize; }
During mkfs we skip allocating a block for the super block, however because we're using the blocks array iterator to determine the offset of our block we're leaving a hole at the beginning of the temporary chunk. This isn't a problem per-se, but I'm going to start generating the free space tree at make_btrfs() time and having this hole makes the free space tree creation slightly more complicated. Instead keep track of which block we're on so that we start from the actual offset of the system chunk. Signed-off-by: Josef Bacik <josef@toxicpanda.com> --- mkfs/common.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)