2 # -*- mode: Bash; tab-width: 4; indent-tabs-mode: t; -*-
3 # vim:shiftwidth=4:softtabstop=4:tabstop=4:
7 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License version 2 only,
11 # as published by the Free Software Foundation.
13 # This program is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # General Public License version 2 for more details (a copy is included
17 # in the LICENSE file that accompanied this code).
19 # You should have received a copy of the GNU General Public License
20 # version 2 along with this program; If not, see
21 # http://www.gnu.org/licenses/gpl-2.0.html
25 # Copyright 2008 Sun Microsystems, Inc. All rights reserved
26 # Use is subject to license terms.
28 # Copyright (c) 2012, 2014, Intel Corporation.
30 # This file is part of Lustre, http://www.lustre.org/
31 # Lustre is a trademark of Sun Microsystems, Inc.
33 # Author: Jitendra Pawar <jitendra@clusterfs.com>
38 modprobe="/sbin/modprobe"
43 declare -a client_names
46 declare -a unique_hosts
49 declare -a do_unload_echo
53 NETTYPE=${NETTYPE:-tcp}
61 command="export PATH=/sbin:/usr/sbin:\$PATH; $command"
65 if [ -n "$user" ]; then
68 $DSH $user$node "$command"
71 if [ -n "$user" ]; then
74 $DSH $user $node "$command"
79 # how to run commands on other nodes
80 # You need to make this work on your cluster if you have specified
81 # non-local obd instances above
86 if [ "$host" = "localhost" -o "$host" = `uname -n` ]; then
89 # split $host into $host and $user
91 if [[ $host == *@* ]]; then
95 dsh $host "$user" "$cmds"
99 # checks whether obdecho module is loded on given host.
100 # parameter: 1. hostname
103 remote_shell $host $lsmod | grep obdecho > /dev/null 2>&1
106 # load obdecho.ko or obdecho.o module on host kernel.
109 local host=${unique_hosts[$index]}
111 do_unload_echo[$index]=0
112 if obdecho_loaded $host; then
115 if [ -z "$lustre_root" ]; then
116 remote_shell $host $modprobe obdecho
117 elif [ -f ${lustre_root}/obdecho/obdecho.ko ]; then
118 remote_shell $host $insmod ${lustre_root}/obdecho/obdecho.ko
120 remote_shell $host $insmod ${lustre_root}/obdecho/obdecho.o
122 if obdecho_loaded $host; then
123 do_unload_echo[$index]=1
125 echo Could not install obdecho on $host
132 for ((i = 0; i < ${#unique_hosts[@]}; i++)); do
133 load_obdecho $i || cleanup 1
137 # unload obdecho module from host kernel.
140 local host=${unique_hosts[$index]}
141 if ((${do_unload_echo[$index]})); then
142 remote_shell $host $rmmod obdecho
143 do_unload_echo[$index]=0
147 # returns the device number which is displayed in "lctl device_list"
149 # parameter: 1. hostname
150 # 2. type of device ex: echo_client
151 # 3. name of device ex: ECHO_matrix.linsyssoft.com
157 remote_shell $host $lctl device_list |
158 awk "{if (\$2 == \"UP\" && \$3 == \"$type\" && \$4 == \"$name\") {\
165 for ((i = 0; i < $count; i++)); do
167 host=${host_list[$i]}
168 dev=$(get_devno $host obdfilter $ost)
170 if [ -z "$dev" ]; then
171 echo "Cannot find device for $ost on $host"
178 # do cleanup for netdisk case.
189 # do cleanup for network case.
191 local clean_srv_OSS=$1
198 remote_shell "root@$server_nid" \
204 if [ $clean_srv_OSS ]; then
205 remote_shell "root@$server_nid" \
214 # do cleanup and exit.
221 for ((i = 0; i < $ndevs; i++)); do
222 host=${host_names[$i]}
223 if [[ -n "${do_teardown_ec[$i]}" ]]; then
224 teardown_ec_devno $host ${client_names[$i]}
228 for ((i = 0; i < ${#unique_hosts[@]}; i++)); do
229 host=${unique_hosts[$i]}
230 remote_shell $host "killall -q vmstat >/dev/null 2>&1" &
232 kill -term ${vmstatpids[$pidcount]} 2>/dev/null
233 kill -kill ${vmstatpids[$pidcount]} 2>/dev/null
235 pidcount=$((pidcount + 1))
236 if ((${do_unload_echo[$i]})); then
240 if [ $case == "network" ]; then
243 if [ $case == "netdisk" ]; then
247 if [ $exit_status ]; then
248 if [ $exit_status -ne 0 ]; then
249 echo "program exited with error "
258 trap 'cleanup 0 $clean_srv_OSS $cleanup_oscs' SIGHUP SIGINT SIGTERM
260 # gets echoclient device number and attach it to the client UUID
261 # Results are returned by an echo followed by an exit
262 # This must run in a subshell.
264 # parameter: 1. hostname
265 # 2. client name, ex:- ns8:ECHO_ns8
266 # 3. name of ost instances, ex:- lustre-OST0001
270 local client_name="$2"
272 local dev_type="${4:-obdfilter}"
273 local stack_type="${5:-}"
275 if [ -z "$client_name" ]; then
276 if [ -z "$ost_name" ]; then
277 echo "client and ost name both null"
280 client_name=${ost_name}_ecc
282 ec=$(get_devno $host echo_client $client_name)
283 if [ -n "$ec" ]; then
284 echo $ec $client_name $client_name >&8
287 if [ -z "$ost_name" ]; then
288 echo "no echo client and ost_name not set, client:" \
289 "$client_name, host: $host"
292 ost=$(get_devno $host $dev_type $ost_name)
293 if [ -z "$ost" ]; then
294 echo "OST $ost_name not setup"
297 client_name=${ost_name}_ecc
300 attach echo_client $client_name ${client_name}_UUID
301 setup $ost_name $stack_type
303 ec=$(get_devno $host echo_client $client_name)
304 if [ -z "$ec" ]; then
305 echo "Can't setup echo-client"
308 echo $ec $client_name 1 >&8
312 # Create echo-clients using osc_names and osc_uuid
313 # It creates echoclients for all osc listed using #lctl device_list command
318 attach echo_client ${osc_name}_ecc ${osc_name}_ecc_UUID
319 cfg_device ${osc_name}_ecc
325 # create echo client using server nid.
326 ec_using_srv_nid () {
331 $lctl add_uuid echo_UUID $server_nid@$NETTYPE >/dev/null 2>&1
333 attach osc $ocsname $oscuuid
335 setup echo_srv_UUID echo_UUID
338 attach echo_client ${ocsname}_ecc $oscuuid
343 setup_osc_for_remote_ost () {
345 local obdfilter_name=$2
346 local host_name=host_$3
348 $lctl add_uuid ${host_name}_UUID $ost_nid@$NETTYPE >/dev/null 2>&1
350 attach osc ${obdfilter_name}_osc ${obdfilter_name}_osc_UUID
351 cfg_device ${obdfilter_name}_osc
352 setup ${obdfilter_name}_UUID ${host_name}_UUID
356 # setup obdecho on server
359 local test_ostfsnm=$2
361 remote_shell "root@$server_nid" \
363 attach obdecho $test_ostfsnm ${test_ostfsnm}_UUID
364 cfg_device $test_ostfsnm
369 # setup OSS on server
373 remote_shell "root@$server_nid" \
375 attach ost OSS OSS_UUID
381 # cleanup and detach the echo-clients that we have created during the test.
382 # parameter: 1. hostname
383 # 2. client name, ex:- ns8:ECHO_ns8
384 teardown_ec_devno () {
397 echo "$@" | xargs -n1 echo | sort -u
404 *:*) host=$(echo $name | sed 's/:.*$//')
405 name=$(echo $name | sed 's/[^:]*://')
415 local osc_names_str=$($lctl dl | grep $type_obj)
418 for name in $osc_names_str; do
422 if [ $count != 0 ]; then
423 echo "$type_obj could not be cleanup";
431 local osc_names_str=$($lctl dl | grep $type_obj)
434 for name in $osc_names_str; do
438 if [ $count == 0 ]; then
439 echo "$type_obj could not be setup";
445 # added from bugzill req.
447 if [ -z "$ost_names" ]; then
448 targets=$($lctl device_list | awk "{if (\$2 == \"UP\" && \
449 \$3 == \"obdfilter\") {print \$4} }")
451 if [ -z "$targets" ]; then
452 echo "Can't find any OSTs to test. Please set targets=..."
457 for name in $targets; do
458 ost_names[$count]=$name
459 str=($(split_hostname $name))
460 host_names[$count]=${str[0]}
466 # split out hostnames from ost names
467 for ((i = 0; i < count; i++)); do
468 local str=($(split_hostname ${targets[$i]}))
469 host_list[$i]=${str[0]}
470 ost_names[$i]=${str[1]}