aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/inode.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/inode.c')
-rw-r--r--fs/btrfs/inode.c49
1 files changed, 35 insertions, 14 deletions
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);