]>
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.
21 # Copyright (c) 2017, Intel Corporation.
24 BASE_DIR
=$
(dirname "$0")
25 SCRIPT_COMMON
=common.sh
26 if [ -f "${BASE_DIR}/${SCRIPT_COMMON}" ]; then
27 .
"${BASE_DIR}/${SCRIPT_COMMON}"
29 echo "Missing helper script ${SCRIPT_COMMON}" && exit 1
32 # shellcheck disable=SC2034
36 DEFAULTWORKDIR
=/var
/tmp
37 DEFAULTCOREDIR
=/var
/tmp
/zloop
41 echo -e "\n$0 [-t <timeout>] [ -s <vdev size> ] [-c <dump directory>]" \
42 "[ -- [extra ztest parameters]]\n" \
44 " This script runs ztest repeatedly with randomized arguments.\n" \
45 " If a crash is encountered, the ztest logs, any associated\n" \
46 " vdev files, and core file (if one exists) are moved to the\n" \
47 " output directory ($DEFAULTCOREDIR by default). Any options\n" \
48 " after the -- end-of-options marker will be passed to ztest.\n" \
51 " -t Total time to loop for, in seconds. If not provided,\n" \
52 " zloop runs forever.\n" \
53 " -s Size of vdev devices.\n" \
54 " -f Specify working directory for ztest vdev files.\n" \
55 " -c Specify a core dump directory to use.\n" \
56 " -m Max number of core dumps to allow before exiting.\n" \
57 " -l Create 'ztest.core.N' symlink to core directory.\n" \
58 " -h Print this help message.\n" \
64 # shellcheck disable=SC2068
66 echo "Command failed: $*"
77 origcorepattern
="$(cat /proc/sys/kernel/core_pattern)"
78 coreglob
="$(grep -E -o '^([^|%[:space:]]*)' /proc/sys/kernel/core_pattern)*"
80 if [[ $coreglob = "*" ]]; then
81 echo "Setting core file pattern..."
82 echo "core" > /proc
/sys
/kernel
/core_pattern
83 coreglob
="$(grep -E -o '^([^|%[:space:]]*)' \
84 /proc/sys/kernel/core_pattern)*"
94 # shellcheck disable=SC2012 disable=2086
95 printf "%s" "$(ls -tr1 $coreglob 2> /dev/null | head -1)"
101 core_id
=$
($GDB --batch -c "$1" |
grep "Core was generated by" | \
103 # shellcheck disable=SC2076
104 if [[ "$core_id" =~
"zdb " ]]; then
113 if [[ $ztrc -ne 0 ]] ||
[[ -f "$core" ]]; then
114 df
-h "$workdir" >>ztest.out
115 coreid
=$
(date "+zloop-%y%m%d-%H%M%S")
116 foundcrashes
=$
((foundcrashes
+ 1))
119 zdbcmd
="$ZDB -U "$workdir/zpool.cache
" -dddMmDDG ztest"
120 zdbdebug
=$
($zdbcmd 2>&1)
121 echo -e "$zdbcmd\n" >>ztest.zdb
122 echo "$zdbdebug" >>ztest.zdb
124 dest
=$coredir/$coreid
125 or_die mkdir
-p "$dest"
126 or_die mkdir
-p "$dest/vdev"
128 if [[ $symlink -ne 0 ]]; then
129 or_die
ln -sf "$dest" ztest.core.
$foundcrashes
132 echo "*** ztest crash found - moving logs to $dest"
134 or_die
mv ztest.
history "$dest/"
135 or_die
mv ztest.zdb
"$dest/"
136 or_die
mv ztest.out
"$dest/"
137 or_die
mv "$workdir/ztest*" "$dest/vdev/"
139 if [[ -e "$workdir/zpool.cache" ]]; then
140 or_die
mv "$workdir/zpool.cache" "$dest/vdev/"
144 if [[ -f "$core" ]]; then
145 coreprog
=$
(core_prog
"$core")
146 coredebug
=$
($GDB --batch --quiet \
147 -ex "set print thread-events off" \
148 -ex "printf \"*\n* Backtrace \n*\n\"" \
150 -ex "printf \"*\n* Libraries \n*\n\"" \
151 -ex "info sharedlib" \
152 -ex "printf \"*\n* Threads (full) \n*\n\"" \
154 -ex "printf \"*\n* Backtraces \n*\n\"" \
155 -ex "thread apply all bt" \
156 -ex "printf \"*\n* Backtraces (full) \n*\n\"" \
157 -ex "thread apply all bt full" \
158 -ex "quit" "$coreprog" "$core" 2>&1 | \
161 # Dump core + logs to stored directory
162 echo "$coredebug" >>"$dest/ztest.gdb"
163 or_die
mv "$core" "$dest/"
165 # Record info in cores logfile
166 echo "*** core @ $coredir/$coreid/$core:" | \
170 if [[ $coremax -gt 0 ]] &&
171 [[ $foundcrashes -ge $coremax ]]; then
172 echo "exiting... max $coremax allowed cores"
181 # expected format: zloop [-t timeout] [-c coredir] [-- extra ztest args]
182 coredir
=$DEFAULTCOREDIR
183 basedir
=$DEFAULTWORKDIR
189 while getopts ":ht:m:s:c:f:l" opt
; do
191 t
) [[ $OPTARG -gt 0 ]] && timeout
=$OPTARG ;;
192 m
) [[ $OPTARG -gt 0 ]] && coremax
=$OPTARG ;;
193 s
) [[ $OPTARG ]] && size
=$OPTARG ;;
194 c
) [[ $OPTARG ]] && coredir
=$OPTARG ;;
195 f
) [[ $OPTARG ]] && basedir
=$
(readlink
-f "$OPTARG") ;;
200 * ) echo "Invalid argument: -$OPTARG";
205 # pass remaining arguments on to ztest
206 shift $
((OPTIND
- 1))
210 export ASAN_OPTIONS
=abort_on_error
=1:disable_coredump
=0
212 if [[ -f "$(core_file)" ]]; then
213 echo -n "There's a core dump here you might want to look at first... "
219 if [[ ! -d $coredir ]]; then
220 echo "core dump directory ($coredir) does not exist, creating it."
221 or_die mkdir
-p "$coredir"
224 if [[ ! -w $coredir ]]; then
225 echo "core dump directory ($coredir) is not writable."
229 or_die
rm -f ztest.
history
230 or_die
rm -f ztest.zdb
231 or_die
rm -f ztest.cores
233 ztrc
=0 # ztest return value
234 foundcrashes
=0 # number of crashes found so far
235 starttime
=$
(date +%s
)
238 # if no timeout was specified, loop forever.
239 while [[ $timeout -eq 0 ]] ||
[[ $curtime -le $
((starttime
+ timeout
)) ]]; do
242 # start each run with an empty directory
243 workdir
="$basedir/$rundir"
244 or_die
rm -rf "$workdir"
245 or_die mkdir
"$workdir"
247 # switch between three types of configs
248 # 1/3 basic, 1/3 raidz mix, and 1/3 draid mix
249 choice
=$
((RANDOM
% 3))
251 # ashift range 9 - 15
252 align
=$
(((RANDOM
% 2) * 3 + 9))
254 # randomly use special classes
255 class
="special=random"
257 if [[ $choice -eq 0 ]]; then
266 elif [[ $choice -eq 1 ]]; then
267 # fully randomized mirror/raidz (sans dRAID)
268 parity
=$
(((RANDOM
% 3) + 1))
269 mirrors
=$
(((RANDOM
% 3) * 1))
272 raid_children
=$
((((RANDOM
% 9) + parity
+ 1) * (RANDOM
% 2)))
273 vdevs
=$
(((RANDOM
% 3) + 3))
276 # fully randomized dRAID (sans mirror/raidz)
277 parity
=$
(((RANDOM
% 3) + 1))
279 draid_data
=$
(((RANDOM
% 8) + 3))
280 draid_spares
=$
(((RANDOM
% 2) + parity
))
281 stripe
=$
((draid_data
+ parity
))
282 extra
=$
((draid_spares
+ (RANDOM
% 4)))
283 raid_children
=$
(((((RANDOM
% 4) + 1) * stripe
) + extra
))
284 vdevs
=$
((RANDOM
% 3))
288 # run from 30 to 120 seconds
289 runtime
=$
(((RANDOM
% 90) + 30))
290 passtime
=$
((RANDOM
% (runtime
/ 3 + 1) + 10))
292 zopt
="$zopt -K $raid_type"
293 zopt
="$zopt -m $mirrors"
294 zopt
="$zopt -r $raid_children"
295 zopt
="$zopt -D $draid_data"
296 zopt
="$zopt -S $draid_spares"
297 zopt
="$zopt -R $parity"
298 zopt
="$zopt -v $vdevs"
299 zopt
="$zopt -a $align"
300 zopt
="$zopt -C $class"
301 zopt
="$zopt -T $runtime"
302 zopt
="$zopt -P $passtime"
303 zopt
="$zopt -s $size"
304 zopt
="$zopt -f $workdir"
306 # shellcheck disable=SC2124
307 cmd
="$ZTEST $zopt $@"
308 desc
="$(date '+%m/%d %T') $cmd"
309 echo "$desc" |
tee -a ztest.
history
310 echo "$desc" >>ztest.out
311 $cmd >>ztest.out
2>&1
313 grep -E '===|WARNING' ztest.out
>>ztest.
history
320 echo "zloop finished, $foundcrashes crashes found"
322 # restore core pattern.
325 echo "$origcorepattern" > /proc
/sys
/kernel
/core_pattern
333 if [[ $foundcrashes -gt 0 ]]; then