public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Josef Bacik <josef@toxicpanda.com>,
	kernel-team@fb.com, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 7/7] btrfs: remove a BUG_ON() from merge_reloc_roots()
Date: Tue, 3 Mar 2020 09:17:22 +0800	[thread overview]
Message-ID: <f0673600-6327-69dd-01d2-8b73e05f2146@gmx.com> (raw)
In-Reply-To: <20200302184757.44176-8-josef@toxicpanda.com>


[-- Attachment #1.1: Type: text/plain, Size: 3139 bytes --]



On 2020/3/3 上午2:47, Josef Bacik wrote:
> This was pretty subtle, we default to reloc roots having 0 root refs, so
> if we crash in the middle of the relocation they can just be deleted.
> If we successfully complete the relocation operations we'll set our root
> refs to 1 in prepare_to_merge() and then go on to merge_reloc_roots().
> 
> At prepare_to_merge() time if any of the reloc roots have a 0 reference
> still, we will remove that reloc root from our reloc root rb tree, and
> then clean it up later.
> 
> However this only happens if we successfully start a transaction.  If
> we've aborted previously we will skip this step completely, and only
> have reloc roots with a reference count of 0, but were never properly
> removed from the reloc control's rb tree.

Great, this explains the reason why we're seeing one internal report of
the BUG_ON() get triggered.

> 
> This isn't a problem per-se, our references are held by the list the
> reloc roots are on, and by the original root the reloc root belongs to.
> If we end up in this situation all the reloc roots will be added to the
> dirty_reloc_list, and then properly dropped at that point.  The reloc
> control will be free'd and the rb tree is no longer used.
> 
> There were two options when fixing this, one was to remove the BUG_ON(),
> the other was to make prepare_to_merge() handle the case where we
> couldn't start a trans handle.
> 
> IMO this is the cleaner solution.  I started with handling the error in
> prepare_to_merge(), but it turned out super ugly.  And in the end this
> BUG_ON() simply doesn't matter, the cleanup was happening properly, we
> were just panicing because this BUG_ON() only matters in the success
> case.  So I've opted to just remove it and add a comment where it was.
> 
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>

Since there is a comment added, it looks pretty OK to me.

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu
> ---
>  fs/btrfs/relocation.c | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
> index c8ff28930677..387b0e7f1372 100644
> --- a/fs/btrfs/relocation.c
> +++ b/fs/btrfs/relocation.c
> @@ -2642,7 +2642,19 @@ void merge_reloc_roots(struct reloc_control *rc)
>  			free_reloc_roots(&reloc_roots);
>  	}
>  
> -	BUG_ON(!RB_EMPTY_ROOT(&rc->reloc_root_tree.rb_root));
> +	/*
> +	 * We used to have
> +	 *
> +	 * BUG_ON(!RB_EMPTY_ROOT(&rc->reloc_root_tree.rb_root));
> +	 *
> +	 * here, but it's wrong.  If we fail to start the transaction in
> +	 * prepare_to_merge() we will have only 0 ref reloc roots, none of which
> +	 * have actually been removed from the reloc_root_tree rb tree.  This is
> +	 * fine because we're bailing here, and we hold a reference on the root
> +	 * for the list that holds it, so these roots will be cleaned up when we
> +	 * do the reloc_dirty_list afterwards.  Meanwhile the root->reloc_root
> +	 * will be cleaned up on unmount.
> +	 */
>  }
>  
>  static void free_block_list(struct rb_root *blocks)
> 


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

      reply	other threads:[~2020-03-03  1:17 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-02 18:47 [PATCH 0/7] relocation error handling fixes Josef Bacik
2020-03-02 18:47 ` [PATCH 1/7] btrfs: drop block from cache on error in relocation Josef Bacik
2020-03-03  0:59   ` Qu Wenruo
2020-03-03 14:59   ` David Sterba
2020-03-03 20:27     ` Josef Bacik
2020-03-02 18:47 ` [PATCH 2/7] btrfs: unset reloc control if we fail to recover Josef Bacik
2020-03-03  0:58   ` Qu Wenruo
2020-03-03  1:03     ` Josef Bacik
2020-03-03  1:18       ` Qu Wenruo
2020-03-03 15:21     ` David Sterba
2020-03-02 18:47 ` [PATCH 3/7] btrfs: splice rc->reloc_roots onto reloc roots in recover Josef Bacik
2020-03-03  1:02   ` Qu Wenruo
2020-03-02 18:47 ` [PATCH 4/7] btrfs: run clean_dirty_subvols if we fail to start a trans Josef Bacik
2020-03-03  1:04   ` Qu Wenruo
2020-03-03 15:32   ` David Sterba
2020-03-02 18:47 ` [PATCH 5/7] btrfs: clear BTRFS_ROOT_DEAD_RELOC_TREE before dropping the reloc root Josef Bacik
2020-03-02 19:31   ` David Sterba
2020-03-02 19:51     ` Josef Bacik
2020-03-03 15:34       ` David Sterba
2020-03-03  0:31   ` Qu Wenruo
2020-03-02 18:47 ` [PATCH 6/7] btrfs: hold a ref on the root->reloc_root Josef Bacik
2020-03-03  1:12   ` Qu Wenruo
2020-03-03  1:14     ` Josef Bacik
2020-03-03 15:51   ` David Sterba
2020-03-02 18:47 ` [PATCH 7/7] btrfs: remove a BUG_ON() from merge_reloc_roots() Josef Bacik
2020-03-03  1:17   ` Qu Wenruo [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=f0673600-6327-69dd-01d2-8b73e05f2146@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=josef@toxicpanda.com \
    --cc=kernel-team@fb.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