From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Josef Bacik <josef@toxicpanda.com>,
linux-btrfs@vger.kernel.org, kernel-team@fb.com
Subject: Re: [PATCH 5/9] btrfs-progs: add helper for writing empty tree nodes
Date: Mon, 23 Aug 2021 16:49:50 +0800 [thread overview]
Message-ID: <ac653ba4-5253-436e-b408-706dcfff7815@gmx.com> (raw)
In-Reply-To: <6692ad0e7a65488ba64f42dce542982d4b7e2047.1629486429.git.josef@toxicpanda.com>
On 2021/8/21 上午3:11, Josef Bacik wrote:
> With extent tree v2 we're going to be writing some more empty trees for
> the initial mkfs step, so take this common code and make it a helper.
>
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Just a small nitpick on the function naming inliend below.
> ---
> mkfs/common.c | 47 +++++++++++++++++++++++++----------------------
> 1 file changed, 25 insertions(+), 22 deletions(-)
>
> diff --git a/mkfs/common.c b/mkfs/common.c
> index 29fc8f12..9263965e 100644
> --- a/mkfs/common.c
> +++ b/mkfs/common.c
> @@ -39,6 +39,25 @@ static u64 reference_root_table[] = {
> [MKFS_CSUM_TREE] = BTRFS_CSUM_TREE_OBJECTID,
> };
>
> +static int btrfs_write_empty_tree(int fd, struct btrfs_mkfs_config *cfg,
> + struct extent_buffer *buf, u64 objectid,
> + u64 block)
Can't we replace the btrfs prefix?
This function is specific to mkfs, and it only works for the initial
btrfs creation.
Thanks,
Qu
> +{
> + int ret;
> +
> + memset(buf->data + sizeof(struct btrfs_header), 0,
> + cfg->nodesize - sizeof(struct btrfs_header));
> + btrfs_set_header_bytenr(buf, block);
> + btrfs_set_header_owner(buf, objectid);
> + btrfs_set_header_nritems(buf, 0);
> + csum_tree_block_size(buf, btrfs_csum_type_size(cfg->csum_type), 0,
> + cfg->csum_type);
> + ret = pwrite(fd, buf->data, cfg->nodesize, block);
> + if (ret != cfg->nodesize)
> + return ret < 0 ? -errno : -EIO;
> + return 0;
> +}
> +
> static int btrfs_create_tree_root(int fd, struct btrfs_mkfs_config *cfg,
> struct extent_buffer *buf,
> const enum btrfs_mkfs_block *blocks,
> @@ -460,31 +479,15 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)
> }
>
> /* create the FS root */
> - memset(buf->data + sizeof(struct btrfs_header), 0,
> - cfg->nodesize - sizeof(struct btrfs_header));
> - btrfs_set_header_bytenr(buf, cfg->blocks[MKFS_FS_TREE]);
> - btrfs_set_header_owner(buf, BTRFS_FS_TREE_OBJECTID);
> - btrfs_set_header_nritems(buf, 0);
> - csum_tree_block_size(buf, btrfs_csum_type_size(cfg->csum_type), 0,
> - cfg->csum_type);
> - ret = pwrite(fd, buf->data, cfg->nodesize, cfg->blocks[MKFS_FS_TREE]);
> - if (ret != cfg->nodesize) {
> - ret = (ret < 0 ? -errno : -EIO);
> + ret = btrfs_write_empty_tree(fd, cfg, buf, BTRFS_FS_TREE_OBJECTID,
> + cfg->blocks[MKFS_FS_TREE]);
> + if (ret)
> goto out;
> - }
> /* finally create the csum root */
> - memset(buf->data + sizeof(struct btrfs_header), 0,
> - cfg->nodesize - sizeof(struct btrfs_header));
> - btrfs_set_header_bytenr(buf, cfg->blocks[MKFS_CSUM_TREE]);
> - btrfs_set_header_owner(buf, BTRFS_CSUM_TREE_OBJECTID);
> - btrfs_set_header_nritems(buf, 0);
> - csum_tree_block_size(buf, btrfs_csum_type_size(cfg->csum_type), 0,
> - cfg->csum_type);
> - ret = pwrite(fd, buf->data, cfg->nodesize, cfg->blocks[MKFS_CSUM_TREE]);
> - if (ret != cfg->nodesize) {
> - ret = (ret < 0 ? -errno : -EIO);
> + ret = btrfs_write_empty_tree(fd, cfg, buf, BTRFS_CSUM_TREE_OBJECTID,
> + cfg->blocks[MKFS_CSUM_TREE]);
> + if (ret)
> goto out;
> - }
>
> /* and write out the super block */
> memset(buf->data, 0, BTRFS_SUPER_INFO_SIZE);
>
next prev parent reply other threads:[~2021-08-23 8:50 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-20 19:11 [PATCH 0/9] btrfs-progs: mkfs fixes and enhancements for extent tree v2 Josef Bacik
2021-08-20 19:11 ` [PATCH 1/9] btrfs-progs: use an associative array for init mkfs blocks Josef Bacik
2021-08-23 8:42 ` Qu Wenruo
2021-08-23 16:10 ` David Sterba
2021-10-09 6:34 ` Wang Yugui
2021-10-11 10:19 ` David Sterba
2021-08-20 19:11 ` [PATCH 2/9] btrfs-progs: use blocks_nr to determine the super used bytes Josef Bacik
2021-08-23 8:43 ` Qu Wenruo
2021-08-20 19:11 ` [PATCH 3/9] btrfs-progs: allocate blocks from the start of the temp system chunk Josef Bacik
2021-08-23 8:45 ` Qu Wenruo
2021-08-20 19:11 ` [PATCH 4/9] btrfs-progs: set nritems based on root items written Josef Bacik
2021-08-23 8:46 ` Qu Wenruo
2021-08-20 19:11 ` [PATCH 5/9] btrfs-progs: add helper for writing empty tree nodes Josef Bacik
2021-08-23 8:49 ` Qu Wenruo [this message]
2021-08-20 19:11 ` [PATCH 6/9] btrfs-progs: add the block group item in make_btrfs() Josef Bacik
2021-08-23 9:00 ` Qu Wenruo
2021-08-23 20:04 ` Josef Bacik
2021-08-23 23:37 ` Qu Wenruo
2021-08-23 23:47 ` Josef Bacik
2021-08-24 0:01 ` Qu Wenruo
2021-08-20 19:11 ` [PATCH 7/9] btrfs-progs: add add_block_group_free_space helper Josef Bacik
2021-08-20 19:11 ` [PATCH 8/9] btrfs-progs: generate free space tree at make_btrfs() time Josef Bacik
2021-08-20 19:11 ` [PATCH 9/9] btrfs-progs: add the incompat flag for extent tree v2 Josef Bacik
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=ac653ba4-5253-436e-b408-706dcfff7815@gmx.com \
--to=quwenruo.btrfs@gmx.com \
--cc=josef@toxicpanda.com \
--cc=kernel-team@fb.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;
as well as URLs for NNTP newsgroup(s).