xfs: fix old fuzz test invocations of xfs_repair
[xfstests-dev.git] / tests / btrfs / 192
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2019 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test 192
6 #
7 # Test btrfs consistency after each FUA for a workload with snapshot creation
8 # and removal
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         cd /
22         kill -q $pid1 &> /dev/null
23         kill -q $pid2 &> /dev/null
24         "$KILLALL_PROG" -q $FSSTRESS_PROG &> /dev/null
25         wait
26         _log_writes_cleanup &> /dev/null
27         rm -f $tmp.*
28 }
29
30 # get standard environment, filters and checks
31 . ./common/rc
32 . ./common/filter
33 . ./common/attr
34 . ./common/dmlogwrites
35
36 # remove previous $seqres.full before test
37 rm -f $seqres.full
38
39 # real QA test starts here
40
41 # Modify as appropriate.
42 _supported_fs btrfs
43
44 _require_command "$KILLALL_PROG" killall
45 _require_command "$BLKDISCARD_PROG" blkdiscard
46 _require_btrfs_fs_feature "no_holes"
47 _require_btrfs_mkfs_feature "no-holes"
48 _require_log_writes
49 _require_scratch
50 _require_attrs
51
52 # We require a 4K nodesize to ensure the test isn't too slow
53 if [ $(get_page_size) -ne 4096 ]; then
54         _notrun "This test doesn't support non-4K page size yet"
55 fi
56
57 runtime=30
58 nr_cpus=$("$here/src/feature" -o)
59 # cap nr_cpus to 8 to avoid spending too much time on hosts with many cpus
60 if [ $nr_cpus -gt 8 ]; then
61         nr_cpus=8
62 fi
63 fsstress_args=$(_scale_fsstress_args -w -d $SCRATCH_MNT -n 99999 -p $nr_cpus \
64                 $FSSTRESS_AVOID)
65 _log_writes_init $SCRATCH_DEV
66
67 # Discard the whole devices so when some tree pointer is wrong, it won't point
68 # to some older valid tree blocks, so we can detect it.
69 $BLKDISCARD_PROG $LOGWRITES_DMDEV > /dev/null 2>&1
70
71 # Use no-holes to avoid warnings of missing file extent items (expected
72 # for holes due to mix of buffered and direct IO writes).
73 # And use 4K nodesize to bump tree height.
74 _log_writes_mkfs -O no-holes -n 4k >> $seqres.full
75 _log_writes_mount
76
77 $BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/src > /dev/null
78 mkdir -p $SCRATCH_MNT/snapshots
79 mkdir -p $SCRATCH_MNT/src/padding
80
81 random_file()
82 {
83         local basedir=$1
84         echo "$basedir/$(ls $basedir | sort -R | tail -1)"
85 }
86
87 snapshot_workload()
88 {
89         trap "wait; exit" SIGTERM
90
91         local i=0
92         while true; do
93                 $BTRFS_UTIL_PROG subvolume snapshot \
94                         $SCRATCH_MNT/src $SCRATCH_MNT/snapshots/$i \
95                         > /dev/null
96                 # Do something small to make snapshots different
97                 rm -f "$(random_file $SCRATCH_MNT/src/padding)"
98                 rm -f "$(random_file $SCRATCH_MNT/src/padding)"
99                 touch "$(random_file $SCRATCH_MNT/src/padding)"
100                 touch "$SCRATCH_MNT/src/padding/random_$RANDOM"
101
102                 i=$(($i + 1))
103                 sleep 1
104         done
105 }
106
107 delete_workload()
108 {
109         trap "wait; exit" SIGTERM
110
111         while true; do
112                 sleep 2
113                 $BTRFS_UTIL_PROG subvolume delete \
114                         "$(random_file $SCRATCH_MNT/snapshots)" \
115                         > /dev/null 2>&1
116         done
117 }
118
119 # Replay and check each fua/flush (specified by $2) point.
120 #
121 # Since dm-log-writes records bio sequentially, even just replaying a range
122 # still needs to iterate all records before the end point.
123 # When number of records grows, it will be unacceptably slow, thus we need
124 # to use relay-log itself to trigger fsck, avoid unnecessary seek.
125 log_writes_fast_replay_check()
126 {
127         local check_point=$1
128         local blkdev=$2
129         local fsck_command="$BTRFS_UTIL_PROG check $blkdev"
130         local ret
131
132         [ -z "$check_point" -o -z "$blkdev" ] && _fail \
133         "check_point and blkdev must be specified for log_writes_fast_replay_check"
134
135         $here/src/log-writes/replay-log --log $LOGWRITES_DEV \
136                 --replay $blkdev --check $check_point --fsck "$fsck_command" \
137                 &> $tmp.full_fsck
138         ret=$?
139         tail -n 150 $tmp.full_fsck > $seqres.full
140         [ $ret -ne 0 ] && _fail "fsck failed during replay"
141 }
142
143 xattr_value=$(printf '%0.sX' $(seq 1 3800))
144
145 # Bumping tree height to level 2.
146 for ((i = 0; i < 64; i++)); do
147         touch "$SCRATCH_MNT/src/padding/$i"
148         $SETFATTR_PROG -n 'user.x1' -v $xattr_value "$SCRATCH_MNT/src/padding/$i"
149 done
150
151 _log_writes_mark prepare
152
153 snapshot_workload &
154 pid1=$!
155 delete_workload &
156 pid2=$!
157
158 "$FSSTRESS_PROG" $fsstress_args > /dev/null &
159 sleep $runtime
160
161 "$KILLALL_PROG" -q "$FSSTRESS_PROG" &> /dev/null
162 kill $pid1 &> /dev/null
163 kill $pid2 &> /dev/null
164 wait
165 _log_writes_unmount
166 _log_writes_remove
167
168 log_writes_fast_replay_check fua "$SCRATCH_DEV"
169
170 echo "Silence is golden"
171
172 # success, all done
173 status=0
174 exit