2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2020-2021 Red Hat, Inc. All Rights Reserved.
7 # XFS online shrinkfs stress test
9 # This test attempts to shrink unused space as much as possible with
10 # background fsstress workload. It will decrease the shrink size if
11 # larger size fails. And totally repeat 2 * TIME_FACTOR times.
14 _begin_fstest auto growfs shrinkfs ioctl prealloc stress
16 # Import common functions.
21 _scratch_mkfs_xfs $@ | tee -a $seqres.full | \
22 _filter_mkfs 2>$tmp.mkfs >/dev/null
26 # fix the reserve block pool to a known size so that the enospc
27 # calculations work out correctly.
28 _scratch_resvblks 1024 > /dev/null 2>&1
33 $XFS_IO_PROG -f -c "falloc 0 $1" $SCRATCH_MNT/resvfile
40 # -w ensures that the only ops are ones which cause write I/O
41 local FSSTRESS_ARGS=`_scale_fsstress_args -d $SCRATCH_MNT -w \
42 -p $procs -n $nops $FSSTRESS_AVOID`
43 $FSSTRESS_PROG $FSSTRESS_ARGS >> $seqres.full 2>&1
46 # real QA test starts here
48 _require_scratch_xfs_shrink
49 _require_xfs_io_command "falloc"
51 _scratch_mkfs_xfs | tee -a $seqres.full | _filter_mkfs 2>$tmp.mkfs >/dev/null
52 . $tmp.mkfs # extract blocksize and data size for scratch device
54 endsize=`expr 125 \* 1048576` # stop after shrinking this big
55 [ `expr $endsize / $dbsize` -lt $dblocks ] || _notrun "Scratch device too small"
58 totalcount=$((2 * TIME_FACTOR))
60 while [ $totalcount -gt 0 ]; do
61 size=`expr 1010 \* 1048576` # 1010 megabytes initially
62 logblks=$(_scratch_find_xfs_min_logblocks -dsize=${size} -dagcount=${nags})
64 create_scratch -lsize=${logblks}b -dsize=${size} -dagcount=${nags}
66 for i in `seq 125 -1 90`; do
67 fillsize=`expr $i \* 1048576`
68 out="$(fill_scratch $fillsize 2>&1)"
69 echo "$out" | grep -q 'No space left on device' && continue
70 test -n "${out}" && echo "$out"
74 # shrink in chunks of this size at most
75 decsize=`expr 41 \* 1048576 + 1 + $RANDOM \* $RANDOM % 1048576`
77 while [ $size -gt $endsize ]; do
81 decb=`expr $decsize / $dbsize` # in data blocks
82 while [ $decb -gt 0 ]; do
83 sizeb=`expr $size / $dbsize - $decb`
85 $XFS_GROWFS_PROG -D ${sizeb} $SCRATCH_MNT \
86 >> $seqres.full 2>&1 && break
88 [ $decb -gt 100 ] && decb=`expr $decb + $RANDOM % 10`
93 [ $decb -eq 0 ] && break
96 $XFS_INFO_PROG $SCRATCH_MNT 2>&1 | _filter_mkfs 2>$tmp.growfs >/dev/null
99 size=`expr $dblocks \* $dbsize`
101 _scratch_xfs_repair -n >> $seqres.full 2>&1 || \
102 _fail "xfs_repair failed with shrinking $sizeb"
107 _scratch_xfs_repair -n >> $seqres.full 2>&1 || \
108 _fail "xfs_repair failed with shrinking $sizeb"
109 totalcount=`expr $totalcount - 1`
112 echo "Silence is golden"