Skip to contentSkip to conversation

btrfs: qgroup: rescan related message minor fixes

PATCH Superseded Qu Wenruo 1 participant 4 messages Nov 20 Btrfs file system

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
author
#1 lore raw

PATCH 1/3 btrfs: qgroup: handle the transaction commit error during rescan

In reply to Qu Wenruo

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.

---
 fs/btrfs/qgroup.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
fs/btrfs/qgroup.c +8 -3
index 3127d3fcab31..9f3886d128d3 100644
@@ -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:
Signature · 1 line
2.56.0
author
#2 lore raw

PATCH 2/3 btrfs: qgroup: ensure the qgroup rescan messages are always shown

In reply to Qu Wenruo

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().

---
 fs/btrfs/qgroup.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
fs/btrfs/qgroup.c +2 -4
index 9f3886d128d3..afac7402af36 100644
@@ -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");
Signature · 1 line
2.56.0
author
#3 lore raw

PATCH 3/3 btrfs: qgroup: show the "qgroup scan cancelled" message correctly

In reply to Qu Wenruo

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

- Change the message priority so that cancelled has a higher priority And for @stopped/@cancelled check, if they hit, output the message and return. So we don't need the complex "if () {} else if () {}" logic anymore.

---
 fs/btrfs/qgroup.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
fs/btrfs/qgroup.c +11 -4
index afac7402af36..3be159541e4c 100644
@@ -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;
 
@@ -3982,18 +3983,24 @@ static void btrfs_qgroup_rescan_worker(struct btrfs_work *work)
 		}
 	}
 	fs_info->qgroup_rescan_running = false;
-	clear_bit(BTRFS_QGROUP_RUNTIME_BIT_CANCEL_RESCAN, &fs_info->qgroup_flags);
+	cancelled = test_and_clear_bit(BTRFS_QGROUP_RUNTIME_BIT_CANCEL_RESCAN,
+				       &fs_info->qgroup_flags);
 	complete_all(&fs_info->qgroup_rescan_completion);
 	mutex_unlock(&fs_info->qgroup_rescan_lock);
 
 	if (trans)
 		btrfs_end_transaction(trans);
 
+	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) {
+		return;
+	}
+
+	if (ret >= 0) {
 		btrfs_info(fs_info, "qgroup scan completed%s",
 			ret > 0 ? " (inconsistency flag cleared)" : "");
 	} else {
Signature · 1 line
2.56.0

Qu Wenruo

author
#0 lore raw

cover btrfs: qgroup: rescan related message minor fixes

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.

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 | 32 +++++++++++++++++++++-----------
 1 file changed, 21 insertions(+), 11 deletions(-)
Signature · 1 line
2.56.0