From patchwork Thu Jul 5 07:37:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 10508301 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6E38E60325 for ; Thu, 5 Jul 2018 07:37:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5EB3B28E69 for ; Thu, 5 Jul 2018 07:37:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 52CBA28E72; Thu, 5 Jul 2018 07:37:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E7D5828E69 for ; Thu, 5 Jul 2018 07:37:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753346AbeGEHhi (ORCPT ); Thu, 5 Jul 2018 03:37:38 -0400 Received: from mx2.suse.de ([195.135.220.15]:53534 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753002AbeGEHhh (ORCPT ); Thu, 5 Jul 2018 03:37:37 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 6E9BEAF53 for ; Thu, 5 Jul 2018 07:37:36 +0000 (UTC) From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH 2/4] btrfs-progs: transaction: Error out other than panic when committing transaction Date: Thu, 5 Jul 2018 15:37:29 +0800 Message-Id: <20180705073731.18459-3-wqu@suse.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180705073731.18459-1-wqu@suse.com> References: <20180705073731.18459-1-wqu@suse.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- transaction.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/transaction.c b/transaction.c index 9619265ef6e8..b82d346b52c8 100644 --- a/transaction.c +++ b/transaction.c @@ -73,7 +73,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; @@ -101,9 +102,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; @@ -162,12 +165,15 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans, root->root_item.level = btrfs_header_level(root->node); ret = btrfs_update_root(trans, root->fs_info->tree_root, &root->root_key, &root->root_item); - BUG_ON(ret); + if (ret < 0) + goto out; commit_tree: ret = commit_tree_roots(trans, fs_info); - BUG_ON(ret); + if (ret < 0) + goto out; 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); @@ -176,7 +182,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)