]>
Commit | Line | Data |
---|---|---|
302ef151 BB |
1 | #!/bin/bash |
2 | # | |
3 | # Wrapper script for easily running zpios based tests | |
4 | # | |
5 | ||
6 | basedir="$(dirname $0)" | |
7 | ||
8 | SCRIPT_COMMON=common.sh | |
9 | if [ -f "${basedir}/${SCRIPT_COMMON}" ]; then | |
10 | . "${basedir}/${SCRIPT_COMMON}" | |
11 | else | |
12 | echo "Missing helper script ${SCRIPT_COMMON}" && exit 1 | |
13 | fi | |
14 | ||
15 | PROG=zpios.sh | |
16 | DATE=`date +%Y%m%d-%H%M%S` | |
17 | if [ "${ZPIOS_MODULES}" ]; then | |
18 | MODULES=(${ZPIOS_MODULES[*]}) | |
19 | else | |
20 | MODULES=(zpios) | |
21 | fi | |
22 | ||
23 | usage() { | |
24 | cat << EOF | |
25 | USAGE: | |
26 | $0 [hvp] <-c config> <-t test> | |
27 | ||
28 | DESCRIPTION: | |
29 | Helper script for easy zpios benchmarking. | |
30 | ||
31 | OPTIONS: | |
32 | -h Show this message | |
33 | -v Verbose | |
34 | -f Force everything | |
35 | -p Enable profiling | |
36 | -c Zpool configuration | |
37 | -t Zpios test | |
38 | -o Additional zpios options | |
39 | -l Additional zpool options | |
40 | -s Additional zfs options | |
41 | ||
42 | EOF | |
43 | } | |
44 | ||
36391312 BB |
45 | unload_die() { |
46 | unload_modules | |
47 | while [ -c /dev/zpios ]; do | |
48 | sleep 1 | |
49 | done | |
50 | ||
51 | exit 1 | |
52 | } | |
53 | ||
302ef151 BB |
54 | print_header() { |
55 | echo --------------------- ZPIOS RESULTS ---------------------------- | |
56 | echo -n "Date: "; date | |
57 | echo -n "Kernel: "; uname -r | |
58 | dmesg | grep "Loaded Solaris Porting Layer" | tail -n1 | |
59 | dmesg | grep "Loaded ZFS Filesystem" | tail -n1 | |
60 | echo | |
61 | } | |
62 | ||
63 | print_spl_info() { | |
64 | echo --------------------- SPL Tunings ------------------------------ | |
65 | ${SYSCTL} -A | grep spl | |
66 | ||
67 | if [ -d /sys/module/spl/parameters ]; then | |
68 | grep [0-9] /sys/module/spl/parameters/* | |
69 | else | |
70 | grep [0-9] /sys/module/spl/* | |
71 | fi | |
72 | ||
73 | echo | |
74 | } | |
75 | ||
76 | print_zfs_info() { | |
77 | echo --------------------- ZFS Tunings ------------------------------ | |
78 | ${SYSCTL} -A | grep zfs | |
79 | ||
80 | if [ -d /sys/module/zfs/parameters ]; then | |
81 | grep [0-9] /sys/module/zfs/parameters/* | |
82 | else | |
83 | grep [0-9] /sys/module/zfs/* | |
84 | fi | |
85 | ||
86 | echo | |
87 | } | |
88 | ||
89 | print_stats() { | |
90 | echo ---------------------- Statistics ------------------------------- | |
91 | ${SYSCTL} -A | grep spl | grep stack_max | |
92 | ||
93 | if [ -d /proc/spl/kstat/ ]; then | |
94 | if [ -f /proc/spl/kstat/zfs/arcstats ]; then | |
95 | echo "* ARC" | |
96 | cat /proc/spl/kstat/zfs/arcstats | |
97 | echo | |
98 | fi | |
99 | ||
100 | if [ -f /proc/spl/kstat/zfs/vdev_cache_stats ]; then | |
101 | echo "* VDEV Cache" | |
102 | cat /proc/spl/kstat/zfs/vdev_cache_stats | |
103 | echo | |
104 | fi | |
105 | fi | |
106 | ||
107 | if [ -f /proc/spl/kmem/slab ]; then | |
108 | echo "* SPL SLAB" | |
109 | cat /proc/spl/kmem/slab | |
110 | echo | |
111 | fi | |
112 | ||
113 | echo | |
114 | } | |
115 | ||
116 | check_test() { | |
117 | ||
118 | if [ ! -f ${ZPIOS_TEST} ]; then | |
119 | local NAME=`basename ${ZPIOS_TEST} .sh` | |
120 | ERROR="Unknown test '${NAME}', available tests are:\n" | |
121 | ||
122 | for TST in `ls ${ZPIOSDIR}/ | grep ".sh"`; do | |
123 | local NAME=`basename ${TST} .sh` | |
124 | ERROR="${ERROR}${NAME}\n" | |
125 | done | |
126 | ||
127 | return 1 | |
128 | fi | |
129 | ||
130 | return 0 | |
131 | } | |
132 | ||
133 | zpios_profile_config() { | |
134 | cat > ${PROFILE_DIR}/zpios-config.sh << EOF | |
135 | # | |
136 | # Zpios Profiling Configuration | |
137 | # | |
138 | ||
139 | PROFILE_DIR=/tmp/zpios/${ZPOOL_CONFIG}+${ZPIOS_TEST_ARG}+${DATE} | |
140 | PROFILE_PRE=${ZPIOSPROFILEDIR}/zpios-profile-pre.sh | |
141 | PROFILE_POST=${ZPIOSPROFILEDIR}/zpios-profile-post.sh | |
142 | PROFILE_USER=${ZPIOSPROFILEDIR}/zpios-profile.sh | |
143 | PROFILE_PIDS=${ZPIOSPROFILEDIR}/zpios-profile-pids.sh | |
144 | PROFILE_DISK=${ZPIOSPROFILEDIR}/zpios-profile-disk.sh | |
145 | PROFILE_ARC_PROC=/proc/spl/kstat/zfs/arcstats | |
146 | PROFILE_VDEV_CACHE_PROC=/proc/spl/kstat/zfs/vdev_cache_stats | |
147 | ||
148 | OPROFILE_KERNEL="/boot/vmlinux-`uname -r`" | |
149 | OPROFILE_KERNEL_DIR="/lib/modules/`uname -r`/kernel/" | |
150 | OPROFILE_SPL_DIR=${SPLBUILD}/module/ | |
151 | OPROFILE_ZFS_DIR=${MODDIR} | |
152 | ||
153 | EOF | |
154 | } | |
155 | ||
156 | zpios_profile_start() { | |
157 | PROFILE_DIR=/tmp/zpios/${ZPOOL_CONFIG}+${ZPIOS_TEST_ARG}+${DATE} | |
158 | ||
159 | mkdir -p ${PROFILE_DIR} | |
160 | zpios_profile_config | |
161 | . ${PROFILE_DIR}/zpios-config.sh | |
162 | ||
163 | ZPIOS_OPTIONS="${ZPIOS_OPTIONS} --log=${PROFILE_DIR}" | |
164 | ZPIOS_OPTIONS="${ZPIOS_OPTIONS} --prerun=${PROFILE_PRE}" | |
165 | ZPIOS_OPTIONS="${ZPIOS_OPTIONS} --postrun=${PROFILE_POST}" | |
166 | ||
167 | /usr/bin/opcontrol --init | |
168 | /usr/bin/opcontrol --setup --vmlinux=${OPROFILE_KERNEL} | |
169 | } | |
170 | ||
171 | zpios_profile_stop() { | |
172 | /usr/bin/opcontrol --shutdown | |
173 | /usr/bin/opcontrol --deinit | |
174 | } | |
175 | ||
176 | PROFILE= | |
177 | ZPOOL_CONFIG=zpool-config.sh | |
178 | ZPIOS_TEST=zpios-test.sh | |
179 | ZPOOL_NAME=zpios | |
180 | ZPIOS_OPTIONS= | |
181 | ZPOOL_OPTIONS="" | |
182 | ZFS_OPTIONS="" | |
183 | ||
184 | while getopts 'hvfpc:t:o:l:s:' OPTION; do | |
185 | case $OPTION in | |
186 | h) | |
187 | usage | |
188 | exit 1 | |
189 | ;; | |
190 | v) | |
191 | VERBOSE=1 | |
192 | VERBOSE_FLAG="-v" | |
193 | ;; | |
194 | f) | |
195 | FORCE=1 | |
196 | FORCE_FLAG="-f" | |
197 | ;; | |
198 | p) | |
199 | PROFILE=1 | |
200 | ;; | |
201 | c) | |
202 | ZPOOL_CONFIG=${OPTARG} | |
203 | ;; | |
204 | t) | |
205 | ZPIOS_TEST_ARG=${OPTARG} | |
206 | ZPIOS_TEST=${ZPIOSDIR}/${OPTARG}.sh | |
207 | ;; | |
208 | o) | |
209 | ZPIOS_OPTIONS=${OPTARG} | |
210 | ;; | |
211 | l) # Passed through to zpool-create.sh | |
212 | ZPOOL_OPTIONS=${OPTARG} | |
213 | ;; | |
214 | s) # Passed through to zpool-create.sh | |
215 | ZFS_OPTIONS=${OPTARG} | |
216 | ;; | |
217 | ?) | |
218 | usage | |
219 | exit | |
220 | ;; | |
221 | esac | |
222 | done | |
223 | ||
224 | if [ $(id -u) != 0 ]; then | |
225 | die "Must run as root" | |
226 | fi | |
227 | ||
228 | # Validate and source your test config | |
229 | check_test || die "${ERROR}" | |
230 | . ${ZPIOS_TEST} | |
231 | ||
232 | # Pull in the zpios test module is not loaded. If this fails it is | |
233 | # likely because the full module stack was not yet loaded with zfs.sh | |
234 | if check_modules; then | |
235 | if ! load_modules; then | |
236 | die "Run 'zfs.sh' to ensure the full module stack is loaded" | |
237 | fi | |
238 | fi | |
239 | ||
240 | # Wait for device creation | |
241 | while [ ! -c /dev/zpios ]; do | |
242 | sleep 1 | |
243 | done | |
244 | ||
245 | if [ ${VERBOSE} ]; then | |
246 | print_header | |
247 | print_spl_info | |
248 | print_zfs_info | |
249 | fi | |
250 | ||
251 | # Create the zpool configuration | |
252 | ${ZPOOL_CREATE_SH} ${VERBOSE_FLAG} ${FORCE_FLAG} \ | |
253 | -p ${ZPOOL_NAME} -c ${ZPOOL_CONFIG} \ | |
36391312 | 254 | -l "${ZPOOL_OPTIONS}" -s "${ZFS_OPTIONS}" || unload_die |
302ef151 BB |
255 | |
256 | if [ ${PROFILE} ]; then | |
257 | zpios_profile_start | |
258 | fi | |
259 | ||
260 | zpios_start | |
261 | zpios_stop | |
262 | ||
263 | if [ ${PROFILE} ]; then | |
264 | zpios_profile_stop | |
265 | fi | |
266 | ||
267 | if [ ${VERBOSE} ]; then | |
268 | print_stats | |
269 | fi | |
270 | ||
271 | # Destroy the zpool configuration | |
272 | ${ZPOOL_CREATE_SH} ${VERBOSE_FLAG} ${FORCE_FLAG} \ | |
36391312 | 273 | -p ${ZPOOL_NAME} -c ${ZPOOL_CONFIG} -d || unload_die |
302ef151 BB |
274 | |
275 | # Unload the test module stack and wait for device removal | |
276 | unload_modules | |
277 | while [ -c /dev/zpios ]; do | |
278 | sleep 1 | |
279 | done | |
280 | ||
281 | exit 0 |