]>
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 BASE_DIR
=$
(dirname "$0")
24 SCRIPT_COMMON
=common.sh
25 if [ -f "${BASE_DIR}/${SCRIPT_COMMON}" ]; then
26 .
"${BASE_DIR}/${SCRIPT_COMMON}"
28 echo "Missing helper script ${SCRIPT_COMMON}" && exit 1
31 # shellcheck disable=SC2034
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" \
59 # shellcheck disable=SC2068
61 # shellcheck disable=SC2181
62 if [[ $?
-ne 0 ]]; then
63 # shellcheck disable=SC2145
64 echo "Command failed: $@"
70 origcorepattern
="$(cat /proc/sys/kernel/core_pattern)"
71 coreglob
="$(egrep -o '^([^|%[:space:]]*)' /proc/sys/kernel/core_pattern)*"
73 if [[ $coreglob = "*" ]]; then
74 echo "Setting core file pattern..."
75 echo "core" > /proc
/sys
/kernel
/core_pattern
76 coreglob
="$(egrep -o '^([^|%[:space:]]*)' \
77 /proc/sys/kernel/core_pattern)*"
82 # shellcheck disable=SC2012 disable=2086
83 printf "%s" "$(ls -tr1 $coreglob 2> /dev/null | head -1)"
89 core_id
=$
($GDB --batch -c "$1" |
grep "Core was generated by" | \
91 # shellcheck disable=SC2076
92 if [[ "$core_id" =~
"zdb " ]]; then
101 if [[ $ztrc -ne 0 ]] ||
[[ -f "$core" ]]; then
102 df
-h "$workdir" >>ztest.out
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
152 if [ -n "$rngdpid" ]; then
159 # expected format: zloop [-t timeout] [-c coredir] [-- extra ztest args]
160 coredir
=$DEFAULTCOREDIR
161 basedir
=$DEFAULTWORKDIR
164 while getopts ":ht:c:f:" opt
; do
166 t
) [[ $OPTARG -gt 0 ]] && timeout
=$OPTARG ;;
167 c
) [[ $OPTARG ]] && coredir
=$OPTARG ;;
168 f
) [[ $OPTARG ]] && basedir
=$
(readlink
-f "$OPTARG") ;;
172 * ) echo "Invalid argument: -$OPTARG";
177 # pass remaining arguments on to ztest
178 shift $
((OPTIND
- 1))
183 if [[ -f "$(core_file)" ]]; then
184 echo -n "There's a core dump here you might want to look at first... "
189 if [[ ! -d $coredir ]]; then
190 echo "core dump directory ($coredir) does not exist, creating it."
191 or_die mkdir
-p "$coredir"
194 if [[ ! -w $coredir ]]; then
195 echo "core dump directory ($coredir) is not writable."
199 or_die
rm -f ztest.
history
200 or_die
rm -f ztest.ddt
201 or_die
rm -f ztest.cores
203 # start rngd in the background so we don't run out of entropy
204 or_die
read -r rngdpid
< <(rngd
-f -r /dev
/urandom
& echo $
!)
206 ztrc
=0 # ztest return value
207 foundcrashes
=0 # number of crashes found so far
208 starttime
=$
(date +%s
)
211 # if no timeout was specified, loop forever.
212 while [[ $timeout -eq 0 ]] ||
[[ $curtime -le $
((starttime
+ timeout
)) ]]; do
215 # start each run with an empty directory
216 workdir
="$basedir/$rundir"
217 or_die
rm -rf "$workdir"
218 or_die mkdir
"$workdir"
220 # switch between common arrangements & fully randomized
221 if [[ $
((RANDOM
% 2)) -eq 0 ]]; then
227 mirrors
=$
(((RANDOM
% 3) * 1))
228 parity
=$
(((RANDOM
% 3) + 1))
229 raidz
=$
((((RANDOM
% 9) + parity
+ 1) * (RANDOM
% 2)))
230 vdevs
=$
(((RANDOM
% 3) + 3))
232 align
=$
(((RANDOM
% 2) * 3 + 9))
233 runtime
=$
((RANDOM
% 100))
234 passtime
=$
((RANDOM
% (runtime
/ 3 + 1) + 10))
237 zopt
="$zopt -m $mirrors"
238 zopt
="$zopt -r $raidz"
239 zopt
="$zopt -R $parity"
240 zopt
="$zopt -v $vdevs"
241 zopt
="$zopt -a $align"
242 zopt
="$zopt -T $runtime"
243 zopt
="$zopt -P $passtime"
244 zopt
="$zopt -s $size"
245 zopt
="$zopt -f $workdir"
247 # shellcheck disable=SC2124
248 cmd
="$ZTEST $zopt $@"
249 desc
="$(date '+%m/%d %T') $cmd"
250 echo "$desc" |
tee -a ztest.
history
251 echo "$desc" >>ztest.out
252 $cmd >>ztest.out
2>&1
254 egrep '===|WARNING' ztest.out
>>ztest.
history
255 $ZDB -U "$workdir/zpool.cache" -DD ztest
>>ztest.ddt
262 echo "zloop finished, $foundcrashes crashes found"
264 #restore core pattern
265 echo "$origcorepattern" > /proc
/sys
/kernel
/core_pattern
269 if [[ $foundcrashes -gt 0 ]]; then