aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2011-08-01 14:27:34 -0400
committerChris Mason <chris.mason@oracle.com>2011-08-01 14:27:34 -0400
commitb43b31bdf2e662006c27cc4dcccf863312d62bc1 (patch)
tree9e12413edbd9d7a77e4c0b692dd28ca4ae5039bd
parentff95acb6733d41a8d45feb0e18b96df25e610e78 (diff)
parent38a1a919535742af677303271eb4ff731547b706 (diff)
Merge branch 'alloc_path' of git://git.kernel.org/pub/scm/linux/kernel/git/mfasheh/btrfs-error-handling into for-linus
-rw-r--r--fs/btrfs/extent-tree.c24
-rw-r--r--fs/btrfs/file-item.c7
-rw-r--r--fs/btrfs/file.c3
-rw-r--r--fs/btrfs/inode.c49
-rw-r--r--fs/btrfs/tree-log.c12
-rw-r--r--fs/btrfs/volumes.c12
6 files changed, 78 insertions, 29 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 4d08ed79405d..55bddffede73 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -663,7 +663,9 @@ int btrfs_lookup_extent(struct btrfs_root *root, u64 start, u64 len)
663 struct btrfs_path *path; 663 struct btrfs_path *path;
664 664
665 path = btrfs_alloc_path(); 665 path = btrfs_alloc_path();
666 BUG_ON(!path); 666 if (!path)
667 return -ENOMEM;
668
667 key.objectid = start; 669 key.objectid = start;
668 key.offset = len; 670 key.offset = len;
669 btrfs_set_key_type(&key, BTRFS_EXTENT_ITEM_KEY); 671 btrfs_set_key_type(&key, BTRFS_EXTENT_ITEM_KEY);
@@ -3272,6 +3274,9 @@ again:
3272 } 3274 }
3273 3275
3274 ret = btrfs_alloc_chunk(trans, extent_root, flags); 3276 ret = btrfs_alloc_chunk(trans, extent_root, flags);
3277 if (ret < 0 && ret != -ENOSPC)
3278 goto out;
3279
3275 spin_lock(&space_info->lock); 3280 spin_lock(&space_info->lock);
3276 if (ret) 3281 if (ret)
3277 space_info->full = 1; 3282 space_info->full = 1;
@@ -3281,6 +3286,7 @@ again:
3281 space_info->force_alloc = CHUNK_ALLOC_NO_FORCE; 3286 space_info->force_alloc = CHUNK_ALLOC_NO_FORCE;
3282 space_info->chunk_alloc = 0; 3287 space_info->chunk_alloc = 0;
3283 spin_unlock(&space_info->lock); 3288 spin_unlock(&space_info->lock);
3289out:
3284 mutex_unlock(&extent_root->fs_info->chunk_mutex); 3290 mutex_unlock(&extent_root->fs_info->chunk_mutex);
3285 return ret; 3291 return ret;
3286} 3292}
@@ -5501,7 +5507,8 @@ static int alloc_reserved_tree_block(struct btrfs_trans_handle *trans,
5501 u32 size = sizeof(*extent_item) + sizeof(*block_info) + sizeof(*iref); 5507 u32 size = sizeof(*extent_item) + sizeof(*block_info) + sizeof(*iref);
5502 5508
5503 path = btrfs_alloc_path(); 5509 path = btrfs_alloc_path();
5504 BUG_ON(!path); 5510 if (!path)
5511 return -ENOMEM;
5505 5512
5506 path->leave_spinning = 1; 5513 path->leave_spinning = 1;
5507 ret = btrfs_insert_empty_item(trans, fs_info->extent_root, path, 5514 ret = btrfs_insert_empty_item(trans, fs_info->extent_root, path,
@@ -6272,10 +6279,14 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
6272 int level; 6279 int level;
6273 6280
6274 path = btrfs_alloc_path(); 6281 path = btrfs_alloc_path();
6275 BUG_ON(!path); 6282 if (!path)
6283 return -ENOMEM;
6276 6284
6277 wc = kzalloc(sizeof(*wc), GFP_NOFS); 6285 wc = kzalloc(sizeof(*wc), GFP_NOFS);
6278 BUG_ON(!wc); 6286 if (!wc) {
6287 btrfs_free_path(path);
6288 return -ENOMEM;
6289 }
6279 6290
6280 trans = btrfs_start_transaction(tree_root, 0); 6291 trans = btrfs_start_transaction(tree_root, 0);
6281 BUG_ON(IS_ERR(trans)); 6292 BUG_ON(IS_ERR(trans));
@@ -7183,7 +7194,10 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
7183 spin_unlock(&cluster->refill_lock); 7194 spin_unlock(&cluster->refill_lock);
7184 7195
7185 path = btrfs_alloc_path(); 7196 path = btrfs_alloc_path();
7186 BUG_ON(!path); 7197 if (!path) {
7198 ret = -ENOMEM;
7199 goto out;
7200 }
7187 7201
7188 inode = lookup_free_space_inode(root, block_group, path); 7202 inode = lookup_free_space_inode(root, block_group, path);
7189 if (!IS_ERR(inode)) { 7203 if (!IS_ERR(inode)) {
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c
index 08bcfa92a222..b910694f61ed 100644
--- a/fs/btrfs/file-item.c
+++ b/fs/btrfs/file-item.c
@@ -291,7 +291,8 @@ int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end,
291 u16 csum_size = btrfs_super_csum_size(&root->fs_info->super_copy); 291 u16 csum_size = btrfs_super_csum_size(&root->fs_info->super_copy);
292 292
293 path = btrfs_alloc_path(); 293 path = btrfs_alloc_path();
294 BUG_ON(!path); 294 if (!path)
295 return -ENOMEM;
295 296
296 if (search_commit) { 297 if (search_commit) {
297 path->skip_locking = 1; 298 path->skip_locking = 1;
@@ -677,7 +678,9 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans,
677 btrfs_super_csum_size(&root->fs_info->super_copy); 678 btrfs_super_csum_size(&root->fs_info->super_copy);
678 679
679 path = btrfs_alloc_path(); 680 path = btrfs_alloc_path();
680 BUG_ON(!path); 681 if (!path)
682 return -ENOMEM;
683
681 sector_sum = sums->sums; 684 sector_sum = sums->sums;
682again: 685again:
683 next_offset = (u64)-1; 686 next_offset = (u64)-1;
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 6e56a468d1f5..41ca5fdaee6c 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -855,7 +855,8 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
855 btrfs_drop_extent_cache(inode, start, end - 1, 0); 855 btrfs_drop_extent_cache(inode, start, end - 1, 0);
856 856
857 path = btrfs_alloc_path(); 857 path = btrfs_alloc_path();
858 BUG_ON(!path); 858 if (!path)
859 return -ENOMEM;
859again: 860again:
860 recow = 0; 861 recow = 0;
861 split = start; 862 split = start;
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 586cf6a43855..4360ccb191b1 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1061,7 +1061,8 @@ static noinline int run_delalloc_nocow(struct inode *inode,
1061 u64 ino = btrfs_ino(inode); 1061 u64 ino = btrfs_ino(inode);
1062 1062
1063 path = btrfs_alloc_path(); 1063 path = btrfs_alloc_path();
1064 BUG_ON(!path); 1064 if (!path)
1065 return -ENOMEM;
1065 1066
1066 nolock = btrfs_is_free_space_inode(root, inode); 1067 nolock = btrfs_is_free_space_inode(root, inode);
1067 1068
@@ -1645,7 +1646,8 @@ static int insert_reserved_file_extent(struct btrfs_trans_handle *trans,
1645 int ret; 1646 int ret;
1646 1647
1647 path = btrfs_alloc_path(); 1648 path = btrfs_alloc_path();
1648 BUG_ON(!path); 1649 if (!path)
1650 return -ENOMEM;
1649 1651
1650 path->leave_spinning = 1; 1652 path->leave_spinning = 1;
1651 1653
@@ -2517,7 +2519,9 @@ static void btrfs_read_locked_inode(struct inode *inode)
2517 filled = true; 2519 filled = true;
2518 2520
2519 path = btrfs_alloc_path(); 2521 path = btrfs_alloc_path();
2520 BUG_ON(!path); 2522 if (!path)
2523 goto make_bad;
2524
2521 path->leave_spinning = 1; 2525 path->leave_spinning = 1;
2522 memcpy(&location, &BTRFS_I(inode)->location, sizeof(location)); 2526 memcpy(&location, &BTRFS_I(inode)->location, sizeof(location));
2523 2527
@@ -3147,6 +3151,11 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
3147 3151
3148 BUG_ON(new_size > 0 && min_type != BTRFS_EXTENT_DATA_KEY); 3152 BUG_ON(new_size > 0 && min_type != BTRFS_EXTENT_DATA_KEY);
3149 3153
3154 path = btrfs_alloc_path();
3155 if (!path)
3156 return -ENOMEM;
3157 path->reada = -1;
3158
3150 if (root->ref_cows || root == root->fs_info->tree_root) 3159 if (root->ref_cows || root == root->fs_info->tree_root)
3151 btrfs_drop_extent_cache(inode, new_size & (~mask), (u64)-1, 0); 3160 btrfs_drop_extent_cache(inode, new_size & (~mask), (u64)-1, 0);
3152 3161
@@ -3159,10 +3168,6 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
3159 if (min_type == 0 && root == BTRFS_I(inode)->root) 3168 if (min_type == 0 && root == BTRFS_I(inode)->root)
3160 btrfs_kill_delayed_inode_items(inode); 3169 btrfs_kill_delayed_inode_items(inode);
3161 3170
3162 path = btrfs_alloc_path();
3163 BUG_ON(!path);
3164 path->reada = -1;
3165
3166 key.objectid = ino; 3171 key.objectid = ino;
3167 key.offset = (u64)-1; 3172 key.offset = (u64)-1;
3168 key.type = (u8)-1; 3173 key.type = (u8)-1;
@@ -3690,7 +3695,8 @@ static int btrfs_inode_by_name(struct inode *dir, struct dentry *dentry,
3690 int ret = 0; 3695 int ret = 0;
3691 3696
3692 path = btrfs_alloc_path(); 3697 path = btrfs_alloc_path();
3693 BUG_ON(!path); 3698 if (!path)
3699 return -ENOMEM;
3694 3700
3695 di = btrfs_lookup_dir_item(NULL, root, path, btrfs_ino(dir), name, 3701 di = btrfs_lookup_dir_item(NULL, root, path, btrfs_ino(dir), name,
3696 namelen, 0); 3702 namelen, 0);
@@ -3946,6 +3952,7 @@ struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location,
3946 struct btrfs_root *root, int *new) 3952 struct btrfs_root *root, int *new)
3947{ 3953{
3948 struct inode *inode; 3954 struct inode *inode;
3955 int bad_inode = 0;
3949 3956
3950 inode = btrfs_iget_locked(s, location->objectid, root); 3957 inode = btrfs_iget_locked(s, location->objectid, root);
3951 if (!inode) 3958 if (!inode)
@@ -3955,10 +3962,19 @@ struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location,
3955 BTRFS_I(inode)->root = root; 3962 BTRFS_I(inode)->root = root;
3956 memcpy(&BTRFS_I(inode)->location, location, sizeof(*location)); 3963 memcpy(&BTRFS_I(inode)->location, location, sizeof(*location));
3957 btrfs_read_locked_inode(inode); 3964 btrfs_read_locked_inode(inode);
3958 inode_tree_add(inode); 3965 if (!is_bad_inode(inode)) {
3959 unlock_new_inode(inode); 3966 inode_tree_add(inode);
3960 if (new) 3967 unlock_new_inode(inode);
3961 *new = 1; 3968 if (new)
3969 *new = 1;
3970 } else {
3971 bad_inode = 1;
3972 }
3973 }
3974
3975 if (bad_inode) {
3976 iput(inode);
3977 inode = ERR_PTR(-ESTALE);
3962 } 3978 }
3963 3979
3964 return inode; 3980 return inode;
@@ -4415,7 +4431,8 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans,
4415 int owner; 4431 int owner;
4416 4432
4417 path = btrfs_alloc_path(); 4433 path = btrfs_alloc_path();
4418 BUG_ON(!path); 4434 if (!path)
4435 return ERR_PTR(-ENOMEM);
4419 4436
4420 inode = new_inode(root->fs_info->sb); 4437 inode = new_inode(root->fs_info->sb);
4421 if (!inode) { 4438 if (!inode) {
@@ -7172,7 +7189,11 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry,
7172 goto out_unlock; 7189 goto out_unlock;
7173 7190
7174 path = btrfs_alloc_path(); 7191 path = btrfs_alloc_path();
7175 BUG_ON(!path); 7192 if (!path) {
7193 err = -ENOMEM;
7194 drop_inode = 1;
7195 goto out_unlock;
7196 }
7176 key.objectid = btrfs_ino(inode); 7197 key.objectid = btrfs_ino(inode);
7177 key.offset = 0; 7198 key.offset = 0;
7178 btrfs_set_key_type(&key, BTRFS_EXTENT_DATA_KEY); 7199 btrfs_set_key_type(&key, BTRFS_EXTENT_DATA_KEY);
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index ac278dd83175..babee65f8eda 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -1617,7 +1617,8 @@ static int replay_one_buffer(struct btrfs_root *log, struct extent_buffer *eb,
1617 return 0; 1617 return 0;
1618 1618
1619 path = btrfs_alloc_path(); 1619 path = btrfs_alloc_path();
1620 BUG_ON(!path); 1620 if (!path)
1621 return -ENOMEM;
1621 1622
1622 nritems = btrfs_header_nritems(eb); 1623 nritems = btrfs_header_nritems(eb);
1623 for (i = 0; i < nritems; i++) { 1624 for (i = 0; i < nritems; i++) {
@@ -1723,7 +1724,9 @@ static noinline int walk_down_log_tree(struct btrfs_trans_handle *trans,
1723 return -ENOMEM; 1724 return -ENOMEM;
1724 1725
1725 if (*level == 1) { 1726 if (*level == 1) {
1726 wc->process_func(root, next, wc, ptr_gen); 1727 ret = wc->process_func(root, next, wc, ptr_gen);
1728 if (ret)
1729 return ret;
1727 1730
1728 path->slots[*level]++; 1731 path->slots[*level]++;
1729 if (wc->free) { 1732 if (wc->free) {
@@ -1788,8 +1791,11 @@ static noinline int walk_up_log_tree(struct btrfs_trans_handle *trans,
1788 parent = path->nodes[*level + 1]; 1791 parent = path->nodes[*level + 1];
1789 1792
1790 root_owner = btrfs_header_owner(parent); 1793 root_owner = btrfs_header_owner(parent);
1791 wc->process_func(root, path->nodes[*level], wc, 1794 ret = wc->process_func(root, path->nodes[*level], wc,
1792 btrfs_header_generation(path->nodes[*level])); 1795 btrfs_header_generation(path->nodes[*level]));
1796 if (ret)
1797 return ret;
1798
1793 if (wc->free) { 1799 if (wc->free) {
1794 struct extent_buffer *next; 1800 struct extent_buffer *next;
1795 1801
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index b89e372c7544..53875ae73ad4 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1037,7 +1037,8 @@ static noinline int find_next_chunk(struct btrfs_root *root,
1037 struct btrfs_key found_key; 1037 struct btrfs_key found_key;
1038 1038
1039 path = btrfs_alloc_path(); 1039 path = btrfs_alloc_path();
1040 BUG_ON(!path); 1040 if (!path)
1041 return -ENOMEM;
1041 1042
1042 key.objectid = objectid; 1043 key.objectid = objectid;
1043 key.offset = (u64)-1; 1044 key.offset = (u64)-1;
@@ -2061,8 +2062,10 @@ int btrfs_balance(struct btrfs_root *dev_root)
2061 2062
2062 /* step two, relocate all the chunks */ 2063 /* step two, relocate all the chunks */
2063 path = btrfs_alloc_path(); 2064 path = btrfs_alloc_path();
2064 BUG_ON(!path); 2065 if (!path) {
2065 2066 ret = -ENOMEM;
2067 goto error;
2068 }
2066 key.objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID; 2069 key.objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID;
2067 key.offset = (u64)-1; 2070 key.offset = (u64)-1;
2068 key.type = BTRFS_CHUNK_ITEM_KEY; 2071 key.type = BTRFS_CHUNK_ITEM_KEY;
@@ -2661,7 +2664,8 @@ static noinline int init_first_rw_device(struct btrfs_trans_handle *trans,
2661 2664
2662 ret = find_next_chunk(fs_info->chunk_root, 2665 ret = find_next_chunk(fs_info->chunk_root,
2663 BTRFS_FIRST_CHUNK_TREE_OBJECTID, &chunk_offset); 2666 BTRFS_FIRST_CHUNK_TREE_OBJECTID, &chunk_offset);
2664 BUG_ON(ret); 2667 if (ret)
2668 return ret;
2665 2669
2666 alloc_profile = BTRFS_BLOCK_GROUP_METADATA | 2670 alloc_profile = BTRFS_BLOCK_GROUP_METADATA |
2667 (fs_info->metadata_alloc_profile & 2671 (fs_info->metadata_alloc_profile &