From patchwork Thu Nov 11 04:32:06 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Kent X-Patchwork-Id: 316432 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oAB4WH3k011546 for ; Thu, 11 Nov 2010 04:32:17 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932329Ab0KKEcO (ORCPT ); Wed, 10 Nov 2010 23:32:14 -0500 Received: from out3.smtp.messagingengine.com ([66.111.4.27]:55275 "EHLO out3.smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932268Ab0KKEcN (ORCPT ); Wed, 10 Nov 2010 23:32:13 -0500 Received: from compute3.internal (compute3.nyi.mail.srv.osa [10.202.2.43]) by gateway1.messagingengine.com (Postfix) with ESMTP id E8EAD673; Wed, 10 Nov 2010 23:32:12 -0500 (EST) Received: from frontend1.messagingengine.com ([10.202.2.160]) by compute3.internal (MEProxy); Wed, 10 Nov 2010 23:32:12 -0500 X-Sasl-enc: JjlOPuKRj7O+YrpLnqa5ZBGdK4lpQgYJyHBS+70qNng/ 1289449931 Received: from [10.49.97.32] (203-206-67-179.dyn.iinet.net.au [203.206.67.179]) by mail.messagingengine.com (Postfix) with ESMTPSA id 63B534019B7; Wed, 10 Nov 2010 23:32:10 -0500 (EST) Subject: Re: On Removing BUG_ON macros From: Ian Kent To: Josef Bacik Cc: Yoshinori Sano , chris.mason@oracle.com, linux-btrfs@vger.kernel.org In-Reply-To: <1289228524.3309.51.camel@localhost> References: <20101107145120.GF9728@dhcp231-156.rdu.redhat.com> <1289184847.3309.26.camel@localhost> <20101108124211.GA27816@dhcp231-156.rdu.redhat.com> <1289225174.3309.48.camel@localhost> <20101108141539.GD2515@localhost.localdomain> <1289228524.3309.51.camel@localhost> Date: Thu, 11 Nov 2010 12:32:06 +0800 Message-ID: <1289449926.3078.9.camel@localhost> Mime-Version: 1.0 X-Mailer: Evolution 2.28.3 (2.28.3-1.fc12) 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.3 (demeter1.kernel.org [140.211.167.41]); Thu, 11 Nov 2010 04:32:18 +0000 (UTC) diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 9ac1715..a1f46fa 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -3832,7 +3832,8 @@ int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root unsigned long ptr; path = btrfs_alloc_path(); - BUG_ON(!path); + if (!path) + return -ENOMEM; ret = btrfs_insert_empty_item(trans, root, path, cpu_key, data_size); if (!ret) { leaf = path->nodes[0]; diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index b40dfe4..066af87 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1105,7 +1105,8 @@ struct btrfs_root *btrfs_read_fs_root_no_radix(struct btrfs_root *tree_root, root, fs_info, location->objectid); path = btrfs_alloc_path(); - BUG_ON(!path); + if (!path) + return ERR_PTR(-ENOMEM); ret = btrfs_search_slot(NULL, tree_root, location, path, 0, 0); if (ret == 0) { l = path->nodes[0]; diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index a541bc8..d737cea6 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -7821,8 +7821,10 @@ static noinline int relocate_one_extent(struct btrfs_root *extent_root, } mutex_lock(&extent_root->fs_info->trans_mutex); - btrfs_record_root_in_trans(found_root); + ret = btrfs_record_root_in_trans(found_root); mutex_unlock(&extent_root->fs_info->trans_mutex); + if (ret < 0) + goto out; if (ref_path->owner_objectid >= BTRFS_FIRST_FREE_OBJECTID) { /* * try to update data extent references while diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 5132c9a..184b86a 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -6521,8 +6521,11 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry, btrfs_set_trans_block_group(trans, new_dir); - if (dest != root) - btrfs_record_root_in_trans(trans, dest); + if (dest != root) { + ret = btrfs_record_root_in_trans(trans, dest); + if (ret) + goto out_fail; + } ret = btrfs_set_inode_index(new_dir, &index); if (ret) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 463d91b..ba94d60 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -311,7 +311,9 @@ static noinline int create_subvol(struct btrfs_root *root, new_root = btrfs_read_fs_root_no_name(root->fs_info, &key); BUG_ON(IS_ERR(new_root)); - btrfs_record_root_in_trans(trans, new_root); + ret = btrfs_record_root_in_trans(trans, new_root); + if (ret) + goto fail; ret = btrfs_create_subvol_root(trans, new_root, new_dirid, BTRFS_I(dir)->block_group); @@ -1442,7 +1444,9 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file, dentry->d_name.len); BUG_ON(ret); - btrfs_record_root_in_trans(trans, dest); + err = btrfs_record_root_in_trans(trans, dest); + if (err) + goto out_up_write; memset(&dest->root_item.drop_progress, 0, sizeof(dest->root_item.drop_progress)); diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 045c9c2..2e81b07 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1264,7 +1264,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; @@ -1274,7 +1275,10 @@ 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) { + kfree(root_item); + return ERR_PTR(ret); + } btrfs_set_root_last_snapshot(&root->root_item, trans->transid - 1); @@ -1288,7 +1292,10 @@ 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) { + kfree(root_item); + return ERR_PTR(ret); + } } memcpy(root_item, &root->root_item, sizeof(*root_item)); @@ -1308,13 +1315,16 @@ static struct btrfs_root *create_reloc_root(struct btrfs_trans_handle *trans, ret = btrfs_insert_root(trans, root->fs_info->tree_root, &root_key, root_item); - BUG_ON(ret); + if (ret) { + kfree(root_item); + return ERR_PTR(ret); + } kfree(root_item); reloc_root = btrfs_read_fs_root_no_radix(root->fs_info->tree_root, &root_key); - BUG_ON(IS_ERR(reloc_root)); - reloc_root->last_trans = trans->transid; + if (!IS_ERR(reloc_root)) + reloc_root->last_trans = trans->transid; return reloc_root; } @@ -1346,6 +1356,8 @@ int btrfs_init_reloc_root(struct btrfs_trans_handle *trans, reloc_root = create_reloc_root(trans, root, root->root_key.objectid); if (clear_rsv) trans->block_rsv = NULL; + if (IS_ERR(reloc_root)) + return PTR_ERR(reloc_root); __add_reloc_root(reloc_root); root->reloc_root = reloc_root; @@ -2275,10 +2287,12 @@ struct btrfs_root *select_reloc_root(struct btrfs_trans_handle *trans, BUG_ON(!root->ref_cows); if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) { + /* TODO: what to do here? */ record_reloc_root_in_trans(trans, root); break; } + /* TODO: what to do here? */ btrfs_record_root_in_trans(trans, root); root = root->reloc_root; @@ -2715,7 +2729,9 @@ static int relocate_tree_block(struct btrfs_trans_handle *trans, if (root->ref_cows) { BUG_ON(node->new_bytenr); BUG_ON(!list_empty(&node->list)); - btrfs_record_root_in_trans(trans, root); + ret = btrfs_record_root_in_trans(trans, root); + if (ret) + goto out; root = root->reloc_root; node->new_bytenr = root->node->start; node->root = root; diff --git a/fs/btrfs/root-tree.c b/fs/btrfs/root-tree.c index 6a1086e..045c924 100644 --- a/fs/btrfs/root-tree.c +++ b/fs/btrfs/root-tree.c @@ -140,7 +140,9 @@ int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root unsigned long ptr; path = btrfs_alloc_path(); - BUG_ON(!path); + if (!path) + return -ENOMEM; + ret = btrfs_search_slot(trans, root, key, path, 0, 1); if (ret < 0) goto out; diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index 1fffbc0..615264f 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -104,14 +104,18 @@ static noinline int record_root_in_trans(struct btrfs_trans_handle *trans, struct btrfs_root *root) { if (root->ref_cows && root->last_trans < trans->transid) { + int ret; + WARN_ON(root == root->fs_info->extent_root); WARN_ON(root->commit_root != root->node); + /* TODO: cleanup tag set on error? */ radix_tree_tag_set(&root->fs_info->fs_roots_radix, (unsigned long)root->root_key.objectid, BTRFS_ROOT_TRANS_TAG); root->last_trans = trans->transid; - btrfs_init_reloc_root(trans, root); + ret = btrfs_init_reloc_root(trans, root); + return ret; } return 0; } @@ -119,6 +123,8 @@ static noinline int record_root_in_trans(struct btrfs_trans_handle *trans, int btrfs_record_root_in_trans(struct btrfs_trans_handle *trans, struct btrfs_root *root) { + int ret; + if (!root->ref_cows) return 0; @@ -128,9 +134,9 @@ int btrfs_record_root_in_trans(struct btrfs_trans_handle *trans, return 0; } - record_root_in_trans(trans, root); + ret = record_root_in_trans(trans, root); mutex_unlock(&root->fs_info->trans_mutex); - return 0; + return ret; } /* wait for commit against the current transaction to become unblocked @@ -227,6 +233,7 @@ again: if (type != TRANS_JOIN_NOLOCK) mutex_lock(&root->fs_info->trans_mutex); + /* TODO: what to do here? */ record_root_in_trans(h, root); if (type != TRANS_JOIN_NOLOCK) mutex_unlock(&root->fs_info->trans_mutex); @@ -943,6 +950,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, dentry = pending->dentry; parent_inode = dentry->d_parent->d_inode; parent_root = BTRFS_I(parent_inode)->root; + /* TODO: What to do here? */ record_root_in_trans(trans, parent_root); /* @@ -961,6 +969,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, ret = btrfs_update_inode(trans, parent_root, parent_inode); BUG_ON(ret); + /* TODO: What to do here? */ record_root_in_trans(trans, root); btrfs_set_root_last_snapshot(&root->root_item, trans->transid); memcpy(new_root_item, &root->root_item, sizeof(*new_root_item)); diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index a29f193..bc25896 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -3106,6 +3106,7 @@ again: BUG_ON(!wc.replay_dest); wc.replay_dest->log_root = log; + /* TODO: What to do here? */ btrfs_record_root_in_trans(trans, wc.replay_dest); ret = walk_log_tree(trans, log, &wc); BUG_ON(ret);