* [PATCH v2 0/3] btrfs: qgroup: rescan related message minor fixes
@ 2026-11-20 9:41 Qu Wenruo
2026-11-20 9:41 ` [PATCH v2 1/3] btrfs: qgroup: handle the transaction commit error during rescan Qu Wenruo
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Qu Wenruo @ 2026-11-20 9:41 UTC (permalink / raw)
To: linux-btrfs
[CHANGELOG]
v2:
- Handle cancelled-after-finished case better
So cancelled is only update when the rescan is stopped. This means
if the rescan is finished properly then cancelled before we commit
everything, at least we still treat the rescan as finished.
This is pointed by sashiko, but I won't handle it any further, as it's
a long existing cancel-rescan race. I don't think it's that important
either.
- Reorder the error messages priority
Now the failure has the highest priority.
The first one is from Sashiko.
The second one is to make sure we output the rescan related message even
if we failed to start a transaction (e.g. transaction aborted).
The final one is to fix a bug that rescan cancelled message is never
shown.
But the final one is also prone to race between scan and cancel. I don't
think there is any good way to really fix that yet nor is really caused by
this patch.
So I'll mostly ignore future scan-cancel race related review from sashiko
on the last patch.
Qu Wenruo (3):
btrfs: qgroup: handle the transaction commit error during rescan
btrfs: qgroup: ensure the qgroup rescan messages are always shown
btrfs: qgroup: show the "qgroup scan cancelled" message correctly
fs/btrfs/qgroup.c | 42 +++++++++++++++++++++++++++---------------
1 file changed, 27 insertions(+), 15 deletions(-)
--
2.56.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 1/3] btrfs: qgroup: handle the transaction commit error during rescan
2026-11-20 9:41 [PATCH v2 0/3] btrfs: qgroup: rescan related message minor fixes Qu Wenruo
@ 2026-11-20 9:41 ` Qu Wenruo
2026-11-20 9:41 ` [PATCH v2 2/3] btrfs: qgroup: ensure the qgroup rescan messages are always shown Qu Wenruo
2026-11-20 9:41 ` [PATCH v2 3/3] btrfs: qgroup: show the "qgroup scan cancelled" message correctly Qu Wenruo
2 siblings, 0 replies; 4+ messages in thread
From: Qu Wenruo @ 2026-11-20 9:41 UTC (permalink / raw)
To: linux-btrfs
After qgroup_rescan_leaf() return 1, meaning it has done the scanning,
btrfs_qgroup_rescan_worker() will call btrfs_commit_transaction() to
update the qgroup infos.
But if that btrfs_commit_transaction() failed, @ret is still 1, which
will treat the rescan as ended successfully, clearing the INCONSISTENT
flag.
Fix the error handling by also check the return value of
btrfs_commit_transaction(). If that failed, update @ret to the error
code so we treat the rescan as failed.
Link: https://sashiko.dev/#/bug/linux-b578ca93-4f5a-4a46-9dfc-71c1ac9af095
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
fs/btrfs/qgroup.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index 3127d3fcab31..9f3886d128d3 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -3928,10 +3928,15 @@ static void btrfs_qgroup_rescan_worker(struct btrfs_work *work)
ret = qgroup_rescan_leaf(trans, path);
did_leaf_rescans = true;
- if (ret > 0)
- btrfs_commit_transaction(trans);
- else
+ if (ret > 0) {
+ int commit_ret;
+
+ commit_ret = btrfs_commit_transaction(trans);
+ if (commit_ret < 0)
+ ret = commit_ret;
+ } else {
btrfs_end_transaction(trans);
+ }
}
out:
--
2.56.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 2/3] btrfs: qgroup: ensure the qgroup rescan messages are always shown
2026-11-20 9:41 [PATCH v2 0/3] btrfs: qgroup: rescan related message minor fixes Qu Wenruo
2026-11-20 9:41 ` [PATCH v2 1/3] btrfs: qgroup: handle the transaction commit error during rescan Qu Wenruo
@ 2026-11-20 9:41 ` Qu Wenruo
2026-11-20 9:41 ` [PATCH v2 3/3] btrfs: qgroup: show the "qgroup scan cancelled" message correctly Qu Wenruo
2 siblings, 0 replies; 4+ messages in thread
From: Qu Wenruo @ 2026-11-20 9:41 UTC (permalink / raw)
To: linux-btrfs
In btrfs_qgroup_rescan_worker(), if by somehow the transaction is
aborted halfway, later we can not start a new transaction.
This marks @trans variable always to be NULL, which later skips the
qgroup scan related messages, this can be a little confusing for end
users.
Fix it by only end the transaction if we have a valid trans handle,
other than returning from btrfs_qgroup_rescan_worker().
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
fs/btrfs/qgroup.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index 9f3886d128d3..afac7402af36 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -3986,10 +3986,8 @@ static void btrfs_qgroup_rescan_worker(struct btrfs_work *work)
complete_all(&fs_info->qgroup_rescan_completion);
mutex_unlock(&fs_info->qgroup_rescan_lock);
- if (!trans)
- return;
-
- btrfs_end_transaction(trans);
+ if (trans)
+ btrfs_end_transaction(trans);
if (stopped) {
btrfs_info(fs_info, "qgroup scan paused");
--
2.56.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 3/3] btrfs: qgroup: show the "qgroup scan cancelled" message correctly
2026-11-20 9:41 [PATCH v2 0/3] btrfs: qgroup: rescan related message minor fixes Qu Wenruo
2026-11-20 9:41 ` [PATCH v2 1/3] btrfs: qgroup: handle the transaction commit error during rescan Qu Wenruo
2026-11-20 9:41 ` [PATCH v2 2/3] btrfs: qgroup: ensure the qgroup rescan messages are always shown Qu Wenruo
@ 2026-11-20 9:41 ` Qu Wenruo
2 siblings, 0 replies; 4+ messages in thread
From: Qu Wenruo @ 2026-11-20 9:41 UTC (permalink / raw)
To: linux-btrfs
There are several reasons why we won't output the "qgroup scan cancelled"
message:
- We always clear BTRFS_QGROUP_RUNTIME_BIT_CANCEL_RESCAN before the
message check
So that test_bit() will never return true.
- @stopped has a higher priority
When a rescan is cancelled, it has a high chance to be caught by
rescan_should_stop(), so in that case @stopped is also true.
Then when checking which message to output, @stopped has a higher
priority, thus it shows the rescan as paused instead.
Fix the problem by:
- Save the previous CANCEL_RESCAN flag into @cancelled, and check that
variable instead
And @cancelled is only updated if the rescan is stopped.
This is to handle finished-then-cancelled rescan a little better.
This won't completely solve the cancel race with rescan though.
But the cancel-race is already there, not caused by this commit, and I
don't think we should bother too much on the mostly cosmetic error
- Change the message priority so that cancelled has a higher priority
The new priority list is:
- Error (ret < 0)
- Cancelled
- Stopped
- Finished
And we no longer go the complex "if () else if ()" way, instead each
hit branch will return, so only one branch will hit.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
fs/btrfs/qgroup.c | 25 +++++++++++++++++--------
1 file changed, 17 insertions(+), 8 deletions(-)
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index afac7402af36..1d4a185dd9fa 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -3900,6 +3900,7 @@ static void btrfs_qgroup_rescan_worker(struct btrfs_work *work)
struct btrfs_path *path;
struct btrfs_trans_handle *trans = NULL;
int ret = 0;
+ bool cancelled = false;
bool stopped = false;
bool did_leaf_rescans = false;
@@ -3971,8 +3972,11 @@ static void btrfs_qgroup_rescan_worker(struct btrfs_work *work)
mutex_lock(&fs_info->qgroup_rescan_lock);
if (!stopped || test_bit(BTRFS_QGROUP_RUNTIME_BIT_CANCEL_RESCAN,
- &fs_info->qgroup_flags))
+ &fs_info->qgroup_flags)) {
+ cancelled = test_bit(BTRFS_QGROUP_RUNTIME_BIT_CANCEL_RESCAN,
+ &fs_info->qgroup_flags);
clear_bit(BTRFS_QGROUP_STATUS_BIT_RESCAN, &fs_info->qgroup_flags);
+ }
if (trans) {
int ret2 = update_qgroup_status_item(trans);
@@ -3989,16 +3993,21 @@ static void btrfs_qgroup_rescan_worker(struct btrfs_work *work)
if (trans)
btrfs_end_transaction(trans);
+ if (ret < 0) {
+ btrfs_err(fs_info, "qgroup scan failed with %pe", ERR_PTR(ret));
+ return;
+ }
+ if (cancelled) {
+ btrfs_info(fs_info, "qgroup scan cancelled");
+ return;
+ }
if (stopped) {
btrfs_info(fs_info, "qgroup scan paused");
- } else if (test_bit(BTRFS_QGROUP_RUNTIME_BIT_CANCEL_RESCAN, &fs_info->qgroup_flags)) {
- btrfs_info(fs_info, "qgroup scan cancelled");
- } else if (ret >= 0) {
- btrfs_info(fs_info, "qgroup scan completed%s",
- ret > 0 ? " (inconsistency flag cleared)" : "");
- } else {
- btrfs_err(fs_info, "qgroup scan failed with %pe", ERR_PTR(ret));
+ return;
}
+
+ btrfs_info(fs_info, "qgroup scan completed%s",
+ ret > 0 ? " (inconsistency flag cleared)" : "");
}
/*
--
2.56.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-20 9:42 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 9:41 [PATCH v2 0/3] btrfs: qgroup: rescan related message minor fixes Qu Wenruo
2026-11-20 9:41 ` [PATCH v2 1/3] btrfs: qgroup: handle the transaction commit error during rescan Qu Wenruo
2026-11-20 9:41 ` [PATCH v2 2/3] btrfs: qgroup: ensure the qgroup rescan messages are always shown Qu Wenruo
2026-11-20 9:41 ` [PATCH v2 3/3] btrfs: qgroup: show the "qgroup scan cancelled" message correctly Qu Wenruo
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.