2 #* Copyright (C) 2002 Cluster File Systems, Inc.
3 #* Author: Jitendra Pawar <jitendra@clusterfs.com>
5 #* Lustre-iokit is free software; you can redistribute it and/or
6 #* modify it under the terms of version 2 of the GNU General Public
7 #* License as published by the Free Software Foundation.
9 #* Lustre-iokit is distributed in the hope that it will be useful,
10 #* but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 #* GNU General Public License for more details.
14 #* You should have received a copy of the GNU General Public License
15 #* along with Lustre; if not, write to the Free Software
16 #* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 modprobe="/sbin/modprobe"
27 declare -a unique_hosts
30 declare -a do_unload_echo
43 command="cd $here; export PATH=/sbin:/usr/sbin:\$PATH; $command"
47 if [ -n "$user" ]; then
50 $DSH $user$node "$command"
53 if [ -n "$user" ]; then
56 $DSH $user $node "$command"
60 # This function executes the command sent through parameters to host
63 # 2. command to be executed on host
64 custom_remote_shell () {
69 # Hop on to the remote node, chdir to 'here' and run the given
70 # commands. One of the following will probably work.
71 ssh $host "cd $here; $cmds"
72 #rsh $host "cd $here; $cmds"
73 # we have to remove the leading `uname -n`: from pdsh output lines
74 #pdsh -w $host "cd $here; $cmds" | sed 's/^[^:]*://'
77 # how to run commands on other nodes
78 # You need to make this work on your cluster if you have specified
79 # non-local obd instances above
84 if [ "$host" = "localhost" -o "$host" = `uname -n` ]; then
87 # split $host into $host and $user
89 if [[ $host == *@* ]]; then
93 dsh $host "$user" "$cmds"
97 # checks whether obdecho module is loded on given host.
98 # parameter: 1. hostname
101 remote_shell $host $lsmod | grep obdecho > /dev/null 2>&1
104 # load obdecho.ko or obdecho.o module on host kernel.
107 local host=${unique_hosts[$index]}
108 do_unload_echo[$index]=0
109 if obdecho_loaded $host; then
112 if [ -z "$lustre_root" ]; then
113 remote_shell $host $modprobe obdecho
114 elif [ -f ${lustre_root}/obdecho/obdecho.ko ]; then
115 remote_shell $host $insmod ${lustre_root}/obdecho/obdecho.ko
117 remote_shell $host $insmod ${lustre_root}/obdecho/obdecho.o
119 if obdecho_loaded $host; then
120 do_unload_echo[$index]=1
122 echo Could not install obdecho on $host
129 for ((i = 0; i < ${#unique_hosts[@]}; i++)); do
130 load_obdecho $i || cleanup 1
134 # unload obdecho module from host kernel.
137 local host=${unique_hosts[$index]}
138 if ((${do_unload_echo[$index]})); then
139 remote_shell $host $rmmod obdecho
140 do_unload_echo[$index]=0
144 # returns the device number which is displayed in "lctl device_list"
146 # parameter: 1. hostname
147 # 2. type of device ex: echo_client
148 # 3. name of device ex: ECHO_matrix.linsyssoft.com
153 remote_shell $host $lctl device_list | \
154 awk "{if (\$2 == \"UP\" && \$3 == \"$type\" && \$4 == \"$name\") {\
161 for ((i = 0; i < $count; i++)); do
163 host=${host_list[$i]}
164 dev=$(get_devno $host obdfilter $ost)
166 if [ -z "$dev" ]; then
167 echo Cant find device for $ost on $host
174 # do cleanup and exit.
176 for ((i = 0; i < ndevs; i++)); do
177 host=${host_names[$i]}
178 if [ -n ${do_teardown_ec[$i]} ]; then
179 teardown_ec_devno $host ${client_names[$i]}
183 for host in ${unique_hosts[@]}; do
184 remote_shell $host "killall vmstat -q" &
186 kill -term ${vmstatpids[$pidcount]} 2>/dev/null
187 kill -kill ${vmstatpids[$pidcount]} 2>/dev/null
189 pidcount=$((pidcount+1))
190 if ((${do_unload_obdecho[$host]})); then
194 if [ $case == "network" ]; then
200 remote_shell "root@$server_nid" "lctl << EOF
209 if [ $1 -ne 0 ]; then
210 echo "program exited with error "
216 trap cleanup SIGHUP SIGINT SIGTERM
218 # gets echoclient device number and attch it to the client UUID
220 # parameter: 1. hostname
221 # 2. client name, ex:- ns8:ECHO_ns8
222 # 3. name of ost instances, ex:- lustre-OST0001
225 local client_name="$2"
227 if [ -z "$client_name" ]; then
228 if [ -z "$ost_name" ]; then
229 echo "client and ost name both null" 1>&2
232 client_name=${ost_name}_echo_client
234 ec=`get_devno $host echo_client $client_name`
235 if [ -n "$ec" ]; then
236 echo $ec $client_name $client_name
239 if [ -z "$ost_name" ]; then
240 echo "no echo client and ost_name not set, client: $client_name, host: $host" 1>&2
243 ost=`get_devno $host obdfilter $ost_name`
244 if [ -z "$ost" ]; then
245 echo "OST $ost_name not setup" 1>&2
248 remote_shell $host "$lctl <<EOF
249 attach echo_client $client_name ${client_name}_UUID
252 ec=`get_devno $host echo_client $client_name`
253 if [ -z "$ec" ]; then
254 echo "Can't setup echo client" 1>&2
257 echo $ec $client_name 1
260 # Create echo-clients using osc_names and osc_uuid
261 # It creates echoclients for all osc listed using #lctl device_list command
266 attach echo_client ECHO_$osc_name $osc_uuid
267 cfg_device ECHO_$osc_name
273 # create echo client using server nid.
274 ec_using_srv_nid () {
279 add_uuid testfs_UUID $server_nid@tcp
280 attach osc $ocsname $oscuuid
282 setup ost_testfs_UUID testfs_UUID
285 attach echo_client ECHO_$ocsname $oscuuid
290 # setup obdecho and ost on server
293 local test_ostfsnm=$2
295 remote_shell "root@$server_nid" "$lctl << EOF
296 attach obdecho $test_ostfsnm ${test_ostfsnm}_UUID
297 cfg_device $test_ostfsnm
299 attach ost OSS OSS_UUID
305 # cleanup and detach the echo-clients that we have created during the test.
306 # parameter: 1. hostname
307 # 2. client name, ex:- ns8:ECHO_ns8
308 teardown_ec_devno () {
311 remote_shell $host "$lctl <<EOF
319 echo "$@" | xargs -n1 echo | sort -u
325 *:*) host=`echo $name | sed 's/:.*$//'`
326 name=`echo $name | sed 's/[^:]*://'`
336 osc_names_str=$(lctl dl | grep $type_obj)
338 for name in $osc_names_str; do
342 if [ $count != 0 ]; then
343 echo "$type_obj could not be cleanup";
351 osc_names_str=$(lctl dl | grep $type_obj)
353 for name in $osc_names_str; do
357 if [ $count == 0 ]; then
358 echo "$type_obj could not be setup";
364 # added from bugzill req.
366 if [ -z "$ost_names" ]; then
367 OSTS=$($lctl device_list | awk "{if (\$2 == \"UP\" && \
368 \$3 == \"obdfilter\") {print \$4} }")
370 if [ -z "$OSTS" ]; then
371 echo "Can't find any OSTs to test. Please set ost_names=..."
375 for name in $OSTS; do
376 ost_names[$count]=$name
382 # split out hostnames from ost names
383 for ((i = 0; i < count; i++)); do
384 str=(`split_hostname ${OSTS[$i]}`)
385 host_list[$i]=${str[0]}
386 ost_names[$i]=${str[1]}