xfs/530: skip test if user MKFS_OPTIONS screw up formatting
[xfstests-dev.git] / tests / xfs / 168
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2020-2021 Red Hat, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 168
6 #
7 # XFS online shrinkfs stress test
8 #
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.
12 #
13 . ./common/preamble
14 _begin_fstest auto growfs shrinkfs ioctl prealloc stress
15
16 # Import common functions.
17 . ./common/filter
18
19 create_scratch()
20 {
21         _scratch_mkfs_xfs $@ | tee -a $seqres.full | \
22                 _filter_mkfs 2>$tmp.mkfs >/dev/null
23         . $tmp.mkfs
24
25         _scratch_mount
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
29 }
30
31 fill_scratch()
32 {
33         $XFS_IO_PROG -f -c "falloc 0 $1" $SCRATCH_MNT/resvfile
34 }
35
36 stress_scratch()
37 {
38         local procs=3
39         local nops=1000
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
44 }
45
46 # real QA test starts here
47 _supported_fs xfs
48 _require_scratch_xfs_shrink
49 _require_xfs_io_command "falloc"
50
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
53
54 endsize=`expr 125 \* 1048576`   # stop after shrinking this big
55 [ `expr $endsize / $dbsize` -lt $dblocks ] || _notrun "Scratch device too small"
56
57 nags=2
58 totalcount=$((2 * TIME_FACTOR))
59
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})
63
64         create_scratch -lsize=${logblks}b -dsize=${size} -dagcount=${nags}
65
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"
71                 break
72         done
73
74         # shrink in chunks of this size at most
75         decsize=`expr  41 \* 1048576 + 1 + $RANDOM \* $RANDOM % 1048576`
76
77         while [ $size -gt $endsize ]; do
78                 stress_scratch &
79                 sleep 1
80
81                 decb=`expr $decsize / $dbsize`    # in data blocks
82                 while [ $decb -gt 0 ]; do
83                         sizeb=`expr $size / $dbsize - $decb`
84
85                         $XFS_GROWFS_PROG -D ${sizeb} $SCRATCH_MNT \
86                                 >> $seqres.full 2>&1 && break
87
88                         [ $decb -gt 100 ] && decb=`expr $decb + $RANDOM % 10`
89                         decb=`expr $decb / 2`
90                 done
91
92                 wait
93                 [ $decb -eq 0 ] && break
94
95                 # get latest dblocks
96                 $XFS_INFO_PROG $SCRATCH_MNT 2>&1 | _filter_mkfs 2>$tmp.growfs >/dev/null
97                 . $tmp.growfs
98
99                 size=`expr $dblocks \* $dbsize`
100                 _scratch_unmount
101                 _scratch_xfs_repair -n >> $seqres.full 2>&1 || \
102                         _fail "xfs_repair failed with shrinking $sizeb"
103                 _scratch_mount
104         done
105
106         _scratch_unmount
107         _scratch_xfs_repair -n >> $seqres.full 2>&1 || \
108                 _fail "xfs_repair failed with shrinking $sizeb"
109         totalcount=`expr $totalcount - 1`
110 done
111
112 echo "Silence is golden"
113 status=0
114 exit