Skip to content

Commit

Permalink
Btrfs: don't return ino to ino cache if inode item removal fails
Browse files Browse the repository at this point in the history
In btrfs_evict_inode(), if btrfs_truncate_inode_items() fails, the inode
item will still be in the tree but we still return the ino to the ino
cache. That will blow up later when someone tries to allocate that ino,
so don't return it to the cache.

Fixes: 581bb05 ("Btrfs: Cache free inode numbers in memory")
Reviewed-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
  • Loading branch information
osandov authored and kdave committed May 28, 2018
1 parent 05a5bd7 commit c08db7d
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions fs/btrfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -5593,13 +5593,18 @@ void btrfs_evict_inode(struct inode *inode)
trans->block_rsv = rsv;

ret = btrfs_truncate_inode_items(trans, root, inode, 0, 0);
if (ret != -ENOSPC && ret != -EAGAIN)
if (ret) {
trans->block_rsv = &fs_info->trans_block_rsv;
btrfs_end_transaction(trans);
btrfs_btree_balance_dirty(fs_info);
if (ret != -ENOSPC && ret != -EAGAIN) {
btrfs_orphan_del(NULL, BTRFS_I(inode));
btrfs_free_block_rsv(fs_info, rsv);
goto no_delete;
}
} else {
break;

trans->block_rsv = &fs_info->trans_block_rsv;
btrfs_end_transaction(trans);
trans = NULL;
btrfs_btree_balance_dirty(fs_info);
}
}

btrfs_free_block_rsv(fs_info, rsv);
Expand All @@ -5608,12 +5613,8 @@ void btrfs_evict_inode(struct inode *inode)
* 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) {
trans->block_rsv = root->orphan_block_rsv;
btrfs_orphan_del(trans, BTRFS_I(inode));
} else {
btrfs_orphan_del(NULL, BTRFS_I(inode));
}
trans->block_rsv = root->orphan_block_rsv;
btrfs_orphan_del(trans, BTRFS_I(inode));

trans->block_rsv = &fs_info->trans_block_rsv;
if (!(root == fs_info->tree_root ||
Expand Down

0 comments on commit c08db7d

Please sign in to comment.