generic/611: Use _getfattr instead of GETFATTR_PROG
[xfstests-dev.git] / tests / generic / 311
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2013 Fusion IO. All Rights Reserved.
4 #
5 # FS QA Test No. 311
6 #
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.
14 #
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.
19 #
20 seq=`basename $0`
21 seqres=$RESULT_DIR/$seq
22 echo "QA output created by $seq"
23
24 here=`pwd`
25 status=1        # failure is the default!
26
27 _cleanup()
28 {
29         _cleanup_flakey
30 }
31 trap "_cleanup; exit \$status" 0 1 2 3 15
32
33 # get standard environment, filters and checks
34 . ./common/rc
35 . ./common/filter
36 . ./common/dmflakey
37
38 # real QA test starts here
39 _supported_fs generic
40 _require_scratch_nocheck
41 _require_odirect
42 _require_dm_target flakey
43
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"
47
48 _require_test_program "fsync-tester"
49
50 rm -f $seqres.full
51 SEED=1
52 testfile=$SCRATCH_MNT/$seq.fsync
53
54 _run_test()
55 {
56         # _run_test <testnum> <0 - buffered | 1 - O_DIRECT>
57         test_num=$1
58
59         direct_opt=""
60         [ $2 -eq 1 ] && direct_opt="-d"
61
62         $here/src/fsync-tester -s $SEED -t $test_num $direct_opt $testfile
63         [ $? -ne 0 ] && _fatal "fsync tester exited abnormally"
64
65         _md5_checksum $testfile
66         _load_flakey_table $FLAKEY_DROP_WRITES $lockfs
67         _unmount_flakey
68
69         #Ok mount so that any recovery that needs to happen is done
70         _load_flakey_table $FLAKEY_ALLOW_WRITES
71         _mount_flakey
72         _md5_checksum $testfile
73
74         #Unmount and fsck to make sure we got a valid fs after replay
75         _unmount_flakey
76         _check_scratch_fs $FLAKEY_DEV
77         [ $? -ne 0 ] && _fatal "fsck failed"
78
79         _mount_flakey
80 }
81
82 _scratch_mkfs >> $seqres.full 2>&1
83 _require_metadata_journaling $SCRATCH_DEV
84
85 # Create a basic flakey device that will never error out
86 _init_flakey
87 _mount_flakey
88
89 buffered=0
90 direct=1
91
92 for i in $(seq 1 20); do
93         lockfs=1
94         SEED=$i
95         echo "Running test $i buffered, normal suspend"
96         _run_test $i $buffered
97         echo "Running test $i direct, normal suspend"
98         _run_test $i $direct
99
100         lockfs=0
101         echo "Running test $i buffered, nolockfs"
102         _run_test $i $buffered
103         echo "Running test $i direct, nolockfs"
104         _run_test $i $direct
105 done
106
107 status=0
108 exit