fstests: fix broken _require_scratch usage
[xfstests-dev.git] / tests / xfs / 109
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2005 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 109
6 #
7 # ENOSPC deadlock case from Asano Masahiro.
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
17
18 # get standard environment, filters and checks
19 . ./common/rc
20 . ./common/filter
21
22 # real QA test starts here
23 _supported_fs xfs
24 _supported_os Linux XFS
25 _require_scratch
26
27 populate()
28 {
29         # "faststart" lets us effectively skip (re-)population
30         [ "X$faststart" != "X" ] && rm -f $SCRATCH_MNT/F*
31
32         # create many small files using most available space
33         echo "creating small files..."
34         i=0
35         while [ $i -le $files -a "X$faststart" = "X" ]; do
36                 file=$SCRATCH_MNT/f$i
37                 $XFS_IO_PROG -f -d -c 'pwrite -b 64k 0 64k' $file >/dev/null
38                 let i=$i+1
39         done
40
41         # remove every second file, freeing up lots of space
42         echo "removing small files..."
43         i=1
44         while [ $i -le $files -a "X$faststart" = "X" ]; do
45                 rm $SCRATCH_MNT/f$i
46                 let i=$i+2
47         done
48
49         echo "flushing changes via umount/mount."
50         _scratch_unmount
51         _scratch_mount
52 }
53
54 allocate()
55 {
56         # now try to hit the deadlock
57         echo "starting parallel allocators..."
58         i=0
59         while [ $i -le 10 ]; do
60                 file=$SCRATCH_MNT/F$i
61                 {
62                         j=0
63                         while [ $j -lt 100 ]; do
64                                 $XFS_IO_PROG -f -c 'pwrite -b 64k 0 16m' $file \
65                                         >/dev/null 2>&1
66                                 test -e $file && rm $file
67                                 let j=$j+1
68                         done
69                 } &
70                 let i=$i+1
71         done
72
73         wait
74         echo "all done!"
75 }
76
77 # real QA test starts here
78 _scratch_mkfs_xfs >> $seqres.full
79 _scratch_mount
80 rm -f $seqres.full
81
82 # see if faststart is possible (and requested)
83 files=2000
84 faststart=""
85 if [ -n "$FASTSTART" -a -f $SCRATCH_MNT/f0 ]; then
86         faststart="-N"  # causes us to skip the mkfs step
87 fi
88 _scratch_unmount
89
90 _scratch_mkfs_xfs -dsize=160m,agcount=4 $faststart | _filter_mkfs 2>$tmp.mkfs
91 cat $tmp.mkfs >>$seqres.full
92 _scratch_mount
93
94 populate
95 allocate
96 status=0
97 exit