2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2013 Fusion IO. All Rights Reserved.
7 # Run various fsync tests with dm flakey in freeze() mode and non freeze()
8 # mode. The idea is that we do random writes and randomly fsync and verify that
9 # after a fsync() followed by a freeze()+failure or just failure that the file
10 # is correct. We remount the file system after the failure so that the file
11 # system can do whatever cleanup it needs to and md5sum the file to make sure
12 # it matches hat it was before the failure. We also fsck to make sure the file
13 # system is consistent.
15 # The fsync tester just random writes into prealloc or not, and then fsync()s
16 # randomly or sync()'s randomly and then fsync()'s before exit. There are a few
17 # tests that were handcrafted to reproduce bugs in btrfs, so it's also a
18 # regression test of sorts.
21 seqres=$RESULT_DIR/$seq
22 echo "QA output created by $seq"
25 status=1 # failure is the default!
31 trap "_cleanup; exit \$status" 0 1 2 3 15
33 # get standard environment, filters and checks
38 # real QA test starts here
41 _require_scratch_nocheck
43 _require_dm_target flakey
45 # xfs_io is not required for this test, but it's the best way to verify
46 # the test system supports fallocate() for allocation
47 _require_xfs_io_command "falloc"
49 _require_test_program "fsync-tester"
53 testfile=$SCRATCH_MNT/$seq.fsync
57 # _run_test <testnum> <0 - buffered | 1 - O_DIRECT>
61 [ $2 -eq 1 ] && direct_opt="-d"
63 $here/src/fsync-tester -s $SEED -t $test_num $direct_opt $testfile
64 [ $? -ne 0 ] && _fatal "fsync tester exited abnormally"
66 _md5_checksum $testfile
67 _load_flakey_table $FLAKEY_DROP_WRITES $lockfs
70 #Ok mount so that any recovery that needs to happen is done
71 _load_flakey_table $FLAKEY_ALLOW_WRITES
73 _md5_checksum $testfile
75 #Unmount and fsck to make sure we got a valid fs after replay
77 _check_scratch_fs $FLAKEY_DEV
78 [ $? -ne 0 ] && _fatal "fsck failed"
83 _scratch_mkfs >> $seqres.full 2>&1
84 _require_metadata_journaling $SCRATCH_DEV
86 # Create a basic flakey device that will never error out
93 for i in $(seq 1 20); do
96 echo "Running test $i buffered, normal suspend"
97 _run_test $i $buffered
98 echo "Running test $i direct, normal suspend"
102 echo "Running test $i buffered, nolockfs"
103 _run_test $i $buffered
104 echo "Running test $i direct, nolockfs"