All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Btrfs: fix transaction handle leak on failure to create hard link
@ 2016-01-05 16:33 fdmanana
  2016-01-06  2:33 ` Liu Bo
  0 siblings, 1 reply; 2+ messages in thread
From: fdmanana @ 2016-01-05 16:33 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Filipe Manana

From: Filipe Manana <fdmanana@suse.com>

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: Filipe Manana <fdmanana@suse.com>
---
 fs/btrfs/inode.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 5dbc07a..018c2a6 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -6488,7 +6488,7 @@ out_unlock_inode:
 static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
 		      struct dentry *dentry)
 {
-	struct btrfs_trans_handle *trans;
+	struct btrfs_trans_handle *trans = NULL;
 	struct btrfs_root *root = BTRFS_I(dir)->root;
 	struct inode *inode = d_inode(old_dentry);
 	u64 index;
@@ -6514,6 +6514,7 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
 	trans = btrfs_start_transaction(root, 5);
 	if (IS_ERR(trans)) {
 		err = PTR_ERR(trans);
+		trans = NULL;
 		goto fail;
 	}
 
@@ -6547,9 +6548,10 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
 		btrfs_log_new_name(trans, inode, NULL, parent);
 	}
 
-	btrfs_end_transaction(trans, root);
 	btrfs_balance_delayed_items(root);
 fail:
+	if (trans)
+		btrfs_end_transaction(trans, root);
 	if (drop_inode) {
 		inode_dec_link_count(inode);
 		iput(inode);
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Btrfs: fix transaction handle leak on failure to create hard link
  2016-01-05 16:33 [PATCH] Btrfs: fix transaction handle leak on failure to create hard link fdmanana
@ 2016-01-06  2:33 ` Liu Bo
  0 siblings, 0 replies; 2+ messages in thread
From: Liu Bo @ 2016-01-06  2:33 UTC (permalink / raw)
  To: fdmanana; +Cc: linux-btrfs, Filipe Manana

On Tue, Jan 05, 2016 at 04:33:02PM +0000, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
> 
> 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.

Reviewed-by: Liu Bo <bo.li.liu@oracle.com>

Thanks,

-liubo
> 
> Signed-off-by: Filipe Manana <fdmanana@suse.com>
> ---
>  fs/btrfs/inode.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index 5dbc07a..018c2a6 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -6488,7 +6488,7 @@ out_unlock_inode:
>  static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
>  		      struct dentry *dentry)
>  {
> -	struct btrfs_trans_handle *trans;
> +	struct btrfs_trans_handle *trans = NULL;
>  	struct btrfs_root *root = BTRFS_I(dir)->root;
>  	struct inode *inode = d_inode(old_dentry);
>  	u64 index;
> @@ -6514,6 +6514,7 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
>  	trans = btrfs_start_transaction(root, 5);
>  	if (IS_ERR(trans)) {
>  		err = PTR_ERR(trans);
> +		trans = NULL;
>  		goto fail;
>  	}
>  
> @@ -6547,9 +6548,10 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
>  		btrfs_log_new_name(trans, inode, NULL, parent);
>  	}
>  
> -	btrfs_end_transaction(trans, root);
>  	btrfs_balance_delayed_items(root);
>  fail:
> +	if (trans)
> +		btrfs_end_transaction(trans, root);
>  	if (drop_inode) {
>  		inode_dec_link_count(inode);
>  		iput(inode);
> -- 
> 2.1.3
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-01-06  2:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-05 16:33 [PATCH] Btrfs: fix transaction handle leak on failure to create hard link fdmanana
2016-01-06  2:33 ` Liu Bo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.