From patchwork Tue Jan 25 02:51: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: 503881 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 p0P2qbKP025120 for ; Tue, 25 Jan 2011 02:52:39 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752685Ab1AYCwb (ORCPT ); Mon, 24 Jan 2011 21:52:31 -0500 Received: from fgwmail5.fujitsu.co.jp ([192.51.44.35]:51646 "EHLO fgwmail5.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751980Ab1AYCwa (ORCPT ); Mon, 24 Jan 2011 21:52:30 -0500 Received: from m4.gw.fujitsu.co.jp (unknown [10.0.50.74]) by fgwmail5.fujitsu.co.jp (Postfix) with ESMTP id 37D5C3EE0AE for ; Tue, 25 Jan 2011 11:52:25 +0900 (JST) Received: from smail (m4 [127.0.0.1]) by outgoing.m4.gw.fujitsu.co.jp (Postfix) with ESMTP id 14F2B45DE50 for ; Tue, 25 Jan 2011 11:52:25 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (s4.gw.fujitsu.co.jp [10.0.50.94]) by m4.gw.fujitsu.co.jp (Postfix) with ESMTP id F258845DE4F for ; Tue, 25 Jan 2011 11:52:24 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id E65FD1DB803B for ; Tue, 25 Jan 2011 11:52:24 +0900 (JST) Received: from m105.s.css.fujitsu.com (m105.s.css.fujitsu.com [10.249.87.105]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id A34491DB8037 for ; Tue, 25 Jan 2011 11:52:24 +0900 (JST) Received: from m105.css.fujitsu.com (m105 [127.0.0.1]) by m105.s.css.fujitsu.com (Postfix) with ESMTP id 6D8F96C8003; Tue, 25 Jan 2011 11:52:24 +0900 (JST) Received: from T-ITOH1.jp.fujitsu.com (unknown [10.124.101.86]) by m105.s.css.fujitsu.com (Postfix) with SMTP id D86AF608001; Tue, 25 Jan 2011 11:52:23 +0900 (JST) X-SecurityPolicyCheck-FJ: OK by FujitsuOutboundMailChecker v1.4.0 Received: from T-ITOH1[10.124.101.86] by T-ITOH1 (FujitsuOutboundMailChecker v1.4.0/9992[10.124.101.86]); Tue, 25 Jan 2011 11:52:06 +0900 (JST) Message-Id: <201101250251.AA00005@T-ITOH1.jp.fujitsu.com> From: Tsutomu Itoh Date: Tue, 25 Jan 2011 11:51:38 +0900 To: linux-btrfs@vger.kernel.org Cc: chris.mason@oracle.com Subject: [PATCH] btrfs: fix return value check of btrfs_join_transaction() 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 (demeter1.kernel.org [140.211.167.41]); Tue, 25 Jan 2011 02:53:42 +0000 (UTC) diff -urNp linux-2.6.38-rc2/fs/btrfs/disk-io.c linux-2.6.38-rc2.new/fs/btrfs/disk-io.c --- linux-2.6.38-rc2/fs/btrfs/disk-io.c 2011-01-22 12:01:34.000000000 +0900 +++ linux-2.6.38-rc2.new/fs/btrfs/disk-io.c 2011-01-24 13:26:29.000000000 +0900 @@ -1550,6 +1550,7 @@ static int transaction_kthread(void *arg spin_unlock(&root->fs_info->new_trans_lock); trans = btrfs_join_transaction(root, 1); + BUG_ON(IS_ERR(trans)); if (transid == trans->transid) { ret = btrfs_commit_transaction(trans, root); BUG_ON(ret); @@ -2453,10 +2454,14 @@ int btrfs_commit_super(struct btrfs_root up_write(&root->fs_info->cleanup_work_sem); trans = btrfs_join_transaction(root, 1); + if (IS_ERR(trans)) + return PTR_ERR(trans); ret = btrfs_commit_transaction(trans, root); BUG_ON(ret); /* run commit again to drop the original snapshot */ trans = btrfs_join_transaction(root, 1); + if (IS_ERR(trans)) + return PTR_ERR(trans); btrfs_commit_transaction(trans, root); ret = btrfs_write_and_wait_transaction(NULL, root); BUG_ON(ret); diff -urNp linux-2.6.38-rc2/fs/btrfs/extent-tree.c linux-2.6.38-rc2.new/fs/btrfs/extent-tree.c --- linux-2.6.38-rc2/fs/btrfs/extent-tree.c 2011-01-22 12:01:34.000000000 +0900 +++ linux-2.6.38-rc2.new/fs/btrfs/extent-tree.c 2011-01-24 13:26:29.000000000 +0900 @@ -7477,7 +7477,7 @@ int btrfs_drop_dead_reloc_roots(struct b BUG_ON(reloc_root->commit_root != NULL); while (1) { trans = btrfs_join_transaction(root, 1); - BUG_ON(!trans); + BUG_ON(IS_ERR(trans)); mutex_lock(&root->fs_info->drop_mutex); ret = btrfs_drop_snapshot(trans, reloc_root); diff -urNp linux-2.6.38-rc2/fs/btrfs/inode.c linux-2.6.38-rc2.new/fs/btrfs/inode.c --- linux-2.6.38-rc2/fs/btrfs/inode.c 2011-01-22 12:01:34.000000000 +0900 +++ linux-2.6.38-rc2.new/fs/btrfs/inode.c 2011-01-24 13:26:29.000000000 +0900 @@ -416,7 +416,7 @@ again: } if (start == 0) { trans = btrfs_join_transaction(root, 1); - BUG_ON(!trans); + BUG_ON(IS_ERR(trans)); btrfs_set_trans_block_group(trans, inode); trans->block_rsv = &root->fs_info->delalloc_block_rsv; @@ -612,6 +612,7 @@ retry: GFP_NOFS); trans = btrfs_join_transaction(root, 1); + BUG_ON(IS_ERR(trans)); ret = btrfs_reserve_extent(trans, root, async_extent->compressed_size, async_extent->compressed_size, @@ -771,7 +772,7 @@ static noinline int cow_file_range(struc BUG_ON(root == root->fs_info->tree_root); trans = btrfs_join_transaction(root, 1); - BUG_ON(!trans); + BUG_ON(IS_ERR(trans)); btrfs_set_trans_block_group(trans, inode); trans->block_rsv = &root->fs_info->delalloc_block_rsv; @@ -1049,7 +1050,7 @@ static noinline int run_delalloc_nocow(s } else { trans = btrfs_join_transaction(root, 1); } - BUG_ON(!trans); + BUG_ON(IS_ERR(trans)); cow_start = (u64)-1; cur_offset = start; @@ -1703,7 +1704,7 @@ static int btrfs_finish_ordered_io(struc trans = btrfs_join_transaction_nolock(root, 1); else trans = btrfs_join_transaction(root, 1); - BUG_ON(!trans); + BUG_ON(IS_ERR(trans)); btrfs_set_trans_block_group(trans, inode); trans->block_rsv = &root->fs_info->delalloc_block_rsv; ret = btrfs_update_inode(trans, root, inode); @@ -1720,6 +1721,7 @@ static int btrfs_finish_ordered_io(struc trans = btrfs_join_transaction_nolock(root, 1); else trans = btrfs_join_transaction(root, 1); + BUG_ON(IS_ERR(trans)); btrfs_set_trans_block_group(trans, inode); trans->block_rsv = &root->fs_info->delalloc_block_rsv; @@ -2381,6 +2383,7 @@ void btrfs_orphan_cleanup(struct btrfs_r if (root->orphan_block_rsv || root->orphan_item_inserted) { trans = btrfs_join_transaction(root, 1); + BUG_ON(IS_ERR(trans)); btrfs_end_transaction(trans, root); } @@ -4347,6 +4350,8 @@ int btrfs_write_inode(struct inode *inod trans = btrfs_join_transaction_nolock(root, 1); else trans = btrfs_join_transaction(root, 1); + if (IS_ERR(trans)) + return PTR_ERR(trans); btrfs_set_trans_block_group(trans, inode); if (nolock) ret = btrfs_end_transaction_nolock(trans, root); @@ -4372,6 +4377,7 @@ void btrfs_dirty_inode(struct inode *ino return; trans = btrfs_join_transaction(root, 1); + BUG_ON(IS_ERR(trans)); btrfs_set_trans_block_group(trans, inode); ret = btrfs_update_inode(trans, root, inode); @@ -5176,6 +5182,8 @@ again: em = NULL; btrfs_release_path(root, path); trans = btrfs_join_transaction(root, 1); + if (IS_ERR(trans)) + return ERR_CAST(trans); goto again; } map = kmap(page); @@ -5280,8 +5288,8 @@ static struct extent_map *btrfs_new_exte btrfs_drop_extent_cache(inode, start, start + len - 1, 0); trans = btrfs_join_transaction(root, 0); - if (!trans) - return ERR_PTR(-ENOMEM); + if (IS_ERR(trans)) + return ERR_CAST(trans); trans->block_rsv = &root->fs_info->delalloc_block_rsv; @@ -5505,7 +5513,7 @@ static int btrfs_get_blocks_direct(struc * while we look for nocow cross refs */ trans = btrfs_join_transaction(root, 0); - if (!trans) + if (IS_ERR(trans)) goto must_cow; if (can_nocow_odirect(trans, inode, start, len) == 1) { @@ -5640,7 +5648,7 @@ again: BUG_ON(!ordered); trans = btrfs_join_transaction(root, 1); - if (!trans) { + if (IS_ERR(trans)) { err = -ENOMEM; goto out; } diff -urNp linux-2.6.38-rc2/fs/btrfs/ioctl.c linux-2.6.38-rc2.new/fs/btrfs/ioctl.c --- linux-2.6.38-rc2/fs/btrfs/ioctl.c 2011-01-22 12:01:34.000000000 +0900 +++ linux-2.6.38-rc2.new/fs/btrfs/ioctl.c 2011-01-24 13:26:29.000000000 +0900 @@ -203,7 +203,7 @@ static int btrfs_ioctl_setflags(struct f trans = btrfs_join_transaction(root, 1); - BUG_ON(!trans); + BUG_ON(IS_ERR(trans)); ret = btrfs_update_inode(trans, root, inode); BUG_ON(ret); diff -urNp linux-2.6.38-rc2/fs/btrfs/relocation.c linux-2.6.38-rc2.new/fs/btrfs/relocation.c --- linux-2.6.38-rc2/fs/btrfs/relocation.c 2011-01-22 12:01:34.000000000 +0900 +++ linux-2.6.38-rc2.new/fs/btrfs/relocation.c 2011-01-24 13:26:29.000000000 +0900 @@ -2147,6 +2147,12 @@ again: } trans = btrfs_join_transaction(rc->extent_root, 1); + if (IS_ERR(trans)) { + if (!err) + btrfs_block_rsv_release(rc->extent_root, + rc->block_rsv, num_bytes); + return PTR_ERR(trans); + } if (!err) { if (num_bytes != rc->merging_rsv_size) { @@ -3222,6 +3228,7 @@ truncate: trans = btrfs_join_transaction(root, 0); if (IS_ERR(trans)) { btrfs_free_path(path); + ret = PTR_ERR(trans); goto out; } @@ -3628,6 +3635,7 @@ int prepare_to_relocate(struct reloc_con set_reloc_control(rc); trans = btrfs_join_transaction(rc->extent_root, 1); + BUG_ON(IS_ERR(trans)); btrfs_commit_transaction(trans, rc->extent_root); return 0; } @@ -3804,7 +3812,10 @@ static noinline_for_stack int relocate_b /* get rid of pinned extents */ trans = btrfs_join_transaction(rc->extent_root, 1); - btrfs_commit_transaction(trans, rc->extent_root); + if (IS_ERR(trans)) + err = PTR_ERR(trans); + else + btrfs_commit_transaction(trans, rc->extent_root); out_free: btrfs_free_block_rsv(rc->extent_root, rc->block_rsv); btrfs_free_path(path); @@ -4125,6 +4136,11 @@ int btrfs_recover_relocation(struct btrf set_reloc_control(rc); trans = btrfs_join_transaction(rc->extent_root, 1); + if (IS_ERR(trans)) { + unset_reloc_control(rc); + err = PTR_ERR(trans); + goto out_free; + } rc->merge_reloc_tree = 1; @@ -4154,9 +4170,13 @@ int btrfs_recover_relocation(struct btrf unset_reloc_control(rc); trans = btrfs_join_transaction(rc->extent_root, 1); - btrfs_commit_transaction(trans, rc->extent_root); -out: + if (IS_ERR(trans)) + err = PTR_ERR(trans); + else + btrfs_commit_transaction(trans, rc->extent_root); +out_free: kfree(rc); +out: while (!list_empty(&reloc_roots)) { reloc_root = list_entry(reloc_roots.next, struct btrfs_root, root_list); diff -urNp linux-2.6.38-rc2/fs/btrfs/transaction.c linux-2.6.38-rc2.new/fs/btrfs/transaction.c --- linux-2.6.38-rc2/fs/btrfs/transaction.c 2011-01-22 12:01:34.000000000 +0900 +++ linux-2.6.38-rc2.new/fs/btrfs/transaction.c 2011-01-24 13:26:29.000000000 +0900 @@ -1161,6 +1161,11 @@ int btrfs_commit_transaction_async(struc INIT_DELAYED_WORK(&ac->work, do_async_commit); ac->root = root; ac->newtrans = btrfs_join_transaction(root, 0); + if (IS_ERR(ac->newtrans)) { + int err = PTR_ERR(ac->newtrans); + kfree(ac); + return err; + } /* take transaction reference */ mutex_lock(&root->fs_info->trans_mutex);