2 # SPDX-License-Identifier: GPL-2.0
5 # Copyright 2008 Sun Microsystems, Inc. All rights reserved
6 # Use is subject to license terms.
8 # Copyright (c) 2012, 2017, Intel Corporation.
12 # This file is part of Lustre, http://www.lustre.org/
14 # Author: Jitendra Pawar <jitendra@clusterfs.com>
19 modprobe="/sbin/modprobe"
24 declare -a client_names
27 declare -a unique_hosts
30 declare -a do_unload_echo
34 NETTYPE=${NETTYPE:-tcp}
42 command="export PATH=/sbin:/usr/sbin:\$PATH; $command"
46 if [ -n "$user" ]; then
49 $DSH $user$node "$command"
52 if [ -n "$user" ]; then
55 $DSH $user $node "$command"
60 # how to run commands on other nodes
61 # You need to make this work on your cluster if you have specified
62 # non-local obd instances above
67 if [ "$host" = "localhost" -o "$host" = `uname -n` ]; then
70 # split $host into $host and $user
72 if [[ $host == *@* ]]; then
76 dsh $host "$user" "$cmds"
80 # checks whether obdecho module is loded on given host.
81 # parameter: 1. hostname
84 remote_shell $host $lsmod | grep obdecho > /dev/null 2>&1
87 # load obdecho.ko or obdecho.o module on host kernel.
90 local host=${unique_hosts[$index]}
92 do_unload_echo[$index]=0
93 if obdecho_loaded $host; then
96 if [ -z "$lustre_root" ]; then
97 remote_shell $host $modprobe obdecho
98 elif [ -f ${lustre_root}/obdecho/obdecho.ko ]; then
99 remote_shell $host $insmod ${lustre_root}/obdecho/obdecho.ko
101 remote_shell $host $insmod ${lustre_root}/obdecho/obdecho.o
103 if obdecho_loaded $host; then
104 do_unload_echo[$index]=1
106 echo Could not install obdecho on $host
113 for ((i = 0; i < ${#unique_hosts[@]}; i++)); do
114 load_obdecho $i || cleanup 1
118 # unload obdecho module from host kernel.
121 local host=${unique_hosts[$index]}
122 if ((${do_unload_echo[$index]})); then
123 remote_shell $host $rmmod obdecho
124 do_unload_echo[$index]=0
128 # returns the device number which is displayed in "lctl device_list"
130 # parameter: 1. hostname
131 # 2. type of device ex: echo_client
132 # 3. name of device ex: ECHO_matrix.linsyssoft.com
138 remote_shell $host $LCTL device_list |
139 awk "{if (\$2 == \"UP\" && \$3 == \"$type\" && \$4 == \"$name\") {\
146 for ((i = 0; i < $count; i++)); do
148 host=${host_list[$i]}
149 dev=$(get_devno $host obdfilter $ost)
151 if [ -z "$dev" ]; then
152 echo "Cannot find device for $ost on $host"
159 # do cleanup for network case.
161 local clean_srv_OSS=$1
164 --device echotmp cleanup
165 --device echotmp detach
167 remote_shell "root@$server_nid" \
169 --device echo_srv cleanup
170 --device echo_srv detach
172 if [ $clean_srv_OSS ]; then
173 remote_shell "root@$server_nid" \
181 # do cleanup and exit.
190 for ((i = 0; i < $ndevs; i++)); do
191 host=${host_names[$i]}
192 if [[ -n "${do_teardown_ec[$i]}" ]]; then
193 teardown_ec_devno $host ${client_names[$i]}
197 for ((i = 0; i < ${#unique_hosts[@]}; i++)); do
198 host=${unique_hosts[$i]}
199 remote_shell $host "killall -q vmstat >/dev/null 2>&1" &
201 kill -term ${vmstatpids[$pidcount]} 2>/dev/null
202 kill -kill ${vmstatpids[$pidcount]} 2>/dev/null
204 pidcount=$((pidcount + 1))
205 if ((${do_unload_echo[$i]})); then
209 if [ $case == "network" ]; then
212 if [ $exit_status ]; then
213 if [ $exit_status -ne 0 ]; then
214 echo "program exited with error "
223 trap 'cleanup 0 $clean_srv_OSS' EXIT SIGHUP SIGINT SIGTERM
225 # gets echoclient device number and attach it to the client UUID
226 # Results are returned by an echo followed by an exit
227 # This must run in a subshell.
229 # parameter: 1. hostname
230 # 2. client name, ex:- ns8:ECHO_ns8
231 # 3. name of ost instances, ex:- lustre-OST0001
235 local client_name="$2"
237 local dev_type="${4:-obdfilter}"
238 local stack_type="${5:-}"
240 if [ -z "$client_name" ]; then
241 if [ -z "$ost_name" ]; then
242 echo "client and ost name both null"
245 client_name=${ost_name}_ecc
247 ec=$(get_devno $host echo_client $client_name)
248 if [ -n "$ec" ]; then
249 echo $ec $client_name $client_name >&8
252 if [ -z "$ost_name" ]; then
253 echo "no echo client and ost_name not set, client:" \
254 "$client_name, host: $host"
257 ost=$(get_devno $host $dev_type $ost_name)
258 if [ -z "$ost" ]; then
259 echo "OST $ost_name not setup"
262 client_name=${ost_name}_ecc
263 # Only 'attach' if '{client_name}_uuid' not already present
264 if ! [[ $($LCTL dl) =~ $client_name ]]; then
267 attach echo_client $client_name \
269 setup $ost_name $stack_type
272 ec=$(get_devno $host echo_client $client_name)
273 if [ -z "$ec" ]; then
274 echo "Can't setup echo-client"
277 echo $ec $client_name 1 >&8
281 # create echo client using server nid.
282 ec_using_srv_nid () {
287 $LCTL add_uuid echo_UUID $server_nid@$NETTYPE >/dev/null 2>&1
289 attach osc $oscname $oscuuid
290 --device $oscname setup echo_srv_UUID echo_UUID
293 attach echo_client ${oscname}_ecc $oscuuid
294 --device ${oscname}_ecc setup $oscname
298 # setup obdecho on server
301 local test_ostfsnm=$2
303 remote_shell "root@$server_nid" \
305 attach obdecho $test_ostfsnm ${test_ostfsnm}_UUID
306 --device $test_ostfsnm setup
310 # setup OSS on server
314 remote_shell "root@$server_nid" \
316 attach ost OSS OSS_UUID
321 # cleanup and detach the echo-clients that we have created during the test.
322 # parameter: 1. hostname
323 # 2. client name, ex:- ns8:ECHO_ns8
324 teardown_ec_devno () {
330 --device $client_name cleanup
331 --device $client_name detach
336 echo "$@" | xargs -n1 echo | sort -u
343 *:*) host=$(echo $name | sed 's/:.*$//')
344 name=$(echo $name | sed 's/[^:]*://')
354 local osc_names_str=$($LCTL dl | grep $type_obj)
357 for name in $osc_names_str; do
361 if [ $count != 0 ]; then
362 echo "$type_obj could not be cleanup";
370 local osc_names_str=$($LCTL dl | grep $type_obj)
373 for name in $osc_names_str; do
377 if [ $count == 0 ]; then
378 echo "$type_obj could not be setup";
384 # added from bugzill req.
386 if [ -z "$ost_names" ]; then
387 targets=$($LCTL device_list | awk "{if (\$2 == \"UP\" && \
388 \$3 == \"obdfilter\") {print \$4} }")
390 if [ -z "$targets" ]; then
391 echo "Can't find any OSTs to test. Please set targets=..."
396 for name in $targets; do
397 ost_names[$count]=$name
398 str=($(split_hostname $name))
399 host_names[$count]=${str[0]}
405 # split out hostnames from ost names
406 for ((i = 0; i < count; i++)); do
407 local str=($(split_hostname ${targets[$i]}))
408 host_list[$i]=${str[0]}
409 ost_names[$i]=${str[1]}