btrfs-progs: mkfs: do proper error handling

Replace BUG_ON after transaction start failures, all the functions
already handle errors and return them to the caller. The other error
handling is for impossible conditions.

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2022-09-30 14:44:38 +02:00
parent a827bb2db8
commit ea0b894967
2 changed files with 29 additions and 6 deletions

View File

@ -101,7 +101,12 @@ static int create_metadata_block_groups(struct btrfs_root *root, bool mixed,
return ret;
trans = btrfs_start_transaction(root, 1);
BUG_ON(IS_ERR(trans));
if (IS_ERR(trans)) {
ret = PTR_ERR(trans);
errno = -ret;
error_msg(ERROR_MSG_START_TRANS, "%m");
return ret;
}
root->fs_info->system_allocs = 1;
/*
@ -586,7 +591,12 @@ static int cleanup_temp_chunks(struct btrfs_fs_info *fs_info,
btrfs_init_path(&path);
trans = btrfs_start_transaction(root, 1);
BUG_ON(IS_ERR(trans));
if (IS_ERR(trans)) {
ret = PTR_ERR(trans);
errno = -ret;
error_msg(ERROR_MSG_START_TRANS, "%m");
return ret;
}
key.objectid = 0;
key.type = BTRFS_BLOCK_GROUP_ITEM_KEY;

View File

@ -655,7 +655,13 @@ int btrfs_mkfs_fill_dir(const char *source_dir, struct btrfs_root *root,
INIT_LIST_HEAD(&dir_head.list);
trans = btrfs_start_transaction(root, 1);
BUG_ON(IS_ERR(trans));
if (IS_ERR(trans)) {
ret = PTR_ERR(trans);
errno = -ret;
error_msg(ERROR_MSG_START_TRANS, "%m");
goto fail;
}
ret = traverse_directory(trans, root, source_dir, &dir_head);
if (ret) {
error("unable to traverse directory %s: %d", source_dir, ret);
@ -807,8 +813,11 @@ static int get_device_extent_end(struct btrfs_fs_info *fs_info,
btrfs_init_path(&path);
ret = btrfs_search_slot(NULL, dev_root, &key, &path, 0, 0);
/* Not really possible */
BUG_ON(ret == 0);
if (ret == 0) {
error("DEV_EXTENT for devid %llu not found", devid);
ret = -EUCLEAN;
goto out;
}
ret = btrfs_previous_item(dev_root, &path, devid, BTRFS_DEV_EXTENT_KEY);
if (ret < 0)
@ -933,7 +942,11 @@ int btrfs_mkfs_shrink_fs(struct btrfs_fs_info *fs_info, u64 *new_size_ret,
return ret;
}
BUG_ON(!IS_ALIGNED(new_size, fs_info->sectorsize));
if (!IS_ALIGNED(new_size, fs_info->sectorsize)) {
error("shrunk filesystem size %llu not aligned to %u",
new_size, fs_info->sectorsize);
return -EUCLEAN;
}
device = list_entry(fs_info->fs_devices->devices.next,
struct btrfs_device, dev_list);