Whamcloud - gitweb
LU-2598 tests: check nr_local in ofd_preprw()
[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)/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     remote_shell $host $lctl --device $devno create $nobj > $rfile 2>&1
91     first=0
92     prev=0
93     count=0
94     error=0
95
96     # Count number of objects (lines containing " is object id "), and
97     # ensure that the objects numbers are sequential.
98     #
99     exec 3< $rfile
100     while read -u3 line; do
101         case "$line" in
102         ( *' is object id '* )
103             set -- $line
104             if test $(( count += 1 )) -gt 1 ; then
105                 (( $6 != prev + 1 )) && error=1
106             else
107                 first=$(( $6 + 0 ))
108             fi
109             prev=$6
110             ;;
111         esac
112     done
113     exec 3<&-
114
115     if [ $nobj -ne $count ]; then 
116         echo "ERROR: $nobj != $count" >&2 
117         cat $rfile >&2 
118         echo "ERROR" 
119     elif [ $error -ne 0 ]; then 
120         echo "ERROR: non contiguous objs found" >&2
121         echo ERROR
122     else 
123         echo $first 
124     fi
125     return $error
126 }
127
128 # destroys all objects created in create_objects routine
129 # parameter: 3. start obj id.
130 destroy_objects () {
131     local host=$1
132     local devno=$2
133     local obj0=$3
134     local nobj=$4
135     local rfile=$5
136     remote_shell $host $lctl --device $devno destroy $obj0 $nobj > $rfile 2>&1
137 }
138
139 get_stats () {
140     local rfile=$1
141     gawk < $rfile \
142         '/^Selected device [0-9]+$/ {n = 0; next}\
143         /error/ {n = -1; exit}\
144         /^Total/ {next}\
145         /^[0-9]+\/[0-9]+ Total: [0-9]+\.[0-9]+\/second$/ {n++; v=strtonum($3); \
146                                                           if (n == 1 || v < min) min = v;\
147                                                           if (n == 1 || v > max) max = v;\
148                                                           next}\
149         {if (n != 0) {n = -1; exit}}\
150         END {printf "%d %f %f\n", n, min, max}'
151 }
152
153 get_global_stats () {
154     local rfile=$1
155     awk < $rfile 'BEGIN {n = 0;}\
156                   {n++; if (n == 1) {err = $1; min = $2; max = $3} else\
157                                     {if ($1 < err) err = $1;\
158                                      if ($2 < min) min = $2;\
159                                      if ($3 > max) max = $3}}\
160                   END {if (n == 0) err = 0;\
161                        printf "%d %f %f\n", err, min, max}'
162 }
163
164 # enable or disable data check.
165 # parameter: 1. read/write
166 testname2type () {
167     # 'x' disables data check
168     if ((verify)); then
169         x=""
170     else
171         x="x"
172     fi
173     case $1 in
174         *write*)  echo "w$x";;
175         *)        echo "r$x";;
176     esac
177 }
178
179 # for "echo_client + obdfilter" case, "prep + commit" mode should be used
180 # for "echo_client + osc" case, "BRW" mode should be used
181 testcase2mode() {
182     case $case in
183     disk) echo "p$1";;
184     *)    echo "g";;
185     esac
186 }
187
188 print_summary () {
189     if [ "$1" = "-n" ]; then
190         minusn=$1; shift
191     else
192         minusn=""
193     fi
194     echo $minusn "$*" >> $rsltf
195     echo $minusn "$*"
196 }
197
198 version_code() {
199         # split arguments like "2.3.61" into "2", "3", "61"
200         eval set -- $(tr "[:punct:]" " " <<< $*)
201         echo -n "$((($1 << 16) | ($2 << 8) | $3))"
202 }
203
204 get_lustre_version() {
205         local host=${1:-${unique_hosts[0]}}
206         remote_shell $host $lctl get_param -n version |
207                 awk '/^lustre:/ {print $2}'
208 }
209
210 # Check whether the record size (KBytes) exceeds the maximum bulk I/O RPC size
211 # or not.
212 check_record_size() {
213         [ $(version_code $(get_lustre_version)) -lt $(version_code 2.3.61) ] &&
214                 rszmax=1024
215
216         if [ "$rszhi" -gt "$rszmax" ]; then
217                 echo "Test disk case support maximum ${rszmax}KB IO data" \
218                      "(rszhi=$rszhi is too big), please use a smaller value."
219                 return 1
220         fi
221         return 0
222 }
223
224 # Customisation variables
225 #####################################################################
226 # One can change variable values in this section as per requirements
227
228 if [ -n "$targets" ]; then
229     declare -a ost_names
230     declare -a client_names
231     count=0
232     for name in $targets; do
233         if [ $case == "disk" ]; then
234             ost_names[$count]=$name
235         else
236             client_names[$count]=$name
237         fi
238         count=$((count+1))
239     done
240 fi
241
242 # what tests to run (first must be write)
243 tests_str=${tests_str:-""}
244 if [ -n "$tests_str" ]; then
245     declare -a tests
246     count=0
247     for name in $tests_str; do
248         tests[$count]=$name
249         count=$((count+1))
250     done
251 else
252     #tests=(write rewrite read reread rewrite_again)
253     tests=(write rewrite read)
254 fi
255
256 # restart from here iff all are defined
257 restart_rsz=
258 restart_thr=1
259 restart_nobj=1
260
261 # machine's page size (K)
262 if [ -z "$PAGE_SIZE" ]; then
263     if which python >/dev/null; then
264         PAGE_SIZE=`echo 'import resource; print resource.getpagesize()/1024;' |python`
265     fi
266 fi
267 PAGE_SIZE=${PAGE_SIZE:-4}
268
269 # max buffer_mem (total_threads * buffer size)
270 # (to avoid lctl ENOMEM problems)
271 max_buffer_mem=$((1024 * 1024))
272 snap=1
273 clean_srv_OSS=0
274 # Customisation variables ends here. 
275 #####################################################################
276 # leave the rest of this alone unless you know what you're doing...
277
278 # check and insert obdecho module
279 if ! lsmod | grep obdecho > /dev/null; then
280     modprobe obdecho
281 fi
282 if [ ${#tests[@]} -eq 0 -o "${tests[0]}" != "write" ]; then
283     echo "tests: ${tests[@]}"
284     echo "First test must be 'write'" 1>&2
285     exit 1
286 fi
287
288 rsltf="${rslt}.summary"
289 workf="${rslt}.detail"
290 cmdsf="${rslt}.script"
291 vmstatf="${rslt}.vmstat"
292 echo -n > $rsltf
293 echo -n > $workf
294
295 # hide a little trick to unset this from the command line
296 if [ "$lustre_root" == " " ]; then
297     unset lustre_root
298 fi
299
300 if [ -z "$lustre_root" ]; then
301     lctl=lctl
302 else
303     lctl=${lustre_root}/utils/lctl
304 fi
305
306 # split out hostnames from client/ost names
307 ndevs=0
308 for trgt in $targets; do
309     str=(`split_hostname $trgt`)
310     host_names[$ndevs]=${str[0]}
311     client_names[$ndevs]=${str[1]}
312     ndevs=$((ndevs+1))
313 done
314 if [ $case == "disk" ]; then
315     for ((i = 0; i < $ndevs; i++)); do
316         ost_names[$i]=${client_names[$i]}
317     done
318 fi
319 if [ $case == "netdisk" ]; then
320         if [ "$targets" ]; then
321             for ((i = 0; i < $ndevs; i++)); do
322                 setup_osc_for_remote_ost ${host_names[$i]} \
323                                          ${client_names[$i]} $i
324                 osc_name=${client_names[$i]}_osc
325                 ec_using_osc $osc_name
326                 cleanup_oscs="$cleanup_oscs $osc_name"
327             done
328         else
329             client_names_str=$($lctl dl | grep -v mdt | \
330                 awk '{if ($2 == "UP" && $3 == "osc") {print $4} }')
331             count=0;
332             for name in $client_names_str; do
333                 client_names[$count]=`echo $name | sed 's/-osc-.*$//'`
334                 count=$((count+1))
335             done
336
337             host_names_str=$($lctl dl -t | grep -v mdt | \
338                 awk '{if ($2 == "UP" && $3 == "osc") {print $7} }')
339             count=0;
340             for name in $host_names_str; do
341                 host_names[$count]=`echo $name | sed 's/@.*$//'`
342                 count=$((count+1))
343             done
344
345             for (( i = 0; i < $count; i++ )) do
346                 setup_osc_for_remote_ost ${host_names[$i]} \
347                                          ${client_names[$i]} $i
348                 osc_name=${client_names[$i]}_osc
349                 ec_using_osc $osc_name
350                 cleanup_oscs="$cleanup_oscs $osc_name"
351             done
352         fi
353
354         echo_clients=$($lctl dl | grep echo_client | awk "{if (\$2 == \"UP\" && \$3 == \"echo_client\") {print \$4} }")
355         cnt=0;
356         for name in $echo_clients; do
357             client_names[$cnt]=$name
358             host_names[$cnt]=localhost
359             cnt=$((cnt+1))
360         done
361         ndevs=${#client_names[@]}
362 fi
363 if [ $case == "network" ]; then
364     server_nid=$targets
365     if [ -z "$server_nid" ]; then
366         echo "Specify hostname or ip-address of server"
367         exit 1;
368     fi
369     # check for obdecho module on server
370     if ! dsh $server_nid root "lsmod | grep obdecho > /dev/null"; then
371         dsh $server_nid root "modprobe obdecho"
372     fi
373     # Now do the server setup
374     setup_srv_obd $server_nid "echo_srv"
375     oss_on_srv=`dsh $server_nid root "$lctl dl | grep OSS" | awk '{ print $4 }'`
376     if [ -z $oss_on_srv ]; then
377         setup_OSS $server_nid
378         clean_srv_OSS=1
379     fi
380     if ! dsh $server_nid root "$lctl dl | grep obdecho > /dev/null 2>&1"; then
381         echo "obdecho not setup on server"
382         exit 1
383     fi
384     if ! dsh $server_nid root "$lctl dl | grep ost > /dev/null 2>&1"; then
385         echo "ost not setup on server"
386         exit 1
387     fi
388     # Now start client setup
389     osc_names_str=$($lctl dl| grep osc | grep -v mdt | grep UP)
390     if [ -n "$osc_names_str" ]; then
391         echo "The existing setup must be cleaned";
392         exit 0;
393     fi
394     ec_using_srv_nid $server_nid "echotmp" "echotmp_UUID"
395     client_names[0]="echotmp_ecc"
396 fi
397 if [ -z "$targets" ]; then
398     if [ $case == "disk" ]; then
399         get_targets
400         ndevs=${#ost_names[@]}  
401     fi  
402 fi
403 # get vmstat started
404 # disable portals debug and get obdecho loaded on all relevant hosts
405 unique_hosts=(`unique ${host_names[@]}`)
406 load_obdechos
407
408 if [ $case == "disk" ]; then
409         check_record_size || cleanup ${PIPESTATUS[0]}
410 fi
411
412 pidcount=0
413 for host in ${unique_hosts[@]}; do
414     host_vmstatf=${vmstatf}_${host}
415     echo -n > $host_vmstatf
416     remote_shell $host "vmstat 5 >> $host_vmstatf" &> /dev/null &
417     pid=$!
418     vmstatpids[$pidcount]=$pid
419     pidcount=$((pidcount+1))
420 done
421 # get all the echo_client device numbers and names
422 for ((i=0; i < $ndevs; i++)); do
423     host=${host_names[$i]}
424     devno=(`get_ec_devno $host "${client_names[$i]}" "${ost_names[$i]}"`)
425     if ((${#devno[@]} != 3)); then
426         exit 1
427     fi
428     devnos[$i]=${devno[0]}
429     client_names[$i]=${devno[1]}
430     do_teardown_ec[$i]=${devno[2]}
431 done
432 if (($ndevs <= 0 || ${#host_names[@]} <= 0)); then
433     echo "no devices or hosts specified"
434     cleanup 0 $clean_srv_OSS $cleanup_oscs
435 fi
436 # Buffers will be spread out among all hosts, so allow for that
437 max_buffer_mem=$(( ${max_buffer_mem} * ${#unique_hosts[@]} ))
438 print_summary "$(date) Obdfilter-survey for case=$case from $(hostname)"
439 for ((rsz = $rszlo; rsz <= $rszhi; rsz*=2)); do
440     for ((nobj = $nobjlo; nobj <= $nobjhi; nobj*=2)); do 
441         for ((thr = $thrlo; thr <= $thrhi; thr*=2)); do
442             if ((thr % nobj)); then
443                 continue
444             fi
445             # restart?
446             if [ -n "$restart_rsz" -a\
447                  -n "$restart_nobj" -a\
448                  -n "$restart_thr" ]; then
449                 if ((rsz < restart_rsz ||\
450                      (rsz == restart_rsz &&\
451                       (nobj < restart_nobj ||\
452                        (nobj == restart_nobj &&\
453                         thr < restart_thr))))); then
454                     continue;
455                 fi
456             fi
457             # compute parameters
458             total_thr=$((ndevs*thr))
459             total_nobj=$((ndevs*nobj))
460             pages=$((rsz/PAGE_SIZE))
461             actual_rsz=$((pages*PAGE_SIZE))
462             count=$((size*1024/(actual_rsz*thr)))
463             actual_size=$((actual_rsz*count*thr))
464             total_size=$((actual_size*ndevs))
465             # show computed parameters
466             str=`printf 'ost %2d sz %8dK rsz %4dK obj %4d thr %4d ' \
467                      $ndevs $total_size $actual_rsz $total_nobj $total_thr`
468             echo "=======================> $str" >> $workf
469             print_summary -n "$str"
470             if ((total_thr * actual_rsz > max_buffer_mem)); then
471                 print_summary "Too much buffer space"
472                 continue
473             fi
474             # create the objects
475             tmpf="${workf}_tmp"
476             for ((idx = 0; idx < $ndevs; idx++)); do
477                 host=${host_names[$idx]}
478                 devno=${devnos[$idx]}
479                 client_name="${host}:${client_names[$idx]}"
480                 echo "=============> Create $nobj on $client_name" >> $workf
481                 first_obj=`create_objects $host $devno $nobj $tmpf`
482                 cat $tmpf >> $workf
483                 rm $tmpf
484                 if [ $first_obj = "ERROR" ]; then
485                     print_summary "created object #s on $client_name not contiguous"
486                     exit 1
487                 fi
488                 first_objs[$idx]=$first_obj
489             done
490             # run tests
491             for test in ${tests[@]}; do
492                 declare -a pidarray
493                 for host in ${unique_hosts[@]}; do
494                     echo "starting run for test: $test rsz: $rsz threads: $thr objects: $nobj" >> ${vmstatf}_${host}
495                 done
496                 print_summary -n "$test "
497                 # create per-host script files
498                 for host in ${unique_hosts[@]}; do
499                     echo -n > ${cmdsf}_${host}
500                 done
501                 for ((idx = 0; idx < $ndevs; idx++)); do
502                     host=${host_names[$idx]}
503                     devno=${devnos[$idx]}
504                     tmpfi="${tmpf}_$idx"
505                     first_obj=${first_objs[$idx]}
506                     thr_per_obj=$((${thr}/${nobj}))
507                     echo >> ${cmdsf}_${host} \
508                         "$lctl > $tmpfi 2>&1 \\
509                          --threads $thr -$snap $devno \\
510                          test_brw $count `testname2type $test` q $pages \\
511                          ${thr_per_obj}t${first_obj} `testcase2mode $pages` &"
512                 done
513                 pidcount=0
514                 for host in ${unique_hosts[@]}; do
515                     echo "wait" >> ${cmdsf}_${host}
516                     pidarray[$pidcount]=0
517                     pidcount=$((pidcount+1))
518                 done
519                 # timed run of all the per-host script files
520                 t0=`date +%s.%N`
521                 pidcount=0
522                 for host in ${unique_hosts[@]}; do
523                     remote_shell $host bash < ${cmdsf}_${host} &
524                     pidarray[$pidcount]=$!
525                     pidcount=$((pidcount+1))
526                 done
527                 pidcount=0
528                 for host in ${unique_hosts[@]}; do
529                     wait ${pidarray[$pidcount]}
530                     pidcount=$((pidcount+1))
531                 done
532                 #wait
533                 t1=`date +%s.%N`
534                 # clean up per-host script files
535                 for host in ${unique_hosts[@]}; do
536                     rm ${cmdsf}_${host}
537                 done
538
539                 # compute bandwidth from total data / elapsed time
540                 str=`awk "BEGIN {printf \"%7.2f \",\
541                          $total_size / (( $t1 - $t0 ) * 1024)}"`
542                 print_summary -n "$str"
543                 # collect/check individual OST stats
544                 echo -n > $tmpf
545                 for ((idx = 0; idx < $ndevs; idx++)); do
546                     client_name="${host_names[$idx]}:${client_names[$idx]}"
547                     tmpfi="${tmpf}_$idx"
548                     echo "=============> $test $client_name" >> $workf
549                     host="${host_names[$idx]}"
550                     remote_shell $host cat $tmpfi > ${tmpfi}_local
551                     cat ${tmpfi}_local >> $workf
552                     get_stats ${tmpfi}_local >> $tmpf
553                     rm -f $tmpfi ${tmpfi}_local
554                 done
555                 # compute/display global min/max stats
556                 echo "=============> $test global" >> $workf
557                 cat $tmpf >> $workf
558                 stats=(`get_global_stats $tmpf`)
559                 rm $tmpf
560                 if ((stats[0] <= 0)); then
561                     if ((stats[0] < 0)); then
562                         str=`printf "%17s " ERROR`
563                     else
564                         str=`printf "%17s " SHORT`
565                     fi
566                 else
567                     str=`awk "BEGIN {printf \"[%7.2f,%7.2f] \",\
568                              (${stats[1]} * $actual_rsz)/1024,\
569                              (${stats[2]} * $actual_rsz)/1024; exit}"`
570                 fi
571                 print_summary -n "$str"
572             done
573             print_summary ""
574             # destroy objects we created
575             for ((idx = 0; idx < $ndevs; idx++)); do
576                 host=${host_names[$idx]}
577                 devno=${devnos[$idx]}
578                 client_name="${host}:${client_names[$idx]}"
579                 first_obj=${first_objs[$idx]}
580                 echo "=============> Destroy $nobj on $client_name" >> $workf
581                 destroy_objects $host $devno $first_obj $nobj $tmpf
582                 cat $tmpf >> $workf
583                 rm $tmpf
584             done
585         done
586     done
587 done
588 cleanup 0 $clean_srv_OSS $cleanup_oscs
589 exit 0