btrfs-progs: Introduce function to initialize csum tree
authorQu Wenruo <quwenruo@cn.fujitsu.com>
Fri, 29 Jan 2016 05:03:20 +0000 (13:03 +0800)
committerDavid Sterba <dsterba@suse.com>
Tue, 7 Jun 2016 16:15:19 +0000 (18:15 +0200)
Introduce new function, setup_temp_csum_tree(), to setup temporary
csum tree for make_btrfs_v2().

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
utils.c

diff --git a/utils.c b/utils.c
index 08ff2f5b23474e91930ae0ab74c1ef484e3b5881..b083b73cff1af46de0cc3be5e9553b6827e99d4e 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -678,6 +678,28 @@ out:
        return ret;
 }
 
+static int setup_temp_csum_tree(int fd, struct btrfs_mkfs_config *cfg,
+                               u64 csum_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, csum_bytenr,
+                                      BTRFS_CSUM_TREE_OBJECTID);
+       if (ret < 0)
+               goto out;
+       /*
+        * Temporary csum tree is completely empty.
+        */
+       ret = write_temp_extent_buffer(fd, buf, csum_bytenr);
+out:
+       free(buf);
+       return ret;
+}
+
 /*
  * Improved version of make_btrfs().
  *
@@ -776,6 +798,9 @@ static int make_convert_btrfs(int fd, struct btrfs_mkfs_config *cfg,
        if (ret < 0)
                goto out;
        ret = setup_temp_fs_tree(fd, cfg, fs_bytenr);
+       if (ret < 0)
+               goto out;
+       ret = setup_temp_csum_tree(fd, cfg, csum_bytenr);
 
 out:
        return ret;