btrfs-progs: convert: improve error hanling of create_subvol
authorDavid Sterba <dsterba@suse.com>
Tue, 23 Aug 2016 17:24:48 +0000 (19:24 +0200)
committerDavid Sterba <dsterba@suse.com>
Wed, 24 Aug 2016 12:37:36 +0000 (14:37 +0200)
Replace BUG_ONs and verbosely report the errors.

Signed-off-by: David Sterba <dsterba@suse.com>
btrfs-convert.c

index 24dc4d8..66f62e8 100644 (file)
@@ -1193,7 +1193,8 @@ static int create_subvol(struct btrfs_trans_handle *trans,
 
        ret = btrfs_copy_root(trans, root, root->node, &tmp,
                              root_objectid);
-       BUG_ON(ret);
+       if (ret)
+               return ret;
 
        memcpy(&root_item, &root->root_item, sizeof(root_item));
        btrfs_set_root_bytenr(&root_item, tmp->start);
@@ -1209,12 +1210,14 @@ static int create_subvol(struct btrfs_trans_handle *trans,
 
        key.offset = (u64)-1;
        new_root = btrfs_read_fs_root(root->fs_info, &key);
-       BUG_ON(!new_root || IS_ERR(new_root));
+       if (!new_root || IS_ERR(new_root)) {
+               error("unable to fs read root: %lu", PTR_ERR(new_root));
+               return PTR_ERR(new_root);
+       }
 
        ret = btrfs_make_root_dir(trans, new_root, BTRFS_FIRST_FREE_OBJECTID);
-       BUG_ON(ret);
 
-       return 0;
+       return ret;
 }
 
 /*
@@ -1323,12 +1326,16 @@ static int init_btrfs(struct btrfs_mkfs_config *cfg, struct btrfs_root *root,
 
        /* subvol for fs image file */
        ret = create_subvol(trans, root, CONV_IMAGE_SUBVOL_OBJECTID);
-       if (ret < 0)
+       if (ret < 0) {
+               error("failed to create subvolume image root: %d", ret);
                goto err;
+       }
        /* subvol for data relocation tree */
        ret = create_subvol(trans, root, BTRFS_DATA_RELOC_TREE_OBJECTID);
-       if (ret < 0)
+       if (ret < 0) {
+               error("failed to create DATA_RELOC root: %d", ret);
                goto err;
+       }
 
        ret = btrfs_commit_transaction(trans, root);
        fs_info->avoid_sys_chunk_alloc = 0;