[PATCH] xfs: test that zone_gc_low_space writes start gc for rw fses

Hans Holmberg <[email protected]>
Newsgroups org.kernel.vger.fstests,org.kernel.vger.linux-xfs
Message-ID <[email protected]>
Test that writes to the systfs attribute zone_gc_low_space triggers
garbage collection for rw (but not ro) file systems.

Signed-off-by: Hans Holmberg <[email protected]>
---

This test will fail currently, but i've submitted a fix:
https://lore.kernel.org/linux-xfs/[email protected]/

 tests/xfs/999     | 89 +++++++++++++++++++++++++++++++++++++++++++++++
 tests/xfs/999.out |  2 ++
 2 files changed, 91 insertions(+)
 create mode 100755 tests/xfs/999
 create mode 100644 tests/xfs/999.out

diff --git a/tests/xfs/999 b/tests/xfs/999
new file mode 100755
index 000000000000..f3c2f868cb1e
--- /dev/null
+++ b/tests/xfs/999
@@ -0,0 +1,89 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 Western Digital Corporation
+#
+# FS QA Test No. 999
+#
+# Tests that writes to gc_low_space will trigger start of garbage
+# collection for rw (but not ro) file systems
+#
+. ./common/preamble
+_begin_fstest auto rw zone quick
+
+. ./common/zoned
+
+_require_scratch
+_require_odirect
+
+get_scratch_mountstat() {
+	awk -v mount="$SCRATCH_MNT" -v stat="$1" \
+		'$0~"mounted on "mount" with fstype xfs"{f=1} f&&index($0,stat){print $NF;exit}' \
+		/proc/self/mountstats
+}
+
+get_user_available_rt_blocks() {
+	get_scratch_mountstat "user available RT blocks:"
+}
+
+gc_required() {
+	get_scratch_mountstat "RT GC required:"
+}
+
+# figure out if the rt section is internal or not
+if [ -z "$SCRATCH_RTDEV" ]; then
+	zdev=$SCRATCH_DEV
+else
+	zdev=$SCRATCH_RTDEV
+fi
+
+capacity=$(_zone_capacity 0 $zdev)
+_scratch_mkfs_sized $(($capacity * 6)) > $seqres.full 2>&1
+
+# limit max open zones to avoid gc to trigger before we want it to
+export MOUNT_OPTIONS="$MOUNT_OPTIONS -o max_open_zones=2"
+_try_scratch_mount || _notrun "mount option not supported"
+_require_xfs_scratch_zoned
+
+# create three zone-sized files and invalidate 95% of the data
+for i in $(seq 1 3); do
+	filename=$SCRATCH_MNT/data_$i
+	dd if=/dev/zero of=$filename bs=1M oflag=direct\
+		count=$(($capacity / (1024 * 1024))) >> $seqres.full 2>&1
+	truncate -s $(($capacity / 20)) $filename
+done
+
+# remount read-only and set the gc limit to free up unused space
+_scratch_remount ro
+rt_available_pre="$(get_user_available_rt_blocks)"
+_set_fs_sysfs_attr $SCRATCH_DEV "zoned/zonegc_low_space" 100
+
+# reclaiming a zone with 5% used blocks should take way less than 1 second
+sleep 1
+
+# gc should not run for read only file systems
+rt_available_post="$(get_user_available_rt_blocks)"
+[ "$rt_available_post" -gt "$rt_available_pre" ] && _fail "gc should not run while read only"
+
+_set_fs_sysfs_attr $SCRATCH_DEV "zoned/zonegc_low_space" 0
+
+# remount rw and check that gc starts, frees up blocks and stops after
+# the threshold is set to reclaim the unused blocks
+_scratch_remount rw
+
+rt_available_pre="$(get_user_available_rt_blocks)"
+_set_fs_sysfs_attr $SCRATCH_DEV "zoned/zonegc_low_space" 100
+
+i=0
+while [ $(gc_required) -eq "1" ]; do
+	sleep 1
+	let i=$i+1
+	[ $i -gt 3 ] && _fail "gc did not complete within a reasonable time"
+done
+
+rt_available_post="$(get_user_available_rt_blocks)"
+[ "$rt_available_pre" -ge "$rt_available_post" ] && _fail "gc did not free up space"
+
+echo "Silence is golden"
+status=0
+
+exit
diff --git a/tests/xfs/999.out b/tests/xfs/999.out
new file mode 100644
index 000000000000..3b276ca804fc
--- /dev/null
+++ b/tests/xfs/999.out
@@ -0,0 +1,2 @@
+QA output created by 999
+Silence is golden
-- 
2.34.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.