Whamcloud - gitweb
LU-6863 tests: change obdfilter-survey.sh for CLIENTONLY mode
[fs/lustre-release.git] / lustre-iokit / obdfilter-survey / obdfilter-survey
1 #!/bin/bash
2 set -e
3 ######################################################################
4 # customize per survey
5
6 # specify obd instances to exercise
7 # these can be either...
8 # obdfilter instances (set 'ost_names')
9 # ...or...
10 # echo_client instances (set 'client_names')
11 # ... use 'host:name' for obd instances on other nodes.
12 # allow these to be passed in via string...
13 # OR
14 # one can specify only case=disk or case=network or case=netdisk through
15 # command line.
16
17 # Prerequisite: For "disk" case and "netdisk" case you need to have lustre setup
18 #             with one or more ost's. For "network" case  you need to have all
19 #             modules (those llmount.sh loades) loaded in kernel. And the
20 #             'lctl dl' output must be blank.
21
22 # How to run test:
23 # case 1 (local disk):
24 #   $ nobjhi=2 thrhi=2 size=1024 case=disk sh obdfilter-survey
25 #   one can also run test with user defined targets as follows,
26 #   $ nobjhi=2 thrhi=2 size=1024 targets="lustre-OST0000 lustre-OST0001 ..." sh obdfilter-survey
27 # case 2 (network):
28 #   $ nobjhi=2 thrhi=2 size=1024 targets="<name/ip_of_server>" case=network sh obdfilter-survey
29 #   where, targets is name or ip address of system, which you want to
30 #   set as server.
31 # case 3 (network and disk):
32 #   $ nobjhi=2 thrhi=2 size=1024 case=netdisk sh obdfilter-survey
33 #   one can also run test with user defined targets as follows,
34 #   $ nobjhi=2 thrhi=2 size=1024 targets="<osc_name> ..." sh obdfilter-survey
35 #[ NOTE: It is advised to have automated login (passwordless entry) between server and
36 #  client systems on which this test runs.]
37
38 # include library
39 source $(dirname $0)/iokit-libecho
40
41 # The following variables can be set in the environment, or on the
42 # command line
43 # result file prefix (date/time + hostname makes unique)
44 # NB ensure path to it exists
45 rslt_loc=${rslt_loc:-"/tmp"}
46 rslt=${rslt:-"$rslt_loc/obdfilter_survey_$(date +%F@%R)_$(uname -n)"}
47
48 # Set this true to check file contents
49 verify=${verify:-0}
50
51 # test targets
52 targets=${targets:-""}
53 # test case
54 case=${case:-"disk"}
55
56 # total size (MBytes) per obd instance
57 # large enough to avoid cache effects
58 # and to make test startup/shutdown overhead insignificant
59 size=${size:-16384}
60
61 # record size (KBytes) ( 7168 max)
62 rszlo=${rszlo:-1024}
63 rszhi=${rszhi:-1024}
64 rszmax=${rszmax:-4096}
65
66 # number of objects per OST
67 nobjlo=${nobjlo:-1}
68 #was nobjhi=${nobjhi:-512}
69 nobjhi=${nobjhi:-16}
70
71 # threads per OST (1024 max)
72 thrlo=${thrlo:-1}
73 thrhi=${thrhi:-16}
74
75 export LC_ALL=POSIX
76
77 # End of variables
78
79 # create a set of objects, check there are 'n' contiguous ones and
80 # echo out the first or 'ERROR'
81 # parameter: 1. hostname
82 #            2. device number
83 #            3. number of object to be created (specified by user)
84 #            4. tempfile name
85 create_objects () {
86         local host=$1
87         local devno=$2
88         local nobj=$3
89         local rfile=$4
90
91         remote_shell $host $lctl --device $devno create $nobj > $rfile 2>&1
92         first=0
93         prev=0
94         count=0
95         error=0
96
97         # Count number of objects (lines containing " is object id "), and
98         # ensure that the objects numbers are sequential.
99         #
100         exec 3< $rfile
101         while read -u3 line; do
102                 case "$line" in
103                 ( *' is object id '* )
104                 set -- $line
105                 if test $(( count += 1 )) -gt 1 ; then
106                         (( $6 != prev + 1 )) && error=1
107                 else
108                         first=$(( $6 + 0 ))
109                 fi
110                 prev=$6
111                 ;;
112                 esac
113         done
114         exec 3<&-
115
116         if [ $nobj -ne $count ]; then
117                 echo "ERROR: $nobj != $count" >&2
118                 cat $rfile >&2
119                 echo "ERROR"
120         elif [ $error -ne 0 ]; then
121                 echo "ERROR: non contiguous objs found" >&2
122                 echo ERROR
123         else
124                 echo $first
125         fi
126         return $error
127 }
128
129 # destroys all objects created in create_objects routine
130 # parameter: 3. start obj id.
131 destroy_objects () {
132         local host=$1
133         local devno=$2
134         local obj0=$3
135         local nobj=$4
136         local rfile=$5
137
138         remote_shell $host $lctl --device $devno destroy $obj0 $nobj > $rfile 2>&1
139 }
140
141 get_stats () {
142         local rfile=$1
143
144         gawk < $rfile                                                   \
145         '/^Selected device [0-9]+$/ {                                   \
146                 n = 0;                                                  \
147                 next;                                                   \
148         }                                                               \
149         /error/ {                                                       \
150                 n = -1;                                                 \
151                 exit;                                                   \
152         }                                                               \
153         /^Total/ {                                                      \
154                 next;                                                   \
155         }                                                               \
156         /^[0-9]+\/[0-9]+ Total: [0-9]+\.[0-9]+\/second$/ {              \
157                 n++;                                                    \
158                 v=strtonum($3);                                         \
159                 if (n == 1 || v < min)                                  \
160                         min = v;                                        \
161                 if (n == 1 || v > max)                                  \
162                         max = v;                                        \
163                 next;                                                   \
164         }                                                               \
165         {                                                               \
166                 if (n != 0) {                                           \
167                         n = -1;                                         \
168                         exit;                                           \
169                 }                                                       \
170         }                                                               \
171         END {                                                           \
172                 printf "%d %f %f\n", n, min, max                        \
173         }'
174 }
175
176 get_global_stats () {
177         local rfile=$1
178
179         awk < $rfile                                                    \
180         'BEGIN {                                                        \
181                 n = 0;                                                  \
182         }                                                               \
183         {                                                               \
184                 n++;                                                    \
185                 if (n == 1) {                                           \
186                         err = $1;                                       \
187                         min = $2;                                       \
188                         max = $3;                                       \
189                 } else {                                                \
190                         if ($1 < err)                                   \
191                                 err = $1;                               \
192                         if ($2 < min)                                   \
193                                 min = $2;                               \
194                         if ($3 > max)                                   \
195                                 max = $3;                               \
196                 }                                                       \
197         }                                                               \
198         END {                                                           \
199                 if (n == 0)                                             \
200                         err = 0;                                        \
201                 printf "%d %f %f\n", err, min, max                      \
202         }'
203 }
204
205 # enable or disable data check.
206 # parameter: 1. read/write
207 testname2type () {
208         # 'x' disables data check
209         if ((verify)); then
210                 x=""
211         else
212                 x="x"
213         fi
214         case $1 in
215         *write*)  echo "w$x";;
216         *)        echo "r$x";;
217         esac
218 }
219
220 # for "echo_client + obdfilter" case, "prep + commit" mode should be used
221 # for "echo_client + osc" case, "BRW" mode should be used
222 testcase2mode() {
223         case $case in
224         disk)   echo "p";;
225         *)      echo "g";;
226         esac
227 }
228
229 print_summary () {
230         if [ "$1" = "-n" ]; then
231                 minusn=$1; shift
232         else
233                 minusn=""
234         fi
235         echo $minusn "$*" >> $rsltf
236         echo $minusn "$*"
237 }
238
239 # Return a numeric version code based on a version string.  The version
240 # code is useful for comparison two version strings to see which is newer.
241 version_code() {
242         # split arguments like "2.3.61" into "2", "3", "61"
243         eval set -- $(tr "[:punct:]" " " <<< $*)
244         echo -n "$((($1 << 16) | ($2 << 8) | $3))"
245 }
246
247 # inspired from the lustre_build_version routine in test-framework.sh
248 get_lustre_version() {
249         local host=${1:-${unique_hosts[0]}}
250         local ver
251
252         ver=$(remote_shell $host "$lctl get_param -n version 2>/dev/null ||
253                                 $lctl lustre_build_version 2>/dev/null ||
254                                 $lctl --version 2>/dev/null | cut -d' ' -f2")
255         local lver=$(egrep -i "lustre: |version: " <<<$ver | head -n 1)
256         [ -n "$lver" ] && ver="$lver"
257
258         sed -e 's/.*: //' -e 's/^v//' -e 's/-.*//' -e 's/_/./g' <<<$ver |
259                 cut -d. -f1-4
260 }
261
262 # Check whether the record size (KBytes) exceeds the maximum bulk I/O RPC size
263 # or not.
264 check_record_size() {
265         [ $(version_code $(get_lustre_version)) -lt $(version_code 2.3.61) ] &&
266                 rszmax=1024
267
268         if [ "$rszhi" -gt "$rszmax" ]; then
269                 echo "Test disk case support maximum ${rszmax}KB IO data" \
270                      "(rszhi=$rszhi is too big), please use a smaller value."
271                 return 1
272         fi
273         return 0
274 }
275
276 # Customisation variables
277 #####################################################################
278 # One can change variable values in this section as per requirements
279
280 if [ -n "$targets" ]; then
281         declare -a ost_names
282         declare -a client_names
283         count=0
284         for name in $targets; do
285                 if [ $case == "disk" ]; then
286                 ost_names[$count]=$name
287                 else
288                 client_names[$count]=$name
289                 fi
290                 count=$((count + 1))
291         done
292 fi
293
294 # what tests to run (first must be write)
295 tests_str=${tests_str:-""}
296 if [ -n "$tests_str" ]; then
297         declare -a tests
298         count=0
299         for name in $tests_str; do
300                 tests[$count]=$name
301                 count=$((count + 1))
302         done
303 else
304         #tests=(write rewrite read reread rewrite_again)
305         tests=(write rewrite read)
306 fi
307
308 # restart from here iff all are defined
309 restart_rsz=
310 restart_thr=1
311 restart_nobj=1
312
313 # machine's page size (KB)
314 PAGE_SIZE=${PAGE_SIZE:-$(($(getconf PAGE_SIZE) / 1024))}
315 PAGE_SIZE=${PAGE_SIZE:-4}
316
317 snap=1
318 clean_srv_OSS=0
319 # Customisation variables ends here.
320 #####################################################################
321 # leave the rest of this alone unless you know what you're doing...
322
323 # check and insert obdecho module
324 if ! lsmod | grep obdecho > /dev/null; then
325         modprobe obdecho
326 fi
327 if [ ${#tests[@]} -eq 0 -o "${tests[0]}" != "write" ]; then
328         echo "tests: ${tests[@]}"
329         echo "First test must be 'write'" 1>&2
330         exit 1
331 fi
332
333 rsltf="${rslt}.summary"
334 workf="${rslt}.detail"
335 cmdsf="${rslt}.script"
336 vmstatf="${rslt}.vmstat"
337 echo -n > $rsltf
338 echo -n > $workf
339
340 # hide a little trick to unset this from the command line
341 if [ "$lustre_root" == " " ]; then
342         unset lustre_root
343 fi
344
345 if [ -z "$lustre_root" ]; then
346         lctl=lctl
347 else
348         lctl=${lustre_root}/utils/lctl
349 fi
350
351 # split out hostnames from client/ost names
352 ndevs=0
353 for trgt in $targets; do
354         str=($(split_hostname $trgt))
355         host_names[$ndevs]=${str[0]}
356         client_names[$ndevs]=${str[1]}
357         ndevs=$((ndevs + 1))
358 done
359 if [ $case == "disk" ]; then
360         for ((i = 0; i < $ndevs; i++)); do
361                 ost_names[$i]=${client_names[$i]}
362         done
363 fi
364 if [ $case == "netdisk" ]; then
365         if [ "$targets" ]; then
366                 for ((i = 0; i < $ndevs; i++)); do
367                         setup_osc_for_remote_ost ${host_names[$i]} \
368                                                  ${client_names[$i]} $i
369                         osc_name=${client_names[$i]}_osc
370                         ec_using_osc $osc_name
371                         cleanup_oscs="$cleanup_oscs $osc_name"
372                 done
373         else
374                 client_names_str=$($lctl dl | grep -v mdt |
375                         awk '{if ($2 == "UP" && $3 == "osc") {print $4} }')
376                 count=0;
377                 for name in $client_names_str; do
378                         client_names[$count]=$(echo $name | sed 's/-osc-.*$//')
379                         count=$((count + 1))
380                 done
381
382                 host_names_str=$($lctl dl -t | grep -v mdt |
383                         awk '{if ($2 == "UP" && $3 == "osc") {print $7} }')
384                 count=0;
385                 for name in $host_names_str; do
386                         host_names[$count]=$(echo $name | sed 's/@.*$//')
387                         count=$((count + 1))
388                 done
389
390                 for (( i = 0; i < $count; i++ )) do
391                         setup_osc_for_remote_ost ${host_names[$i]} \
392                                                  ${client_names[$i]} $i
393                         osc_name=${client_names[$i]}_osc
394                         ec_using_osc $osc_name
395                         cleanup_oscs="$cleanup_oscs $osc_name"
396                 done
397         fi
398
399         echo_clients=$($lctl dl | grep echo_client |
400                        awk "{if (\$2 == \"UP\" && \$3 == \"echo_client\") { \
401                                 print \$4} }")
402         cnt=0;
403         for name in $echo_clients; do
404                 client_names[$cnt]=$name
405                 host_names[$cnt]=localhost
406                 cnt=$((cnt + 1))
407         done
408         ndevs=${#client_names[@]}
409 fi
410 if [ $case == "network" ]; then
411         server_nid=$targets
412         if [ -z "$server_nid" ]; then
413                 echo "Specify hostname or ip-address of server"
414                 exit 1;
415         fi
416         # check for obdecho module on server
417         if ! dsh $server_nid root "lsmod | grep obdecho > /dev/null"; then
418                 dsh $server_nid root "modprobe obdecho"
419         fi
420         # Now do the server setup
421         setup_srv_obd $server_nid "echo_srv"
422         oss_on_srv=$(dsh $server_nid root "$lctl dl | grep OSS" |
423                      awk '{ print $4 }')
424         if [ -z $oss_on_srv ]; then
425                 setup_OSS $server_nid
426                 clean_srv_OSS=1
427         fi
428         if ! dsh $server_nid root "$lctl dl | grep obdecho > /dev/null 2>&1"; then
429                 echo "obdecho not setup on server"
430                 exit 1
431         fi
432         if ! dsh $server_nid root "$lctl dl | grep ost > /dev/null 2>&1"; then
433                 echo "ost not setup on server"
434                 exit 1
435         fi
436         # Now start client setup
437         osc_names_str=$($lctl dl| grep osc | grep -v mdt | grep UP)
438         if [ -n "$osc_names_str" ]; then
439                 echo "The existing setup must be cleaned";
440                 exit 0;
441         fi
442         ec_using_srv_nid $server_nid "echotmp" "echotmp_UUID"
443         client_names[0]="echotmp_ecc"
444 fi
445 if [ -z "$targets" ]; then
446         if [ $case == "disk" ]; then
447                 get_targets
448                 ndevs=${#ost_names[@]}
449         fi
450 fi
451 # get vmstat started
452 # disable portals debug and get obdecho loaded on all relevant hosts
453 unique_hosts=($(unique ${host_names[@]}))
454 load_obdechos
455
456 if [ $case == "disk" ]; then
457         check_record_size || cleanup ${PIPESTATUS[0]}
458 fi
459
460 pidcount=0
461 for host in ${unique_hosts[@]}; do
462         host_vmstatf=${vmstatf}_${host}
463         echo -n > $host_vmstatf
464         remote_shell $host "vmstat 5 >> $host_vmstatf" &> /dev/null &
465         pid=$!
466         vmstatpids[$pidcount]=$pid
467         pidcount=$((pidcount + 1))
468 done
469 # get all the echo_client device numbers and names
470 for ((i=0; i < $ndevs; i++)); do
471         host=${host_names[$i]}
472         devno=($(get_ec_devno $host "${client_names[$i]}" "${ost_names[$i]}"))
473         if ((${#devno[@]} != 3)); then
474                 exit 1
475         fi
476         devnos[$i]=${devno[0]}
477         client_names[$i]=${devno[1]}
478         do_teardown_ec[$i]=${devno[2]}
479 done
480 if (($ndevs <= 0 || ${#host_names[@]} <= 0)); then
481         echo "no devices or hosts specified"
482         cleanup 0 $clean_srv_OSS $cleanup_oscs
483 fi
484
485 print_summary "$(date) Obdfilter-survey for case=$case from $(hostname)"
486 for ((rsz = $rszlo; rsz <= $rszhi; rsz*=2)); do
487         for ((nobj = $nobjlo; nobj <= $nobjhi; nobj*=2)); do
488                 for ((thr = $thrlo; thr <= $thrhi; thr*=2)); do
489                         if ((thr % nobj)); then
490                                 continue
491                         fi
492                         # restart?
493                         if [ -n "$restart_rsz" -a \
494                              -n "$restart_nobj" -a \
495                              -n "$restart_thr" ]; then
496                                 if ((rsz < restart_rsz ||
497                                      (rsz == restart_rsz &&
498                                       (nobj < restart_nobj ||
499                                        (nobj == restart_nobj &&
500                                         thr < restart_thr))))); then
501                                         continue;
502                                 fi
503                         fi
504
505                         # compute parameters
506                         total_thr=$((ndevs * thr))
507                         total_nobj=$((ndevs * nobj))
508                         pages=$((rsz / PAGE_SIZE))
509                         actual_rsz=$((pages * PAGE_SIZE))
510                         count=$((size * 1024 / (actual_rsz * thr)))
511                         actual_size=$((actual_rsz * count * thr))
512                         total_size=$((actual_size * ndevs))
513
514                         # show computed parameters
515                         str=$(printf 'ost %2d sz %8dK rsz %4dK obj %4d thr %4d ' \
516                               $ndevs $total_size $actual_rsz $total_nobj $total_thr)
517                         echo "=======================> $str" >> $workf
518                         print_summary -n "$str"
519
520                         # create the objects
521                         tmpf="${workf}_tmp"
522                         for ((idx = 0; idx < $ndevs; idx++)); do
523                                 host=${host_names[$idx]}
524                                 devno=${devnos[$idx]}
525                                 client_name="${host}:${client_names[$idx]}"
526                                 echo "=============> Create $nobj on $client_name" >> $workf
527                                 first_obj=$(create_objects $host $devno $nobj $tmpf)
528                                 cat $tmpf >> $workf
529                                 rm $tmpf
530                                 if [ $first_obj = "ERROR" ]; then
531                                         print_summary "created object #s on $client_name not contiguous"
532                                         exit 1
533                                 fi
534                                 first_objs[$idx]=$first_obj
535                         done # $ndevs
536
537                         # run tests
538                         for test in ${tests[@]}; do
539                                 declare -a pidarray
540                                 for host in ${unique_hosts[@]}; do
541                                         remote_shell $host \
542                                             "lctl set_param -n osd*.*OST*.force_sync 1"
543                                         echo "starting run for test: $test rsz: $rsz " \
544                                         "threads: $thr objects: $nobj" >> ${vmstatf}_${host}
545                                 done
546                                 print_summary -n "$test "
547
548                                 # create per-host script files
549                                 for host in ${unique_hosts[@]}; do
550                                         echo -n > ${cmdsf}_${host}
551                                 done
552                                 for ((idx = 0; idx < $ndevs; idx++)); do
553                                         host=${host_names[$idx]}
554                                         devno=${devnos[$idx]}
555                                         tmpfi="${tmpf}_$idx"
556                                         first_obj=${first_objs[$idx]}
557                                         thr_per_obj=$((${thr}/${nobj}))
558                                         echo >> ${cmdsf}_${host} \
559                                         "$lctl > $tmpfi 2>&1 \\
560                                         --threads $thr -$snap $devno \\
561                                         test_brw $count $(testname2type $test) q $pages \\
562                                         ${thr_per_obj}t${first_obj} $(testcase2mode)$pages &"
563                                 done # $ndevs
564                                 pidcount=0
565                                 for host in ${unique_hosts[@]}; do
566                                         echo "wait" >> ${cmdsf}_${host}
567                                         pidarray[$pidcount]=0
568                                         pidcount=$((pidcount + 1))
569                                 done
570                                 # timed run of all the per-host script files
571                                 t0=$(date +%s.%N)
572                                 pidcount=0
573                                 for host in ${unique_hosts[@]}; do
574                                         remote_shell $host bash < ${cmdsf}_${host} &
575                                         pidarray[$pidcount]=$!
576                                         pidcount=$((pidcount + 1))
577                                 done
578                                 pidcount=0
579                                 for host in ${unique_hosts[@]}; do
580                                         wait ${pidarray[$pidcount]}
581                                         pidcount=$((pidcount + 1))
582                                 done
583                                 #wait
584                                 t1=$(date +%s.%N)
585                                 # clean up per-host script files
586                                 for host in ${unique_hosts[@]}; do
587                                         rm ${cmdsf}_${host}
588                                 done
589
590                                 # compute bandwidth from total data / elapsed time
591                                 str=$(awk "BEGIN {printf \"%7.2f \",\
592                                 $total_size / (( $t1 - $t0 ) * 1024)}")
593                                 print_summary -n "$str"
594                                 # collect/check individual OST stats
595                                 echo -n > $tmpf
596                                 for ((idx = 0; idx < $ndevs; idx++)); do
597                                         client_name="${host_names[$idx]}:${client_names[$idx]}"
598                                         tmpfi="${tmpf}_$idx"
599                                         echo "=============> $test $client_name" >> $workf
600                                         host="${host_names[$idx]}"
601                                         remote_shell $host cat $tmpfi > ${tmpfi}_local
602                                         cat ${tmpfi}_local >> $workf
603                                         get_stats ${tmpfi}_local >> $tmpf
604                                         rm -f $tmpfi ${tmpfi}_local
605                                 done # $ndevs
606
607                                 # compute/display global min/max stats
608                                 echo "=============> $test global" >> $workf
609                                 cat $tmpf >> $workf
610                                 stats=($(get_global_stats $tmpf))
611                                 rm $tmpf
612                                 if ((stats[0] <= 0)); then
613                                         if ((stats[0] < 0)); then
614                                                 str=$(printf "%17s " ERROR)
615                                         else
616                                                 str=$(printf "%17s " SHORT)
617                                         fi
618                                 else
619                                         str=$(awk "BEGIN {printf \"[%7.2f, %7.2f] \",\
620                                         (${stats[1]} * $actual_rsz)/1024,\
621                                         (${stats[2]} * $actual_rsz)/1024; exit}")
622                                 fi
623                                 print_summary -n "$str"
624                         done # $tests[]
625                         print_summary ""
626
627                         # destroy objects we created
628                         for ((idx = 0; idx < $ndevs; idx++)); do
629                                 host=${host_names[$idx]}
630                                 devno=${devnos[$idx]}
631                                 client_name="${host}:${client_names[$idx]}"
632                                 first_obj=${first_objs[$idx]}
633                                 echo "=============> Destroy $nobj on $client_name" >> $workf
634                                 destroy_objects $host $devno $first_obj $nobj $tmpf
635                                 cat $tmpf >> $workf
636                                 rm $tmpf
637                         done # $ndevs
638                 done # $thr
639         done # $nobj
640 done # $rsz
641 cleanup 0 $clean_srv_OSS $cleanup_oscs
642 exit 0