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
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.
19 # Copyright (c) 2015 by Delphix. All rights reserved.
20 # Copyright (C) 2016 Lawrence Livermore National Security, LLC.
23 basedir
=$
(dirname "$0")
25 SCRIPT_COMMON
=common.sh
26 if [ -f "${basedir}/${SCRIPT_COMMON}" ]; then
27 .
"${basedir}/${SCRIPT_COMMON}"
29 echo "Missing helper script ${SCRIPT_COMMON}" && exit 1
32 # shellcheck disable=SC2034
35 DEFAULTWORKDIR
=/var
/tmp
36 DEFAULTCOREDIR
=/var
/tmp
/zloop
40 echo -e "\n$0 [-t <timeout>] [-c <dump directory>]" \
41 "[ -- [extra ztest parameters]]\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" \
50 " -t Total time to loop for, in seconds. If not provided,\n" \
51 " zloop runs forever.\n" \
52 " -f Specify working directory for ztest vdev files.\n" \
53 " -c Specify a core dump directory to use.\n" \
54 " -h Print this help message.\n" \
60 # shellcheck disable=SC2068
62 # shellcheck disable=SC2181
63 if [[ $?
-ne 0 ]]; then
64 # shellcheck disable=SC2145
65 echo "Command failed: $@"
71 origcorepattern
="$(cat /proc/sys/kernel/core_pattern)"
72 coreglob
="$(egrep -o '^([^|%[:space:]]*)' /proc/sys/kernel/core_pattern)*"
74 if [[ $coreglob = "*" ]]; then
75 echo "Setting core file pattern..."
76 echo "core" > /proc
/sys
/kernel
/core_pattern
77 coreglob
="$(egrep -o '^([^|%[:space:]]*)' \
78 /proc/sys/kernel/core_pattern)*"
83 # shellcheck disable=SC2012 disable=2086
84 printf "%s" "$(ls -tr1 $coreglob 2> /dev/null | head -1)"
90 core_id
=$
($GDB --batch -c "$1" |
grep "Core was generated by" | \
92 # shellcheck disable=SC2076
93 if [[ "$core_id" =~
"zdb " ]]; then
102 if [[ $ztrc -ne 0 ]] ||
[[ -f "$core" ]]; then
103 coreid
=$
(date "+zloop-%y%m%d-%H%M%S")
104 foundcrashes
=$
((foundcrashes
+ 1))
106 dest
=$coredir/$coreid
107 or_die mkdir
-p "$dest"
108 or_die mkdir
-p "$dest/vdev"
110 echo "*** ztest crash found - moving logs to $dest"
112 or_die
mv ztest.
history "$dest/"
113 or_die
mv ztest.ddt
"$dest/"
114 or_die
mv ztest.out
"$dest/"
115 or_die
mv "$workdir/ztest*" "$dest/vdev/"
116 or_die
mv "$workdir/zpool.cache" "$dest/vdev/"
119 if [[ -f "$core" ]]; then
120 coreprog
=$
(core_prog
"$core")
121 corestatus
=$
($GDB --batch --quiet \
122 -ex "set print thread-events off" \
123 -ex "printf \"*\n* Backtrace \n*\n\"" \
125 -ex "printf \"*\n* Libraries \n*\n\"" \
126 -ex "info sharedlib" \
127 -ex "printf \"*\n* Threads (full) \n*\n\"" \
129 -ex "printf \"*\n* Backtraces \n*\n\"" \
130 -ex "thread apply all bt" \
131 -ex "printf \"*\n* Backtraces (full) \n*\n\"" \
132 -ex "thread apply all bt full" \
133 -ex "quit" "$coreprog" "$core" |
grep -v "New LWP")
135 # Dump core + logs to stored directory
136 echo "$corestatus" >>"$dest/status"
137 or_die
mv "$core" "$dest/"
139 # Record info in cores logfile
140 echo "*** core @ $coredir/$coreid/$core:" | \
142 echo "$corestatus" |
tee -a ztest.cores
143 echo "" |
tee -a ztest.cores
150 # expected format: zloop [-t timeout] [-c coredir] [-- extra ztest args]
151 coredir
=$DEFAULTCOREDIR
152 workdir
=$DEFAULTWORKDIR
154 while getopts ":ht:c:f:" opt
; do
156 t
) [[ $OPTARG -gt 0 ]] && timeout
=$OPTARG ;;
157 c
) [[ $OPTARG ]] && coredir
=$OPTARG ;;
158 f
) [[ $OPTARG ]] && workdir
=$
(readlink
-f "$OPTARG") ;;
162 * ) echo "Invalid argument: -$OPTARG";
167 # pass remaining arguments on to ztest
168 shift $
((OPTIND
- 1))
173 if [[ -f "$(core_file)" ]]; then
174 echo -n "There's a core dump here you might want to look at first... "
179 if [[ ! -d $coredir ]]; then
180 echo "core dump directory ($coredir) does not exist, creating it."
181 or_die mkdir
-p "$coredir"
184 if [[ ! -w $coredir ]]; then
185 echo "core dump directory ($coredir) is not writable."
189 or_die
rm -f ztest.
history
190 or_die
rm -f ztest.ddt
191 or_die
rm -f ztest.cores
193 ztrc
=0 # ztest return value
194 foundcrashes
=0 # number of crashes found so far
195 starttime
=$
(date +%s
)
198 # if no timeout was specified, loop forever.
199 while [[ $timeout -eq 0 ]] ||
[[ $curtime -le $
((starttime
+ timeout
)) ]]; do
202 # switch between common arrangements & fully randomized
203 if [[ $
((RANDOM
% 2)) -eq 0 ]]; then
209 mirrors
=$
(((RANDOM
% 3) * 1))
210 parity
=$
(((RANDOM
% 3) + 1))
211 raidz
=$
((((RANDOM
% 9) + parity
+ 1) * (RANDOM
% 2)))
212 vdevs
=$
(((RANDOM
% 3) + 3))
214 align
=$
(((RANDOM
% 2) * 3 + 9))
215 runtime
=$
((RANDOM
% 100))
216 passtime
=$
((RANDOM
% (runtime
/ 3 + 1) + 10))
219 zopt
="$zopt -m $mirrors"
220 zopt
="$zopt -r $raidz"
221 zopt
="$zopt -R $parity"
222 zopt
="$zopt -v $vdevs"
223 zopt
="$zopt -a $align"
224 zopt
="$zopt -T $runtime"
225 zopt
="$zopt -P $passtime"
226 zopt
="$zopt -s $size"
227 zopt
="$zopt -f $workdir"
229 # shellcheck disable=SC2124
230 cmd
="$ZTEST $zopt $@"
231 desc
="$(date '+%m/%d %T') $cmd"
232 echo "$desc" |
tee -a ztest.
history
233 echo "$desc" >>ztest.out
234 $cmd >>ztest.out
2>&1
236 egrep '===|WARNING' ztest.out
>>ztest.
history
237 $ZDB -U "$workdir/zpool.cache" -DD ztest
>>ztest.ddt
244 echo "zloop finished, $foundcrashes crashes found"
246 #restore core pattern
247 echo "$origcorepattern" > /proc
/sys
/kernel
/core_pattern
251 if [[ $foundcrashes -gt 0 ]]; then