public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Nikolay Borisov <nborisov@suse.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>,
	gniebler@suse.com, linux-btrfs@vger.kernel.org
Subject: Re: [bug report] btrfs: turn fs_roots_radix in btrfs_fs_info into an XArray
Date: Mon, 16 May 2022 17:18:24 +0200	[thread overview]
Message-ID: <20220516151824.GY18596@twin.jikos.cz> (raw)
In-Reply-To: <576a6039-5ee3-6b5e-aa3c-8caaeec956df@suse.com>

On Mon, May 16, 2022 at 02:45:57PM +0300, Nikolay Borisov wrote:
> On 16.05.22 г. 14:02 ч., Dan Carpenter wrote:
> > On Mon, May 16, 2022 at 01:39:52PM +0300, Nikolay Borisov wrote:
> >> On 16.05.22 г. 11:04 ч., Dan Carpenter wrote:
> >>>       4538                 xa_for_each_start(&fs_info->fs_roots, index, root, index) {
> >>>       4539                         /* Avoid grabbing roots in dead_roots */
> >>>       4540                         if (btrfs_root_refs(&root->root_item) > 0)
> >>>       4541                                 roots[grabbed++] = btrfs_grab_root(root);
> >>>       4542                         if (grabbed >= ARRAY_SIZE(roots))
> >>>       4543                                 break;
> > 
> > breaks out of xa_for_each_start() loop.
> 
> This is fine, as when we fill root[] then we'd process it in the 
> subsequent for loop.
> 
> > 
> >>>       4544                 }
> >>>       4545                 spin_unlock(&fs_info->fs_roots_lock);
> >>>       4546
> >>>       4547                 for (i = 0; i < grabbed; i++) {
> >>>       4548                         if (!roots[i])
> >>>       4549                                 continue;
> >>>       4550                         index = roots[i]->root_key.objectid;
> >>>       4551                         err = btrfs_orphan_cleanup(roots[i]);
> >>>       4552                         if (err)
> >>>       4553                                 break;
> > 
> > breaks out of for loop.
> 
> However, this is indeed a genuine bug, and the fix for it is:
> 
> diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
> index fe309db9f5ff..f33093513360 100644
> --- a/fs/btrfs/disk-io.c
> +++ b/fs/btrfs/disk-io.c
> @@ -4549,12 +4549,13 @@ int btrfs_cleanup_fs_roots(struct btrfs_fs_info 
> *fs_info)
>                          index = roots[i]->root_key.objectid;
>                          err = btrfs_orphan_cleanup(roots[i]);
>                          if (err)
> -                               break;
> +                               goto out;
>                          btrfs_put_root(roots[i]);
>                  }
>                  index++;
>          }
> 
> +out:
>          /* Release the roots that remain uncleaned due to error */
>          for (; i < grabbed; i++) {
>                  if (roots[i])

Thanks Dan for the report, fixup folded and pushed.

  reply	other threads:[~2022-05-16 15:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-16  8:04 [bug report] btrfs: turn fs_roots_radix in btrfs_fs_info into an XArray Dan Carpenter
2022-05-16 10:39 ` Nikolay Borisov
2022-05-16 11:02   ` Dan Carpenter
2022-05-16 11:45     ` Nikolay Borisov
2022-05-16 15:18       ` David Sterba [this message]
  -- strict thread matches above, loose matches on Subject: below --
2022-05-04 15:29 Dan Carpenter
2022-05-11 13:10 ` David Sterba

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=20220516151824.GY18596@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=dan.carpenter@oracle.com \
    --cc=gniebler@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