btrfs/012: check free size of scratch device before copying files
[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 _require_scratch
25
26 populate()
27 {
28         # "faststart" lets us effectively skip (re-)population
29         [ "X$faststart" != "X" ] && rm -f $SCRATCH_MNT/F*
30
31         # create many small files using most available space
32         echo "creating small files..."
33         i=0
34         while [ $i -le $files -a "X$faststart" = "X" ]; do
35                 file=$SCRATCH_MNT/f$i
36                 $XFS_IO_PROG -f -d -c 'pwrite -b 64k 0 64k' $file >/dev/null
37                 let i=$i+1
38         done
39
40         # remove every second file, freeing up lots of space
41         echo "removing small files..."
42         i=1
43         while [ $i -le $files -a "X$faststart" = "X" ]; do
44                 rm $SCRATCH_MNT/f$i
45                 let i=$i+2
46         done
47
48         echo "flushing changes via umount/mount."
49         _scratch_unmount
50         _scratch_mount
51 }
52
53 allocate()
54 {
55         # now try to hit the deadlock
56         echo "starting parallel allocators..."
57         i=0
58         while [ $i -le 10 ]; do
59                 file=$SCRATCH_MNT/F$i
60                 {
61                         j=0
62                         while [ $j -lt 100 ]; do
63                                 $XFS_IO_PROG -f -c 'pwrite -b 64k 0 16m' $file \
64                                         >/dev/null 2>&1
65                                 test -e $file && rm $file
66                                 let j=$j+1
67                         done
68                 } &
69                 let i=$i+1
70         done
71
72         wait
73         echo "all done!"
74 }
75
76 # real QA test starts here
77 _scratch_mkfs_xfs >> $seqres.full
78 _scratch_mount
79 rm -f $seqres.full
80
81 # see if faststart is possible (and requested)
82 files=2000
83 faststart=""
84 if [ -n "$FASTSTART" -a -f $SCRATCH_MNT/f0 ]; then
85         faststart="-N"  # causes us to skip the mkfs step
86 fi
87 _scratch_unmount
88
89 _scratch_mkfs_xfs -dsize=160m,agcount=4 $faststart | _filter_mkfs 2>$tmp.mkfs
90 cat $tmp.mkfs >>$seqres.full
91 _scratch_mount
92
93 populate
94 allocate
95 status=0
96 exit