浏览代码

Btrfs: fix inode leak on failure to setup whiteout inode in rename

If we failed to fully setup the whiteout inode during a rename operation
with the whiteout flag, we ended up leaking the inode, not decrementing
its link count nor removing all its items from the fs/subvol tree.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
Filipe Manana 9 年之前
父节点
当前提交
c990161888
共有 1 个文件被更改,包括 6 次插入6 次删除
  1. 6 6
      fs/btrfs/inode.c

+ 6 - 6
fs/btrfs/inode.c

@@ -9612,21 +9612,21 @@ static int btrfs_whiteout_for_rename(struct btrfs_trans_handle *trans,
 	ret = btrfs_init_inode_security(trans, inode, dir,
 	ret = btrfs_init_inode_security(trans, inode, dir,
 				&dentry->d_name);
 				&dentry->d_name);
 	if (ret)
 	if (ret)
-		return ret;
+		goto out;
 
 
 	ret = btrfs_add_nondir(trans, dir, dentry,
 	ret = btrfs_add_nondir(trans, dir, dentry,
 				inode, 0, index);
 				inode, 0, index);
 	if (ret)
 	if (ret)
-		return ret;
+		goto out;
 
 
 	ret = btrfs_update_inode(trans, root, inode);
 	ret = btrfs_update_inode(trans, root, inode);
-	if (ret)
-		return ret;
-
+out:
 	unlock_new_inode(inode);
 	unlock_new_inode(inode);
+	if (ret)
+		inode_dec_link_count(inode);
 	iput(inode);
 	iput(inode);
 
 
-	return 0;
+	return ret;
 }
 }
 
 
 static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
 static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,