aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/inode.c
diff options
context:
space:
mode:
authorTsutomu Itoh <t-itoh@jp.fujitsu.com>2011-01-24 21:51:38 -0500
committerChris Mason <chris.mason@oracle.com>2011-01-28 16:40:37 -0500
commit3612b49598c303cfb22a4b609427f829828e2427 (patch)
treed0e9eabb176777ab80af5d78eab0555044172370 /fs/btrfs/inode.c
parent34d19bada00f4825588b338a8ee193820f9ceeb0 (diff)
btrfs: fix return value check of btrfs_join_transaction()
The error check of btrfs_join_transaction()/btrfs_join_transaction_nolock() is added, and the mistake of the error check in several places is corrected. For more stable Btrfs, I think that we should reduce BUG_ON(). But, I think that long time is necessary for this. So, I propose this patch as a short-term solution. With this patch: - To more stable Btrfs, the part that should be corrected is clarified. - The panic isn't done by the NULL pointer reference etc. (even if BUG_ON() is increased temporarily) - The error code is returned in the place where the error can be easily returned. As a long-term plan: - BUG_ON() is reduced by using the forced-readonly framework, etc. Signed-off-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com> Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/inode.c')
-rw-r--r--fs/btrfs/inode.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 2b7d251d6ad1..40fee137dd11 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -416,7 +416,7 @@ again:
416 } 416 }
417 if (start == 0) { 417 if (start == 0) {
418 trans = btrfs_join_transaction(root, 1); 418 trans = btrfs_join_transaction(root, 1);
419 BUG_ON(!trans); 419 BUG_ON(IS_ERR(trans));
420 btrfs_set_trans_block_group(trans, inode); 420 btrfs_set_trans_block_group(trans, inode);
421 trans->block_rsv = &root->fs_info->delalloc_block_rsv; 421 trans->block_rsv = &root->fs_info->delalloc_block_rsv;
422 422
@@ -612,6 +612,7 @@ retry:
612 GFP_NOFS); 612 GFP_NOFS);
613 613
614 trans = btrfs_join_transaction(root, 1); 614 trans = btrfs_join_transaction(root, 1);
615 BUG_ON(IS_ERR(trans));
615 ret = btrfs_reserve_extent(trans, root, 616 ret = btrfs_reserve_extent(trans, root,
616 async_extent->compressed_size, 617 async_extent->compressed_size,
617 async_extent->compressed_size, 618 async_extent->compressed_size,
@@ -771,7 +772,7 @@ static noinline int cow_file_range(struct inode *inode,
771 772
772 BUG_ON(root == root->fs_info->tree_root); 773 BUG_ON(root == root->fs_info->tree_root);
773 trans = btrfs_join_transaction(root, 1); 774 trans = btrfs_join_transaction(root, 1);
774 BUG_ON(!trans); 775 BUG_ON(IS_ERR(trans));
775 btrfs_set_trans_block_group(trans, inode); 776 btrfs_set_trans_block_group(trans, inode);
776 trans->block_rsv = &root->fs_info->delalloc_block_rsv; 777 trans->block_rsv = &root->fs_info->delalloc_block_rsv;
777 778
@@ -1049,7 +1050,7 @@ static noinline int run_delalloc_nocow(struct inode *inode,
1049 } else { 1050 } else {
1050 trans = btrfs_join_transaction(root, 1); 1051 trans = btrfs_join_transaction(root, 1);
1051 } 1052 }
1052 BUG_ON(!trans); 1053 BUG_ON(IS_ERR(trans));
1053 1054
1054 cow_start = (u64)-1; 1055 cow_start = (u64)-1;
1055 cur_offset = start; 1056 cur_offset = start;
@@ -1704,7 +1705,7 @@ static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end)
1704 trans = btrfs_join_transaction_nolock(root, 1); 1705 trans = btrfs_join_transaction_nolock(root, 1);
1705 else 1706 else
1706 trans = btrfs_join_transaction(root, 1); 1707 trans = btrfs_join_transaction(root, 1);
1707 BUG_ON(!trans); 1708 BUG_ON(IS_ERR(trans));
1708 btrfs_set_trans_block_group(trans, inode); 1709 btrfs_set_trans_block_group(trans, inode);
1709 trans->block_rsv = &root->fs_info->delalloc_block_rsv; 1710 trans->block_rsv = &root->fs_info->delalloc_block_rsv;
1710 ret = btrfs_update_inode(trans, root, inode); 1711 ret = btrfs_update_inode(trans, root, inode);
@@ -1721,6 +1722,7 @@ static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end)
1721 trans = btrfs_join_transaction_nolock(root, 1); 1722 trans = btrfs_join_transaction_nolock(root, 1);
1722 else 1723 else
1723 trans = btrfs_join_transaction(root, 1); 1724 trans = btrfs_join_transaction(root, 1);
1725 BUG_ON(IS_ERR(trans));
1724 btrfs_set_trans_block_group(trans, inode); 1726 btrfs_set_trans_block_group(trans, inode);
1725 trans->block_rsv = &root->fs_info->delalloc_block_rsv; 1727 trans->block_rsv = &root->fs_info->delalloc_block_rsv;
1726 1728
@@ -2382,6 +2384,7 @@ void btrfs_orphan_cleanup(struct btrfs_root *root)
2382 2384
2383 if (root->orphan_block_rsv || root->orphan_item_inserted) { 2385 if (root->orphan_block_rsv || root->orphan_item_inserted) {
2384 trans = btrfs_join_transaction(root, 1); 2386 trans = btrfs_join_transaction(root, 1);
2387 BUG_ON(IS_ERR(trans));
2385 btrfs_end_transaction(trans, root); 2388 btrfs_end_transaction(trans, root);
2386 } 2389 }
2387 2390
@@ -4350,6 +4353,8 @@ int btrfs_write_inode(struct inode *inode, struct writeback_control *wbc)
4350 trans = btrfs_join_transaction_nolock(root, 1); 4353 trans = btrfs_join_transaction_nolock(root, 1);
4351 else 4354 else
4352 trans = btrfs_join_transaction(root, 1); 4355 trans = btrfs_join_transaction(root, 1);
4356 if (IS_ERR(trans))
4357 return PTR_ERR(trans);
4353 btrfs_set_trans_block_group(trans, inode); 4358 btrfs_set_trans_block_group(trans, inode);
4354 if (nolock) 4359 if (nolock)
4355 ret = btrfs_end_transaction_nolock(trans, root); 4360 ret = btrfs_end_transaction_nolock(trans, root);
@@ -4375,6 +4380,7 @@ void btrfs_dirty_inode(struct inode *inode)
4375 return; 4380 return;
4376 4381
4377 trans = btrfs_join_transaction(root, 1); 4382 trans = btrfs_join_transaction(root, 1);
4383 BUG_ON(IS_ERR(trans));
4378 btrfs_set_trans_block_group(trans, inode); 4384 btrfs_set_trans_block_group(trans, inode);
4379 4385
4380 ret = btrfs_update_inode(trans, root, inode); 4386 ret = btrfs_update_inode(trans, root, inode);
@@ -5179,6 +5185,8 @@ again:
5179 em = NULL; 5185 em = NULL;
5180 btrfs_release_path(root, path); 5186 btrfs_release_path(root, path);
5181 trans = btrfs_join_transaction(root, 1); 5187 trans = btrfs_join_transaction(root, 1);
5188 if (IS_ERR(trans))
5189 return ERR_CAST(trans);
5182 goto again; 5190 goto again;
5183 } 5191 }
5184 map = kmap(page); 5192 map = kmap(page);
@@ -5283,8 +5291,8 @@ static struct extent_map *btrfs_new_extent_direct(struct inode *inode,
5283 btrfs_drop_extent_cache(inode, start, start + len - 1, 0); 5291 btrfs_drop_extent_cache(inode, start, start + len - 1, 0);
5284 5292
5285 trans = btrfs_join_transaction(root, 0); 5293 trans = btrfs_join_transaction(root, 0);
5286 if (!trans) 5294 if (IS_ERR(trans))
5287 return ERR_PTR(-ENOMEM); 5295 return ERR_CAST(trans);
5288 5296
5289 trans->block_rsv = &root->fs_info->delalloc_block_rsv; 5297 trans->block_rsv = &root->fs_info->delalloc_block_rsv;
5290 5298
@@ -5508,7 +5516,7 @@ static int btrfs_get_blocks_direct(struct inode *inode, sector_t iblock,
5508 * while we look for nocow cross refs 5516 * while we look for nocow cross refs
5509 */ 5517 */
5510 trans = btrfs_join_transaction(root, 0); 5518 trans = btrfs_join_transaction(root, 0);
5511 if (!trans) 5519 if (IS_ERR(trans))
5512 goto must_cow; 5520 goto must_cow;
5513 5521
5514 if (can_nocow_odirect(trans, inode, start, len) == 1) { 5522 if (can_nocow_odirect(trans, inode, start, len) == 1) {
@@ -5643,7 +5651,7 @@ again:
5643 BUG_ON(!ordered); 5651 BUG_ON(!ordered);
5644 5652
5645 trans = btrfs_join_transaction(root, 1); 5653 trans = btrfs_join_transaction(root, 1);
5646 if (!trans) { 5654 if (IS_ERR(trans)) {
5647 err = -ENOMEM; 5655 err = -ENOMEM;
5648 goto out; 5656 goto out;
5649 } 5657 }