Commit 4289a667 authored by Josef Bacik's avatar Josef Bacik

Btrfs: fix how we reserve space for deleting inodes

I converted btrfs_truncate to do sane reservations for truncate, but didn't
convert btrfs_evict_inode.  Basically we need to save the orphan_rsv for
deleting the orphan item, and do normal reservations for our truncate.  Thanks,
Signed-off-by: default avatarJosef Bacik <josef@redhat.com>
parent 37be25bc
...@@ -3527,6 +3527,8 @@ void btrfs_evict_inode(struct inode *inode) ...@@ -3527,6 +3527,8 @@ void btrfs_evict_inode(struct inode *inode)
{ {
struct btrfs_trans_handle *trans; struct btrfs_trans_handle *trans;
struct btrfs_root *root = BTRFS_I(inode)->root; struct btrfs_root *root = BTRFS_I(inode)->root;
struct btrfs_block_rsv *rsv;
u64 min_size = btrfs_calc_trans_metadata_size(root, 2);
unsigned long nr; unsigned long nr;
int ret; int ret;
...@@ -3554,22 +3556,44 @@ void btrfs_evict_inode(struct inode *inode) ...@@ -3554,22 +3556,44 @@ void btrfs_evict_inode(struct inode *inode)
goto no_delete; goto no_delete;
} }
rsv = btrfs_alloc_block_rsv(root);
if (!rsv) {
btrfs_orphan_del(NULL, inode);
goto no_delete;
}
btrfs_i_size_write(inode, 0); btrfs_i_size_write(inode, 0);
/*
* This is a bit simpler than btrfs_truncate since
*
* 1) We've already reserved our space for our orphan item in the
* unlink.
* 2) We're going to delete the inode item, so we don't need to update
* it at all.
*
* So we just need to reserve some slack space in case we add bytes when
* doing the truncate.
*/
while (1) { while (1) {
trans = btrfs_join_transaction(root); ret = btrfs_block_rsv_check(NULL, root, rsv, min_size, 0);
BUG_ON(IS_ERR(trans));
trans->block_rsv = root->orphan_block_rsv;
ret = btrfs_block_rsv_check(trans, root,
root->orphan_block_rsv, 0, 5);
if (ret) { if (ret) {
BUG_ON(ret != -EAGAIN); printk(KERN_WARNING "Could not get space for a "
ret = btrfs_commit_transaction(trans, root); "delete, will truncate on mount\n");
BUG_ON(ret); btrfs_orphan_del(NULL, inode);
continue; btrfs_free_block_rsv(root, rsv);
goto no_delete;
} }
trans = btrfs_start_transaction(root, 0);
if (IS_ERR(trans)) {
btrfs_orphan_del(NULL, inode);
btrfs_free_block_rsv(root, rsv);
goto no_delete;
}
trans->block_rsv = rsv;
ret = btrfs_truncate_inode_items(trans, root, inode, 0, 0); ret = btrfs_truncate_inode_items(trans, root, inode, 0, 0);
if (ret != -EAGAIN) if (ret != -EAGAIN)
break; break;
...@@ -3578,14 +3602,17 @@ void btrfs_evict_inode(struct inode *inode) ...@@ -3578,14 +3602,17 @@ void btrfs_evict_inode(struct inode *inode)
btrfs_end_transaction(trans, root); btrfs_end_transaction(trans, root);
trans = NULL; trans = NULL;
btrfs_btree_balance_dirty(root, nr); btrfs_btree_balance_dirty(root, nr);
} }
btrfs_free_block_rsv(root, rsv);
if (ret == 0) { if (ret == 0) {
trans->block_rsv = root->orphan_block_rsv;
ret = btrfs_orphan_del(trans, inode); ret = btrfs_orphan_del(trans, inode);
BUG_ON(ret); BUG_ON(ret);
} }
trans->block_rsv = &root->fs_info->trans_block_rsv;
if (!(root == root->fs_info->tree_root || if (!(root == root->fs_info->tree_root ||
root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)) root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID))
btrfs_return_ino(root, btrfs_ino(inode)); btrfs_return_ino(root, btrfs_ino(inode));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment