linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Josef Bacik <josef@toxicpanda.com>
To: linux-btrfs@vger.kernel.org, kernel-team@fb.com
Cc: Qu Wenruo <wqu@suse.com>
Subject: [PATCH v2 05/10] btrfs-progs: mkfs: add helper for writing empty tree nodes
Date: Mon, 23 Aug 2021 16:14:50 -0400	[thread overview]
Message-ID: <fe2a03b4c09ccc01bace112d68f09b2a372e1dae.1629749291.git.josef@toxicpanda.com> (raw)
In-Reply-To: <cover.1629749291.git.josef@toxicpanda.com>

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.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 mkfs/common.c | 47 +++++++++++++++++++++++++----------------------
 1 file changed, 25 insertions(+), 22 deletions(-)

diff --git a/mkfs/common.c b/mkfs/common.c
index 339c5556..a392a5b0 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)
+{
+	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,
@@ -453,31 +472,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);
-- 
2.26.3


  parent reply	other threads:[~2021-08-23 20:15 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-23 20:14 [PATCH v2 00/10] btrfs-progs: mkfs fixes and prep work for extent tree v2 Josef Bacik
2021-08-23 20:14 ` [PATCH v2 01/10] btrfs-progs: mkfs: use an associative array for init blocks Josef Bacik
2021-08-23 20:14 ` [PATCH v2 02/10] btrfs-progs: mkfs: get rid of MKFS_SUPER_BLOCK Josef Bacik
2021-08-23 20:14 ` [PATCH v2 03/10] btrfs-progs: mkfs: use blocks_nr to determine the super used bytes Josef Bacik
2021-08-23 20:14 ` [PATCH v2 04/10] btrfs-progs: mkfs: set nritems based on root items written Josef Bacik
2021-08-23 20:14 ` Josef Bacik [this message]
2021-08-23 20:14 ` [PATCH v2 06/10] btrfs-progs: make sure track_dirty and ref_cows is set properly Josef Bacik
2021-08-23 20:14 ` [PATCH v2 07/10] btrfs-progs: mkfs: add the block group item in make_btrfs() Josef Bacik
2021-08-23 20:14 ` [PATCH v2 08/10] btrfs-progs: add add_block_group_free_space helper Josef Bacik
2021-08-23 20:14 ` [PATCH v2 09/10] btrfs-progs: mkfs: generate free space tree at make_btrfs() time Josef Bacik
2021-10-11  1:24   ` Qu Wenruo
2021-08-23 20:14 ` [PATCH v2 10/10] btrfs-progs: add the incompat flag for extent tree v2 Josef Bacik
2021-08-25 13:58 ` [PATCH v2 00/10] btrfs-progs: mkfs fixes and prep work " David Sterba
2021-09-03 13:53   ` David Sterba
2021-10-11 18:35   ` Goffredo Baroncelli
2021-10-11 18:47     ` David Sterba
2021-10-11 19:39       ` Goffredo Baroncelli

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=fe2a03b4c09ccc01bace112d68f09b2a372e1dae.1629749291.git.josef@toxicpanda.com \
    --to=josef@toxicpanda.com \
    --cc=kernel-team@fb.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=wqu@suse.com \
    /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).