linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Liu Bo <bo.li.liu@oracle.com>
To: Josef Bacik <jbacik@fusionio.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] Btrfs: fix deadlock with freeze and sync V2
Date: Sat, 25 Aug 2012 10:32:43 +0800	[thread overview]
Message-ID: <5038394B.9080106@oracle.com> (raw)
In-Reply-To: <1345834383-2172-1-git-send-email-jbacik@fusionio.com>

On 08/25/2012 02:53 AM, Josef Bacik wrote:
> We can deadlock with freeze right now because we unconditionally start a
> transaction in our ->sync_fs() call.  To fix this just check and see if we
> have a running transaction to commit.  This saves us from the deadlock
> because at this point we'll have the umount sem for the sb so we're safe
> from freezes coming in after we've done our check.  With this patch the
> freeze xfstests no longer deadlocks.  Thanks,
> 

Actually I have a same patch pending to send...

Anyway, I'm happy with the bug has been fixed.

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

> Signed-off-by: Josef Bacik <jbacik@fusionio.com>
> ---
> V1->V2: got a little overzealous and cleaned up the ret thing without actually
> removing the now unused ret variable.
> 
>  fs/btrfs/super.c |   13 +++++++++----
>  1 files changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
> index 7b65fe8..83d6f9f 100644
> --- a/fs/btrfs/super.c
> +++ b/fs/btrfs/super.c
> @@ -838,7 +838,6 @@ int btrfs_sync_fs(struct super_block *sb, int wait)
>  	struct btrfs_trans_handle *trans;
>  	struct btrfs_fs_info *fs_info = btrfs_sb(sb);
>  	struct btrfs_root *root = fs_info->tree_root;
> -	int ret;
>  
>  	trace_btrfs_sync_fs(wait);
>  
> @@ -849,11 +848,17 @@ int btrfs_sync_fs(struct super_block *sb, int wait)
>  
>  	btrfs_wait_ordered_extents(root, 0, 0);
>  
> -	trans = btrfs_start_transaction(root, 0);
> +	spin_lock(&fs_info->trans_lock);
> +	if (!fs_info->running_transaction) {
> +		spin_unlock(&fs_info->trans_lock);
> +		return 0;
> +	}
> +	spin_unlock(&fs_info->trans_lock);
> +
> +	trans = btrfs_join_transaction(root);
>  	if (IS_ERR(trans))
>  		return PTR_ERR(trans);
> -	ret = btrfs_commit_transaction(trans, root);
> -	return ret;
> +	return btrfs_commit_transaction(trans, root);
>  }
>  
>  static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry)
> 


      reply	other threads:[~2012-08-25  2:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-24 18:53 [PATCH] Btrfs: fix deadlock with freeze and sync V2 Josef Bacik
2012-08-25  2:32 ` Liu Bo [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5038394B.9080106@oracle.com \
    --to=bo.li.liu@oracle.com \
    --cc=jbacik@fusionio.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).