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