summaryrefslogtreecommitdiff
path: root/convert
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 /convert
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>
Diffstat (limited to 'convert')
-rw-r--r--convert/main.c10
-rw-r--r--convert/source-ext2.c6
-rw-r--r--convert/source-reiserfs.c24
3 files changed, 20 insertions, 20 deletions
diff --git a/convert/main.c b/convert/main.c
index 22884bd5..7ec6202d 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 f1075da5..559669ff 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 d6389bf9..be79d8e2 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);