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
33 # This function executes the command sent through parameters to host
36 # 2. command to be executed on host
37 custom_remote_shell () {
42 # Hop on to the remote node, chdir to 'here' and run the given
43 # commands. One of the following will probably work.
44 ssh $host "cd $here; $cmds"
45 #rsh $host "cd $here; $cmds"
46 # we have to remove the leading `uname -n`: from pdsh output lines
47 #pdsh -w $host "cd $here; $cmds" | sed 's/^[^:]*://'
50 # how to run commands on other nodes
51 # You need to make this work on your cluster if you have specified
52 # non-local obd instances above
57 if [ "$host" = "localhost" -o "$host" = `uname -n` ]; then
60 custom_remote_shell $host "$cmds"
64 # checks whether obdecho module is loded on given host.
65 # parameter: 1. hostname
68 remote_shell $host $lsmod | grep obdecho > /dev/null 2>&1
71 # load obdecho.ko or obdecho.o module on host kernel.
74 local host=${unique_hosts[$index]}
75 do_unload_echo[$index]=0
76 if obdecho_loaded $host; then
79 if [ -z "$lustre_root" ]; then
80 remote_shell $host $modprobe obdecho
81 elif [ -f ${lustre_root}/obdecho/obdecho.ko ]; then
82 remote_shell $host $insmod ${lustre_root}/obdecho/obdecho.ko
84 remote_shell $host $insmod ${lustre_root}/obdecho/obdecho.o
86 if obdecho_loaded $host; then
87 do_unload_echo[$index]=1
89 echo Could not install obdecho on $host
96 for ((i = 0; i < ${#unique_hosts[@]}; i++)); do
97 load_obdecho $i || cleanup 1
101 # unload obdecho module from host kernel.
104 local host=${unique_hosts[$index]}
105 if ((${do_unload_echo[$index]})); then
106 remote_shell $host $rmmod obdecho
107 do_unload_echo[$index]=0
111 # returns the device number which is displayed in "lctl device_list"
113 # parameter: 1. hostname
114 # 2. type of device ex: echo_client
115 # 3. name of device ex: ECHO_matrix.linsyssoft.com
120 remote_shell $host $lctl device_list | \
121 awk "{if (\$2 == \"UP\" && \$3 == \"$type\" && \$4 == \"$name\") {\
128 for ((i = 0; i < $count; i++)); do
130 host=${host_list[$i]}
131 dev=$(get_devno $host obdfilter $ost)
133 if [ -z "$dev" ]; then
134 echo Cant find device for $ost on $host
141 # do cleanup and exit.
143 for ((i = 0; i < ndevs; i++)); do
144 host=${host_names[$i]}
145 if [ -n ${do_teardown_ec[$i]} ]; then
146 teardown_ec_devno $host ${client_names[$i]}
150 for host in ${unique_hosts[@]}; do
151 remote_shell $host "killall vmstat -q" &
153 kill -term ${vmstatpids[$pidcount]} 2>/dev/null
154 kill -kill ${vmstatpids[$pidcount]} 2>/dev/null
156 pidcount=$((pidcount+1))
157 if ((${do_unload_obdecho[$host]})); then
161 if [ $case == "network" ]; then
167 remote_shell "root@$server_nid" "lctl << EOF
176 if [ $1 -ne 0 ]; then
177 echo "program exited with error "
183 trap cleanup SIGHUP SIGINT SIGTERM
185 # gets echoclient device number and attch it to the client UUID
187 # parameter: 1. hostname
188 # 2. client name, ex:- ns8:ECHO_ns8
189 # 3. name of ost instances, ex:- lustre-OST0001
192 local client_name="$2"
194 if [ -z "$client_name" ]; then
195 if [ -z "$ost_name" ]; then
196 echo "client and ost name both null" 1>&2
199 client_name=${ost_name}_echo_client
201 ec=`get_devno $host echo_client $client_name`
202 if [ -n "$ec" ]; then
203 echo $ec $client_name $client_name
206 if [ -z "$ost_name" ]; then
207 echo "no echo client and ost_name not set, client: $client_name, host: $host" 1>&2
210 ost=`get_devno $host obdfilter $ost_name`
211 if [ -z "$ost" ]; then
212 echo "OST $ost_name not setup" 1>&2
215 remote_shell $host "$lctl <<EOF
216 attach echo_client $client_name ${client_name}_UUID
219 ec=`get_devno $host echo_client $client_name`
220 if [ -z "$ec" ]; then
221 echo "Can't setup echo client" 1>&2
224 echo $ec $client_name 1
227 # Create echo-clients using osc_names and osc_uuid
228 # It creates echoclients for all osc listed using #lctl device_list command
233 attach echo_client ECHO_$osc_name $osc_uuid
234 cfg_device ECHO_$osc_name
240 # create echo client using server nid.
241 ec_using_srv_nid () {
246 add_uuid testfs_UUID $server_nid@tcp
247 attach osc $ocsname $oscuuid
249 setup ost_testfs_UUID testfs_UUID
252 attach echo_client ECHO_$ocsname $oscuuid
257 # setup obdecho and ost on server
260 local test_ostfsnm=$2
262 remote_shell "root@$server_nid" "$lctl << EOF
263 attach obdecho $test_ostfsnm ${test_ostfsnm}_UUID
264 cfg_device $test_ostfsnm
266 attach ost OSS OSS_UUID
272 # cleanup and detach the echo-clients that we have created during the test.
273 # parameter: 1. hostname
274 # 2. client name, ex:- ns8:ECHO_ns8
275 teardown_ec_devno () {
278 remote_shell $host "$lctl <<EOF
286 echo "$@" | xargs -n1 echo | sort -u
292 *:*) host=`echo $name | sed 's/:.*$//'`
293 name=`echo $name | sed 's/[^:]*://'`
303 osc_names_str=$(lctl dl | grep $type_obj)
305 for name in $osc_names_str; do
309 if [ $count != 0 ]; then
310 echo "$type_obj could not be cleanup";
318 osc_names_str=$(lctl dl | grep $type_obj)
320 for name in $osc_names_str; do
324 if [ $count == 0 ]; then
325 echo "$type_obj could not be setup";
331 # added from bugzill req.
333 if [ -z "$ost_names" ]; then
334 OSTS=$($lctl device_list | awk "{if (\$2 == \"UP\" && \
335 \$3 == \"obdfilter\") {print \$4} }")
337 if [ -z "$OSTS" ]; then
338 echo "Can't find any OSTs to test. Please set ost_names=..."
342 for name in $OSTS; do
343 ost_names[$count]=$name
349 # split out hostnames from ost names
350 for ((i = 0; i < count; i++)); do
351 str=(`split_hostname ${OSTS[$i]}`)
352 host_list[$i]=${str[0]}
353 ost_names[$i]=${str[1]}