* [PATCH v3 1/3] btrfs: qgroup: handle the transaction commit error during rescan
2026-11-20 9:57 [PATCH v3 0/3] btrfs: qgroup: rescan related message minor fixes Qu Wenruo
@ 2026-11-20 9:57 ` Qu Wenruo
2026-11-20 9:57 ` [PATCH v3 2/3] btrfs: qgroup: ensure the qgroup rescan messages are always shown Qu Wenruo
2026-11-20 9:57 ` [PATCH v3 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:57 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 v3 3/3] btrfs: qgroup: show the "qgroup scan cancelled" message correctly
2026-11-20 9:57 [PATCH v3 0/3] btrfs: qgroup: rescan related message minor fixes Qu Wenruo
2026-11-20 9:57 ` [PATCH v3 1/3] btrfs: qgroup: handle the transaction commit error during rescan Qu Wenruo
2026-11-20 9:57 ` [PATCH v3 2/3] btrfs: qgroup: ensure the qgroup rescan messages are always shown Qu Wenruo
@ 2026-11-20 9:57 ` Qu Wenruo
2 siblings, 0 replies; 4+ messages in thread
From: Qu Wenruo @ 2026-11-20 9:57 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, 16 insertions(+), 9 deletions(-)
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index afac7402af36..ab382f41957f 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;
@@ -3970,8 +3971,9 @@ 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))
+ cancelled = stopped && test_bit(BTRFS_QGROUP_RUNTIME_BIT_CANCEL_RESCAN,
+ &fs_info->qgroup_flags);
+ if (!stopped || cancelled)
clear_bit(BTRFS_QGROUP_STATUS_BIT_RESCAN, &fs_info->qgroup_flags);
if (trans) {
int ret2 = update_qgroup_status_item(trans);
@@ -3989,16 +3991,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