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, 2017, Intel Corporation.
30 # This file is part of Lustre, http://www.lustre.org/
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]}
110 do_unload_echo[$index]=0
111 if obdecho_loaded $host; then
114 if [ -z "$lustre_root" ]; then
115 remote_shell $host $modprobe obdecho
116 elif [ -f ${lustre_root}/obdecho/obdecho.ko ]; then
117 remote_shell $host $insmod ${lustre_root}/obdecho/obdecho.ko
119 remote_shell $host $insmod ${lustre_root}/obdecho/obdecho.o
121 if obdecho_loaded $host; then
122 do_unload_echo[$index]=1
124 echo Could not install obdecho on $host
131 for ((i = 0; i < ${#unique_hosts[@]}; i++)); do
132 load_obdecho $i || cleanup 1
136 # unload obdecho module from host kernel.
139 local host=${unique_hosts[$index]}
140 if ((${do_unload_echo[$index]})); then
141 remote_shell $host $rmmod obdecho
142 do_unload_echo[$index]=0
146 # returns the device number which is displayed in "lctl device_list"
148 # parameter: 1. hostname
149 # 2. type of device ex: echo_client
150 # 3. name of device ex: ECHO_matrix.linsyssoft.com
156 remote_shell $host $lctl device_list |
157 awk "{if (\$2 == \"UP\" && \$3 == \"$type\" && \$4 == \"$name\") {\
164 for ((i = 0; i < $count; i++)); do
166 host=${host_list[$i]}
167 dev=$(get_devno $host obdfilter $ost)
169 if [ -z "$dev" ]; then
170 echo "Cannot find device for $ost on $host"
177 # do cleanup for netdisk case.
188 # do cleanup for network case.
190 local clean_srv_OSS=$1
197 remote_shell "root@$server_nid" \
203 if [ $clean_srv_OSS ]; then
204 remote_shell "root@$server_nid" \
213 # do cleanup and exit.
222 for ((i = 0; i < $ndevs; i++)); do
223 host=${host_names[$i]}
224 if [[ -n "${do_teardown_ec[$i]}" ]]; then
225 teardown_ec_devno $host ${client_names[$i]}
229 for ((i = 0; i < ${#unique_hosts[@]}; i++)); do
230 host=${unique_hosts[$i]}
231 remote_shell $host "killall -q vmstat >/dev/null 2>&1" &
233 kill -term ${vmstatpids[$pidcount]} 2>/dev/null
234 kill -kill ${vmstatpids[$pidcount]} 2>/dev/null
236 pidcount=$((pidcount + 1))
237 if ((${do_unload_echo[$i]})); then
241 if [ $case == "network" ]; then
244 if [ $case == "netdisk" ]; then
248 if [ $exit_status ]; then
249 if [ $exit_status -ne 0 ]; then
250 echo "program exited with error "
259 trap 'cleanup 0 $clean_srv_OSS $cleanup_oscs' EXIT SIGHUP SIGINT SIGTERM
261 # gets echoclient device number and attach it to the client UUID
262 # Results are returned by an echo followed by an exit
263 # This must run in a subshell.
265 # parameter: 1. hostname
266 # 2. client name, ex:- ns8:ECHO_ns8
267 # 3. name of ost instances, ex:- lustre-OST0001
271 local client_name="$2"
273 local dev_type="${4:-obdfilter}"
274 local stack_type="${5:-}"
276 if [ -z "$client_name" ]; then
277 if [ -z "$ost_name" ]; then
278 echo "client and ost name both null"
281 client_name=${ost_name}_ecc
283 ec=$(get_devno $host echo_client $client_name)
284 if [ -n "$ec" ]; then
285 echo $ec $client_name $client_name >&8
288 if [ -z "$ost_name" ]; then
289 echo "no echo client and ost_name not set, client:" \
290 "$client_name, host: $host"
293 ost=$(get_devno $host $dev_type $ost_name)
294 if [ -z "$ost" ]; then
295 echo "OST $ost_name not setup"
298 client_name=${ost_name}_ecc
301 attach echo_client $client_name ${client_name}_UUID
302 setup $ost_name $stack_type
304 ec=$(get_devno $host echo_client $client_name)
305 if [ -z "$ec" ]; then
306 echo "Can't setup echo-client"
309 echo $ec $client_name 1 >&8
313 # Create echo-clients using osc_names and osc_uuid
314 # It creates echoclients for all osc listed using #lctl device_list command
319 attach echo_client ${osc_name}_ecc ${osc_name}_ecc_UUID
320 cfg_device ${osc_name}_ecc
326 # create echo client using server nid.
327 ec_using_srv_nid () {
332 $lctl add_uuid echo_UUID $server_nid@$NETTYPE >/dev/null 2>&1
334 attach osc $ocsname $oscuuid
336 setup echo_srv_UUID echo_UUID
339 attach echo_client ${ocsname}_ecc $oscuuid
344 setup_osc_for_remote_ost () {
346 local obdfilter_name=$2
347 local host_name=host_$3
349 $lctl add_uuid ${host_name}_UUID $ost_nid@$NETTYPE >/dev/null 2>&1
351 attach osc ${obdfilter_name}_osc ${obdfilter_name}_osc_UUID
352 cfg_device ${obdfilter_name}_osc
353 setup ${obdfilter_name}_UUID ${host_name}_UUID
357 # setup obdecho on server
360 local test_ostfsnm=$2
362 remote_shell "root@$server_nid" \
364 attach obdecho $test_ostfsnm ${test_ostfsnm}_UUID
365 cfg_device $test_ostfsnm
370 # setup OSS on server
374 remote_shell "root@$server_nid" \
376 attach ost OSS OSS_UUID
382 # cleanup and detach the echo-clients that we have created during the test.
383 # parameter: 1. hostname
384 # 2. client name, ex:- ns8:ECHO_ns8
385 teardown_ec_devno () {
398 echo "$@" | xargs -n1 echo | sort -u
405 *:*) host=$(echo $name | sed 's/:.*$//')
406 name=$(echo $name | sed 's/[^:]*://')
416 local osc_names_str=$($lctl dl | grep $type_obj)
419 for name in $osc_names_str; do
423 if [ $count != 0 ]; then
424 echo "$type_obj could not be cleanup";
432 local osc_names_str=$($lctl dl | grep $type_obj)
435 for name in $osc_names_str; do
439 if [ $count == 0 ]; then
440 echo "$type_obj could not be setup";
446 # added from bugzill req.
448 if [ -z "$ost_names" ]; then
449 targets=$($lctl device_list | awk "{if (\$2 == \"UP\" && \
450 \$3 == \"obdfilter\") {print \$4} }")
452 if [ -z "$targets" ]; then
453 echo "Can't find any OSTs to test. Please set targets=..."
458 for name in $targets; do
459 ost_names[$count]=$name
460 str=($(split_hostname $name))
461 host_names[$count]=${str[0]}
467 # split out hostnames from ost names
468 for ((i = 0; i < count; i++)); do
469 local str=($(split_hostname ${targets[$i]}))
470 host_list[$i]=${str[0]}
471 ost_names[$i]=${str[1]}