fstests: convert remaining tests to SPDX license tags
[xfstests-dev.git] / tests / generic / 457
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2017 CTERA Networks. All Rights Reserved.
4 #
5 # FS QA Test No. 457
6 #
7 # Run fsx with log writes on cloned files to verify power fail safeness.
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 status=1        # failure is the default!
15
16 _cleanup()
17 {
18         _log_writes_cleanup
19 }
20 trap "_cleanup; exit \$status" 0 1 2 3 15
21
22 # get standard environment, filters and checks
23 . ./common/rc
24 . ./common/filter
25 . ./common/reflink
26 . ./common/dmlogwrites
27
28 # real QA test starts here
29 _supported_fs generic
30 _supported_os Linux
31 _require_test
32 _require_scratch_reflink
33 _require_cp_reflink
34 _require_log_writes
35
36 rm -f $seqres.full
37
38 check_files()
39 {
40         local name=$1
41
42         # Now look for our files
43         for i in $(find $SANITY_DIR -type f | grep $name | grep mark); do
44                 local filename=$(basename $i)
45                 local mark="${filename##*.}"
46                 echo "checking $filename" >> $seqres.full
47                 _log_writes_replay_log $filename
48                 _scratch_mount
49                 local expected_md5=$(_md5_checksum $i)
50                 local md5=$(_md5_checksum $SCRATCH_MNT/$name)
51                 [ "${md5}" != "${expected_md5}" ] && _fail "$filename md5sum mismatched"
52                 _scratch_unmount
53                 _check_scratch_fs
54         done
55 }
56
57 SANITY_DIR=$TEST_DIR/fsxtests
58 rm -rf $SANITY_DIR
59 mkdir $SANITY_DIR
60
61 # Create the log
62 _log_writes_init
63
64 _log_writes_mkfs >> $seqres.full 2>&1
65
66 # Log writes emulates discard support, turn it on for maximum crying.
67 _log_writes_mount -o discard
68
69 # write testfile index -1 to be cloned to testfile0
70 $XFS_IO_PROG -f -c "pwrite -S 0xff 0 256k" -c "fsync" \
71         $SCRATCH_MNT/testfile-1 > /dev/null 2>&1
72
73 NUM_FILES=10
74 NUM_OPS=10
75 FSX_OPTS="-N $NUM_OPS -d -k -P $SANITY_DIR -i $LOGWRITES_DMDEV"
76 # Run fsx for a while
77 # Set random seeds for fsx runs (0 for timestamp + pid)
78 for j in `seq 0 $((NUM_FILES-1))`; do
79         # clone the clone from prev iteration which may have already mutated
80         _cp_reflink $SCRATCH_MNT/testfile$((j-1)) $SCRATCH_MNT/testfile$j
81         run_check $here/ltp/fsx $FSX_OPTS -S 0 -j $j $SCRATCH_MNT/testfile$j &
82 done
83 wait
84
85 test_md5=()
86 for j in `seq 0 $((NUM_FILES-1))`; do
87         test_md5[$j]=$(_md5_checksum $SCRATCH_MNT/testfile$j)
88 done
89
90 # Unmount the scratch dir and tear down the log writes target
91 _log_writes_mark last
92 _log_writes_unmount
93 _log_writes_mark end
94 _log_writes_remove
95 _check_scratch_fs
96
97 # check pre umount
98 echo "checking pre umount" >> $seqres.full
99 _log_writes_replay_log last
100 _scratch_mount
101 _scratch_unmount
102 _check_scratch_fs
103
104 for j in `seq 0 $((NUM_FILES-1))`; do
105         check_files testfile$j
106 done
107
108 # Check the end
109 echo "checking post umount" >> $seqres.full
110 _log_writes_replay_log end
111 _scratch_mount
112 for j in `seq 0 $((NUM_FILES-1))`; do
113         md5=$(_md5_checksum $SCRATCH_MNT/testfile$j)
114         [ "${md5}" != "${test_md5[$j]}" ] && _fail "testfile$j end md5sum mismatched"
115 done
116
117 echo "Silence is golden"
118 status=0
119 exit