fstests: don't _require_metadata_journaling before _scratch_mkfs
[xfstests-dev.git] / tests / generic / 311
1 #! /bin/bash
2 # FS QA Test No. 311
3 #
4 # Run various fsync tests with dm flakey in freeze() mode and non freeze()
5 # mode. The idea is that we do random writes and randomly fsync and verify that
6 # after a fsync() followed by a freeze()+failure or just failure that the file
7 # is correct.  We remount the file system after the failure so that the file
8 # system can do whatever cleanup it needs to and md5sum the file to make sure
9 # it matches hat it was before the failure.  We also fsck to make sure the file
10 # system is consistent.
11 #
12 # The fsync tester just random writes into prealloc or not, and then fsync()s
13 # randomly or sync()'s randomly and then fsync()'s before exit.  There are a few
14 # tests that were handcrafted to reproduce bugs in btrfs, so it's also a
15 # regression test of sorts.
16 #
17 #-----------------------------------------------------------------------
18 # Copyright (c) 2013 Fusion IO. All Rights Reserved.
19 #
20 # This program is free software; you can redistribute it and/or
21 # modify it under the terms of the GNU General Public License as
22 # published by the Free Software Foundation.
23 #
24 # This program is distributed in the hope that it would be useful,
25 # but WITHOUT ANY WARRANTY; without even the implied warranty of
26 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27 # GNU General Public License for more details.
28 #
29 # You should have received a copy of the GNU General Public License
30 # along with this program; if not, write the Free Software Foundation,
31 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
32 #-----------------------------------------------------------------------
33 #
34
35 seq=`basename $0`
36 seqres=$RESULT_DIR/$seq
37 echo "QA output created by $seq"
38
39 here=`pwd`
40 status=1        # failure is the default!
41
42 _cleanup()
43 {
44         _cleanup_flakey
45 }
46 trap "_cleanup; exit \$status" 0 1 2 3 15
47
48 # get standard environment, filters and checks
49 . ./common/rc
50 . ./common/filter
51 . ./common/dmflakey
52
53 # real QA test starts here
54 _supported_fs generic
55 _supported_os Linux
56 _require_scratch_nocheck
57 _require_odirect
58 _require_dm_target flakey
59
60 # xfs_io is not required for this test, but it's the best way to verify
61 # the test system supports fallocate() for allocation
62 _require_xfs_io_command "falloc"
63
64 _require_test_program "fsync-tester"
65
66 rm -f $seqres.full
67 SEED=1
68 testfile=$SCRATCH_MNT/$seq.fsync
69
70 _run_test()
71 {
72         # _run_test <testnum> <0 - buffered | 1 - O_DIRECT>
73         test_num=$1
74
75         direct_opt=""
76         [ $2 -eq 1 ] && direct_opt="-d"
77
78         $here/src/fsync-tester -s $SEED -t $test_num $direct_opt $testfile
79         [ $? -ne 0 ] && _fatal "fsync tester exited abnormally"
80
81         _md5_checksum $testfile
82         _load_flakey_table $FLAKEY_DROP_WRITES $lockfs
83         _unmount_flakey
84
85         #Ok mount so that any recovery that needs to happen is done
86         _load_flakey_table $FLAKEY_ALLOW_WRITES
87         _mount_flakey
88         _md5_checksum $testfile
89
90         #Unmount and fsck to make sure we got a valid fs after replay
91         _unmount_flakey
92         _check_scratch_fs $FLAKEY_DEV
93         [ $? -ne 0 ] && _fatal "fsck failed"
94
95         _mount_flakey
96 }
97
98 _scratch_mkfs >> $seqres.full 2>&1
99 _require_metadata_journaling $SCRATCH_DEV
100
101 # Create a basic flakey device that will never error out
102 _init_flakey
103 _mount_flakey
104
105 buffered=0
106 direct=1
107
108 for i in $(seq 1 20); do
109         lockfs=1
110         SEED=$i
111         echo "Running test $i buffered, normal suspend"
112         _run_test $i $buffered
113         echo "Running test $i direct, normal suspend"
114         _run_test $i $direct
115
116         lockfs=0
117         echo "Running test $i buffered, nolockfs"
118         _run_test $i $buffered
119         echo "Running test $i direct, nolockfs"
120         _run_test $i $direct
121 done
122
123 status=0
124 exit