From 9f45658fd2ccc9a2cbc259eb7e4d3132e2b92f83 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Thu, 5 Jul 2018 15:37:29 +0800 Subject: 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 Reviewed-by: Gu Jinxiang Signed-off-by: David Sterba --- transaction.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'transaction.c') 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) -- cgit v1.2.3