summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2017-08-28 16:48:16 +0200
committerDavid Sterba <dsterba@suse.com>2017-09-08 16:15:05 +0200
commit448999d84ddc2eaf36938176fb5091d2c2029e2f (patch)
tree4e90505605420f6d3467639d2899e93c893596dd
parent4ef5a112c9d2fe9d6f03ac2ea3aa5b1af0f37254 (diff)
btrfs-progs: add crude error handling when transaction start fails
Currently transaction bugs out insided btrfs_start_transaction in case of error, we want to lift the error handling to the callers. This patch adds the BUG_ON anywhere it's been missing so far. This is not the best way of course. Transforming BUG_ON to a proper error handling highly depends on the caller and should be dealt with case by case. Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--btrfs-corrupt-block.c7
-rw-r--r--btrfs-zero-log.c1
-rw-r--r--btrfstune.c2
-rw-r--r--chunk-recover.c1
-rw-r--r--cmds-rescue.c1
-rw-r--r--convert/main.c10
-rw-r--r--convert/source-ext2.c6
-rw-r--r--convert/source-reiserfs.c24
-rw-r--r--dir-test.c1
-rw-r--r--disk-io.c2
-rw-r--r--mkfs/main.c8
-rw-r--r--quick-test.c5
-rw-r--r--random-test.c1
-rw-r--r--utils.c1
14 files changed, 48 insertions, 22 deletions
diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c
index 83adcf8..59ee1b4 100644
--- a/btrfs-corrupt-block.c
+++ b/btrfs-corrupt-block.c
@@ -1226,13 +1226,16 @@ int main(int argc, char **argv)
if (logical == (u64)-1)
print_usage(1);
trans = btrfs_start_transaction(root, 1);
+ BUG_ON(IS_ERR(trans));
ret = corrupt_extent(trans, root, logical);
btrfs_commit_transaction(trans, root);
goto out_close;
}
if (extent_tree) {
struct btrfs_trans_handle *trans;
+
trans = btrfs_start_transaction(root, 1);
+ BUG_ON(IS_ERR(trans));
btrfs_corrupt_extent_tree(trans, root->fs_info->extent_root,
root->fs_info->extent_root->node);
btrfs_commit_transaction(trans, root);
@@ -1258,6 +1261,7 @@ int main(int argc, char **argv)
goto out_close;
}
trans = btrfs_start_transaction(root, 1);
+ BUG_ON(IS_ERR(trans));
ret = corrupt_item_nocow(trans, root->fs_info->chunk_root,
path, del);
if (ret < 0)
@@ -1267,7 +1271,9 @@ int main(int argc, char **argv)
}
if (chunk_tree) {
struct btrfs_trans_handle *trans;
+
trans = btrfs_start_transaction(root, 1);
+ BUG_ON(IS_ERR(trans));
ret = corrupt_chunk_tree(trans, root->fs_info->chunk_root);
if (ret < 0)
fprintf(stderr, "Failed to corrupt chunk tree\n");
@@ -1281,6 +1287,7 @@ int main(int argc, char **argv)
print_usage(1);
trans = btrfs_start_transaction(root, 1);
+ BUG_ON(IS_ERR(trans));
if (file_extent == (u64)-1) {
printf("corrupting inode\n");
ret = corrupt_inode(trans, root, inode, field);
diff --git a/btrfs-zero-log.c b/btrfs-zero-log.c
index 697026a..2fce59e 100644
--- a/btrfs-zero-log.c
+++ b/btrfs-zero-log.c
@@ -68,6 +68,7 @@ int main(int argc, char **argv)
(unsigned long long)btrfs_super_log_root(sb),
(unsigned)btrfs_super_log_root_level(sb));
trans = btrfs_start_transaction(root, 1);
+ BUG_ON(IS_ERR(trans));
btrfs_set_super_log_root(root->fs_info->super_copy, 0);
btrfs_set_super_log_root_level(root->fs_info->super_copy, 0);
btrfs_commit_transaction(trans, root);
diff --git a/btrfstune.c b/btrfstune.c
index 0139e40..eccedf7 100644
--- a/btrfstune.c
+++ b/btrfstune.c
@@ -66,6 +66,7 @@ static int update_seeding_flag(struct btrfs_root *root, int set_flag)
}
trans = btrfs_start_transaction(root, 1);
+ BUG_ON(IS_ERR(trans));
btrfs_set_super_flags(disk_super, super_flags);
ret = btrfs_commit_transaction(trans, root);
@@ -83,6 +84,7 @@ static int set_super_incompat_flags(struct btrfs_root *root, u64 flags)
super_flags = btrfs_super_incompat_flags(disk_super);
super_flags |= flags;
trans = btrfs_start_transaction(root, 1);
+ BUG_ON(IS_ERR(trans));
btrfs_set_super_incompat_flags(disk_super, super_flags);
ret = btrfs_commit_transaction(trans, root);
diff --git a/chunk-recover.c b/chunk-recover.c
index f1fa750..4a6d714 100644
--- a/chunk-recover.c
+++ b/chunk-recover.c
@@ -2389,6 +2389,7 @@ int btrfs_recover_chunk_tree(char *path, int verbose, int yes)
}
trans = btrfs_start_transaction(root, 1);
+ BUG_ON(IS_ERR(trans));
ret = remove_chunk_extent_item(trans, &rc, root);
BUG_ON(ret);
diff --git a/cmds-rescue.c b/cmds-rescue.c
index 7e7344e..d1bec02 100644
--- a/cmds-rescue.c
+++ b/cmds-rescue.c
@@ -191,6 +191,7 @@ static int cmd_rescue_zero_log(int argc, char **argv)
(unsigned long long)btrfs_super_log_root(sb),
(unsigned)btrfs_super_log_root_level(sb));
trans = btrfs_start_transaction(root, 1);
+ BUG_ON(IS_ERR(trans));
btrfs_set_super_log_root(sb, 0);
btrfs_set_super_log_root_level(sb, 0);
btrfs_commit_transaction(trans, root);
diff --git a/convert/main.c b/convert/main.c
index 22884bd..7ec6202 100644
--- a/convert/main.c
+++ b/convert/main.c
@@ -751,8 +751,8 @@ static int create_image(struct btrfs_root *root,
flags |= BTRFS_INODE_NODATASUM;
trans = btrfs_start_transaction(root, 1);
- if (!trans)
- return -ENOMEM;
+ if (IS_ERR(trans))
+ return PTR_ERR(trans);
cache_tree_init(&used_tmp);
btrfs_init_path(&path);
@@ -881,7 +881,7 @@ static struct btrfs_root* link_subvol(struct btrfs_root *root,
btrfs_release_path(&path);
trans = btrfs_start_transaction(root, 1);
- if (!trans) {
+ if (IS_ERR(trans)) {
error("unable to start transaction");
goto fail;
}
@@ -1077,9 +1077,9 @@ static int init_btrfs(struct btrfs_mkfs_config *cfg, struct btrfs_root *root,
fs_info->avoid_sys_chunk_alloc = 1;
fs_info->avoid_meta_chunk_alloc = 1;
trans = btrfs_start_transaction(root, 1);
- if (!trans) {
+ if (IS_ERR(trans)) {
error("unable to start transaction");
- ret = -EINVAL;
+ ret = PTR_ERR(trans);
goto err;
}
ret = btrfs_fix_block_accounting(trans, root);
diff --git a/convert/source-ext2.c b/convert/source-ext2.c
index f1075da..559669f 100644
--- a/convert/source-ext2.c
+++ b/convert/source-ext2.c
@@ -803,8 +803,8 @@ static int ext2_copy_inodes(struct btrfs_convert_context *cctx,
struct btrfs_trans_handle *trans;
trans = btrfs_start_transaction(root, 1);
- if (!trans)
- return -ENOMEM;
+ if (IS_ERR(trans))
+ return PTR_ERR(trans);
err = ext2fs_open_inode_scan(ext2_fs, 0, &ext2_scan);
if (err) {
fprintf(stderr, "ext2fs_open_inode_scan: %s\n", error_message(err));
@@ -830,7 +830,7 @@ static int ext2_copy_inodes(struct btrfs_convert_context *cctx,
ret = btrfs_commit_transaction(trans, root);
BUG_ON(ret);
trans = btrfs_start_transaction(root, 1);
- BUG_ON(!trans);
+ BUG_ON(IS_ERR(trans));
}
}
if (err) {
diff --git a/convert/source-reiserfs.c b/convert/source-reiserfs.c
index d6389bf..be79d8e 100644
--- a/convert/source-reiserfs.c
+++ b/convert/source-reiserfs.c
@@ -500,8 +500,8 @@ static int reiserfs_copy_dirent(reiserfs_filsys_t fs,
return ret;
}
trans = btrfs_start_transaction(root, 1);
- if (!trans)
- return -ENOMEM;
+ if (IS_ERR(trans))
+ return PTR_ERR(trans);
ret = convert_insert_dirent(trans, root, name, len, dir_objectid,
objectid, type, dirent_data->index++,
@@ -613,8 +613,8 @@ static int reiserfs_copy_meta(reiserfs_filsys_t fs, struct btrfs_root *root,
switch (mode & S_IFMT) {
case S_IFREG:
trans = btrfs_start_transaction(root, 1);
- if (!trans) {
- ret = -ENOMEM;
+ if (IS_ERR(trans)) {
+ ret = PTR_ERR(trans);
goto fail;
}
ret = reiserfs_record_file_extents(fs, trans, root, objectid,
@@ -629,8 +629,8 @@ static int reiserfs_copy_meta(reiserfs_filsys_t fs, struct btrfs_root *root,
if (ret)
goto fail;
trans = btrfs_start_transaction(root, 1);
- if (!trans) {
- ret = -ENOMEM;
+ if (IS_ERR(trans)) {
+ ret = PTR_ERR(trans);
goto fail;
}
@@ -639,8 +639,8 @@ static int reiserfs_copy_meta(reiserfs_filsys_t fs, struct btrfs_root *root,
break;
case S_IFLNK:
trans = btrfs_start_transaction(root, 1);
- if (!trans) {
- ret = -ENOMEM;
+ if (IS_ERR(trans)) {
+ ret = PTR_ERR(trans);
goto fail;
}
ret = reiserfs_copy_symlink(trans, root, objectid,
@@ -650,8 +650,8 @@ static int reiserfs_copy_meta(reiserfs_filsys_t fs, struct btrfs_root *root,
break;
default:
trans = btrfs_start_transaction(root, 1);
- if (!trans) {
- ret = -ENOMEM;
+ if (IS_ERR(trans)) {
+ ret = PTR_ERR(trans);
goto fail;
}
}
@@ -872,8 +872,8 @@ static int reiserfs_copy_xattr_dir(reiserfs_filsys_t fs,
xa_data->target_oid += OID_OFFSET;
xa_data->trans = btrfs_start_transaction(xa_data->root, 1);
- if (!xa_data->trans)
- return -ENOMEM;
+ if (IS_ERR(xa_data->trans))
+ return PTR_ERR(xa_data->trans);
ret = reiserfs_iterate_dir(fs, &dir_key,
reiserfs_copy_one_xattr, xa_data);
diff --git a/dir-test.c b/dir-test.c
index 24f2c2e..cfb77f2 100644
--- a/dir-test.c
+++ b/dir-test.c
@@ -443,6 +443,7 @@ int main(int ac, char **av)
}
trans = btrfs_start_transaction(root, 1);
+ BUG_ON(IS_ERR(trans));
dir_oid = btrfs_super_root_dir(&super);
diff --git a/disk-io.c b/disk-io.c
index 30e656c..f969c9b 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -1753,8 +1753,10 @@ int close_ctree_fs_info(struct btrfs_fs_info *fs_info)
fs_info->generation) {
BUG_ON(!root);
trans = btrfs_start_transaction(root, 1);
+ BUG_ON(IS_ERR(trans));
btrfs_commit_transaction(trans, root);
trans = btrfs_start_transaction(root, 1);
+ BUG_ON(IS_ERR(trans));
ret = commit_tree_roots(trans, fs_info);
BUG_ON(ret);
ret = __commit_transaction(trans, root);
diff --git a/mkfs/main.c b/mkfs/main.c
index dfa7a03..f495258 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -75,6 +75,7 @@ static int create_metadata_block_groups(struct btrfs_root *root, int mixed,
int ret;
trans = btrfs_start_transaction(root, 1);
+ BUG_ON(IS_ERR(trans));
bytes_used = btrfs_super_bytes_used(fs_info->super_copy);
root->fs_info->system_allocs = 1;
@@ -1047,6 +1048,7 @@ static int make_image(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));
ret = traverse_directory(trans, root, source_dir, &dir_head);
if (ret) {
error("unable to traverse directory %s: %d", source_dir, ret);
@@ -1325,6 +1327,7 @@ 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));
key.objectid = 0;
key.type = BTRFS_BLOCK_GROUP_ITEM_KEY;
@@ -1758,7 +1761,7 @@ int main(int argc, char **argv)
}
trans = btrfs_start_transaction(root, 1);
- if (!trans) {
+ if (IS_ERR(trans)) {
error("failed to start transaction");
goto error;
}
@@ -1782,7 +1785,7 @@ int main(int argc, char **argv)
}
trans = btrfs_start_transaction(root, 1);
- if (!trans) {
+ if (IS_ERR(trans)) {
error("failed to start transaction");
goto error;
}
@@ -1860,6 +1863,7 @@ raid_groups:
if (source_dir_set) {
trans = btrfs_start_transaction(root, 1);
+ BUG_ON(IS_ERR(trans));
ret = create_chunks(trans, root,
num_of_meta_chunks, size_of_data,
&allocation);
diff --git a/quick-test.c b/quick-test.c
index f99ecc3..b1e7999 100644
--- a/quick-test.c
+++ b/quick-test.c
@@ -56,6 +56,7 @@ int main(int ac, char **av) {
exit(1);
}
trans = btrfs_start_transaction(root, 1);
+ BUG_ON(IS_ERR(trans));
srand(55);
ins.type = BTRFS_STRING_ITEM_KEY;
for (i = 0; i < run_size; i++) {
@@ -72,6 +73,7 @@ int main(int ac, char **av) {
if (i == run_size - 5) {
btrfs_commit_transaction(trans, root);
trans = btrfs_start_transaction(root, 1);
+ BUG_ON(IS_ERR(trans));
}
}
btrfs_commit_transaction(trans, root);
@@ -114,6 +116,7 @@ int main(int ac, char **av) {
i = 0;
srand(55);
trans = btrfs_start_transaction(root, 1);
+ BUG_ON(IS_ERR(trans));
for (i = 0 ; i < run_size/4; i++) {
num = next_key(i, max_key);
ins.objectid = num;
@@ -138,6 +141,7 @@ int main(int ac, char **av) {
exit(1);
}
trans = btrfs_start_transaction(root, 1);
+ BUG_ON(IS_ERR(trans));
srand(128);
for (i = 0; i < run_size; i++) {
num = next_key(i, max_key);
@@ -175,6 +179,7 @@ int main(int ac, char **av) {
}
printf("starting big long delete run\n");
trans = btrfs_start_transaction(root, 1);
+ BUG_ON(IS_ERR(trans));
while(root->node && btrfs_header_nritems(root->node) > 0) {
struct extent_buffer *leaf;
int slot;
diff --git a/random-test.c b/random-test.c
index 410a110..d5f830a 100644
--- a/random-test.c
+++ b/random-test.c
@@ -380,6 +380,7 @@ int main(int ac, char **av)
}
printf("initial fill\n");
trans = btrfs_start_transaction(root, 1);
+ BUG_ON(IS_ERR(trans));
ret = fill_tree(trans, root, &radix, init_fill_count);
printf("starting run\n");
if (ret) {
diff --git a/utils.c b/utils.c
index bb04913..2d0ff8b 100644
--- a/utils.c
+++ b/utils.c
@@ -1229,6 +1229,7 @@ static int set_label_unmounted(const char *dev, const char *label)
return -1;
trans = btrfs_start_transaction(root, 1);
+ BUG_ON(IS_ERR(trans));
__strncpy_null(root->fs_info->super_copy->label, label, BTRFS_LABEL_SIZE - 1);
btrfs_commit_transaction(trans, root);