generic: crash consistency fsx test using dm-log-writes
[xfstests-dev.git] / tests / generic / 500
1 #! /bin/bash
2 # FS QA Test No. 500
3 #
4 # Run fsx with log writes to verify power fail safeness.
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2015 Facebook. All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #-----------------------------------------------------------------------
22 #
23
24 seq=`basename $0`
25 seqres=$RESULT_DIR/$seq
26 echo "QA output created by $seq"
27
28 here=`pwd`
29 status=1        # failure is the default!
30
31 _cleanup()
32 {
33         _log_writes_cleanup
34 }
35 trap "_cleanup; exit \$status" 0 1 2 3 15
36
37 # get standard environment, filters and checks
38 . ./common/rc
39 . ./common/filter
40 . ./common/dmlogwrites
41
42 # real QA test starts here
43 _supported_fs generic
44 _supported_os Linux
45 _require_test
46 _require_scratch_nocheck
47 _require_log_writes
48
49 rm -f $seqres.full
50
51 check_files()
52 {
53         local name=$1
54
55         # Now look for our files
56         for i in $(find $SANITY_DIR -type f | grep $name | grep mark); do
57                 local filename=$(basename $i)
58                 local mark="${filename##*.}"
59                 echo "checking $filename" >> $seqres.full
60                 _log_writes_replay_log $filename
61                 _scratch_mount
62                 local expected_md5=$(_md5_checksum $i)
63                 local md5=$(_md5_checksum $SCRATCH_MNT/$name)
64                 [ "${md5}" != "${expected_md5}" ] && _fail "$filename md5sum mismatched"
65                 _scratch_unmount
66                 _check_scratch_fs
67         done
68 }
69
70 SANITY_DIR=$TEST_DIR/fsxtests
71 rm -rf $SANITY_DIR
72 mkdir $SANITY_DIR
73
74 # Create the log
75 _log_writes_init
76
77 _log_writes_mkfs >> $seqres.full 2>&1
78
79 # Log writes emulates discard support, turn it on for maximum crying.
80 _log_writes_mount -o discard
81
82 NUM_FILES=4
83 NUM_OPS=200
84 FSX_OPTS="-N $NUM_OPS -d -P $SANITY_DIR -i $LOGWRITES_DMDEV"
85 # Set random seeds for fsx runs (0 for timestamp + pid)
86 # When test failure is detected, check the seed values printed
87 # by fsx processes to $seqres.full and set them in this array
88 # to repeat the same fsx runs
89 seeds=(0 0 0 0)
90 # Run fsx for a while
91 for j in `seq 0 $((NUM_FILES-1))`; do
92         run_check $here/ltp/fsx $FSX_OPTS -S ${seeds[$j]} -j $j $SCRATCH_MNT/testfile$j &
93 done
94 wait
95
96 test_md5=()
97 for j in `seq 0 $((NUM_FILES-1))`; do
98         test_md5[$j]=$(_md5_checksum $SCRATCH_MNT/testfile$j)
99 done
100
101 # Unmount the scratch dir and tear down the log writes target
102 _log_writes_mark last
103 _log_writes_unmount
104 _log_writes_mark end
105 _log_writes_remove
106 _check_scratch_fs
107
108 # check pre umount
109 echo "checking pre umount" >> $seqres.full
110 _log_writes_replay_log last
111 _scratch_mount
112 _scratch_unmount
113 _check_scratch_fs
114
115 for j in `seq 0 $((NUM_FILES-1))`; do
116         check_files testfile$j
117 done
118
119 # Check the end
120 echo "checking post umount" >> $seqres.full
121 _log_writes_replay_log end
122 _scratch_mount
123 for j in `seq 0 $((NUM_FILES-1))`; do
124         md5=$(_md5_checksum $SCRATCH_MNT/testfile$j)
125         [ "${md5}" != "${test_md5[$j]}" ] && _fail "testfile$j end md5sum mismatched"
126 done
127 _scratch_unmount
128 _check_scratch_fs
129
130 echo "Silence is golden"
131 status=0
132 exit