]> git.proxmox.com Git - mirror_zfs.git/blame - scripts/zloop.sh
Add parity generation/rebuild using 128-bits NEON for Aarch64
[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
23basedir="$(dirname $0)"
24
25SCRIPT_COMMON=common.sh
26if [ -f "${basedir}/${SCRIPT_COMMON}" ]; then
27 . "${basedir}/${SCRIPT_COMMON}"
28else
29 echo "Missing helper script ${SCRIPT_COMMON}" && exit 1
30fi
31
32PROG=zloop.sh
33
34DEFAULTWORKDIR=/var/tmp
35DEFAULTCOREDIR=/var/tmp/zloop
36
37function usage
38{
39 echo -e "\n$0 [-t <timeout>] [-c <dump directory>]" \
40 "[ -- [extra ztest parameters]]\n" \
41 "\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" \
47 "\n" \
48 " Options:\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" \
54 "" >&2
55}
56
57function or_die
58{
59 $@
60 if [[ $? -ne 0 ]]; then
61 echo "Command failed: $@"
62 exit 1
63 fi
64}
65
20da0566
GN
66# core file helpers
67origcorepattern="$(cat /proc/sys/kernel/core_pattern)"
68coreglob="$(egrep -o '^([^|%[:space:]]*)' /proc/sys/kernel/core_pattern)*"
69
70if [[ $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)*"
74fi
75
76function core_file
77{
78 printf "%s" "$(ls -tr1 $coreglob 2> /dev/null | head -1)"
79}
80
541a0901
BB
81function store_core
82{
20da0566
GN
83 core="$(core_file)"
84 if [[ $ztrc -ne 0 ]] || [[ -f "$core" ]]; then
541a0901
BB
85 coreid=$(date "+zloop-%y%m%d-%H%M%S")
86 foundcrashes=$(($foundcrashes + 1))
87
88 dest=$coredir/$coreid
89 or_die mkdir -p $dest
90 or_die mkdir -p $dest/vdev
91
92 echo "*** ztest crash found - moving logs to $dest"
93
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/
99
100 # check for core
20da0566 101 if [[ -f "$core" ]]; then
541a0901
BB
102 corestatus=$($GDB --batch --quiet \
103 -ex "set print thread-events off" \
104 -ex "printf \"*\n* Backtrace \n*\n\"" \
105 -ex "bt" \
106 -ex "printf \"*\n* Libraries \n*\n\"" \
107 -ex "info sharedlib" \
108 -ex "printf \"*\n* Threads (full) \n*\n\"" \
109 -ex "info threads" \
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" \
20da0566 114 -ex "quit" $ZTEST "$core" | grep -v "New LWP")
541a0901
BB
115
116 # Dump core + logs to stored directory
117 echo "$corestatus" >>$dest/status
20da0566 118 or_die mv "$core" $dest/
541a0901
BB
119
120 # Record info in cores logfile
20da0566 121 echo "*** core @ $coredir/$coreid/$core:" | \
541a0901
BB
122 tee -a ztest.cores
123 echo "$corestatus" | tee -a ztest.cores
124 echo "" | tee -a ztest.cores
125 fi
126 echo "continuing..."
127 fi
128}
129
130# parse arguments
131# expected format: zloop [-t timeout] [-c coredir] [-- extra ztest args]
132coredir=$DEFAULTCOREDIR
133workdir=$DEFAULTWORKDIR
134timeout=0
135while getopts ":ht:c:f:" opt; do
136 case $opt in
137 t ) [[ $OPTARG -gt 0 ]] && timeout=$OPTARG ;;
138 c ) [[ $OPTARG ]] && coredir=$OPTARG ;;
139 f ) [[ $OPTARG ]] && workdir=$(readlink -f $OPTARG) ;;
140 h ) usage
141 exit 2
142 ;;
143 * ) echo "Invalid argument: -$OPTARG";
144 usage
145 exit 1
146 esac
147done
148# pass remaining arguments on to ztest
149shift $((OPTIND - 1))
150
151# enable core dumps
152ulimit -c unlimited
153
20da0566
GN
154if [[ -f "$(core_file)" ]]; then
155 echo -n "There's a core dump here you might want to look at first... "
156 echo "$(core_file)"
541a0901
BB
157 exit 1
158fi
159
160if [[ ! -d $coredir ]]; then
161 echo "core dump directory ($coredir) does not exist, creating it."
162 or_die mkdir -p $coredir
163fi
164
165if [[ ! -w $coredir ]]; then
166 echo "core dump directory ($coredir) is not writable."
167 exit 1
168fi
169
170or_die rm -f ztest.history
171or_die rm -f ztest.ddt
172or_die rm -f ztest.cores
173
174ztrc=0 # ztest return value
175foundcrashes=0 # number of crashes found so far
176starttime=$(date +%s)
177curtime=$starttime
178
179# if no timeout was specified, loop forever.
180while [[ $timeout -eq 0 ]] || [[ $curtime -le $(($starttime + $timeout)) ]]; do
181 zopt="-VVVVV"
182
183 # switch between common arrangements & fully randomized
184 if [[ $((RANDOM % 2)) -eq 0 ]]; then
185 mirrors=2
186 raidz=0
187 parity=1
188 vdevs=2
189 else
190 mirrors=$(((RANDOM % 3) * 1))
191 parity=$(((RANDOM % 3) + 1))
192 raidz=$((((RANDOM % 9) + parity + 1) * (RANDOM % 2)))
193 vdevs=$(((RANDOM % 3) + 3))
194 fi
195 align=$(((RANDOM % 2) * 3 + 9))
196 runtime=$((RANDOM % 100))
197 passtime=$((RANDOM % (runtime / 3 + 1) + 10))
198 size=128m
199
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"
209
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
215 ztrc=$?
216 egrep '===|WARNING' ztest.out >>ztest.history
217 $ZDB -U $workdir/zpool.cache -DD ztest >>ztest.ddt
218
219 store_core
220
221 curtime=$(date +%s)
222done
223
224echo "zloop finished, $foundcrashes crashes found"
225
20da0566
GN
226#restore core pattern
227echo "$origcorepattern" > /proc/sys/kernel/core_pattern
228
541a0901
BB
229uptime >>ztest.out
230
231if [[ $foundcrashes -gt 0 ]]; then
232 exit 1
233fi