]> git.proxmox.com Git - mirror_zfs-debian.git/blame - scripts/zpios.sh
Imported Upstream version 0.6.1
[mirror_zfs-debian.git] / scripts / zpios.sh
CommitLineData
302ef151
BB
1#!/bin/bash
2#
3# Wrapper script for easily running zpios based tests
4#
5
6basedir="$(dirname $0)"
7
8SCRIPT_COMMON=common.sh
9if [ -f "${basedir}/${SCRIPT_COMMON}" ]; then
10. "${basedir}/${SCRIPT_COMMON}"
11else
12echo "Missing helper script ${SCRIPT_COMMON}" && exit 1
13fi
14
15PROG=zpios.sh
16DATE=`date +%Y%m%d-%H%M%S`
17if [ "${ZPIOS_MODULES}" ]; then
18 MODULES=(${ZPIOS_MODULES[*]})
19else
20 MODULES=(zpios)
21fi
22
23usage() {
24cat << EOF
25USAGE:
26$0 [hvp] <-c config> <-t test>
27
28DESCRIPTION:
29 Helper script for easy zpios benchmarking.
30
31OPTIONS:
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
42EOF
43}
44
36391312
BB
45unload_die() {
46 unload_modules
47 while [ -c /dev/zpios ]; do
48 sleep 1
49 done
50
51 exit 1
52}
53
302ef151
BB
54print_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
63print_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
76print_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
89print_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
116check_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
133zpios_profile_config() {
134cat > ${PROFILE_DIR}/zpios-config.sh << EOF
135#
136# Zpios Profiling Configuration
137#
138
139PROFILE_DIR=/tmp/zpios/${ZPOOL_CONFIG}+${ZPIOS_TEST_ARG}+${DATE}
140PROFILE_PRE=${ZPIOSPROFILEDIR}/zpios-profile-pre.sh
141PROFILE_POST=${ZPIOSPROFILEDIR}/zpios-profile-post.sh
142PROFILE_USER=${ZPIOSPROFILEDIR}/zpios-profile.sh
143PROFILE_PIDS=${ZPIOSPROFILEDIR}/zpios-profile-pids.sh
144PROFILE_DISK=${ZPIOSPROFILEDIR}/zpios-profile-disk.sh
145PROFILE_ARC_PROC=/proc/spl/kstat/zfs/arcstats
146PROFILE_VDEV_CACHE_PROC=/proc/spl/kstat/zfs/vdev_cache_stats
147
148OPROFILE_KERNEL="/boot/vmlinux-`uname -r`"
149OPROFILE_KERNEL_DIR="/lib/modules/`uname -r`/kernel/"
150OPROFILE_SPL_DIR=${SPLBUILD}/module/
151OPROFILE_ZFS_DIR=${MODDIR}
152
153EOF
154}
155
156zpios_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
171zpios_profile_stop() {
172 /usr/bin/opcontrol --shutdown
173 /usr/bin/opcontrol --deinit
174}
175
176PROFILE=
177ZPOOL_CONFIG=zpool-config.sh
178ZPIOS_TEST=zpios-test.sh
179ZPOOL_NAME=zpios
180ZPIOS_OPTIONS=
181ZPOOL_OPTIONS=""
182ZFS_OPTIONS=""
183
184while 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
222done
223
224if [ $(id -u) != 0 ]; then
225 die "Must run as root"
226fi
227
228# Validate and source your test config
229check_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
234if check_modules; then
235 if ! load_modules; then
236 die "Run 'zfs.sh' to ensure the full module stack is loaded"
237 fi
238fi
239
240# Wait for device creation
241while [ ! -c /dev/zpios ]; do
242 sleep 1
243done
244
245if [ ${VERBOSE} ]; then
246 print_header
247 print_spl_info
248 print_zfs_info
249fi
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
256if [ ${PROFILE} ]; then
257 zpios_profile_start
258fi
259
260zpios_start
261zpios_stop
262
263if [ ${PROFILE} ]; then
264 zpios_profile_stop
265fi
266
267if [ ${VERBOSE} ]; then
268 print_stats
269fi
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
276unload_modules
277while [ -c /dev/zpios ]; do
278 sleep 1
279done
280
281exit 0