Commit 4ef31a45 authored by Josef Bacik's avatar Josef Bacik Committed by Chris Mason

Btrfs: fix the error handling wrt orphan items

There are several places where we BUG_ON() if we fail to remove the orphan items
and such, which is not ok, so remove those and either abort or just carry on.
This also fixes a problem where if we couldn't start a transaction we wouldn't
actually remove the orphan item reserve for the inode.  Thanks,
Signed-off-by: default avatarJosef Bacik <jbacik@fusionio.com>
Signed-off-by: default avatarChris Mason <chris.mason@fusionio.com>
parent 175a2b87
...@@ -2940,7 +2940,9 @@ void btrfs_orphan_commit_root(struct btrfs_trans_handle *trans, ...@@ -2940,7 +2940,9 @@ void btrfs_orphan_commit_root(struct btrfs_trans_handle *trans,
btrfs_root_refs(&root->root_item) > 0) { btrfs_root_refs(&root->root_item) > 0) {
ret = btrfs_del_orphan_item(trans, root->fs_info->tree_root, ret = btrfs_del_orphan_item(trans, root->fs_info->tree_root,
root->root_key.objectid); root->root_key.objectid);
BUG_ON(ret); if (ret)
btrfs_abort_transaction(trans, root, ret);
else
root->orphan_item_inserted = 0; root->orphan_item_inserted = 0;
} }
...@@ -3010,12 +3012,19 @@ int btrfs_orphan_add(struct btrfs_trans_handle *trans, struct inode *inode) ...@@ -3010,12 +3012,19 @@ int btrfs_orphan_add(struct btrfs_trans_handle *trans, struct inode *inode)
/* insert an orphan item to track this unlinked/truncated file */ /* insert an orphan item to track this unlinked/truncated file */
if (insert >= 1) { if (insert >= 1) {
ret = btrfs_insert_orphan_item(trans, root, btrfs_ino(inode)); ret = btrfs_insert_orphan_item(trans, root, btrfs_ino(inode));
if (ret && ret != -EEXIST) { if (ret) {
clear_bit(BTRFS_INODE_HAS_ORPHAN_ITEM, clear_bit(BTRFS_INODE_HAS_ORPHAN_ITEM,
&BTRFS_I(inode)->runtime_flags); &BTRFS_I(inode)->runtime_flags);
if (reserve) {
clear_bit(BTRFS_INODE_ORPHAN_META_RESERVED,
&BTRFS_I(inode)->runtime_flags);
btrfs_orphan_release_metadata(inode);
}
if (ret != -EEXIST) {
btrfs_abort_transaction(trans, root, ret); btrfs_abort_transaction(trans, root, ret);
return ret; return ret;
} }
}
ret = 0; ret = 0;
} }
...@@ -3053,17 +3062,15 @@ static int btrfs_orphan_del(struct btrfs_trans_handle *trans, ...@@ -3053,17 +3062,15 @@ static int btrfs_orphan_del(struct btrfs_trans_handle *trans,
release_rsv = 1; release_rsv = 1;
spin_unlock(&root->orphan_lock); spin_unlock(&root->orphan_lock);
if (trans && delete_item) { if (trans && delete_item)
ret = btrfs_del_orphan_item(trans, root, btrfs_ino(inode)); ret = btrfs_del_orphan_item(trans, root, btrfs_ino(inode));
BUG_ON(ret); /* -ENOMEM or corruption (JDM: Recheck) */
}
if (release_rsv) { if (release_rsv) {
btrfs_orphan_release_metadata(inode); btrfs_orphan_release_metadata(inode);
atomic_dec(&root->orphan_inodes); atomic_dec(&root->orphan_inodes);
} }
return 0; return ret;
} }
/* /*
...@@ -3193,8 +3200,9 @@ int btrfs_orphan_cleanup(struct btrfs_root *root) ...@@ -3193,8 +3200,9 @@ int btrfs_orphan_cleanup(struct btrfs_root *root)
found_key.objectid); found_key.objectid);
ret = btrfs_del_orphan_item(trans, root, ret = btrfs_del_orphan_item(trans, root,
found_key.objectid); found_key.objectid);
BUG_ON(ret); /* -ENOMEM or corruption (JDM: Recheck) */
btrfs_end_transaction(trans, root); btrfs_end_transaction(trans, root);
if (ret)
goto out;
continue; continue;
} }
...@@ -4570,10 +4578,15 @@ void btrfs_evict_inode(struct inode *inode) ...@@ -4570,10 +4578,15 @@ void btrfs_evict_inode(struct inode *inode)
btrfs_free_block_rsv(root, rsv); btrfs_free_block_rsv(root, rsv);
/*
* Errors here aren't a big deal, it just means we leave orphan items
* in the tree. They will be cleaned up on the next mount.
*/
if (ret == 0) { if (ret == 0) {
trans->block_rsv = root->orphan_block_rsv; trans->block_rsv = root->orphan_block_rsv;
ret = btrfs_orphan_del(trans, inode); btrfs_orphan_del(trans, inode);
BUG_ON(ret); } else {
btrfs_orphan_del(NULL, inode);
} }
trans->block_rsv = &root->fs_info->trans_block_rsv; trans->block_rsv = &root->fs_info->trans_block_rsv;
...@@ -8120,10 +8133,8 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -8120,10 +8133,8 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
new_dentry->d_name.name, new_dentry->d_name.name,
new_dentry->d_name.len); new_dentry->d_name.len);
} }
if (!ret && new_inode->i_nlink == 0) { if (!ret && new_inode->i_nlink == 0)
ret = btrfs_orphan_add(trans, new_dentry->d_inode); ret = btrfs_orphan_add(trans, new_dentry->d_inode);
BUG_ON(ret);
}
if (ret) { if (ret) {
btrfs_abort_transaction(trans, root, ret); btrfs_abort_transaction(trans, root, ret);
goto out_fail; goto out_fail;
......
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