2 # SPDX-License-Identifier: GPL-2.0
5 # This file is part of Lustre, http://www.lustre.org/
8 ######################################################################
11 # Prerequisite: For "stripe_count > 0" you need to have ost setup and mounted.
14 # case 1 (stripe_count=0 default):
15 # $ thrhi=8 dir_count=4 sh mds-survey
16 # one can also run test with user defined targets as follows,
17 # $ thrhi=8 dir_count=4 file_count=50000 targets="lustre-MDT0000" sh mds-survey
18 # case 2 (stripe_count > 0, must have ost mounted):
19 # $ thrhi=8 dir_count=4 file_count=50000 stripe_count=2
20 # targets="lustre-MDT0000" sh mds-survey
21 # [ NOTE: It is advised to have automated login (passwordless entry) on server ]
24 source $(dirname $0)/iokit-libecho
26 # Customisation variables
27 #####################################################################
28 # One can change variable values in this section as per requirements
29 # The following variables can be set in the environment, or on the
31 # result file prefix (date/time + hostname makes unique)
32 # NB ensure path to it exists
33 rslt_loc=${rslt_loc:-"/tmp"}
34 rslt=${rslt:-"$rslt_loc/mds_survey_`date +%F@%R`_`uname -n`"}
36 # min and max thread count
40 # number of directories to test
41 dir_count=${dir_count:-$thrlo}
42 # number of files per thread
43 file_count=${file_count:-100000}
45 targets=${targets:-""}
46 stripe_count=${stripe_count:-0}
47 # what tests to run (first must be create, and last must be destroy)
48 # default=(create lookup md_getattr setxattr destroy)
49 tests_str=${tests_str:-"create lookup md_getattr setxattr destroy"}
51 # start number for each thread
52 start_number=${start_number:-2}
56 # Customisation variables ends here.
57 #####################################################################
58 # leave the rest of this alone unless you know what you're doing...
63 create_directories () {
72 for ((idx = 0; idx < $ndir; idx++)); do
73 if (( idx == 0 )); then
74 dirname="$(printf "${mdtbasedir}" $mdtidx)${basedir}"
76 dirname="$(printf "${mdtbasedir}" $mdtidx)${basedir}${idx}"
78 remote_shell $host $LCTL --device $devno test_mkdir /$dirname \
79 -c $dir_stripes --stripe_index $mdtidx > $rfile 2>&1
81 echo "$line" | grep -q 'error: test_mkdir'
84 echo "ERROR: fail test_mkdir" >&2
93 destroy_directories () {
101 for ((idx = 0; idx < $ndir; idx++)); do
102 if (( idx == 0 )); then
103 dirname="$(printf "${mdtbasedir}" $mdtidx)${basedir}"
105 dirname="$(printf "${mdtbasedir}" $mdtidx)${basedir}${idx}"
107 remote_shell $host $LCTL --device $devno test_rmdir /$dirname > $rfile 2>&1
122 /^Total: total [0-9]+ threads [0-9]+ sec [0-9\.]+ [0-9]+\.[0-9]+\/second$/ { \
123 ave = strtonum($8); \
127 /^[0-9]+\/[0-9]+ Total: [0-9]+\.[0-9]+\/second$/ { \
128 n++; v = strtonum($3); \
129 if (n == 1 || v < min) min = v; \
130 if (n == 1 || v > max) max = v; \
144 printf "%d %f %f %f\n", n, ave, min, max \
148 get_global_stats () {
175 printf "%d %f %f %f\n", err, ave/n, min, max \
180 if [ "$1" = "-n" ]; then
185 echo $minusn "$*" >> $rsltf
191 for name in $tests_str; do
196 # hide a little trick to unset this from the command line
197 if [ "$lustre_root" == " " ]; then
201 # find where 'lctl' binary is installed on this system
202 if [[ -x "$LCTL" ]]; then # full pathname specified
203 : # echo "LCTL=$LCTL"
204 elif [[ -n "$lustre_root" && -x "$lustre_root/utils/lctl" ]]; then
205 LCTL=${lustre_root}/utils/lctl
206 elif [[ -n "$LUSTRE" && -x "$LUSTRE/utils/lctl" ]]; then
207 LCTL=$LUSTRE/utils/lctl
208 else # hope that it is in the PATH
211 [[ -n "$(which $LCTL)" ]] || { echo "error: lctl not found"; exit 99; }
213 declare -a client_names
214 declare -a host_names
215 declare -a client_indexes
216 if [ -z "$targets" ]; then
217 targets=$($LCTL device_list | awk "{if (\$2 == \"UP\" && \
218 \$3 == \"mdt\") {print \$4} }")
219 if [ -z "$targets" ]; then
220 echo "Can't find any MDT to test. Please set targets=..."
225 # split out hostnames from mdt names
227 for trgt in $targets; do
228 str=($(split_hostname $trgt))
229 host_names[$ndevs]=${str[0]}
230 client_names[$ndevs]=${str[1]}
231 client_indexes[$ndevs]=0x$(echo ${str[1]} |
232 sed 's/.*MDT\([0-9a-f][0-9a-f][0-9a-f][0-9a-f]\).*/\1/')
237 if (( $stripe_count > 0 )); then
238 for ((i=0; i < $ndevs; i++)); do
239 host=${host_names[$i]}
240 obd=$(remote_shell $host $LCTL device_list |
241 awk "{ if (\$2 == \"UP\" &&
242 (\$3 == \"osc\" || \$3 == \"osp\"))
244 if [ -z "$obd" ]; then
245 echo "Need obdfilter to test stripe_count"
251 # check and insert obdecho module
252 if ! lsmod | grep obdecho > /dev/null; then
256 if [ $count -eq 0 -o "${tests[0]}" != "create" -o "${tests[(($count - 1))]}" != "destroy" ]; then
257 echo "tests: ${tests[@]}"
258 echo "First test must be 'create', and last test must be 'destroy'" 1>&2
262 rsltf="${rslt}.summary"
263 workf="${rslt}.detail"
264 cmdsf="${rslt}.script"
265 vmstatf="${rslt}.vmstat"
270 # disable portals debug and get obdecho loaded on all relevant hosts
271 unique_hosts=($(unique ${host_names[@]}))
274 for host in ${unique_hosts[@]}; do
275 host_vmstatf=${vmstatf}_${host}
276 echo -n > $host_vmstatf
277 remote_shell $host "vmstat 5 >> $host_vmstatf" &> /dev/null &
279 vmstatpids[$pidcount]=$pid
280 pidcount=$((pidcount+1))
282 # get all the echo_client device numbers and names
283 for ((i=0; i < $ndevs; i++)); do
284 host=${host_names[$i]}
285 devno=($(get_ec_devno $host "${client_names[$i]}" "${client_names[$i]}" "mdt" $layer))
286 if ((${#devno[@]} != 3)); then
289 devnos[$i]=${devno[0]}
290 client_names[$i]=${devno[1]}
291 do_teardown_ec[$i]=${devno[2]}
293 if (($ndevs <= 0 || ${#host_names[@]} <= 0)); then
294 echo "no devices or hosts specified"
297 print_summary "$(date) $0 from $(hostname)"
300 for ((idx = 0; idx < $ndevs; idx++)); do
301 host=${host_names[$idx]}
302 devno=${devnos[$idx]}
303 client_name="${host}:${client_names[$idx]}"
304 mdtidx=${client_indexes[$idx]}
305 echo "=======> Create $dir_count directories on $client_name" >> $workf
306 destroy_directories $host $devno $dir_count $tmpf $mdtidx
307 ret=$(create_directories $host $devno $dir_count $tmpf $mdtidx $ndevs)
310 if [ $ret = "ERROR" ]; then
311 print_summary "created directories on $client_name failed"
318 for ((thr = $thrlo; thr <= $thrhi; thr*=2)); do
319 thr_per_dir=$((${thr}/${dir_count}))
320 # skip if no enough thread
321 if (( thr_per_dir <= 0 )); then
324 file_count_per_thread=$((${file_count}/${thr}))
325 str=$(printf 'mdt %1d file %7d dir %4d thr %4d ' \
326 $ndevs $file_count $dir_count $thr)
327 echo "=======> $str" >> $workf
328 print_summary -n "$str"
330 for test in ${tests[@]}; do
332 for host in ${unique_hosts[@]}; do
333 echo "starting run for config: $config test: $test " \
334 "file: $file_count threads: $thr " \
335 "directories: $dir_count" >> ${vmstatf}_${host}
337 print_summary -n "$test "
338 # create per-host script files
339 for host in ${unique_hosts[@]}; do
340 echo -n > ${cmdsf}_${host}
342 for ((idx = 0; idx < $ndevs; idx++)); do
343 host=${host_names[$idx]}
344 devno=${devnos[$idx]}
345 dirname="$(printf "${mdtbasedir}" ${client_indexes[$idx]})$basedir"
347 [ "$test" = "create" ] && test="create -c $stripe_count"
348 echo >> ${cmdsf}_${host} \
349 "$LCTL > $tmpfi 2>&1 \
350 --threads $thr -$snap $devno test_$test \
351 -d /$dirname -D $dir_count \
352 -b $start_number -n $file_count_per_thread"
355 for host in ${unique_hosts[@]}; do
356 echo "wait" >> ${cmdsf}_${host}
357 pidarray[$pidcount]=0
358 pidcount=$((pidcount+1))
361 for host in ${unique_hosts[@]}; do
362 remote_shell $host bash < ${cmdsf}_${host} &
363 pidarray[$pidcount]=$!
364 pidcount=$((pidcount+1))
367 for host in ${unique_hosts[@]}; do
368 wait ${pidarray[$pidcount]}
369 pidcount=$((pidcount+1))
372 # clean up per-host script files
373 for host in ${unique_hosts[@]}; do
377 # collect/check individual MDT stats
379 for ((idx = 0; idx < $ndevs; idx++)); do
380 client_name="${host_names[$idx]}:${client_names[$idx]}"
382 echo "=============> $test $client_name" >> $workf
383 host="${host_names[$idx]}"
384 remote_shell $host cat $tmpfi > ${tmpfi}_local
385 cat ${tmpfi}_local >> $workf
386 get_stats ${tmpfi}_local >> $tmpf
387 rm -f $tmpfi ${tmpfi}_local
389 # compute/display global min/max stats
390 echo "=============> $test global" >> $workf
392 stats=($(get_global_stats $tmpf))
394 if ((stats[0] <= 0)); then
395 str=$(printf "%17s " ERROR)
398 str=$(awk "BEGIN {printf \"%7.2f [ %7.2f, %7.2f] \", \
399 ${stats[1]}, ${stats[2]}, ${stats[3]}; exit}")
401 print_summary -n "$str"
406 # destroy directories
408 for ((idx = 0; idx < $ndevs; idx++)); do
409 host=${host_names[$idx]}
410 devno=${devnos[$idx]}
411 mdtidx=${client_indexes[$idx]}
412 client_name="${host}:${client_names[$idx]}"
413 echo "====> Destroy $dir_count directories on $client_name" >> $workf
414 destroy_directories $host $devno $dir_count $tmpf $mdtidx