From patchwork Thu Aug 25 09:19:38 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tsutomu Itoh X-Patchwork-Id: 1095812 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p7P9LM72014399 for ; Thu, 25 Aug 2011 09:21:22 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753142Ab1HYJVT (ORCPT ); Thu, 25 Aug 2011 05:21:19 -0400 Received: from fgwmail5.fujitsu.co.jp ([192.51.44.35]:48007 "EHLO fgwmail5.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752594Ab1HYJVS (ORCPT ); Thu, 25 Aug 2011 05:21:18 -0400 Received: from m3.gw.fujitsu.co.jp (unknown [10.0.50.73]) by fgwmail5.fujitsu.co.jp (Postfix) with ESMTP id 37E2A3EE0BC for ; Thu, 25 Aug 2011 18:21:17 +0900 (JST) Received: from smail (m3 [127.0.0.1]) by outgoing.m3.gw.fujitsu.co.jp (Postfix) with ESMTP id 17A2445DEA6 for ; Thu, 25 Aug 2011 18:21:17 +0900 (JST) Received: from s3.gw.fujitsu.co.jp (s3.gw.fujitsu.co.jp [10.0.50.93]) by m3.gw.fujitsu.co.jp (Postfix) with ESMTP id ED85645DE9E for ; Thu, 25 Aug 2011 18:21:16 +0900 (JST) Received: from s3.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s3.gw.fujitsu.co.jp (Postfix) with ESMTP id E19F61DB8038 for ; Thu, 25 Aug 2011 18:21:16 +0900 (JST) Received: from m105.s.css.fujitsu.com (m105.s.css.fujitsu.com [10.240.81.145]) by s3.gw.fujitsu.co.jp (Postfix) with ESMTP id 9A6001DB8037 for ; Thu, 25 Aug 2011 18:21:16 +0900 (JST) Received: from m105.css.fujitsu.com (m105 [127.0.0.1]) by m105.s.css.fujitsu.com (Postfix) with ESMTP id DCC0F9C803E; Thu, 25 Aug 2011 18:21:15 +0900 (JST) Received: from T-ITOH1.jp.fujitsu.com (unknown [10.124.101.84]) by m105.s.css.fujitsu.com (Postfix) with SMTP id F0B397C8057; Thu, 25 Aug 2011 18:21:14 +0900 (JST) X-SecurityPolicyCheck-FJ: OK by FujitsuOutboundMailChecker v1.4.0 Received: from T-ITOH1[10.124.101.84] by T-ITOH1 (FujitsuOutboundMailChecker v1.4.0/9992[10.124.101.84]); Thu, 25 Aug 2011 18:20:28 +0900 (JST) Message-Id: <201108250919.AA00033@T-ITOH1.jp.fujitsu.com> From: Tsutomu Itoh Date: Thu, 25 Aug 2011 18:19:38 +0900 To: linux-btrfs@vger.kernel.org Cc: chris.mason@oracle.com Subject: [PATCH] Btrfs: fix error handling of create_reloc_root() and btrfs_copy_root() MIME-Version: 1.0 X-Mailer: AL-Mail32 Version 1.13 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Thu, 25 Aug 2011 09:21:22 +0000 (UTC) If kmalloc() or btrfs_copy_root() in create_reloc_root() failed, error is returned to the caller instead of BUG_ON(). and, error handling of btrfs_copy_root() is corrected properly. Signed-off-by: Tsutomu Itoh --- fs/btrfs/ctree.c | 5 ++++- fs/btrfs/relocation.c | 16 +++++++++++++--- fs/btrfs/transaction.c | 3 ++- 3 files changed, 19 insertions(+), 5 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 011cab3..837ff58 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -265,8 +265,11 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans, else ret = btrfs_inc_ref(trans, root, cow, 0); - if (ret) + if (ret) { + btrfs_tree_unlock(cow); + free_extent_buffer(cow); return ret; + } btrfs_mark_buffer_dirty(cow); *cow_ret = cow; diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 59bb176..57b6a57 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1268,7 +1268,8 @@ static struct btrfs_root *create_reloc_root(struct btrfs_trans_handle *trans, int ret; root_item = kmalloc(sizeof(*root_item), GFP_NOFS); - BUG_ON(!root_item); + if (!root_item) + return ERR_PTR(-ENOMEM); root_key.objectid = BTRFS_TREE_RELOC_OBJECTID; root_key.type = BTRFS_ROOT_ITEM_KEY; @@ -1278,7 +1279,8 @@ static struct btrfs_root *create_reloc_root(struct btrfs_trans_handle *trans, /* called by btrfs_init_reloc_root */ ret = btrfs_copy_root(trans, root, root->commit_root, &eb, BTRFS_TREE_RELOC_OBJECTID); - BUG_ON(ret); + if (ret) + goto out; btrfs_set_root_last_snapshot(&root->root_item, trans->transid - 1); @@ -1292,7 +1294,8 @@ static struct btrfs_root *create_reloc_root(struct btrfs_trans_handle *trans, */ ret = btrfs_copy_root(trans, root, root->node, &eb, BTRFS_TREE_RELOC_OBJECTID); - BUG_ON(ret); + if (ret) + goto out; } memcpy(root_item, &root->root_item, sizeof(*root_item)); @@ -1320,6 +1323,10 @@ static struct btrfs_root *create_reloc_root(struct btrfs_trans_handle *trans, BUG_ON(IS_ERR(reloc_root)); reloc_root->last_trans = trans->transid; return reloc_root; + +out: + kfree(root_item); + return ERR_PTR(ret); } /* @@ -1348,6 +1355,8 @@ int btrfs_init_reloc_root(struct btrfs_trans_handle *trans, clear_rsv = 1; } reloc_root = create_reloc_root(trans, root, root->root_key.objectid); + BUG_ON(IS_ERR(reloc_root)); + if (clear_rsv) trans->block_rsv = NULL; @@ -4403,6 +4412,7 @@ void btrfs_reloc_post_snapshot(struct btrfs_trans_handle *trans, new_root = pending->snap; reloc_root = create_reloc_root(trans, root->reloc_root, new_root->root_key.objectid); + BUG_ON(IS_ERR(reloc_root)); __add_reloc_root(reloc_root); new_root->reloc_root = reloc_root; diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index 7dc36fa..bdcc320 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -972,9 +972,10 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, btrfs_cow_block(trans, root, old, NULL, 0, &old); btrfs_set_lock_blocking(old); - btrfs_copy_root(trans, root, old, &tmp, objectid); + ret = btrfs_copy_root(trans, root, old, &tmp, objectid); btrfs_tree_unlock(old); free_extent_buffer(old); + BUG_ON(ret); btrfs_set_root_node(new_root_item, tmp); /* record when the snapshot was created in key.offset */