4 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 2 only,
8 # as published by the Free Software Foundation.
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License version 2 for more details (a copy is included
14 # in the LICENSE file that accompanied this code).
16 # You should have received a copy of the GNU General Public License
17 # version 2 along with this program; If not, see
18 # http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 # Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 # CA 95054 USA or visit www.sun.com if you need additional information or
26 # Copyright 2008 Sun Microsystems, Inc. All rights reserved
27 # Use is subject to license terms.
29 # This file is part of Lustre, http://www.lustre.org/
30 # Lustre is a trademark of Sun Microsystems, Inc.
32 # Author: Jitendra Pawar <jitendra@clusterfs.com>
37 modprobe="/sbin/modprobe"
42 declare -a client_names
45 declare -a unique_hosts
48 declare -a do_unload_echo
52 NETTYPE=${NETTYPE:-tcp}
60 command="export PATH=/sbin:/usr/sbin:\$PATH; $command"
64 if [ -n "$user" ]; then
67 $DSH $user$node "$command"
70 if [ -n "$user" ]; then
73 $DSH $user $node "$command"
78 # how to run commands on other nodes
79 # You need to make this work on your cluster if you have specified
80 # non-local obd instances above
85 if [ "$host" = "localhost" -o "$host" = `uname -n` ]; then
88 # split $host into $host and $user
90 if [[ $host == *@* ]]; then
94 dsh $host "$user" "$cmds"
98 # checks whether obdecho module is loded on given host.
99 # parameter: 1. hostname
102 remote_shell $host $lsmod | grep obdecho > /dev/null 2>&1
105 # load obdecho.ko or obdecho.o module on host kernel.
108 local host=${unique_hosts[$index]}
109 do_unload_echo[$index]=0
110 if obdecho_loaded $host; then
113 if [ -z "$lustre_root" ]; then
114 remote_shell $host $modprobe obdecho
115 elif [ -f ${lustre_root}/obdecho/obdecho.ko ]; then
116 remote_shell $host $insmod ${lustre_root}/obdecho/obdecho.ko
118 remote_shell $host $insmod ${lustre_root}/obdecho/obdecho.o
120 if obdecho_loaded $host; then
121 do_unload_echo[$index]=1
123 echo Could not install obdecho on $host
130 for ((i = 0; i < ${#unique_hosts[@]}; i++)); do
131 load_obdecho $i || cleanup 1
135 # unload obdecho module from host kernel.
138 local host=${unique_hosts[$index]}
139 if ((${do_unload_echo[$index]})); then
140 remote_shell $host $rmmod obdecho
141 do_unload_echo[$index]=0
145 # returns the device number which is displayed in "lctl device_list"
147 # parameter: 1. hostname
148 # 2. type of device ex: echo_client
149 # 3. name of device ex: ECHO_matrix.linsyssoft.com
154 remote_shell $host $lctl device_list | \
155 awk "{if (\$2 == \"UP\" && \$3 == \"$type\" && \$4 == \"$name\") {\
162 for ((i = 0; i < $count; i++)); do
164 host=${host_list[$i]}
165 dev=$(get_devno $host obdfilter $ost)
167 if [ -z "$dev" ]; then
168 echo Cant find device for $ost on $host
175 # do cleanup for netdisk case.
186 # do cleanup for network case.
188 local clean_srv_OSS=$1
194 remote_shell "root@$server_nid" "$lctl << EOF
199 if [ $clean_srv_OSS ]; then
200 remote_shell "root@$server_nid" "$lctl << EOF
208 # do cleanup and exit.
212 for ((i = 0; i < $ndevs; i++)); do
213 host=${host_names[$i]}
214 if [ -n ${do_teardown_ec[$i]} ]; then
215 teardown_ec_devno $host ${client_names[$i]}
219 for host in ${unique_hosts[@]}; do
220 remote_shell $host "killall -q vmstat >/dev/null 2>&1" &
222 kill -term ${vmstatpids[$pidcount]} 2>/dev/null
223 kill -kill ${vmstatpids[$pidcount]} 2>/dev/null
225 pidcount=$((pidcount+1))
226 if ((${do_unload_obdecho[$host]})); then
230 if [ $case == "network" ]; then
233 if [ $case == "netdisk" ]; then
237 if [ $exit_status ]; then
238 if [ $exit_status -ne 0 ]; then
239 echo "program exited with error "
248 trap cleanup SIGHUP SIGINT SIGTERM
250 # gets echoclient device number and attach it to the client UUID
252 # parameter: 1. hostname
253 # 2. client name, ex:- ns8:ECHO_ns8
254 # 3. name of ost instances, ex:- lustre-OST0001
257 local client_name="$2"
259 if [ -z "$client_name" ]; then
260 if [ -z "$ost_name" ]; then
261 echo "client and ost name both null" 1>&2
264 client_name=${ost_name}_ecc
266 ec=`get_devno $host echo_client $client_name`
267 if [ -n "$ec" ]; then
268 echo $ec $client_name $client_name
271 if [ -z "$ost_name" ]; then
272 echo "no echo client and ost_name not set, client: $client_name, host: $host" 1>&2
275 ost=`get_devno $host obdfilter $ost_name`
276 if [ -z "$ost" ]; then
277 echo "OST $ost_name not setup" 1>&2
280 client_name=${ost_name}_ecc
281 remote_shell $host "$lctl <<EOF
282 attach echo_client $client_name ${client_name}_UUID
285 ec=`get_devno $host echo_client $client_name`
286 if [ -z "$ec" ]; then
287 echo "Can't setup echo-client" 1>&2
290 echo $ec $client_name 1
293 # Create echo-clients using osc_names and osc_uuid
294 # It creates echoclients for all osc listed using #lctl device_list command
298 attach echo_client ${osc_name}_ecc ${osc_name}_ecc_UUID
299 cfg_device ${osc_name}_ecc
305 # create echo client using server nid.
306 ec_using_srv_nid () {
310 $lctl add_uuid echo_UUID $server_nid@$NETTYPE >/dev/null 2>&1
312 attach osc $ocsname $oscuuid
314 setup echo_srv_UUID echo_UUID
317 attach echo_client ${ocsname}_ecc $oscuuid
322 setup_osc_for_remote_ost () {
324 local obdfilter_name=$2
325 local host_name=host_$3
326 $lctl add_uuid ${host_name}_UUID $ost_nid@$NETTYPE >/dev/null 2>&1
328 attach osc ${obdfilter_name}_osc ${obdfilter_name}_osc_UUID
329 cfg_device ${obdfilter_name}_osc
330 setup ${obdfilter_name}_UUID ${host_name}_UUID
334 # setup obdecho on server
337 local test_ostfsnm=$2
338 remote_shell "root@$server_nid" "$lctl << EOF
339 attach obdecho $test_ostfsnm ${test_ostfsnm}_UUID
340 cfg_device $test_ostfsnm
345 # setup OSS on server
348 remote_shell "root@$server_nid" "$lctl << EOF
349 attach ost OSS OSS_UUID
355 # cleanup and detach the echo-clients that we have created during the test.
356 # parameter: 1. hostname
357 # 2. client name, ex:- ns8:ECHO_ns8
358 teardown_ec_devno () {
361 remote_shell $host "$lctl <<EOF
369 echo "$@" | xargs -n1 echo | sort -u
375 *:*) host=`echo $name | sed 's/:.*$//'`
376 name=`echo $name | sed 's/[^:]*://'`
386 osc_names_str=$($lctl dl | grep $type_obj)
388 for name in $osc_names_str; do
392 if [ $count != 0 ]; then
393 echo "$type_obj could not be cleanup";
401 osc_names_str=$($lctl dl | grep $type_obj)
403 for name in $osc_names_str; do
407 if [ $count == 0 ]; then
408 echo "$type_obj could not be setup";
414 # added from bugzill req.
416 if [ -z "$ost_names" ]; then
417 targets=$($lctl device_list | awk "{if (\$2 == \"UP\" && \
418 \$3 == \"obdfilter\") {print \$4} }")
420 if [ -z "$targets" ]; then
421 echo "Can't find any OSTs to test. Please set targets=..."
425 for name in $targets; do
426 ost_names[$count]=$name
427 str=(`split_hostname $name`)
428 host_names[$count]=${str[0]}
434 # split out hostnames from ost names
435 for ((i = 0; i < count; i++)); do
436 str=(`split_hostname ${targets[$i]}`)
437 host_list[$i]=${str[0]}
438 ost_names[$i]=${str[1]}