summaryrefslogtreecommitdiff
path: root/fs/btrfs
diff options
context:
space:
mode:
authorOmar Sandoval <osandov@fb.com>2018-05-11 23:13:35 +0300
committerBen Hutchings <ben@decadent.org.uk>2018-11-20 21:05:04 +0300
commit72bfa437a54ef3cd46afedec7376b5b9cab787a9 (patch)
treef84cb436ee4bc238e7a8381f99c296f79c7e06e9 /fs/btrfs
parentc43320eb30c1f753a83d851ddb428f1c677eff32 (diff)
downloadlinux-72bfa437a54ef3cd46afedec7376b5b9cab787a9.tar.xz
Btrfs: don't return ino to ino cache if inode item removal fails
commit c08db7d8d295a4f3a10faaca376de011afff7950 upstream. 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: 581bb050941b ("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> [bwh: Backported to 3.16: - Pass inode, not btrfs_inode, to btrfs_orphan_del() - Pass btrfs_root, not btrfs_fs_info, to btrfs_free_block_rsv() - Adjust context] Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Diffstat (limited to 'fs/btrfs')
-rw-r--r--fs/btrfs/inode.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index b3a0d19abaac..106e2e006318 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -4908,13 +4908,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)
+ if (ret) {
+ trans->block_rsv = &root->fs_info->trans_block_rsv;
+ btrfs_end_transaction(trans, root);
+ btrfs_btree_balance_dirty(root);
+ if (ret != -ENOSPC) {
+ btrfs_orphan_del(NULL, inode);
+ btrfs_free_block_rsv(root, rsv);
+ goto no_delete;
+ }
+ } else {
break;
-
- trans->block_rsv = &root->fs_info->trans_block_rsv;
- btrfs_end_transaction(trans, root);
- trans = NULL;
- btrfs_btree_balance_dirty(root);
+ }
}
btrfs_free_block_rsv(root, rsv);
@@ -4923,12 +4928,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, inode);
- } else {
- btrfs_orphan_del(NULL, inode);
- }
+ trans->block_rsv = root->orphan_block_rsv;
+ btrfs_orphan_del(trans, inode);
trans->block_rsv = &root->fs_info->trans_block_rsv;
if (!(root == root->fs_info->tree_root ||