Introudce new function, setup_temp_fs_tree(), to setup temporary fs tree
for make_btrfs_v2().

Signed-off-by: Qu Wenruo <quwen...@cn.fujitsu.com>
---
 utils.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/utils.c b/utils.c
index 3be484a..edd8ac1 100644
--- a/utils.c
+++ b/utils.c
@@ -840,6 +840,28 @@ out:
        return ret;
 }
 
+static int setup_temp_fs_tree(int fd, struct btrfs_mkfs_config *cfg,
+                             u64 fs_bytenr)
+{
+       struct extent_buffer *buf = NULL;
+       int ret;
+
+       buf = malloc(sizeof(*buf) + cfg->nodesize);
+       if (!buf)
+               return -ENOMEM;
+       ret = setup_temp_extent_buffer(buf, cfg, fs_bytenr,
+                                      BTRFS_FS_TREE_OBJECTID);
+       if (ret < 0)
+               goto out;
+       /*
+        * Temporary fs tree is completely empty.
+        */
+       ret = write_temp_extent_buffer(fd, buf, fs_bytenr);
+out:
+       free(buf);
+       return ret;
+}
+
 /*
  * Improved version of make_btrfs().
  *
@@ -934,6 +956,10 @@ static int make_btrfs_v2(int fd, struct btrfs_mkfs_config 
*cfg)
                goto out;
        ret = setup_temp_dev_tree(fd, cfg, sys_chunk_start, meta_chunk_start,
                                  dev_bytenr);
+       if (ret < 0)
+               goto out;
+       ret = setup_temp_fs_tree(fd, cfg, fs_bytenr);
+
 out:
        free(free_tree);
        return ret;
-- 
2.6.2

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to