]>
git.proxmox.com Git - mirror_zfs.git/blob - scripts/zloop.sh
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
34 DEFAULTWORKDIR
=/var
/tmp
35 DEFAULTCOREDIR
=/var
/tmp
/zloop
39 echo -e "\n$0 [-t <timeout>] [-c <dump directory>]" \
40 "[ -- [extra ztest parameters]]\n" \
42 " This script runs ztest repeatedly with randomized arguments.\n" \
43 " If a crash is encountered, the ztest logs, any associated\n" \
44 " vdev files, and core file (if one exists) are moved to the\n" \
45 " output directory ($DEFAULTCOREDIR by default). Any options\n" \
46 " after the -- end-of-options marker will be passed to ztest.\n" \
49 " -t Total time to loop for, in seconds. If not provided,\n" \
50 " zloop runs forever.\n" \
51 " -f Specify working directory for ztest vdev files.\n" \
52 " -c Specify a core dump directory to use.\n" \
53 " -h Print this help message.\n" \
60 if [[ $?
-ne 0 ]]; then
61 echo "Command failed: $@"
67 origcorepattern
="$(cat /proc/sys/kernel/core_pattern)"
68 coreglob
="$(egrep -o '^([^|%[:space:]]*)' /proc/sys/kernel/core_pattern)*"
70 if [[ $coreglob = "*" ]]; then
71 echo "Setting core file pattern..."
72 echo "core" > /proc
/sys
/kernel
/core_pattern
73 coreglob
="$(egrep -o '^([^|%[:space:]]*)' /proc/sys/kernel/core_pattern)*"
78 printf "%s" "$(ls -tr1 $coreglob 2> /dev/null | head -1)"
84 if [[ $ztrc -ne 0 ]] ||
[[ -f "$core" ]]; then
85 coreid
=$
(date "+zloop-%y%m%d-%H%M%S")
86 foundcrashes
=$
(($foundcrashes + 1))
90 or_die mkdir
-p $dest/vdev
92 echo "*** ztest crash found - moving logs to $dest"
94 or_die
mv ztest.
history $dest/
95 or_die
mv ztest.ddt
$dest/
96 or_die
mv ztest.out
$dest/
97 or_die
mv $workdir/ztest
* $dest/vdev
/
98 or_die
mv $workdir/zpool.cache
$dest/vdev
/
101 if [[ -f "$core" ]]; then
102 corestatus
=$
($GDB --batch --quiet \
103 -ex "set print thread-events off" \
104 -ex "printf \"*\n* Backtrace \n*\n\"" \
106 -ex "printf \"*\n* Libraries \n*\n\"" \
107 -ex "info sharedlib" \
108 -ex "printf \"*\n* Threads (full) \n*\n\"" \
110 -ex "printf \"*\n* Backtraces \n*\n\"" \
111 -ex "thread apply all bt" \
112 -ex "printf \"*\n* Backtraces (full) \n*\n\"" \
113 -ex "thread apply all bt full" \
114 -ex "quit" $ZTEST "$core" |
grep -v "New LWP")
116 # Dump core + logs to stored directory
117 echo "$corestatus" >>$dest/status
118 or_die
mv "$core" $dest/
120 # Record info in cores logfile
121 echo "*** core @ $coredir/$coreid/$core:" | \
123 echo "$corestatus" |
tee -a ztest.cores
124 echo "" |
tee -a ztest.cores
131 # expected format: zloop [-t timeout] [-c coredir] [-- extra ztest args]
132 coredir
=$DEFAULTCOREDIR
133 workdir
=$DEFAULTWORKDIR
135 while getopts ":ht:c:f:" opt
; do
137 t
) [[ $OPTARG -gt 0 ]] && timeout
=$OPTARG ;;
138 c
) [[ $OPTARG ]] && coredir
=$OPTARG ;;
139 f
) [[ $OPTARG ]] && workdir
=$
(readlink
-f $OPTARG) ;;
143 * ) echo "Invalid argument: -$OPTARG";
148 # pass remaining arguments on to ztest
149 shift $
((OPTIND
- 1))
154 if [[ -f "$(core_file)" ]]; then
155 echo -n "There's a core dump here you might want to look at first... "
160 if [[ ! -d $coredir ]]; then
161 echo "core dump directory ($coredir) does not exist, creating it."
162 or_die mkdir
-p $coredir
165 if [[ ! -w $coredir ]]; then
166 echo "core dump directory ($coredir) is not writable."
170 or_die
rm -f ztest.
history
171 or_die
rm -f ztest.ddt
172 or_die
rm -f ztest.cores
174 ztrc
=0 # ztest return value
175 foundcrashes
=0 # number of crashes found so far
176 starttime
=$
(date +%s
)
179 # if no timeout was specified, loop forever.
180 while [[ $timeout -eq 0 ]] ||
[[ $curtime -le $
(($starttime + $timeout)) ]]; do
183 # switch between common arrangements & fully randomized
184 if [[ $
((RANDOM
% 2)) -eq 0 ]]; then
190 mirrors
=$
(((RANDOM
% 3) * 1))
191 parity
=$
(((RANDOM
% 3) + 1))
192 raidz
=$
((((RANDOM
% 9) + parity
+ 1) * (RANDOM
% 2)))
193 vdevs
=$
(((RANDOM
% 3) + 3))
195 align
=$
(((RANDOM
% 2) * 3 + 9))
196 runtime
=$
((RANDOM
% 100))
197 passtime
=$
((RANDOM
% (runtime
/ 3 + 1) + 10))
200 zopt
="$zopt -m $mirrors"
201 zopt
="$zopt -r $raidz"
202 zopt
="$zopt -R $parity"
203 zopt
="$zopt -v $vdevs"
204 zopt
="$zopt -a $align"
205 zopt
="$zopt -T $runtime"
206 zopt
="$zopt -P $passtime"
207 zopt
="$zopt -s $size"
208 zopt
="$zopt -f $workdir"
210 cmd
="$ZTEST $zopt $@"
211 desc
="$(date '+%m/%d %T') $cmd"
212 echo "$desc" |
tee -a ztest.
history
213 echo "$desc" >>ztest.out
214 $cmd >>ztest.out
2>&1
216 egrep '===|WARNING' ztest.out
>>ztest.
history
217 $ZDB -U $workdir/zpool.cache
-DD ztest
>>ztest.ddt
224 echo "zloop finished, $foundcrashes crashes found"
226 #restore core pattern
227 echo "$origcorepattern" > /proc
/sys
/kernel
/core_pattern
231 if [[ $foundcrashes -gt 0 ]]; then