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