summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQu Wenruo <wqu@suse.com>2018-07-05 15:37:29 +0800
committerDavid Sterba <dsterba@suse.com>2018-09-13 20:11:12 +0200
commit9f45658fd2ccc9a2cbc259eb7e4d3132e2b92f83 (patch)
tree1e2f245a51204175946de844a8b0dad4699055a9
parenta8985f549cb897e28999bf3d8cdac78cc2d1555e (diff)
btrfs-progs: transaction: do proper error handling in transaction commit
There are cases that btrfs_commit_transaction() itself can fail, mostly due to ENOSPC when allocating space. Don't panic out in this case. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Gu Jinxiang <gujx@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--transaction.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/transaction.c b/transaction.c
index ecafbb15..1e2a7b96 100644
--- a/transaction.c
+++ b/transaction.c
@@ -74,7 +74,8 @@ static int update_cowonly_root(struct btrfs_trans_handle *trans,
ret = btrfs_update_root(trans, tree_root,
&root->root_key,
&root->root_item);
- BUG_ON(ret);
+ if (ret < 0)
+ return ret;
btrfs_write_dirty_block_groups(trans, root);
}
return 0;
@@ -102,9 +103,11 @@ int commit_tree_roots(struct btrfs_trans_handle *trans,
next = fs_info->dirty_cowonly_roots.next;
list_del_init(next);
root = list_entry(next, struct btrfs_root, dirty_list);
- update_cowonly_root(trans, root);
+ ret = update_cowonly_root(trans, root);
free_extent_buffer(root->commit_root);
root->commit_root = NULL;
+ if (ret < 0)
+ return ret;
}
return 0;
@@ -168,7 +171,8 @@ commit_tree:
ret = commit_tree_roots(trans, fs_info);
BUG_ON(ret);
ret = __commit_transaction(trans, root);
- BUG_ON(ret);
+ if (ret < 0)
+ goto out;
write_ctree_super(trans);
btrfs_finish_extent_commit(trans, fs_info->extent_root,
&fs_info->pinned_extents);
@@ -177,7 +181,8 @@ commit_tree:
root->commit_root = NULL;
fs_info->running_transaction = NULL;
fs_info->last_trans_committed = transid;
- return 0;
+out:
+ return ret;
}
void btrfs_abort_transaction(struct btrfs_trans_handle *trans, int error)