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.sun.com/software/products/lustre/docs/GPLv2.pdf
23 # Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
24 # CA 95054 USA or visit www.sun.com if you need additional information or
29 # Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 # Use is subject to license terms.
32 # Copyright (c) 2012, 2014, Intel Corporation.
34 # This file is part of Lustre, http://www.lustre.org/
35 # Lustre is a trademark of Sun Microsystems, Inc.
37 # Author: Jitendra Pawar <jitendra@clusterfs.com>
42 modprobe="/sbin/modprobe"
47 declare -a client_names
50 declare -a unique_hosts
53 declare -a do_unload_echo
57 NETTYPE=${NETTYPE:-tcp}
65 command="export PATH=/sbin:/usr/sbin:\$PATH; $command"
69 if [ -n "$user" ]; then
72 $DSH $user$node "$command"
75 if [ -n "$user" ]; then
78 $DSH $user $node "$command"
83 # how to run commands on other nodes
84 # You need to make this work on your cluster if you have specified
85 # non-local obd instances above
90 if [ "$host" = "localhost" -o "$host" = `uname -n` ]; then
93 # split $host into $host and $user
95 if [[ $host == *@* ]]; then
99 dsh $host "$user" "$cmds"
103 # checks whether obdecho module is loded on given host.
104 # parameter: 1. hostname
107 remote_shell $host $lsmod | grep obdecho > /dev/null 2>&1
110 # load obdecho.ko or obdecho.o module on host kernel.
113 local host=${unique_hosts[$index]}
115 do_unload_echo[$index]=0
116 if obdecho_loaded $host; then
119 if [ -z "$lustre_root" ]; then
120 remote_shell $host $modprobe obdecho
121 elif [ -f ${lustre_root}/obdecho/obdecho.ko ]; then
122 remote_shell $host $insmod ${lustre_root}/obdecho/obdecho.ko
124 remote_shell $host $insmod ${lustre_root}/obdecho/obdecho.o
126 if obdecho_loaded $host; then
127 do_unload_echo[$index]=1
129 echo Could not install obdecho on $host
136 for ((i = 0; i < ${#unique_hosts[@]}; i++)); do
137 load_obdecho $i || cleanup 1
141 # unload obdecho module from host kernel.
144 local host=${unique_hosts[$index]}
145 if ((${do_unload_echo[$index]})); then
146 remote_shell $host $rmmod obdecho
147 do_unload_echo[$index]=0
151 # returns the device number which is displayed in "lctl device_list"
153 # parameter: 1. hostname
154 # 2. type of device ex: echo_client
155 # 3. name of device ex: ECHO_matrix.linsyssoft.com
161 remote_shell $host $lctl device_list |
162 awk "{if (\$2 == \"UP\" && \$3 == \"$type\" && \$4 == \"$name\") {\
169 for ((i = 0; i < $count; i++)); do
171 host=${host_list[$i]}
172 dev=$(get_devno $host obdfilter $ost)
174 if [ -z "$dev" ]; then
175 echo "Cannot find device for $ost on $host"
182 # do cleanup for netdisk case.
193 # do cleanup for network case.
195 local clean_srv_OSS=$1
202 remote_shell "root@$server_nid" \
208 if [ $clean_srv_OSS ]; then
209 remote_shell "root@$server_nid" \
218 # do cleanup and exit.
225 for ((i = 0; i < $ndevs; i++)); do
226 host=${host_names[$i]}
227 if [[ -n "${do_teardown_ec[$i]}" ]]; then
228 teardown_ec_devno $host ${client_names[$i]}
232 for ((i = 0; i < ${#unique_hosts[@]}; i++)); do
233 host=${unique_hosts[$i]}
234 remote_shell $host "killall -q vmstat >/dev/null 2>&1" &
236 kill -term ${vmstatpids[$pidcount]} 2>/dev/null
237 kill -kill ${vmstatpids[$pidcount]} 2>/dev/null
239 pidcount=$((pidcount + 1))
240 if ((${do_unload_echo[$i]})); then
244 if [ $case == "network" ]; then
247 if [ $case == "netdisk" ]; then
251 if [ $exit_status ]; then
252 if [ $exit_status -ne 0 ]; then
253 echo "program exited with error "
262 trap 'cleanup 0 $clean_srv_OSS $cleanup_oscs' SIGHUP SIGINT SIGTERM
264 # gets echoclient device number and attach it to the client UUID
265 # Results are returned by an echo followed by an exit
266 # This must run in a subshell.
268 # parameter: 1. hostname
269 # 2. client name, ex:- ns8:ECHO_ns8
270 # 3. name of ost instances, ex:- lustre-OST0001
274 local client_name="$2"
276 local dev_type="${4:-obdfilter}"
277 local stack_type="${5:-}"
279 if [ -z "$client_name" ]; then
280 if [ -z "$ost_name" ]; then
281 echo "client and ost name both null"
284 client_name=${ost_name}_ecc
286 ec=$(get_devno $host echo_client $client_name)
287 if [ -n "$ec" ]; then
288 echo $ec $client_name $client_name >&8
291 if [ -z "$ost_name" ]; then
292 echo "no echo client and ost_name not set, client:" \
293 "$client_name, host: $host"
296 ost=$(get_devno $host $dev_type $ost_name)
297 if [ -z "$ost" ]; then
298 echo "OST $ost_name not setup"
301 client_name=${ost_name}_ecc
304 attach echo_client $client_name ${client_name}_UUID
305 setup $ost_name $stack_type
307 ec=$(get_devno $host echo_client $client_name)
308 if [ -z "$ec" ]; then
309 echo "Can't setup echo-client"
312 echo $ec $client_name 1 >&8
316 # Create echo-clients using osc_names and osc_uuid
317 # It creates echoclients for all osc listed using #lctl device_list command
322 attach echo_client ${osc_name}_ecc ${osc_name}_ecc_UUID
323 cfg_device ${osc_name}_ecc
329 # create echo client using server nid.
330 ec_using_srv_nid () {
335 $lctl add_uuid echo_UUID $server_nid@$NETTYPE >/dev/null 2>&1
337 attach osc $ocsname $oscuuid
339 setup echo_srv_UUID echo_UUID
342 attach echo_client ${ocsname}_ecc $oscuuid
347 setup_osc_for_remote_ost () {
349 local obdfilter_name=$2
350 local host_name=host_$3
352 $lctl add_uuid ${host_name}_UUID $ost_nid@$NETTYPE >/dev/null 2>&1
354 attach osc ${obdfilter_name}_osc ${obdfilter_name}_osc_UUID
355 cfg_device ${obdfilter_name}_osc
356 setup ${obdfilter_name}_UUID ${host_name}_UUID
360 # setup obdecho on server
363 local test_ostfsnm=$2
365 remote_shell "root@$server_nid" \
367 attach obdecho $test_ostfsnm ${test_ostfsnm}_UUID
368 cfg_device $test_ostfsnm
373 # setup OSS on server
377 remote_shell "root@$server_nid" \
379 attach ost OSS OSS_UUID
385 # cleanup and detach the echo-clients that we have created during the test.
386 # parameter: 1. hostname
387 # 2. client name, ex:- ns8:ECHO_ns8
388 teardown_ec_devno () {
401 echo "$@" | xargs -n1 echo | sort -u
408 *:*) host=$(echo $name | sed 's/:.*$//')
409 name=$(echo $name | sed 's/[^:]*://')
419 local osc_names_str=$($lctl dl | grep $type_obj)
422 for name in $osc_names_str; do
426 if [ $count != 0 ]; then
427 echo "$type_obj could not be cleanup";
435 local osc_names_str=$($lctl dl | grep $type_obj)
438 for name in $osc_names_str; do
442 if [ $count == 0 ]; then
443 echo "$type_obj could not be setup";
449 # added from bugzill req.
451 if [ -z "$ost_names" ]; then
452 targets=$($lctl device_list | awk "{if (\$2 == \"UP\" && \
453 \$3 == \"obdfilter\") {print \$4} }")
455 if [ -z "$targets" ]; then
456 echo "Can't find any OSTs to test. Please set targets=..."
461 for name in $targets; do
462 ost_names[$count]=$name
463 str=($(split_hostname $name))
464 host_names[$count]=${str[0]}
470 # split out hostnames from ost names
471 for ((i = 0; i < count; i++)); do
472 local str=($(split_hostname ${targets[$i]}))
473 host_list[$i]=${str[0]}
474 ost_names[$i]=${str[1]}