common: Check the file system consistency on SCRATCH_DEV
[xfstests-dev.git] / tests / generic / 027
1 #! /bin/bash
2 # FS QA Test No. generic/027
3 #
4 # Run 8 processes writing 1k files to seperate files in seperate dirs to
5 # hit ENOSPC on small fs with little free space. Loop for 100 iterations.
6 #
7 # Regression test for
8 # 34cf865 ext4: fix deadlock when writing in ENOSPC conditions
9 #
10 #-----------------------------------------------------------------------
11 # Copyright (c) 2014 Red Hat Inc.  All Rights Reserved.
12 #
13 # This program is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License as
15 # published by the Free Software Foundation.
16 #
17 # This program is distributed in the hope that it would be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write the Free Software Foundation,
24 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
25 #-----------------------------------------------------------------------
26 #
27
28 seq=`basename $0`
29 seqres=$RESULT_DIR/$seq
30 echo "QA output created by $seq"
31
32 here=`pwd`
33 tmp=/tmp/$$
34 status=1        # failure is the default!
35 trap "_cleanup; exit \$status" 0 1 2 3 15
36
37 _cleanup()
38 {
39     cd /
40     rm -f $tmp.*
41 }
42
43 create_file()
44 {
45         local dir=$1
46         local direct=$2
47         local i=0
48
49         mkdir -p $dir
50         while $XFS_IO_PROG -f $direct -c "pwrite 0 1k" $dir/file_$i >/dev/null 2>&1; do
51                 let i=$i+1
52         done
53 }
54
55 # get standard environment, filters and checks
56 . ./common/rc
57 . ./common/filter
58
59 # real QA test starts here
60 _supported_fs generic
61 _supported_os Linux
62
63 _require_scratch
64
65 rm -f $seqres.full
66 echo "Silence is golden"
67
68 _scratch_mkfs_sized $((256 * 1024 * 1024)) >>$seqres.full 2>&1
69 _scratch_mount
70
71 echo "Reserve 2M space" >>$seqres.full
72 $XFS_IO_PROG -f -c "pwrite 0 2m" $SCRATCH_MNT/testfile >>$seqres.full 2>&1
73 echo "Fulfill the fs" >>$seqres.full
74 $XFS_IO_PROG -f -c "pwrite 0 254m" $SCRATCH_MNT/bigfile >>$seqres.full 2>&1
75 echo "Remove reserved file" >>$seqres.full
76 rm -f $SCRATCH_MNT/testfile
77
78 loop=100
79 # btrfs takes much longer time, reduce the loop count
80 if [ "$FSTYP" == "btrfs" ]; then
81         loop=10
82 fi
83
84 dir=$SCRATCH_MNT/testdir
85 echo -n "iteration" >>$seqres.full
86 i=1
87 while [ $i -le $loop ]; do
88         echo -n " $i" >>$seqres.full
89         nr_worker=8
90         while [ $nr_worker -gt 0 ]; do
91                 # half buffered I/O half direct I/O
92                 if [ `expr $nr_worker % 2` -eq 0 ]; then
93                         create_file $dir/$nr_worker -d >>$seqres.full &
94                 else
95                         create_file $dir/$nr_worker >>$seqres.full &
96                 fi
97                 let nr_worker=$nr_worker-1
98         done
99         wait
100         rm -rf $dir
101         let i=$i+1
102 done
103 _scratch_unmount
104
105 status=0
106 exit