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
40 _require_scratch_nocheck
42 _require_dm_target flakey
44 # xfs_io is not required for this test, but it's the best way to verify
45 # the test system supports fallocate() for allocation
46 _require_xfs_io_command "falloc"
48 _require_test_program "fsync-tester"
52 testfile=$SCRATCH_MNT/$seq.fsync
56 # _run_test <testnum> <0 - buffered | 1 - O_DIRECT>
60 [ $2 -eq 1 ] && direct_opt="-d"
62 $here/src/fsync-tester -s $SEED -t $test_num $direct_opt $testfile
63 [ $? -ne 0 ] && _fatal "fsync tester exited abnormally"
65 _md5_checksum $testfile
66 _load_flakey_table $FLAKEY_DROP_WRITES $lockfs
69 #Ok mount so that any recovery that needs to happen is done
70 _load_flakey_table $FLAKEY_ALLOW_WRITES
72 _md5_checksum $testfile
74 #Unmount and fsck to make sure we got a valid fs after replay
76 _check_scratch_fs $FLAKEY_DEV
77 [ $? -ne 0 ] && _fatal "fsck failed"
82 _scratch_mkfs >> $seqres.full 2>&1
83 _require_metadata_journaling $SCRATCH_DEV
85 # Create a basic flakey device that will never error out
92 for i in $(seq 1 20); do
95 echo "Running test $i buffered, normal suspend"
96 _run_test $i $buffered
97 echo "Running test $i direct, normal suspend"
101 echo "Running test $i buffered, nolockfs"
102 _run_test $i $buffered
103 echo "Running test $i direct, nolockfs"