linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Josef Bacik <jbacik@fusionio.com>
To: Miao Xie <miaox@cn.fujitsu.com>
Cc: Josef Bacik <JBacik@fusionio.com>,
	"linux-btrfs@vger.kernel.org" <linux-btrfs@vger.kernel.org>
Subject: Re: [PATCH] Btrfs: fix race with freeze and free space inodes
Date: Mon, 17 Sep 2012 09:38:14 -0400	[thread overview]
Message-ID: <20120917133814.GA3143@localhost.localdomain> (raw)
In-Reply-To: <5056B6F9.4000708@cn.fujitsu.com>

On Sun, Sep 16, 2012 at 11:36:57PM -0600, Miao Xie wrote:
> On fri, 14 Sep 2012 11:26:20 -0400, Josef Bacik wrote:
> > So we start our freeze, somebody comes in and does an fsync() on a file
> > where we have to commit a transaction for whatever reason, and we will
> > deadlock because the freeze is waiting on FS_FREEZE people to stop writing
> > to the file system, but the transaction is waiting for its free space inodes
> > to be written out, which are in turn waiting on sb_start_intwrite while
> > trying to write the file extents.  To fix this we'll just skip the
> > sb_start_intwrite() if we TRANS_JOIN_NOLOCK since we're being waited on by a
> > transaction commit so we're safe wrt to freeze and this will keep us from
> > deadlocking.  Thanks,
> > 
> > Signed-off-by: Josef Bacik <jbacik@fusionio.com>
> > ---
> >  fs/btrfs/transaction.c |   10 +++++++++-
> >  1 files changed, 9 insertions(+), 1 deletions(-)
> > 
> > diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
> > index c9265a6..ba74dfb 100644
> > --- a/fs/btrfs/transaction.c
> > +++ b/fs/btrfs/transaction.c
> > @@ -342,7 +342,15 @@ again:
> >  	if (!h)
> >  		return ERR_PTR(-ENOMEM);
> >  
> > -	if (!__sb_start_write(root->fs_info->sb, SB_FREEZE_FS, false)) {
> > +	/*
> > +	 * If we are JOIN_NOLOCK we're already committing a transaction and
> > +	 * waiting on this guy, so we don't need to do the sb_start_intwrite
> > +	 * because we're already holding a ref.  We need this because we could
> > +	 * have raced in and did an fsync() on a file which can kick a commit
> > +	 * and then we deadlock with somebody doing a freeze.
> > +	 */
> > +	if (type != TRANS_JOIN_NOLOCK &&
> > +	    !__sb_start_write(root->fs_info->sb, SB_FREEZE_FS, false)) {
> >  		if (type == TRANS_JOIN_FREEZE)
> >  			return ERR_PTR(-EPERM);
> >  		sb_start_intwrite(root->fs_info->sb);
> > 
> 
> This patch forgets to deal with it in __btrfs_end_transaction(), or the freeze counter
> will be wrong.
> 

This was fixed locally I just sent the wrong patch, thanks,

Josef

      reply	other threads:[~2012-09-17 13:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-14 15:26 [PATCH] Btrfs: fix race with freeze and free space inodes Josef Bacik
2012-09-17  5:36 ` Miao Xie
2012-09-17 13:38   ` Josef Bacik [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=20120917133814.GA3143@localhost.localdomain \
    --to=jbacik@fusionio.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=miaox@cn.fujitsu.com \
    /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).