generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / generic / 455
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Facebook. All Rights Reserved.
4 #
5 # FS QA Test No. 455
6 #
7 # Run fsx with log writes to verify power fail safeness.
8 #
9 . ./common/preamble
10 _begin_fstest auto log replay recoveryloop
11
12 # Override the default cleanup function.
13 _cleanup()
14 {
15         _log_writes_cleanup
16         _dmthin_cleanup
17 }
18
19 # Import common functions.
20 . ./common/filter
21 . ./common/dmthin
22 . ./common/dmlogwrites
23
24 # real QA test starts here
25 _supported_fs generic
26 _require_test
27 _require_scratch_nocheck
28 _require_log_writes
29 _require_dm_target thin-pool
30
31 check_files()
32 {
33         local name=$1
34
35         # Now look for our files
36         for i in $(find $SANITY_DIR -type f | grep $name | grep mark); do
37                 local filename=$(basename $i)
38                 local mark="${filename##*.}"
39                 echo "checking $filename" >> $seqres.full
40                 _log_writes_replay_log $filename $DMTHIN_VOL_DEV
41                 _dmthin_mount
42                 local expected_md5=$(_md5_checksum $i)
43                 local md5=$(_md5_checksum $SCRATCH_MNT/$name)
44                 [ "${md5}" != "${expected_md5}" ] && _fail "$filename md5sum mismatched"
45                 _dmthin_check_fs
46         done
47 }
48
49 SANITY_DIR=$TEST_DIR/fsxtests
50 rm -rf $SANITY_DIR
51 mkdir $SANITY_DIR
52
53 devsize=$((1024*1024*200 / 512))        # 200m phys/virt size
54 csize=$((1024*64 / 512))                # 64k cluster size
55 lowspace=$((1024*1024 / 512))           # 1m low space threshold
56
57 # Use a thin device to provide deterministic discard behavior. Discards are used
58 # by the log replay tool for fast zeroing to prevent out-of-order replay issues.
59 _dmthin_init $devsize $devsize $csize $lowspace
60
61 # Create the log
62 _log_writes_init $DMTHIN_VOL_DEV
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 NUM_FILES=4
70 NUM_OPS=200
71 FSX_OPTS="-N $NUM_OPS -d -P $SANITY_DIR -i $LOGWRITES_DMDEV"
72 # Set random seeds for fsx runs (0 for timestamp + pid)
73 # When test failure is detected, check the seed values printed
74 # by fsx processes to $seqres.full and set them in this array
75 # to repeat the same fsx runs
76 seeds=(0 0 0 0)
77 # Run fsx for a while
78 for j in `seq 0 $((NUM_FILES-1))`; do
79         run_check $here/ltp/fsx $FSX_OPTS -S ${seeds[$j]} -j $j $SCRATCH_MNT/testfile$j &
80 done
81 wait
82
83 test_md5=()
84 for j in `seq 0 $((NUM_FILES-1))`; do
85         test_md5[$j]=$(_md5_checksum $SCRATCH_MNT/testfile$j)
86 done
87
88 # Unmount the scratch dir and tear down the log writes target
89 _log_writes_mark last
90 _log_writes_unmount
91 _log_writes_mark end
92 _log_writes_remove
93 _dmthin_check_fs
94
95 # check pre umount
96 echo "checking pre umount" >> $seqres.full
97 _log_writes_replay_log last $DMTHIN_VOL_DEV
98 _dmthin_mount
99 _dmthin_check_fs
100
101 for j in `seq 0 $((NUM_FILES-1))`; do
102         check_files testfile$j
103 done
104
105 # Check the end
106 echo "checking post umount" >> $seqres.full
107 _log_writes_replay_log end $DMTHIN_VOL_DEV
108 _dmthin_mount
109 for j in `seq 0 $((NUM_FILES-1))`; do
110         md5=$(_md5_checksum $SCRATCH_MNT/testfile$j)
111         [ "${md5}" != "${test_md5[$j]}" ] && _fail "testfile$j end md5sum mismatched"
112 done
113 _dmthin_check_fs
114
115 echo "Silence is golden"
116 status=0
117 exit