mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: Guanjie Chen <jk.chen1095@gmail.com>, linux-btrfs@vger.kernel.org
Cc: clm@fb.com, dsterba@suse.com, fdmanana@suse.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] btrfs: free qgroup configuration when quota enable fails
Date: Fri, 14 Aug 2026 21:19:44 +0930	[thread overview]
Message-ID: <694e88fd-a165-4518-88d4-cb2f22e8925b@suse.com> (raw)
In-Reply-To: <20260814112240.93514-1-jk.chen1095@gmail.com>



在 2026/8/14 20:52, Guanjie Chen 写道:
> Quota enable adds qgroups to fs_info->qgroup_tree before the operation is
> guaranteed to succeed.  On failure, the current error path removes only the
> sysfs entries, leaving the qgroups and their relations in memory.
> 
> Use btrfs_free_qgroup_config() instead.  It is the existing qgroup teardown
> helper and removes the in-memory qgroups, their relations and the sysfs
> entries.
> 
> This is safe because the failure cleanup runs with qgroup_ioctl_lock held
> and before quota_root is published or quota accounting is enabled.  Qgroups
> already added to the tree are freed by btrfs_free_qgroup_config(), while an
> untransferred preallocation and quota_root are still released by the
> existing cleanup code.  Transaction handling is unchanged.
> 
> Signed-off-by: Guanjie Chen <jk.chen1095@gmail.com>

LLM disclosure.

In fact, for anyone who doesn't have any previous btrfs involvement, I 
have a strong feeling such error handling bug is fully exposed by LLM, 
not yourself.

> ---
>   fs/btrfs/qgroup.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
> --- a/fs/btrfs/qgroup.c
> +++ b/fs/btrfs/qgroup.c
> @@ -1292,7 +1292,7 @@ out_free_root:
>   		btrfs_put_root(quota_root);
>   out:
>   	if (ret)
> -		btrfs_sysfs_del_qgroups(fs_info);
> +		btrfs_free_qgroup_config(fs_info);

And the error handling, no matter the older or the newer one, is 
incorrect in the first place.

In fact, the newer one is worse.

We can reach this out branch if btrfs_start_transaction() failed, but 
the fs_info->quota_root is already setup by another process.

In that case, the older code only removes the sysfs files, but keeps the 
qgroups in the rb tree.

But now all qgroups are removed unexpectedly.

>   	mutex_unlock(&fs_info->qgroup_ioctl_lock);
>   	if (ret && trans)
>   		btrfs_end_transaction(trans);


  reply	other threads:[~2026-08-14 11:49 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-14 11:22 Guanjie Chen
2026-08-14 11:49 ` Qu Wenruo [this message]
2026-08-14 12:30   ` Guanjie Chen
2026-08-14 22:13     ` Qu Wenruo
2026-08-15  6:44       ` Guanjie Chen
2026-08-15  8:03         ` Qu Wenruo
     [not found] <d239645a-b291-4fe9-b256-f0be849c875a@suse.com@suse.com>
2026-08-15  9:00 ` Guanjie Chen
2026-08-15  9:08   ` Qu Wenruo

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=694e88fd-a165-4518-88d4-cb2f22e8925b@suse.com \
    --to=wqu@suse.com \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=fdmanana@suse.com \
    --cc=jk.chen1095@gmail.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@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

all inboxes | Powered by JetHome®