public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Shinichiro Kawasaki <shinichiro.kawasaki@wdc.com>
To: Nikolay Borisov <nborisov@suse.com>
Cc: "linux-btrfs@vger.kernel.org" <linux-btrfs@vger.kernel.org>,
	David Sterba <dsterba@suse.com>,
	Naohiro Aota <Naohiro.Aota@wdc.com>,
	Johannes Thumshirn <Johannes.Thumshirn@wdc.com>,
	Damien Le Moal <damien.lemoal@opensource.wdc.com>
Subject: Re: [PATCH] btrfs: fix deadlock between quota disable and qgroup rescan worker
Date: Sat, 15 Jan 2022 05:36:39 +0000	[thread overview]
Message-ID: <20220115053638.bh2gp2t337io47dh@shindev> (raw)
In-Reply-To: <20220114040314.q46pvlcyyno2ze3d@shindev>

On Jan 14, 2022 / 04:03, Shinichiro Kawasaki wrote:
> On Jan 14, 2022 / 00:52, Shinichiro Kawasaki wrote:
> > On Jan 13, 2022 / 14:53, Nikolay Borisov wrote:
> > > 
> > > 
> > > On 13.01.22 г. 12:40, Shin'ichiro Kawasaki wrote:
> > > > Quota disable ioctl starts a transaction before waiting for the qgroup
> > > > rescan worker completes. However, this wait can be infinite and results
> > > > in deadlock because of circular dependency among the quota disable
> > > > ioctl, the qgroup rescan worker and the other task with transaction such
> > > > as block group relocation task.
> > > 
> > > <snip>
> > > 
> > > > Suggested-by: Naohiro Aota <naohiro.aota@wdc.com>
> > > > Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
> > > > ---
> > > >  fs/btrfs/ctree.h  |  2 ++
> > > >  fs/btrfs/qgroup.c | 20 ++++++++++++++++++--
> > > >  2 files changed, 20 insertions(+), 2 deletions(-)
> > > > 
> > > > diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
> > > > index b4a9b1c58d22..fe275697e3eb 100644
> > > > --- a/fs/btrfs/ctree.h
> > > > +++ b/fs/btrfs/ctree.h
> > > > @@ -145,6 +145,8 @@ enum {
> > > >  	BTRFS_FS_STATE_DUMMY_FS_INFO,
> > > >  
> > > >  	BTRFS_FS_STATE_NO_CSUMS,
> > > > +	/* Quota is in disabling process */
> > > > +	BTRFS_FS_STATE_QUOTA_DISABLING,
> > > >  };
> > > >  
> > > >  #define BTRFS_BACKREF_REV_MAX		256
> > > > diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
> > > > index 8928275823a1..6f94da4896bc 100644
> > > > --- a/fs/btrfs/qgroup.c
> > > > +++ b/fs/btrfs/qgroup.c
> > > > @@ -1188,6 +1188,17 @@ int btrfs_quota_disable(struct btrfs_fs_info *fs_info)
> > > >  	mutex_lock(&fs_info->qgroup_ioctl_lock);
> > > >  	if (!fs_info->quota_root)
> > > >  		goto out;
> > > > +	/*
> > > > +	 * Request qgroup rescan worker to complete and wait for it. This wait
> > > > +	 * must be done before transaction start for quota disable since it may
> > > > +	 * deadlock with transaction by the qgroup rescan worker.
> > > > +	 */
> > > > +	if (test_and_set_bit(BTRFS_FS_STATE_QUOTA_DISABLING,
> > > > +			     &fs_info->fs_state)) {
> > > > +		ret = -EBUSY;
> > > > +		goto busy;
> > > > +	}
> > > > +	btrfs_qgroup_wait_for_completion(fs_info, false);
> > > 
> > > Actually you don't need to introduce a separate flag to have this logic,
> > > simply clear QUOTA_ENABLED, do the wait, start the transaction - in case
> > > of failure i.e not able to get a trans handle just set QUOTA_ENABLED

I have just posted v2 patch based on this approach. Review comments will be
appreciated.

> > > again. Still, moving QUOTA_ENABLED check in rescan_should_stop would be
> > > useful as well.

I saw Nikolay posted this part as a separated patch, so it is not included in
the v2 patch.

https://lore.kernel.org/linux-btrfs/20220113151618.2149736-1-nborisov@suse.com/T/#u

-- 
Best Regards,
Shin'ichiro Kawasaki

      reply	other threads:[~2022-01-15  5:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-13 10:40 [PATCH] btrfs: fix deadlock between quota disable and qgroup rescan worker Shin'ichiro Kawasaki
2022-01-13 11:41 ` David Sterba
2022-01-13 12:44 ` Nikolay Borisov
2022-01-13 12:53 ` Nikolay Borisov
2022-01-14  0:52   ` Shinichiro Kawasaki
2022-01-14  4:03     ` Shinichiro Kawasaki
2022-01-15  5:36       ` Shinichiro Kawasaki [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=20220115053638.bh2gp2t337io47dh@shindev \
    --to=shinichiro.kawasaki@wdc.com \
    --cc=Johannes.Thumshirn@wdc.com \
    --cc=Naohiro.Aota@wdc.com \
    --cc=damien.lemoal@opensource.wdc.com \
    --cc=dsterba@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=nborisov@suse.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