generic/223: make sure all files get created on the data device
[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         _dmthin_cleanup
20 }
21 trap "_cleanup; exit \$status" 0 1 2 3 15
22
23 # get standard environment, filters and checks
24 . ./common/rc
25 . ./common/filter
26 . ./common/reflink
27 . ./common/dmthin
28 . ./common/dmlogwrites
29
30 # real QA test starts here
31 _supported_fs generic
32 _require_test
33 _require_scratch_reflink
34 _require_cp_reflink
35 _require_log_writes
36 _require_dm_target thin-pool
37
38 rm -f $seqres.full
39
40 check_files()
41 {
42         local name=$1
43
44         # Now look for our files
45         for i in $(find $SANITY_DIR -type f | grep $name | grep mark); do
46                 local filename=$(basename $i)
47                 local mark="${filename##*.}"
48                 echo "checking $filename" >> $seqres.full
49                 _log_writes_replay_log $filename $DMTHIN_VOL_DEV
50                 _dmthin_mount
51                 local expected_md5=$(_md5_checksum $i)
52                 local md5=$(_md5_checksum $SCRATCH_MNT/$name)
53                 [ "${md5}" != "${expected_md5}" ] && _fail "$filename md5sum mismatched"
54                 _dmthin_check_fs
55         done
56 }
57
58 SANITY_DIR=$TEST_DIR/fsxtests
59 rm -rf $SANITY_DIR
60 mkdir $SANITY_DIR
61
62 devsize=$((1024*1024*200 / 512))        # 200m phys/virt size
63 csize=$((1024*64 / 512))                # 64k cluster size
64 lowspace=$((1024*1024 / 512))           # 1m low space threshold
65
66 # Use a thin device to provide deterministic discard behavior. Discards are used
67 # by the log replay tool for fast zeroing to prevent out-of-order replay issues.
68 _dmthin_init $devsize $devsize $csize $lowspace
69
70 # Create the log
71 _log_writes_init $DMTHIN_VOL_DEV
72
73 _log_writes_mkfs >> $seqres.full 2>&1
74
75 # Log writes emulates discard support, turn it on for maximum crying.
76 _log_writes_mount -o discard
77
78 # write testfile index -1 to be cloned to testfile0
79 $XFS_IO_PROG -f -c "pwrite -S 0xff 0 256k" -c "fsync" \
80         $SCRATCH_MNT/testfile-1 > /dev/null 2>&1
81
82 NUM_FILES=10
83 NUM_OPS=10
84 FSX_OPTS="-N $NUM_OPS -d -k -P $SANITY_DIR -i $LOGWRITES_DMDEV"
85 # Run fsx for a while
86 # Set random seeds for fsx runs (0 for timestamp + pid)
87 for j in `seq 0 $((NUM_FILES-1))`; do
88         # clone the clone from prev iteration which may have already mutated
89         _cp_reflink $SCRATCH_MNT/testfile$((j-1)) $SCRATCH_MNT/testfile$j
90         run_check $here/ltp/fsx $FSX_OPTS -S 0 -j $j $SCRATCH_MNT/testfile$j &
91 done
92 wait
93
94 test_md5=()
95 for j in `seq 0 $((NUM_FILES-1))`; do
96         test_md5[$j]=$(_md5_checksum $SCRATCH_MNT/testfile$j)
97 done
98
99 # Unmount the scratch dir and tear down the log writes target
100 _log_writes_mark last
101 _log_writes_unmount
102 _log_writes_mark end
103 _log_writes_remove
104 _dmthin_check_fs
105
106 # check pre umount
107 echo "checking pre umount" >> $seqres.full
108 _log_writes_replay_log last $DMTHIN_VOL_DEV
109 _dmthin_mount
110 _dmthin_check_fs
111
112 for j in `seq 0 $((NUM_FILES-1))`; do
113         check_files testfile$j
114 done
115
116 # Check the end
117 echo "checking post umount" >> $seqres.full
118 _log_writes_replay_log end $DMTHIN_VOL_DEV
119 _dmthin_mount
120 for j in `seq 0 $((NUM_FILES-1))`; do
121         md5=$(_md5_checksum $SCRATCH_MNT/testfile$j)
122         [ "${md5}" != "${test_md5[$j]}" ] && _fail "testfile$j end md5sum mismatched"
123 done
124
125 echo "Silence is golden"
126 status=0
127 exit