From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Boris Burkov <boris@bur.io>,
linux-btrfs@vger.kernel.org, kernel-team@fb.com
Cc: marc@merlins.org
Subject: Re: [PATCH 3/4] btrfs: clamp to avoid squota underflow
Date: Wed, 13 May 2026 10:23:24 +0930 [thread overview]
Message-ID: <acddd455-be08-47c0-b4d3-18e8e294713a@gmx.com> (raw)
In-Reply-To: <de66dfbdf8abcaba1b16b1779f8718f1583c8f5b.1778613519.git.boris@bur.io>
在 2026/5/13 05:04, Boris Burkov 写道:
> Simple quota accounting can undercount metadata tree block allocations
> in certain scenarios. When an undercounted subvolume is deleted and its
> tree blocks freed, the free deltas decrement rfer/excl past zero,
> wrapping the u64 to a value near U64_MAX.
>
> Once wrapped, can_delete_squota_qgroup() sees non-zero rfer and refuses
> to delete the qgroup. The qgroup becomes permanently orphaned in the
> quota tree, since there is no subvolume left to generate frees that
> would bring the counter back to zero.
>
> While we ultimately want to fix any mis-accounting at the source, it is
> also helpful and worthwhile to mitigate the damage by clamping rfer and
> excl to zero on underflow rather than allowing the u64 to wrap. This at
> least allows us to clean up the messed up qgroups on subvol deletion.
>
> Signed-off-by: Boris Burkov <boris@bur.io>
> ---
> fs/btrfs/qgroup.c | 15 +++++++++++++--
> 1 file changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
> index 96746ca19e17..a93d49015fc7 100644
> --- a/fs/btrfs/qgroup.c
> +++ b/fs/btrfs/qgroup.c
> @@ -4968,8 +4968,19 @@ int btrfs_record_squota_delta(struct btrfs_fs_info *fs_info,
> list_for_each_entry(qg, &qgroup_list, iterator) {
> struct btrfs_qgroup_list *glist;
>
> - qg->excl += num_bytes * sign;
> - qg->rfer += num_bytes * sign;
> + ASSERT(qg->excl == qg->rfer);
> + if (sign < 0 && qg->excl < num_bytes) {
> + btrfs_warn(fs_info,
> + "squota underflow qg %hu/%llu excl %llu num_bytes %llu",
> + btrfs_qgroup_level(qg->qgroupid),
> + btrfs_qgroup_subvolid(qg->qgroupid),
> + qg->excl, num_bytes);
This may not be noisy enough for fstests to catch.
Maybe a WARN_ON_ONCE()?
Thanks,
Qu
> + qg->excl = 0;
> + qg->rfer = 0;
> + } else {
> + qg->excl += num_bytes * sign;
> + qg->rfer += num_bytes * sign;
> + }
> qgroup_dirty(fs_info, qg);
>
> list_for_each_entry(glist, &qg->groups, next_group)
next prev parent reply other threads:[~2026-05-13 0:53 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-12 19:34 [PATCH 0/4] btrfs: squota lifetime fixes Boris Burkov
2026-05-12 19:34 ` [PATCH 1/4] btrfs: check for subvolume before deleting squota qgroup Boris Burkov
2026-05-12 19:34 ` [PATCH 2/4] btrfs: fix squota accounting during enable generation Boris Burkov
2026-05-12 19:34 ` [PATCH 3/4] btrfs: clamp to avoid squota underflow Boris Burkov
2026-05-13 0:53 ` Qu Wenruo [this message]
2026-05-12 19:34 ` [PATCH 4/4] btrfs: swallow btrfs_record_squota_delta() enoent Boris Burkov
2026-05-13 0:54 ` Qu Wenruo
2026-05-13 1:01 ` [PATCH 0/4] btrfs: squota lifetime fixes Qu Wenruo
2026-05-13 2:13 ` 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=acddd455-be08-47c0-b4d3-18e8e294713a@gmx.com \
--to=quwenruo.btrfs@gmx.com \
--cc=boris@bur.io \
--cc=kernel-team@fb.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=marc@merlins.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