[PATCH v1 6/7] xfs: Add multi rt group shrink + shutdown + recovery tests

Nirjhar Roy (IBM)
2026-02-19T06:12:08Z

From: "Nirjhar Roy (IBM)" <nirjhar.roy.lists@gmail.com>

This test repeatedly shrinks, then shuts down the filesystem and checks
that recovery works fine - this is similar to what is already being done
in xfs/609 but this tests with filesystem shrink and in xfs/609 it is
tested with filesystem growth.

Signed-off-by: Nirjhar Roy (IBM) <nirjhar.roy.lists@gmail.com>
---
tests/xfs/333 | 95 +++++++++++++++++++++++++++++++++++++++++++++++
tests/xfs/333.out | 5 +++
2 files changed, 100 insertions(+)
create mode 100755 tests/xfs/333
create mode 100644 tests/xfs/333.out

diff --git a/tests/xfs/333 b/tests/xfs/333
new file mode 100755
index 00000000..6dba8c6a
--- /dev/null
+++ b/tests/xfs/333
@@ -0,0 +1,95 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 Nirjhar Roy (IBM) <nirjhar.roy.lists@gmail.com>. All Rights Reserved.
+#
+# FS QA Test 333
+#
+# Test XFS online growfs log recover with shrinking the realtime filesystem
+#
+. ./common/preamble
+_begin_fstest auto growfs stress shutdown log recoveryloop shrinkfs
+
+# Import common functions.
+. ./common/filter
+
+_stress_scratch()
+{
+ procs=4
+ nops=999
+ # -w ensures that the only ops are ones which cause write I/O
+ FSSTRESS_ARGS=`_scale_fsstress_args -d $SCRATCH_MNT -w -p $procs \
+ -n $nops`
+ _run_fsstress_bg $FSSTRESS_ARGS >> $seqres.full 2>&1
+}
+FSSIZE=$(( 1024 * 1024 * 1024 )) # 1G
+_require_realtime_xfs_shrink
+_require_scratch_size $((FSSIZE / 1024)) #KB
+_require_command "$XFS_GROWFS_PROG" xfs_growfs
+
+_fixed_by_kernel_commit a65fd8120766 "xfs: Fix xfs_grow_last_rtg()"
+_fixed_by_kernel_commit xxxxxxxxxxxx "xfs: Fix in xfs_rtalloc_query_range()"
+
+_scratch_mkfs_xfs | _filter_mkfs >$seqres.full 2>$tmp.mkfs
+. $tmp.mkfs
+
+endsize=`expr 128 \* 1048576` # stop after shrinking to this size
+[ `expr $endsize / $dbsize` -lt $dblocks ] || _notrun "Scratch device too small"
+
+nrgs=16
+nags="$nrgs"
+# We want to test with and without stress. The reason is that, if stress
+# fills up the filesystem such that all the RGs are non-empty, then all
+# the shrink commands will fail and we won't be able to test recovery
+# during shrink. So to cover all the types of scenarios, we are testing
+# with and without stress.
+for stress in 0 1
+do
+ for metadir in 0 1
+ do
+ size=`expr 512 \* 1048576` # 512 megabytes initially
+ sizeb=`expr $size / $dbsize` # in data blocks
+ _scratch_mkfs_xfs -bsize=4k -dsize=${size} -dagcount=${nags} -rsize=${size} \
+ -mmetadir="$metadir" -rrgcount=${nrgs} >> $seqres.full 2>&1 || _fail "mkfs failed"
+ _scratch_mount
+
+ $XFS_INFO_PROG $SCRATCH_MNT 2>&1 | _filter_mkfs 2>$tmp.xfsinfo >/dev/null
+ . $tmp.xfsinfo
+
+ if [[ "$stress" -eq 1 ]]; then
+ echo -n "Testing with Stress "
+ else
+ echo -n "Testing without Stress "
+ fi
+
+ echo -n "-m metadir = $metadir "
+ # Shrink the filesystem in random sized chunks while performing shutdown and
+ # recovery. The randomization is intended to create a mix of sub-rtg and
+ # multi-rtg shrinks.
+
+ while [ $size -ge $endsize ]; do
+ echo "*** shrinking a ${sizeb} block filesystem (shrink)" >> \
+ $seqres.full
+ if [[ "$stress" -eq 1 ]]; then
+ _stress_scratch
+ fi
+
+ decsize=$((RANDOM % 40 * 1048576))
+ size=`expr $size - $decsize`
+ sizeb=`expr $size / $dbsize`
+ $XFS_GROWFS_PROG -R ${sizeb} $SCRATCH_MNT >> $seqres.full 2>&1
+
+ sleep $((RANDOM % 3))
+ _scratch_shutdown
+ if [[ "$stress" -eq 1 ]]; then
+ _kill_fsstress
+ fi
+ _scratch_cycle_mount
+ done > /dev/null 2>&1
+ wait
+ _scratch_unmount
+ echo "succeeded"
+ done
+done
+
+_exit 0
+
diff --git a/tests/xfs/333.out b/tests/xfs/333.out
new file mode 100644
index 00000000..ae10574c
--- /dev/null
+++ b/tests/xfs/333.out
@@ -0,0 +1,5 @@
+QA output created by 333
+Testing without Stress -m metadir = 0 succeeded
+Testing without Stress -m metadir = 1 succeeded
+Testing with Stress -m metadir = 0 succeeded
+Testing with Stress -m metadir = 1 succeeded
--
2.34.1