diff options
Diffstat (limited to 'fs/btrfs/inode.c')
-rw-r--r-- | fs/btrfs/inode.c | 98 |
1 files changed, 53 insertions, 45 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index ae762dab37f8..15fceefbca0a 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 | ||
@@ -1282,17 +1283,16 @@ static int run_delalloc_range(struct inode *inode, struct page *locked_page, | |||
1282 | return ret; | 1283 | return ret; |
1283 | } | 1284 | } |
1284 | 1285 | ||
1285 | static int btrfs_split_extent_hook(struct inode *inode, | 1286 | static void btrfs_split_extent_hook(struct inode *inode, |
1286 | struct extent_state *orig, u64 split) | 1287 | struct extent_state *orig, u64 split) |
1287 | { | 1288 | { |
1288 | /* not delalloc, ignore it */ | 1289 | /* not delalloc, ignore it */ |
1289 | if (!(orig->state & EXTENT_DELALLOC)) | 1290 | if (!(orig->state & EXTENT_DELALLOC)) |
1290 | return 0; | 1291 | return; |
1291 | 1292 | ||
1292 | spin_lock(&BTRFS_I(inode)->lock); | 1293 | spin_lock(&BTRFS_I(inode)->lock); |
1293 | BTRFS_I(inode)->outstanding_extents++; | 1294 | BTRFS_I(inode)->outstanding_extents++; |
1294 | spin_unlock(&BTRFS_I(inode)->lock); | 1295 | spin_unlock(&BTRFS_I(inode)->lock); |
1295 | return 0; | ||
1296 | } | 1296 | } |
1297 | 1297 | ||
1298 | /* | 1298 | /* |
@@ -1301,18 +1301,17 @@ static int btrfs_split_extent_hook(struct inode *inode, | |||
1301 | * extents, such as when we are doing sequential writes, so we can properly | 1301 | * extents, such as when we are doing sequential writes, so we can properly |
1302 | * account for the metadata space we'll need. | 1302 | * account for the metadata space we'll need. |
1303 | */ | 1303 | */ |
1304 | static int btrfs_merge_extent_hook(struct inode *inode, | 1304 | static void btrfs_merge_extent_hook(struct inode *inode, |
1305 | struct extent_state *new, | 1305 | struct extent_state *new, |
1306 | struct extent_state *other) | 1306 | struct extent_state *other) |
1307 | { | 1307 | { |
1308 | /* not delalloc, ignore it */ | 1308 | /* not delalloc, ignore it */ |
1309 | if (!(other->state & EXTENT_DELALLOC)) | 1309 | if (!(other->state & EXTENT_DELALLOC)) |
1310 | return 0; | 1310 | return; |
1311 | 1311 | ||
1312 | spin_lock(&BTRFS_I(inode)->lock); | 1312 | spin_lock(&BTRFS_I(inode)->lock); |
1313 | BTRFS_I(inode)->outstanding_extents--; | 1313 | BTRFS_I(inode)->outstanding_extents--; |
1314 | spin_unlock(&BTRFS_I(inode)->lock); | 1314 | spin_unlock(&BTRFS_I(inode)->lock); |
1315 | return 0; | ||
1316 | } | 1315 | } |
1317 | 1316 | ||
1318 | /* | 1317 | /* |
@@ -1320,8 +1319,8 @@ static int btrfs_merge_extent_hook(struct inode *inode, | |||
1320 | * bytes in this file, and to maintain the list of inodes that | 1319 | * bytes in this file, and to maintain the list of inodes that |
1321 | * have pending delalloc work to be done. | 1320 | * have pending delalloc work to be done. |
1322 | */ | 1321 | */ |
1323 | static int btrfs_set_bit_hook(struct inode *inode, | 1322 | static void btrfs_set_bit_hook(struct inode *inode, |
1324 | struct extent_state *state, int *bits) | 1323 | struct extent_state *state, int *bits) |
1325 | { | 1324 | { |
1326 | 1325 | ||
1327 | /* | 1326 | /* |
@@ -1351,14 +1350,13 @@ static int btrfs_set_bit_hook(struct inode *inode, | |||
1351 | } | 1350 | } |
1352 | spin_unlock(&root->fs_info->delalloc_lock); | 1351 | spin_unlock(&root->fs_info->delalloc_lock); |
1353 | } | 1352 | } |
1354 | return 0; | ||
1355 | } | 1353 | } |
1356 | 1354 | ||
1357 | /* | 1355 | /* |
1358 | * extent_io.c clear_bit_hook, see set_bit_hook for why | 1356 | * extent_io.c clear_bit_hook, see set_bit_hook for why |
1359 | */ | 1357 | */ |
1360 | static int btrfs_clear_bit_hook(struct inode *inode, | 1358 | static void btrfs_clear_bit_hook(struct inode *inode, |
1361 | struct extent_state *state, int *bits) | 1359 | struct extent_state *state, int *bits) |
1362 | { | 1360 | { |
1363 | /* | 1361 | /* |
1364 | * set_bit and clear bit hooks normally require _irqsave/restore | 1362 | * set_bit and clear bit hooks normally require _irqsave/restore |
@@ -1395,7 +1393,6 @@ static int btrfs_clear_bit_hook(struct inode *inode, | |||
1395 | } | 1393 | } |
1396 | spin_unlock(&root->fs_info->delalloc_lock); | 1394 | spin_unlock(&root->fs_info->delalloc_lock); |
1397 | } | 1395 | } |
1398 | return 0; | ||
1399 | } | 1396 | } |
1400 | 1397 | ||
1401 | /* | 1398 | /* |
@@ -1645,7 +1642,8 @@ static int insert_reserved_file_extent(struct btrfs_trans_handle *trans, | |||
1645 | int ret; | 1642 | int ret; |
1646 | 1643 | ||
1647 | path = btrfs_alloc_path(); | 1644 | path = btrfs_alloc_path(); |
1648 | BUG_ON(!path); | 1645 | if (!path) |
1646 | return -ENOMEM; | ||
1649 | 1647 | ||
1650 | path->leave_spinning = 1; | 1648 | path->leave_spinning = 1; |
1651 | 1649 | ||
@@ -2215,7 +2213,8 @@ int btrfs_orphan_add(struct btrfs_trans_handle *trans, struct inode *inode) | |||
2215 | 2213 | ||
2216 | if (!root->orphan_block_rsv) { | 2214 | if (!root->orphan_block_rsv) { |
2217 | block_rsv = btrfs_alloc_block_rsv(root); | 2215 | block_rsv = btrfs_alloc_block_rsv(root); |
2218 | BUG_ON(!block_rsv); | 2216 | if (!block_rsv) |
2217 | return -ENOMEM; | ||
2219 | } | 2218 | } |
2220 | 2219 | ||
2221 | spin_lock(&root->orphan_lock); | 2220 | spin_lock(&root->orphan_lock); |
@@ -2517,7 +2516,9 @@ static void btrfs_read_locked_inode(struct inode *inode) | |||
2517 | filled = true; | 2516 | filled = true; |
2518 | 2517 | ||
2519 | path = btrfs_alloc_path(); | 2518 | path = btrfs_alloc_path(); |
2520 | BUG_ON(!path); | 2519 | if (!path) |
2520 | goto make_bad; | ||
2521 | |||
2521 | path->leave_spinning = 1; | 2522 | path->leave_spinning = 1; |
2522 | memcpy(&location, &BTRFS_I(inode)->location, sizeof(location)); | 2523 | memcpy(&location, &BTRFS_I(inode)->location, sizeof(location)); |
2523 | 2524 | ||
@@ -2998,13 +2999,16 @@ static int btrfs_unlink(struct inode *dir, struct dentry *dentry) | |||
2998 | 2999 | ||
2999 | ret = btrfs_unlink_inode(trans, root, dir, dentry->d_inode, | 3000 | ret = btrfs_unlink_inode(trans, root, dir, dentry->d_inode, |
3000 | dentry->d_name.name, dentry->d_name.len); | 3001 | dentry->d_name.name, dentry->d_name.len); |
3001 | BUG_ON(ret); | 3002 | if (ret) |
3003 | goto out; | ||
3002 | 3004 | ||
3003 | if (inode->i_nlink == 0) { | 3005 | if (inode->i_nlink == 0) { |
3004 | ret = btrfs_orphan_add(trans, inode); | 3006 | ret = btrfs_orphan_add(trans, inode); |
3005 | BUG_ON(ret); | 3007 | if (ret) |
3008 | goto out; | ||
3006 | } | 3009 | } |
3007 | 3010 | ||
3011 | out: | ||
3008 | nr = trans->blocks_used; | 3012 | nr = trans->blocks_used; |
3009 | __unlink_end_trans(trans, root); | 3013 | __unlink_end_trans(trans, root); |
3010 | btrfs_btree_balance_dirty(root, nr); | 3014 | btrfs_btree_balance_dirty(root, nr); |
@@ -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; |
@@ -4451,7 +4467,8 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans, | |||
4451 | int owner; | 4467 | int owner; |
4452 | 4468 | ||
4453 | path = btrfs_alloc_path(); | 4469 | path = btrfs_alloc_path(); |
4454 | BUG_ON(!path); | 4470 | if (!path) |
4471 | return ERR_PTR(-ENOMEM); | ||
4455 | 4472 | ||
4456 | inode = new_inode(root->fs_info->sb); | 4473 | inode = new_inode(root->fs_info->sb); |
4457 | if (!inode) { | 4474 | if (!inode) { |
@@ -6711,19 +6728,6 @@ int btrfs_create_subvol_root(struct btrfs_trans_handle *trans, | |||
6711 | return 0; | 6728 | return 0; |
6712 | } | 6729 | } |
6713 | 6730 | ||
6714 | /* helper function for file defrag and space balancing. This | ||
6715 | * forces readahead on a given range of bytes in an inode | ||
6716 | */ | ||
6717 | unsigned long btrfs_force_ra(struct address_space *mapping, | ||
6718 | struct file_ra_state *ra, struct file *file, | ||
6719 | pgoff_t offset, pgoff_t last_index) | ||
6720 | { | ||
6721 | pgoff_t req_size = last_index - offset + 1; | ||
6722 | |||
6723 | page_cache_sync_readahead(mapping, ra, file, offset, req_size); | ||
6724 | return offset + req_size; | ||
6725 | } | ||
6726 | |||
6727 | struct inode *btrfs_alloc_inode(struct super_block *sb) | 6731 | struct inode *btrfs_alloc_inode(struct super_block *sb) |
6728 | { | 6732 | { |
6729 | struct btrfs_inode *ei; | 6733 | struct btrfs_inode *ei; |
@@ -7206,7 +7210,11 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry, | |||
7206 | goto out_unlock; | 7210 | goto out_unlock; |
7207 | 7211 | ||
7208 | path = btrfs_alloc_path(); | 7212 | path = btrfs_alloc_path(); |
7209 | BUG_ON(!path); | 7213 | if (!path) { |
7214 | err = -ENOMEM; | ||
7215 | drop_inode = 1; | ||
7216 | goto out_unlock; | ||
7217 | } | ||
7210 | key.objectid = btrfs_ino(inode); | 7218 | key.objectid = btrfs_ino(inode); |
7211 | key.offset = 0; | 7219 | key.offset = 0; |
7212 | btrfs_set_key_type(&key, BTRFS_EXTENT_DATA_KEY); | 7220 | btrfs_set_key_type(&key, BTRFS_EXTENT_DATA_KEY); |