Whamcloud - gitweb
Revert "LU-8383 build: Spec file cleanup after LU-5614"
[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 # Perquisite: 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 version_code() {
240         # split arguments like "2.3.61" into "2", "3", "61"
241         eval set -- $(tr "[:punct:]" " " <<< $*)
242         echo -n "$((($1 << 16) | ($2 << 8) | $3))"
243 }
244
245 get_lustre_version() {
246         local host=${1:-${unique_hosts[0]}}
247         remote_shell $host $lctl get_param -n version |
248                 awk '/^lustre:/ {print $2}'
249 }
250
251 # Check whether the record size (KBytes) exceeds the maximum bulk I/O RPC size
252 # or not.
253 check_record_size() {
254         [ $(version_code $(get_lustre_version)) -lt $(version_code 2.3.61) ] &&
255                 rszmax=1024
256
257         if [ "$rszhi" -gt "$rszmax" ]; then
258                 echo "Test disk case support maximum ${rszmax}KB IO data" \
259                      "(rszhi=$rszhi is too big), please use a smaller value."
260                 return 1
261         fi
262         return 0
263 }
264
265 # Customisation variables
266 #####################################################################
267 # One can change variable values in this section as per requirements
268
269 if [ -n "$targets" ]; then
270         declare -a ost_names
271         declare -a client_names
272         count=0
273         for name in $targets; do
274                 if [ $case == "disk" ]; then
275                 ost_names[$count]=$name
276                 else
277                 client_names[$count]=$name
278                 fi
279                 count=$((count + 1))
280         done
281 fi
282
283 # what tests to run (first must be write)
284 tests_str=${tests_str:-""}
285 if [ -n "$tests_str" ]; then
286         declare -a tests
287         count=0
288         for name in $tests_str; do
289                 tests[$count]=$name
290                 count=$((count + 1))
291         done
292 else
293         #tests=(write rewrite read reread rewrite_again)
294         tests=(write rewrite read)
295 fi
296
297 # restart from here iff all are defined
298 restart_rsz=
299 restart_thr=1
300 restart_nobj=1
301
302 # machine's page size (KB)
303 PAGE_SIZE=${PAGE_SIZE:-$(($(getconf PAGE_SIZE) / 1024))}
304 PAGE_SIZE=${PAGE_SIZE:-4}
305
306 snap=1
307 clean_srv_OSS=0
308 # Customisation variables ends here.
309 #####################################################################
310 # leave the rest of this alone unless you know what you're doing...
311
312 # check and insert obdecho module
313 if ! lsmod | grep obdecho > /dev/null; then
314         modprobe obdecho
315 fi
316 if [ ${#tests[@]} -eq 0 -o "${tests[0]}" != "write" ]; then
317         echo "tests: ${tests[@]}"
318         echo "First test must be 'write'" 1>&2
319         exit 1
320 fi
321
322 rsltf="${rslt}.summary"
323 workf="${rslt}.detail"
324 cmdsf="${rslt}.script"
325 vmstatf="${rslt}.vmstat"
326 echo -n > $rsltf
327 echo -n > $workf
328
329 # hide a little trick to unset this from the command line
330 if [ "$lustre_root" == " " ]; then
331         unset lustre_root
332 fi
333
334 if [ -z "$lustre_root" ]; then
335         lctl=lctl
336 else
337         lctl=${lustre_root}/utils/lctl
338 fi
339
340 # split out hostnames from client/ost names
341 ndevs=0
342 for trgt in $targets; do
343         str=($(split_hostname $trgt))
344         host_names[$ndevs]=${str[0]}
345         client_names[$ndevs]=${str[1]}
346         ndevs=$((ndevs + 1))
347 done
348 if [ $case == "disk" ]; then
349         for ((i = 0; i < $ndevs; i++)); do
350                 ost_names[$i]=${client_names[$i]}
351         done
352 fi
353 if [ $case == "netdisk" ]; then
354         if [ "$targets" ]; then
355                 for ((i = 0; i < $ndevs; i++)); do
356                         setup_osc_for_remote_ost ${host_names[$i]} \
357                                                  ${client_names[$i]} $i
358                         osc_name=${client_names[$i]}_osc
359                         ec_using_osc $osc_name
360                         cleanup_oscs="$cleanup_oscs $osc_name"
361                 done
362         else
363                 client_names_str=$($lctl dl | grep -v mdt |
364                         awk '{if ($2 == "UP" && $3 == "osc") {print $4} }')
365                 count=0;
366                 for name in $client_names_str; do
367                         client_names[$count]=$(echo $name | sed 's/-osc-.*$//')
368                         count=$((count + 1))
369                 done
370
371                 host_names_str=$($lctl dl -t | grep -v mdt |
372                         awk '{if ($2 == "UP" && $3 == "osc") {print $7} }')
373                 count=0;
374                 for name in $host_names_str; do
375                         host_names[$count]=$(echo $name | sed 's/@.*$//')
376                         count=$((count + 1))
377                 done
378
379                 for (( i = 0; i < $count; i++ )) do
380                         setup_osc_for_remote_ost ${host_names[$i]} \
381                                                  ${client_names[$i]} $i
382                         osc_name=${client_names[$i]}_osc
383                         ec_using_osc $osc_name
384                         cleanup_oscs="$cleanup_oscs $osc_name"
385                 done
386         fi
387
388         echo_clients=$($lctl dl | grep echo_client |
389                        awk "{if (\$2 == \"UP\" && \$3 == \"echo_client\") { \
390                                 print \$4} }")
391         cnt=0;
392         for name in $echo_clients; do
393                 client_names[$cnt]=$name
394                 host_names[$cnt]=localhost
395                 cnt=$((cnt + 1))
396         done
397         ndevs=${#client_names[@]}
398 fi
399 if [ $case == "network" ]; then
400         server_nid=$targets
401         if [ -z "$server_nid" ]; then
402                 echo "Specify hostname or ip-address of server"
403                 exit 1;
404         fi
405         # check for obdecho module on server
406         if ! dsh $server_nid root "lsmod | grep obdecho > /dev/null"; then
407                 dsh $server_nid root "modprobe obdecho"
408         fi
409         # Now do the server setup
410         setup_srv_obd $server_nid "echo_srv"
411         oss_on_srv=$(dsh $server_nid root "$lctl dl | grep OSS" |
412                      awk '{ print $4 }')
413         if [ -z $oss_on_srv ]; then
414                 setup_OSS $server_nid
415                 clean_srv_OSS=1
416         fi
417         if ! dsh $server_nid root "$lctl dl | grep obdecho > /dev/null 2>&1"; then
418                 echo "obdecho not setup on server"
419                 exit 1
420         fi
421         if ! dsh $server_nid root "$lctl dl | grep ost > /dev/null 2>&1"; then
422                 echo "ost not setup on server"
423                 exit 1
424         fi
425         # Now start client setup
426         osc_names_str=$($lctl dl| grep osc | grep -v mdt | grep UP)
427         if [ -n "$osc_names_str" ]; then
428                 echo "The existing setup must be cleaned";
429                 exit 0;
430         fi
431         ec_using_srv_nid $server_nid "echotmp" "echotmp_UUID"
432         client_names[0]="echotmp_ecc"
433 fi
434 if [ -z "$targets" ]; then
435         if [ $case == "disk" ]; then
436                 get_targets
437                 ndevs=${#ost_names[@]}
438         fi
439 fi
440 # get vmstat started
441 # disable portals debug and get obdecho loaded on all relevant hosts
442 unique_hosts=($(unique ${host_names[@]}))
443 load_obdechos
444
445 if [ $case == "disk" ]; then
446         check_record_size || cleanup ${PIPESTATUS[0]}
447 fi
448
449 pidcount=0
450 for host in ${unique_hosts[@]}; do
451         host_vmstatf=${vmstatf}_${host}
452         echo -n > $host_vmstatf
453         remote_shell $host "vmstat 5 >> $host_vmstatf" &> /dev/null &
454         pid=$!
455         vmstatpids[$pidcount]=$pid
456         pidcount=$((pidcount + 1))
457 done
458 # get all the echo_client device numbers and names
459 for ((i=0; i < $ndevs; i++)); do
460         host=${host_names[$i]}
461         devno=($(get_ec_devno $host "${client_names[$i]}" "${ost_names[$i]}"))
462         if ((${#devno[@]} != 3)); then
463                 exit 1
464         fi
465         devnos[$i]=${devno[0]}
466         client_names[$i]=${devno[1]}
467         do_teardown_ec[$i]=${devno[2]}
468 done
469 if (($ndevs <= 0 || ${#host_names[@]} <= 0)); then
470         echo "no devices or hosts specified"
471         cleanup 0 $clean_srv_OSS $cleanup_oscs
472 fi
473
474 print_summary "$(date) Obdfilter-survey for case=$case from $(hostname)"
475 for ((rsz = $rszlo; rsz <= $rszhi; rsz*=2)); do
476         for ((nobj = $nobjlo; nobj <= $nobjhi; nobj*=2)); do
477                 for ((thr = $thrlo; thr <= $thrhi; thr*=2)); do
478                         if ((thr % nobj)); then
479                                 continue
480                         fi
481                         # restart?
482                         if [ -n "$restart_rsz" -a \
483                              -n "$restart_nobj" -a \
484                              -n "$restart_thr" ]; then
485                                 if ((rsz < restart_rsz ||
486                                      (rsz == restart_rsz &&
487                                       (nobj < restart_nobj ||
488                                        (nobj == restart_nobj &&
489                                         thr < restart_thr))))); then
490                                         continue;
491                                 fi
492                         fi
493
494                         # compute parameters
495                         total_thr=$((ndevs * thr))
496                         total_nobj=$((ndevs * nobj))
497                         pages=$((rsz / PAGE_SIZE))
498                         actual_rsz=$((pages * PAGE_SIZE))
499                         count=$((size * 1024 / (actual_rsz * thr)))
500                         actual_size=$((actual_rsz * count * thr))
501                         total_size=$((actual_size * ndevs))
502
503                         # show computed parameters
504                         str=$(printf 'ost %2d sz %8dK rsz %4dK obj %4d thr %4d ' \
505                               $ndevs $total_size $actual_rsz $total_nobj $total_thr)
506                         echo "=======================> $str" >> $workf
507                         print_summary -n "$str"
508
509                         # create the objects
510                         tmpf="${workf}_tmp"
511                         for ((idx = 0; idx < $ndevs; idx++)); do
512                                 host=${host_names[$idx]}
513                                 devno=${devnos[$idx]}
514                                 client_name="${host}:${client_names[$idx]}"
515                                 echo "=============> Create $nobj on $client_name" >> $workf
516                                 first_obj=$(create_objects $host $devno $nobj $tmpf)
517                                 cat $tmpf >> $workf
518                                 rm $tmpf
519                                 if [ $first_obj = "ERROR" ]; then
520                                         print_summary "created object #s on $client_name not contiguous"
521                                         exit 1
522                                 fi
523                                 first_objs[$idx]=$first_obj
524                         done # $ndevs
525
526                         # run tests
527                         for test in ${tests[@]}; do
528                                 declare -a pidarray
529                                 for host in ${unique_hosts[@]}; do
530                                         remote_shell $host \
531                                             "lctl set_param -n osd*.*OST*.force_sync 1"
532                                         echo "starting run for test: $test rsz: $rsz " \
533                                         "threads: $thr objects: $nobj" >> ${vmstatf}_${host}
534                                 done
535                                 print_summary -n "$test "
536
537                                 # create per-host script files
538                                 for host in ${unique_hosts[@]}; do
539                                         echo -n > ${cmdsf}_${host}
540                                 done
541                                 for ((idx = 0; idx < $ndevs; idx++)); do
542                                         host=${host_names[$idx]}
543                                         devno=${devnos[$idx]}
544                                         tmpfi="${tmpf}_$idx"
545                                         first_obj=${first_objs[$idx]}
546                                         thr_per_obj=$((${thr}/${nobj}))
547                                         echo >> ${cmdsf}_${host} \
548                                         "$lctl > $tmpfi 2>&1 \\
549                                         --threads $thr -$snap $devno \\
550                                         test_brw $count $(testname2type $test) q $pages \\
551                                         ${thr_per_obj}t${first_obj} $(testcase2mode)$pages &"
552                                 done # $ndevs
553                                 pidcount=0
554                                 for host in ${unique_hosts[@]}; do
555                                         echo "wait" >> ${cmdsf}_${host}
556                                         pidarray[$pidcount]=0
557                                         pidcount=$((pidcount + 1))
558                                 done
559                                 # timed run of all the per-host script files
560                                 t0=$(date +%s.%N)
561                                 pidcount=0
562                                 for host in ${unique_hosts[@]}; do
563                                         remote_shell $host bash < ${cmdsf}_${host} &
564                                         pidarray[$pidcount]=$!
565                                         pidcount=$((pidcount + 1))
566                                 done
567                                 pidcount=0
568                                 for host in ${unique_hosts[@]}; do
569                                         wait ${pidarray[$pidcount]}
570                                         pidcount=$((pidcount + 1))
571                                 done
572                                 #wait
573                                 t1=$(date +%s.%N)
574                                 # clean up per-host script files
575                                 for host in ${unique_hosts[@]}; do
576                                         rm ${cmdsf}_${host}
577                                 done
578
579                                 # compute bandwidth from total data / elapsed time
580                                 str=$(awk "BEGIN {printf \"%7.2f \",\
581                                 $total_size / (( $t1 - $t0 ) * 1024)}")
582                                 print_summary -n "$str"
583                                 # collect/check individual OST stats
584                                 echo -n > $tmpf
585                                 for ((idx = 0; idx < $ndevs; idx++)); do
586                                         client_name="${host_names[$idx]}:${client_names[$idx]}"
587                                         tmpfi="${tmpf}_$idx"
588                                         echo "=============> $test $client_name" >> $workf
589                                         host="${host_names[$idx]}"
590                                         remote_shell $host cat $tmpfi > ${tmpfi}_local
591                                         cat ${tmpfi}_local >> $workf
592                                         get_stats ${tmpfi}_local >> $tmpf
593                                         rm -f $tmpfi ${tmpfi}_local
594                                 done # $ndevs
595
596                                 # compute/display global min/max stats
597                                 echo "=============> $test global" >> $workf
598                                 cat $tmpf >> $workf
599                                 stats=($(get_global_stats $tmpf))
600                                 rm $tmpf
601                                 if ((stats[0] <= 0)); then
602                                         if ((stats[0] < 0)); then
603                                                 str=$(printf "%17s " ERROR)
604                                         else
605                                                 str=$(printf "%17s " SHORT)
606                                         fi
607                                 else
608                                         str=$(awk "BEGIN {printf \"[%7.2f, %7.2f] \",\
609                                         (${stats[1]} * $actual_rsz)/1024,\
610                                         (${stats[2]} * $actual_rsz)/1024; exit}")
611                                 fi
612                                 print_summary -n "$str"
613                         done # $tests[]
614                         print_summary ""
615
616                         # destroy objects we created
617                         for ((idx = 0; idx < $ndevs; idx++)); do
618                                 host=${host_names[$idx]}
619                                 devno=${devnos[$idx]}
620                                 client_name="${host}:${client_names[$idx]}"
621                                 first_obj=${first_objs[$idx]}
622                                 echo "=============> Destroy $nobj on $client_name" >> $workf
623                                 destroy_objects $host $devno $first_obj $nobj $tmpf
624                                 cat $tmpf >> $workf
625                                 rm $tmpf
626                         done # $ndevs
627                 done # $thr
628         done # $nobj
629 done # $rsz
630 cleanup 0 $clean_srv_OSS $cleanup_oscs
631 exit 0