]> git.proxmox.com Git - mirror_zfs.git/blame - scripts/zloop.sh
Remove l2arc_nocompress from zfs-module-parameters(5)
[mirror_zfs.git] / scripts / zloop.sh
CommitLineData
9c13b489 1#!/bin/bash
541a0901
BB
2
3#
4# CDDL HEADER START
5#
6# This file and its contents are supplied under the terms of the
7# Common Development and Distribution License ("CDDL"), version 1.0.
8# You may only use this file in accordance with the terms of version
9# 1.0 of the CDDL.
10#
11# A full copy of the text of the CDDL should have accompanied this
12# source. A copy of the CDDL is also available via the Internet at
13# http://www.illumos.org/license/CDDL.
14#
15# CDDL HEADER END
16#
17
18#
19# Copyright (c) 2015 by Delphix. All rights reserved.
20# Copyright (C) 2016 Lawrence Livermore National Security, LLC.
21#
22
c8f9061f 23BASE_DIR=$(dirname "$0")
541a0901 24SCRIPT_COMMON=common.sh
c8f9061f
BB
25if [ -f "${BASE_DIR}/${SCRIPT_COMMON}" ]; then
26 . "${BASE_DIR}/${SCRIPT_COMMON}"
541a0901
BB
27else
28 echo "Missing helper script ${SCRIPT_COMMON}" && exit 1
29fi
30
c552fbc5 31# shellcheck disable=SC2034
541a0901 32PROG=zloop.sh
fed90353 33GDB=${GDB:-gdb}
541a0901
BB
34
35DEFAULTWORKDIR=/var/tmp
36DEFAULTCOREDIR=/var/tmp/zloop
37
38function usage
39{
aea899a6 40 echo -e "\n$0 [-t <timeout>] [ -s <vdev size> ] [-c <dump directory>]" \
541a0901
BB
41 "[ -- [extra ztest parameters]]\n" \
42 "\n" \
43 " This script runs ztest repeatedly with randomized arguments.\n" \
44 " If a crash is encountered, the ztest logs, any associated\n" \
45 " vdev files, and core file (if one exists) are moved to the\n" \
46 " output directory ($DEFAULTCOREDIR by default). Any options\n" \
47 " after the -- end-of-options marker will be passed to ztest.\n" \
48 "\n" \
49 " Options:\n" \
50 " -t Total time to loop for, in seconds. If not provided,\n" \
51 " zloop runs forever.\n" \
aea899a6 52 " -s Size of vdev devices.\n" \
541a0901
BB
53 " -f Specify working directory for ztest vdev files.\n" \
54 " -c Specify a core dump directory to use.\n" \
55 " -h Print this help message.\n" \
56 "" >&2
57}
58
59function or_die
60{
c552fbc5 61 # shellcheck disable=SC2068
541a0901 62 $@
c552fbc5 63 # shellcheck disable=SC2181
541a0901 64 if [[ $? -ne 0 ]]; then
c552fbc5 65 # shellcheck disable=SC2145
541a0901
BB
66 echo "Command failed: $@"
67 exit 1
68 fi
69}
70
20da0566
GN
71# core file helpers
72origcorepattern="$(cat /proc/sys/kernel/core_pattern)"
73coreglob="$(egrep -o '^([^|%[:space:]]*)' /proc/sys/kernel/core_pattern)*"
74
75if [[ $coreglob = "*" ]]; then
76 echo "Setting core file pattern..."
77 echo "core" > /proc/sys/kernel/core_pattern
0c313d2f
GN
78 coreglob="$(egrep -o '^([^|%[:space:]]*)' \
79 /proc/sys/kernel/core_pattern)*"
20da0566
GN
80fi
81
82function core_file
83{
c552fbc5 84 # shellcheck disable=SC2012 disable=2086
20da0566
GN
85 printf "%s" "$(ls -tr1 $coreglob 2> /dev/null | head -1)"
86}
87
0c313d2f
GN
88function core_prog
89{
90 prog=$ZTEST
c552fbc5 91 core_id=$($GDB --batch -c "$1" | grep "Core was generated by" | \
0c313d2f 92 tr \' ' ')
c552fbc5 93 # shellcheck disable=SC2076
0c313d2f
GN
94 if [[ "$core_id" =~ "zdb " ]]; then
95 prog=$ZDB
96 fi
97 printf "%s" "$prog"
98}
99
541a0901
BB
100function store_core
101{
20da0566
GN
102 core="$(core_file)"
103 if [[ $ztrc -ne 0 ]] || [[ -f "$core" ]]; then
5df5d06a 104 df -h "$workdir" >>ztest.out
541a0901 105 coreid=$(date "+zloop-%y%m%d-%H%M%S")
c552fbc5 106 foundcrashes=$((foundcrashes + 1))
541a0901
BB
107
108 dest=$coredir/$coreid
c552fbc5
GDN
109 or_die mkdir -p "$dest"
110 or_die mkdir -p "$dest/vdev"
541a0901
BB
111
112 echo "*** ztest crash found - moving logs to $dest"
113
c552fbc5
GDN
114 or_die mv ztest.history "$dest/"
115 or_die mv ztest.ddt "$dest/"
116 or_die mv ztest.out "$dest/"
117 or_die mv "$workdir/ztest*" "$dest/vdev/"
118 or_die mv "$workdir/zpool.cache" "$dest/vdev/"
541a0901
BB
119
120 # check for core
20da0566 121 if [[ -f "$core" ]]; then
c552fbc5 122 coreprog=$(core_prog "$core")
541a0901
BB
123 corestatus=$($GDB --batch --quiet \
124 -ex "set print thread-events off" \
125 -ex "printf \"*\n* Backtrace \n*\n\"" \
126 -ex "bt" \
127 -ex "printf \"*\n* Libraries \n*\n\"" \
128 -ex "info sharedlib" \
129 -ex "printf \"*\n* Threads (full) \n*\n\"" \
130 -ex "info threads" \
131 -ex "printf \"*\n* Backtraces \n*\n\"" \
132 -ex "thread apply all bt" \
133 -ex "printf \"*\n* Backtraces (full) \n*\n\"" \
134 -ex "thread apply all bt full" \
c552fbc5 135 -ex "quit" "$coreprog" "$core" | grep -v "New LWP")
541a0901
BB
136
137 # Dump core + logs to stored directory
c552fbc5
GDN
138 echo "$corestatus" >>"$dest/status"
139 or_die mv "$core" "$dest/"
541a0901
BB
140
141 # Record info in cores logfile
20da0566 142 echo "*** core @ $coredir/$coreid/$core:" | \
541a0901
BB
143 tee -a ztest.cores
144 echo "$corestatus" | tee -a ztest.cores
145 echo "" | tee -a ztest.cores
146 fi
147 echo "continuing..."
148 fi
149}
150
151# parse arguments
152# expected format: zloop [-t timeout] [-c coredir] [-- extra ztest args]
153coredir=$DEFAULTCOREDIR
5df5d06a
DB
154basedir=$DEFAULTWORKDIR
155rundir="zloop-run"
541a0901 156timeout=0
aea899a6
BB
157size="512m"
158while getopts ":ht:s:c:f:" opt; do
541a0901
BB
159 case $opt in
160 t ) [[ $OPTARG -gt 0 ]] && timeout=$OPTARG ;;
aea899a6 161 s ) [[ $OPTARG ]] && size=$OPTARG ;;
541a0901 162 c ) [[ $OPTARG ]] && coredir=$OPTARG ;;
5df5d06a 163 f ) [[ $OPTARG ]] && basedir=$(readlink -f "$OPTARG") ;;
541a0901
BB
164 h ) usage
165 exit 2
166 ;;
167 * ) echo "Invalid argument: -$OPTARG";
168 usage
169 exit 1
170 esac
171done
172# pass remaining arguments on to ztest
173shift $((OPTIND - 1))
174
175# enable core dumps
176ulimit -c unlimited
fed90353 177export ASAN_OPTIONS=abort_on_error=1:disable_coredump=0
541a0901 178
20da0566
GN
179if [[ -f "$(core_file)" ]]; then
180 echo -n "There's a core dump here you might want to look at first... "
c552fbc5 181 core_file
541a0901
BB
182 exit 1
183fi
184
185if [[ ! -d $coredir ]]; then
186 echo "core dump directory ($coredir) does not exist, creating it."
c552fbc5 187 or_die mkdir -p "$coredir"
541a0901
BB
188fi
189
190if [[ ! -w $coredir ]]; then
191 echo "core dump directory ($coredir) is not writable."
192 exit 1
193fi
194
195or_die rm -f ztest.history
196or_die rm -f ztest.ddt
197or_die rm -f ztest.cores
198
199ztrc=0 # ztest return value
200foundcrashes=0 # number of crashes found so far
201starttime=$(date +%s)
202curtime=$starttime
203
204# if no timeout was specified, loop forever.
c552fbc5 205while [[ $timeout -eq 0 ]] || [[ $curtime -le $((starttime + timeout)) ]]; do
541a0901
BB
206 zopt="-VVVVV"
207
5df5d06a
DB
208 # start each run with an empty directory
209 workdir="$basedir/$rundir"
210 or_die rm -rf "$workdir"
211 or_die mkdir "$workdir"
212
541a0901
BB
213 # switch between common arrangements & fully randomized
214 if [[ $((RANDOM % 2)) -eq 0 ]]; then
215 mirrors=2
216 raidz=0
217 parity=1
218 vdevs=2
219 else
220 mirrors=$(((RANDOM % 3) * 1))
221 parity=$(((RANDOM % 3) + 1))
222 raidz=$((((RANDOM % 9) + parity + 1) * (RANDOM % 2)))
223 vdevs=$(((RANDOM % 3) + 3))
224 fi
225 align=$(((RANDOM % 2) * 3 + 9))
226 runtime=$((RANDOM % 100))
227 passtime=$((RANDOM % (runtime / 3 + 1) + 10))
541a0901
BB
228
229 zopt="$zopt -m $mirrors"
230 zopt="$zopt -r $raidz"
231 zopt="$zopt -R $parity"
232 zopt="$zopt -v $vdevs"
233 zopt="$zopt -a $align"
234 zopt="$zopt -T $runtime"
235 zopt="$zopt -P $passtime"
236 zopt="$zopt -s $size"
237 zopt="$zopt -f $workdir"
238
c552fbc5 239 # shellcheck disable=SC2124
541a0901
BB
240 cmd="$ZTEST $zopt $@"
241 desc="$(date '+%m/%d %T') $cmd"
242 echo "$desc" | tee -a ztest.history
243 echo "$desc" >>ztest.out
244 $cmd >>ztest.out 2>&1
245 ztrc=$?
246 egrep '===|WARNING' ztest.out >>ztest.history
1ce23dca 247 $ZDB -U "$workdir/zpool.cache" -DD ztest >>ztest.ddt 2>&1
541a0901
BB
248
249 store_core
250
251 curtime=$(date +%s)
252done
253
254echo "zloop finished, $foundcrashes crashes found"
255
20da0566
GN
256#restore core pattern
257echo "$origcorepattern" > /proc/sys/kernel/core_pattern
258
541a0901
BB
259uptime >>ztest.out
260
261if [[ $foundcrashes -gt 0 ]]; then
262 exit 1
263fi