forked from Mirrors/btrfs-progs
btrfs-progs: mkfs: improve error handling in main()
Signed-off-by: David Sterba <dsterba@suse.com>master
parent
7b6c4bb33f
commit
0408296c7a
49
mkfs.c
49
mkfs.c
|
@ -1805,7 +1805,10 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
ret = btrfs_add_to_fsid(trans, root, fd, file, dev_block_count,
|
ret = btrfs_add_to_fsid(trans, root, fd, file, dev_block_count,
|
||||||
sectorsize, sectorsize, sectorsize);
|
sectorsize, sectorsize, sectorsize);
|
||||||
BUG_ON(ret);
|
if (ret) {
|
||||||
|
error("unable to add %s to filesystem: %d", file, ret);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
if (verbose >= 2) {
|
if (verbose >= 2) {
|
||||||
struct btrfs_device *device;
|
struct btrfs_device *device;
|
||||||
|
|
||||||
|
@ -1820,11 +1823,17 @@ raid_groups:
|
||||||
if (!source_dir_set) {
|
if (!source_dir_set) {
|
||||||
ret = create_raid_groups(trans, root, data_profile,
|
ret = create_raid_groups(trans, root, data_profile,
|
||||||
metadata_profile, mixed, &allocation);
|
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);
|
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);
|
btrfs_commit_transaction(trans, root);
|
||||||
|
|
||||||
|
@ -1833,11 +1842,21 @@ raid_groups:
|
||||||
ret = create_chunks(trans, root,
|
ret = create_chunks(trans, root,
|
||||||
num_of_meta_chunks, size_of_data,
|
num_of_meta_chunks, size_of_data,
|
||||||
&allocation);
|
&allocation);
|
||||||
BUG_ON(ret);
|
if (ret) {
|
||||||
btrfs_commit_transaction(trans, root);
|
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);
|
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,
|
ret = cleanup_temp_chunks(root->fs_info, &allocation, data_profile,
|
||||||
metadata_profile, metadata_profile);
|
metadata_profile, metadata_profile);
|
||||||
|
@ -1886,17 +1905,19 @@ raid_groups:
|
||||||
root->fs_info->finalize_on_close = 1;
|
root->fs_info->finalize_on_close = 1;
|
||||||
out:
|
out:
|
||||||
ret = close_ctree(root);
|
ret = close_ctree(root);
|
||||||
BUG_ON(ret);
|
|
||||||
|
|
||||||
optind = saved_optind;
|
if (!ret) {
|
||||||
dev_cnt = argc - optind;
|
optind = saved_optind;
|
||||||
while (dev_cnt-- > 0) {
|
dev_cnt = argc - optind;
|
||||||
file = argv[optind++];
|
while (dev_cnt-- > 0) {
|
||||||
if (is_block_device(file) == 1)
|
file = argv[optind++];
|
||||||
btrfs_register_one_device(file);
|
if (is_block_device(file) == 1)
|
||||||
|
btrfs_register_one_device(file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
btrfs_close_all_devices();
|
btrfs_close_all_devices();
|
||||||
free(label);
|
free(label);
|
||||||
return 0;
|
|
||||||
|
return !!ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue