Skip to contentSkip to conversation

fstests: btrfs/301: handle auto-removed qgroups

PATCH Applied Qu Wenruo 3 participants 3 messages May 7, 2024 – May 23, 2024 Btrfs file system

lore
Share & tools
lore

Qu Wenruo

author
#0 lore raw

PATCH 1/1 fstests: btrfs/301: handle auto-removed qgroups

There are always attempts to auto-remove empty qgroups after dropping a subvolume.

For squota mode, not all qgroups can or should be dropped, as there are common cases where the dropped subvolume are still referred by other snapshots.
In that case, the numbers can only be freed when the last referencer got dropped.

The latest kernel attempt would only try to drop empty qgroups for squota mode.
But even with such safe change, the test case still needs to handle auto-removed qgroups, by explicitly echoing "0", or later calculation would break bash grammar.

This patch would add extra handling for such removed qgroups, to be future proof for qgroup auto-removal behavior change.

---
 tests/btrfs/301 | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
tests/btrfs/301 +10 -2
index db469724..bb18ab04 100755
@@ -51,9 +51,17 @@ _require_fio $fio_config
 get_qgroup_usage()
 {
 	local qgroupid=$1
+	local output
 
-	$BTRFS_UTIL_PROG qgroup show --sync --raw $SCRATCH_MNT | \
-				grep "$qgroupid" | $AWK_PROG '{print $3}'
+	output=$($BTRFS_UTIL_PROG qgroup show --sync --raw $SCRATCH_MNT | \
+		 grep "$qgroupid" | $AWK_PROG '{print $3}')
+	# The qgroup is auto-removed, this can only happen if its numbers are
+	# already all zeros, so here we only need to explicitly echo "0".
+	if [ -z "$output" ]; then
+		echo "0"
+	else
+		echo "$output"
+	fi
 }
 
 get_subvol_usage()
Signature · 1 line
2.44.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · Qu Wenruo

There are always attempts to auto-remove empty qgroups after dropping a subvolume.

For squota mode, not all qgroups can or should be dropped, as there are common cases where the dropped subvolume are still referred by other snapshots.
In that case, the numbers can only be freed when the last referencer got dropped.

The latest kernel attempt would only try to drop empty qgroups for squota mode.
But even with such safe change, the test case still needs to handle auto-removed qgroups, by explicitly echoing "0", or later calculation would break bash grammar.

Quoted 4 lines

This patch would add extra handling for such removed qgroups, to be future proof for qgroup auto-removal behavior change.

Looks good, thanks!

Quoted 31 lines
---
 tests/btrfs/301 | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
tests/btrfs/301 +10 -2
index db469724..bb18ab04 100755
@@ -51,9 +51,17 @@ _require_fio $fio_config
 get_qgroup_usage()
 {
 	local qgroupid=$1
+	local output
 
-	$BTRFS_UTIL_PROG qgroup show --sync --raw $SCRATCH_MNT | \
-				grep "$qgroupid" | $AWK_PROG '{print $3}'
+	output=$($BTRFS_UTIL_PROG qgroup show --sync --raw $SCRATCH_MNT | \
+		 grep "$qgroupid" | $AWK_PROG '{print $3}')
+	# The qgroup is auto-removed, this can only happen if its numbers are
+	# already all zeros, so here we only need to explicitly echo "0".
+	if [ -z "$output" ]; then
+		echo "0"
+	else
+		echo "$output"
+	fi
 }
 
 get_subvol_usage()
Signature · 1 line
2.44.0
Reviewed-by on v1 1/1 Applied
#2 lore raw
In reply to Qu Wenruo
Quoted 15 lines · Qu Wenruo

There are always attempts to auto-remove empty qgroups after dropping a subvolume.

For squota mode, not all qgroups can or should be dropped, as there are common cases where the dropped subvolume are still referred by other snapshots.
In that case, the numbers can only be freed when the last referencer got dropped.

The latest kernel attempt would only try to drop empty qgroups for squota mode.
But even with such safe change, the test case still needs to handle auto-removed qgroups, by explicitly echoing "0", or later calculation would break bash grammar.

Quoted 4 lines

This patch would add extra handling for such removed qgroups, to be future proof for qgroup auto-removal behavior change.

Looks good.

Applied.

Thanks, Anand

Quoted 28 lines
---
  tests/btrfs/301 | 12 ++++++++++--
  1 file changed, 10 insertions(+), 2 deletions(-)
tests/btrfs/301 +10 -2
index db469724..bb18ab04 100755
@@ -51,9 +51,17 @@ _require_fio $fio_config
  get_qgroup_usage()
  {
  	local qgroupid=$1
+	local output
 
-	$BTRFS_UTIL_PROG qgroup show --sync --raw $SCRATCH_MNT | \
-				grep "$qgroupid" | $AWK_PROG '{print $3}'
+	output=$($BTRFS_UTIL_PROG qgroup show --sync --raw $SCRATCH_MNT | \
+		 grep "$qgroupid" | $AWK_PROG '{print $3}')
+	# The qgroup is auto-removed, this can only happen if its numbers are
+	# already all zeros, so here we only need to explicitly echo "0".
+	if [ -z "$output" ]; then
+		echo "0"
+	else
+		echo "$output"
+	fi
  }
 
  get_subvol_usage()