summaryrefslogtreecommitdiff
path: root/mkfs.c
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2016-08-22 17:50:49 +0200
committerDavid Sterba <dsterba@suse.com>2016-08-24 14:37:36 +0200
commit0408296c7a032d1c1904dc4f247e100e60f3af7a (patch)
tree78aeeff2732e585c4fb8cb6af25bcddf9cab6304 /mkfs.c
parent7b6c4bb33ff298a02841315212fe66ce9a959398 (diff)
btrfs-progs: mkfs: improve error handling in main()
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'mkfs.c')
-rw-r--r--mkfs.c49
1 files changed, 35 insertions, 14 deletions
diff --git a/mkfs.c b/mkfs.c
index b2baf47b..94b349f1 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -1805,7 +1805,10 @@ int main(int argc, char **argv)
ret = btrfs_add_to_fsid(trans, root, fd, file, dev_block_count,
sectorsize, sectorsize, sectorsize);
- BUG_ON(ret);
+ if (ret) {
+ error("unable to add %s to filesystem: %d", file, ret);
+ goto out;
+ }
if (verbose >= 2) {
struct btrfs_device *device;
@@ -1820,11 +1823,17 @@ raid_groups:
if (!source_dir_set) {
ret = create_raid_groups(trans, root, data_profile,
metadata_profile, mixed, &allocation);
- BUG_ON(ret);
+ if (ret) {
+ error("unable to create raid groups: %d", ret);
+ goto out;
+ }
}
ret = create_data_reloc_tree(trans, root);
- BUG_ON(ret);
+ if (ret) {
+ error("unable to create data reloc tree: %d", ret);
+ goto out;
+ }
btrfs_commit_transaction(trans, root);
@@ -1833,11 +1842,21 @@ raid_groups:
ret = create_chunks(trans, root,
num_of_meta_chunks, size_of_data,
&allocation);
- BUG_ON(ret);
- btrfs_commit_transaction(trans, root);
+ if (ret) {
+ error("unable to create chunks: %d", ret);
+ goto out;
+ }
+ ret = btrfs_commit_transaction(trans, root);
+ if (ret) {
+ error("transaction commit failed: %d", ret);
+ goto out;
+ }
ret = make_image(source_dir, root, fd);
- BUG_ON(ret);
+ if (ret) {
+ error("error wihle filling filesystem: %d", ret);
+ goto out;
+ }
}
ret = cleanup_temp_chunks(root->fs_info, &allocation, data_profile,
metadata_profile, metadata_profile);
@@ -1886,17 +1905,19 @@ raid_groups:
root->fs_info->finalize_on_close = 1;
out:
ret = close_ctree(root);
- BUG_ON(ret);
- optind = saved_optind;
- dev_cnt = argc - optind;
- while (dev_cnt-- > 0) {
- file = argv[optind++];
- if (is_block_device(file) == 1)
- btrfs_register_one_device(file);
+ if (!ret) {
+ optind = saved_optind;
+ dev_cnt = argc - optind;
+ while (dev_cnt-- > 0) {
+ file = argv[optind++];
+ if (is_block_device(file) == 1)
+ btrfs_register_one_device(file);
+ }
}
btrfs_close_all_devices();
free(label);
- return 0;
+
+ return !!ret;
}