tools: add a dm-logwrites replay tool
[xfstests-dev.git] / tests / generic / 482
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 SUSE Linux Products GmbH.  All Rights Reserved.
4 #
5 # FS QA Test 482
6 #
7 # Test filesystem consistency after each FUA operation
8 #
9 # Will do log replay and check the filesystem.
10 #
11 . ./common/preamble
12 _begin_fstest auto metadata replay thin
13
14 # Override the default cleanup function.
15 #
16 # If debugging logwrites failures using the tools/dm-logwrite-replay script,
17 # switch the cleanup function to the version that is commented out below so that
18 # failure leaves the corpse intact for post-mortem failure analysis.
19 _cleanup()
20 {
21         cd /
22         $KILLALL_PROG -KILL -q $FSSTRESS_PROG &> /dev/null
23         _log_writes_cleanup &> /dev/null
24         _dmthin_cleanup
25         rm -f $tmp.*
26 }
27
28 # tools/dm-logwrite-replay _cleanup version
29 #_cleanup()
30 #{
31 #       cd /
32 #       $KILLALL_PROG -KILL -q $FSSTRESS_PROG &> /dev/null
33 #       if [ $status -eq 0 ]; then
34 #               _log_writes_cleanup &> /dev/null
35 #               _dmthin_cleanup
36 #       else
37 #               echo dm-thinvol-dev: $DMTHIN_VOL_DEV >> $seqres.full
38 #       fi
39 #       rm -f $tmp.*
40 #}
41
42 # Import common functions.
43 . ./common/filter
44 . ./common/dmthin
45 . ./common/dmlogwrites
46
47 # real QA test starts here
48
49 # Modify as appropriate.
50 _supported_fs generic
51
52 _require_command "$KILLALL_PROG" killall
53 # Use thin device as replay device, which requires $SCRATCH_DEV
54 _require_scratch_nocheck
55 # and we need extra device as log device
56 _require_log_writes
57 _require_dm_target thin-pool
58
59 nr_cpus=$("$here/src/feature" -o)
60 # cap nr_cpus to 8 to avoid spending too much time on hosts with many cpus
61 if [ $nr_cpus -gt 8 ]; then
62         nr_cpus=8
63 fi
64 fsstress_args=$(_scale_fsstress_args -w -d $SCRATCH_MNT -n 512 -p $nr_cpus \
65                 $FSSTRESS_AVOID)
66 devsize=$((1024*1024*200 / 512))        # 200m phys/virt size
67 csize=$((1024*64 / 512))                # 64k cluster size
68 lowspace=$((1024*1024 / 512))           # 1m low space threshold
69
70 # Use a thin device to provide deterministic discard behavior. Discards are used
71 # by the log replay tool for fast zeroing to prevent out-of-order replay issues.
72 _test_unmount
73 _dmthin_init $devsize $devsize $csize $lowspace
74 _log_writes_init $DMTHIN_VOL_DEV
75 _log_writes_mkfs >> $seqres.full 2>&1
76 _log_writes_mark mkfs
77
78 _log_writes_mount
79 run_check $FSSTRESS_PROG $fsstress_args > /dev/null 2>&1
80 _log_writes_unmount
81
82 _log_writes_remove
83 prev=$(_log_writes_mark_to_entry_number mkfs)
84 [ -z "$prev" ] && _fail "failed to locate entry mark 'mkfs'"
85 cur=$(_log_writes_find_next_fua $prev)
86 [ -z "$cur" ] && _fail "failed to locate next FUA write"
87
88 while [ ! -z "$cur" ]; do
89         _log_writes_replay_log_range $cur $DMTHIN_VOL_DEV >> $seqres.full
90
91         # Here we need extra mount to replay the log, mainly for journal based
92         # fs, as their fsck will report dirty log as error.
93         # We don't care to preserve any data on the replay dev, as we can replay
94         # back to the point we need, and in fact sometimes creating/deleting
95         # snapshots repeatedly can be slower than replaying the log.
96         _dmthin_mount
97         _dmthin_check_fs
98
99         prev=$cur
100         cur=$(_log_writes_find_next_fua $(($cur + 1)))
101         [ -z "$cur" ] && break
102 done
103
104 echo "Silence is golden"
105
106 # success, all done
107 status=0
108 exit