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 _begin_fstest auto metadata log
23 # Override the default cleanup function.
29 # Import common functions.
33 # real QA test starts here
35 _require_scratch_nocheck
37 _require_dm_target flakey
39 # xfs_io is not required for this test, but it's the best way to verify
40 # the test system supports fallocate() for allocation
41 _require_xfs_io_command "falloc"
43 _require_test_program "fsync-tester"
46 testfile=$SCRATCH_MNT/$seq.fsync
50 # _run_test <testnum> <0 - buffered | 1 - O_DIRECT>
54 [ $2 -eq 1 ] && direct_opt="-d"
56 $here/src/fsync-tester -s $SEED -t $test_num $direct_opt $testfile
57 [ $? -ne 0 ] && _fatal "fsync tester exited abnormally"
59 _md5_checksum $testfile
60 _load_flakey_table $FLAKEY_DROP_WRITES $lockfs
63 #Ok mount so that any recovery that needs to happen is done
64 _load_flakey_table $FLAKEY_ALLOW_WRITES
66 _md5_checksum $testfile
68 #Unmount and fsck to make sure we got a valid fs after replay
70 _check_scratch_fs $FLAKEY_DEV
71 [ $? -ne 0 ] && _fatal "fsck failed"
76 _scratch_mkfs >> $seqres.full 2>&1
77 _require_metadata_journaling $SCRATCH_DEV
79 # Create a basic flakey device that will never error out
86 for i in $(seq 1 20); do
89 echo "Running test $i buffered, normal suspend"
90 _run_test $i $buffered
91 echo "Running test $i direct, normal suspend"
95 echo "Running test $i buffered, nolockfs"
96 _run_test $i $buffered
97 echo "Running test $i direct, nolockfs"