Commit 9bf972e8 authored by Filipe Manana's avatar Filipe Manana Committed by Sasha Levin

Btrfs: fix transaction handle leak on failure to create hard link

[ Upstream commit 271dba45 ]

If we failed to create a hard link we were not always releasing the
the transaction handle we got before, resulting in a memory leak and
preventing any other tasks from being able to commit the current
transaction.
Fix this by always releasing our transaction handle.
Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
Reviewed-by: default avatarLiu Bo <bo.li.liu@oracle.com>
Signed-off-by: default avatarSasha Levin <sasha.levin@oracle.com>
parent a1f535ac
...@@ -6421,7 +6421,7 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry, ...@@ -6421,7 +6421,7 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry,
static int btrfs_link(struct dentry *old_dentry, struct inode *dir, static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
struct dentry *dentry) struct dentry *dentry)
{ {
struct btrfs_trans_handle *trans; struct btrfs_trans_handle *trans = NULL;
struct btrfs_root *root = BTRFS_I(dir)->root; struct btrfs_root *root = BTRFS_I(dir)->root;
struct inode *inode = d_inode(old_dentry); struct inode *inode = d_inode(old_dentry);
u64 index; u64 index;
...@@ -6447,6 +6447,7 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir, ...@@ -6447,6 +6447,7 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
trans = btrfs_start_transaction(root, 5); trans = btrfs_start_transaction(root, 5);
if (IS_ERR(trans)) { if (IS_ERR(trans)) {
err = PTR_ERR(trans); err = PTR_ERR(trans);
trans = NULL;
goto fail; goto fail;
} }
...@@ -6480,9 +6481,10 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir, ...@@ -6480,9 +6481,10 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
btrfs_log_new_name(trans, inode, NULL, parent); btrfs_log_new_name(trans, inode, NULL, parent);
} }
btrfs_end_transaction(trans, root);
btrfs_balance_delayed_items(root); btrfs_balance_delayed_items(root);
fail: fail:
if (trans)
btrfs_end_transaction(trans, root);
if (drop_inode) { if (drop_inode) {
inode_dec_link_count(inode); inode_dec_link_count(inode);
iput(inode); iput(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