2 # -*- mode: Bash; tab-width: 4; indent-tabs-mode: t; -*-
3 # vim:shiftwidth=4:softtabstop=4:tabstop=4:
7 # ha.sh - test Lustre HA (aka failover) configurations
15 # ha.sh tests Lustre HA (aka failover) configurations with a CRM.
23 # Specify client nodes.
26 # Specify server nodes.
29 # Specify victim nodes to be rebooted.
32 # Choose a parent of the test directory. "/mnt/lustre" if not specified.
35 # Define a duration for the test. 86400 seconds if not specified.
38 # Define a max failover period. 10 minutes if not set.
41 # Only run the workloads; no failure will be introduced.
42 # -v, -s are ignored in this case.
44 # Workloads dry run for several seconds; no failures will be introduced.
45 # This option is useful to verify the loads.
46 # -u is ignored in this case
48 # Reboot victim nodes simultaneously.
53 # A Lustre file system is up and mounted on all client nodes. This script
54 # does not mount or unmount any Lustre targets or clients, let alone format
57 # Each target has a failnode, so that workloads can continue after a power
60 # CRM could be configured by 2 ways:
62 # Targets are automatically failed back when their primary node is back. This
63 # assumption avoids calling CRM-specific commands to trigger failbacks, making
64 # this script more CRM-neural.
66 # Targets are not automatically failed back when their primary node is back.
67 # CRM-specific command is executed to trigger failbacks.
69 # A crash dump mechanism is configured to catch LBUGs, panics, etc.
73 # Each client runs set of MPI and non-MPI workloads. These
74 # applications are run in short loops so that their exit status can be waited
75 # for and checked within reasonable time by ha_wait_loads.
76 # The set of MPI and non-MPI workloads are configurable by parameters:
78 # default set: dd, tar, iozone
80 # default set: ior, simul, mdtest
82 # The number of clients run MPI loads is configured by parameter
83 # ha_mpi_instances. Only one client runs MPI workloads by default.
85 # MPI workloads can be run from several users. The list of users to use is
86 # configured by parameter ha_mpi_users, default is "mpiuser".
88 # PROCESS STRUCTURE AND IPC
90 # On the node where this script is run, the processes look like this:
94 # ~ ha.sh (ha_repeat_mpi_load ior)
96 # ~ ha.sh (ha_repeat_mpi_load simul)
98 # ~ ha.sh (ha_repeat_mpi_load mdtest)
100 # ~ ... (one for each MPI load)
102 # ~ ha.sh (ha_repeat_nonmpi_load client2 dbench)
103 # ~ pdsh client2 dbench
104 # ~ ha.sh (ha_repeat_nonmpi_load client2 iozone)
105 # ~ pdsh client2 iozone
106 # ~ ha.sh (ha_repeat_nonmpi_load client5 iozone)
107 # ~ pdsh client5 iozone
108 # ~ ... (one for each non-MPI load on each client)
110 # Each tilde represents a process. Indentations imply parent-children
113 # IPC is done by files in the temporary directory.
118 SIMUL=${SIMUL:-$(which simul 2> /dev/null || true)}
119 IOR=${IOR:-$(which IOR 2> /dev/null || true)}
120 MDTEST=${MDTEST:-$(which mdtest 2> /dev/null || true)}
122 ior_blockSize=${ior_blockSize:-6g}
123 mpi_threads_per_client=${mpi_threads_per_client:-2}
125 iozone_SIZE=${iozone_SIZE:-262144} # 256m
127 mpirun=${MPIRUN:-$(which mpirun)}
128 LFS=${LFS:-$(which lfs)}
132 for ((load = 0; load < ${#ha_mpi_load_tags[@]}; load++)); do
133 local tag=${ha_mpi_load_tags[$load]}
134 local bin=$(echo $tag | tr '[:lower:]' '[:upper:]')
135 if [ x${!bin} = x ]; then
136 ha_error ha_mpi_loads: ${ha_mpi_loads}, $bin is not set
144 echo "$0: $(date +%H:%M:%S' '%s):" "$@"
149 local nodes=${1// /,}
151 ha_on $nodes "lctl mark $*"
163 ha_error "Trap ERR triggered by:"
164 ha_error " $BASH_COMMAND"
165 ha_error "Call trace:"
166 for ((i = 0; i < ${#FUNCNAME[@]}; i++)); do
167 ha_error " ${FUNCNAME[$i]} [${BASH_SOURCE[$i]}:${BASH_LINENO[$i]}]"
174 declare ha_tmp_dir=/tmp/$(basename $0)-$$
175 declare ha_stop_file=$ha_tmp_dir/stop
176 declare ha_fail_file=$ha_tmp_dir/fail
177 declare ha_pm_states=$ha_tmp_dir/ha_pm_states
178 declare ha_status_file_prefix=$ha_tmp_dir/status
179 declare -a ha_status_files
180 declare ha_machine_file=$ha_tmp_dir/machine_file
181 declare ha_lfsck_log=$ha_tmp_dir/lfsck.log
182 declare ha_lfsck_lock=$ha_tmp_dir/lfsck.lock
183 declare ha_lfsck_stop=$ha_tmp_dir/lfsck.stop
184 declare ha_lfsck_bg=${LFSCK_BG:-false}
185 declare ha_lfsck_after=${LFSCK_AFTER:-false}
186 declare ha_lfsck_node=${LFSCK_NODE:-""}
187 declare ha_lfsck_device=${LFSCK_DEV:-""}
188 declare ha_lfsck_types=${LFSCK_TYPES:-"namespace layout"}
189 declare ha_lfsck_custom_params=${LFSCK_CUSTOM_PARAMS:-""}
190 declare ha_lfsck_wait=${LFSCK_WAIT:-1200}
191 declare ha_lfsck_fail_on_repaired=${LFSCK_FAIL_ON_REPAIRED:-false}
192 declare ha_power_down_cmd=${POWER_DOWN:-"pm -0"}
193 declare ha_power_up_cmd=${POWER_UP:-"pm -1"}
194 declare ha_power_delay=${POWER_DELAY:-60}
195 declare ha_node_up_delay=${NODE_UP_DELAY:-10}
196 declare ha_pm_host=${PM_HOST:-$(hostname)}
197 declare ha_failback_delay=${DELAY:-5}
198 declare ha_failback_cmd=${FAILBACK:-""}
199 declare ha_stripe_params=${STRIPEPARAMS:-"-c 0"}
200 declare ha_test_dir_stripe_count=${TDSTRIPECOUNT:-"1"}
201 declare ha_test_dir_mdt_index=${TDMDTINDEX:-"0"}
202 declare ha_test_dir_mdt_index_random=${TDMDTINDEXRAND:-false}
203 declare ha_dir_stripe_count=${DSTRIPECOUNT:-"1"}
204 declare ha_mdt_index=${MDTINDEX:-"0"}
205 declare ha_mdt_index_random=${MDTINDEXRAND:-false}
206 declare -a ha_clients
207 declare -a ha_servers
208 declare -a ha_victims
209 declare -a ha_victims_pair
210 declare ha_test_dir=/mnt/lustre/$(basename $0)-$$
211 declare ha_start_time=$(date +%s)
212 declare ha_expected_duration=$((60 * 60 * 24))
213 declare ha_max_failover_period=10
214 declare ha_nr_loops=0
215 declare ha_stop_signals="SIGINT SIGTERM SIGHUP"
216 declare ha_load_timeout=${LOAD_TIMEOUT:-$((60 * 10))}
217 declare ha_workloads_only=false
218 declare ha_workloads_dry_run=false
219 declare ha_simultaneous=false
221 declare ha_mpi_instances=${ha_mpi_instances:-1}
223 declare ha_mpi_loads=${ha_mpi_loads="ior simul mdtest"}
224 declare -a ha_mpi_load_tags=($ha_mpi_loads)
225 declare -a ha_mpiusers=(${ha_mpi_users="mpiuser"})
227 declare -A ha_mpiopts
229 for ((i=0; i<${#ha_mpiusers[@]}; i++)); do
230 u=${ha_mpiusers[i]%%:*}
232 # user gets empty option if ha_mpi_users does not specify it explicitly
233 [[ ${ha_mpiusers[i]} =~ : ]] && o=${ha_mpiusers[i]##*:}
235 ha_mpiopts[$u]+=" $o"
237 ha_users=(${!ha_mpiopts[@]})
239 declare ha_ior_params=${IORP:-'" -b $ior_blockSize -t 2m -w -W -T 1"'}
240 declare ha_simul_params=${SIMULP:-'" -n 10"'}
241 declare ha_mdtest_params=${MDTESTP:-'" -i 1 -n 1000"'}
242 declare ha_mpirun_options=${MPIRUN_OPTIONS:-""}
243 declare ha_clients_stripe=${CLIENTSSTRIPE:-'"$STRIPEPARAMS"'}
244 declare ha_nclientsset=${NCLIENTSSET:-1}
245 declare ha_ninstmustfail=${NINSTMUSTFAIL:-0}
247 declare ha_racer_params=${RACERP:-"MDSCOUNT=1"}
249 eval ha_params_ior=($ha_ior_params)
250 eval ha_params_simul=($ha_simul_params)
251 eval ha_params_mdtest=($ha_mdtest_params)
252 eval ha_stripe_clients=($ha_clients_stripe)
254 declare ha_nparams_ior=${#ha_params_ior[@]}
255 declare ha_nparams_simul=${#ha_params_simul[@]}
256 declare ha_nparams_mdtest=${#ha_params_mdtest[@]}
257 declare ha_nstripe_clients=${#ha_stripe_clients[@]}
259 declare -A ha_mpi_load_cmds=(
260 [ior]="$IOR -o {}/f.ior {params}"
261 [simul]="$SIMUL {params} -d {}"
262 [mdtest]="$MDTEST {params} -d {}"
265 declare racer=${RACER:-"$(dirname $0)/racer/racer.sh"}
267 declare ha_nonmpi_loads=${ha_nonmpi_loads="dd tar iozone"}
268 declare -a ha_nonmpi_load_tags=($ha_nonmpi_loads)
269 declare -A ha_nonmpi_load_cmds=(
270 [dd]="dd if=/dev/zero of={}/f.dd bs=1M count=256"
271 [tar]="tar cf - /etc | tar xf - -C {}"
272 [iozone]="iozone -a -e -+d -s $iozone_SIZE {}/f.iozone"
273 [racer]="$ha_racer_params $racer {}"
278 ha_info "Usage: $0 -c HOST[,...] -s HOST[,...]" \
279 "-v HOST[,...] -f HOST[,...] [-d DIRECTORY] [-u SECONDS]"
282 ha_process_arguments()
286 while getopts hc:s:v:d:p:u:wrmf: opt; do
293 ha_clients=(${OPTARG//,/ })
296 ha_servers=(${OPTARG//,/ })
299 ha_victims=(${OPTARG//,/ })
302 ha_test_dir=$OPTARG/$(basename $0)-$$
305 ha_expected_duration=$OPTARG
308 ha_max_failover_period=$OPTARG
311 ha_workloads_only=true
314 ha_workloads_dry_run=true
320 ha_victims_pair=(${OPTARG//,/ })
329 if [ -z "${ha_clients[*]}" ]; then
330 ha_error "-c is mandatory"
334 if ! ($ha_workloads_dry_run ||
335 $ha_workloads_only) &&
336 ([ -z "${ha_servers[*]}" ] ||
337 [ -z "${ha_victims[*]}" ]); then
338 ha_error "-s, and -v are all mandatory"
352 # -S is to be used here to track the
353 # remote command return values
355 pdsh -S -w $nodes "PATH=/usr/local/sbin:/usr/local/bin:/sbin:\
356 /bin:/usr/sbin:/usr/bin; $@" ||
363 touch "$ha_stop_file"
365 if [ -e "$ha_fail_file" ]; then
366 ha_info "Test directory $ha_test_dir not removed"
367 ha_info "Temporary directory $ha_tmp_dir not removed"
369 ha_on ${ha_clients[0]} rm -rf "$ha_test_dir"
370 ha_info "Please find the results in the directory $ha_tmp_dir"
374 ha_trap_stop_signals()
376 ha_info "${ha_stop_signals// /,} received"
377 touch "$ha_stop_file"
384 ha_info "Sleeping for ${n}s"
386 # sleep(1) could interrupted.
395 while [ -e $lock ]; do
404 until mkdir "$lock" >/dev/null 2>&1; do
405 ha_sleep 1 >/dev/null
418 local nodes=${1// /,}
419 local file=/tmp/$(basename $0)-$$-$(date +%s).dk
420 local lock=$ha_tmp_dir/lock-dump-logs
424 ha_info "Dumping lctl log to $file"
427 # some nodes could crash, so
428 # do not exit with error if not all logs are dumped
430 ha_on $nodes "lctl dk >>$file" || rc=$?
433 ha_error "not all logs are dumped! Some nodes are unreachable."
444 local stripeparams=$6
447 local mpirunoptions=$9
448 local tag=${ha_mpi_load_tags[$load]}
449 local cmd=${ha_mpi_load_cmds[$tag]}
450 local dir=$ha_test_dir/$client-$tag
451 local log=$ha_tmp_dir/$client-$tag
454 local avg_loop_time=0
455 local start_time=$(date +%s)
457 cmd=${cmd//"{}"/$dir}
458 cmd=${cmd//"{params}"/$parameter}
460 [[ -n "$ha_postcmd" ]] && ha_postcmd=${ha_postcmd//"{}"/$dir}
461 [[ -n "$ha_precmd" ]] && ha_precmd=${ha_precmd//"{}"/$dir}
462 ha_info "Starting $tag"
464 machines="-machinefile $machines"
465 while [ ! -e "$ha_stop_file" ] && ((rc == 0)); do
466 ha_info "$client Starts: $mpiuser: $cmd" 2>&1 | tee -a $log
469 if $ha_mdt_index_random && [ $ha_mdt_index -ne 0 ]; then
470 mdt_index=$(ha_rand $ha_mdt_index)
472 mdt_index=$ha_mdt_index
474 [[ -n "$ha_precmd" ]] && ha_info "$ha_precmd" &&
475 ha_on $client "$ha_precmd" >>"$log" 2>&1
476 ha_on $client $LFS mkdir -i$mdt_index -c$ha_dir_stripe_count "$dir" &&
477 ha_on $client $LFS getdirstripe "$dir" &&
478 ha_on $client $LFS setstripe $stripeparams $dir &&
479 ha_on $client $LFS getstripe $dir &&
480 ha_on $client chmod a+xwr $dir &&
481 ha_on $client "su $mpiuser sh -c \" $mpirun $mpirunoptions \
482 -np $((${#ha_clients[@]} * mpi_threads_per_client / ha_nclientsset)) \
483 $machines $cmd \" " || rc=$?
484 [[ -n "$ha_postcmd" ]] && ha_info "$ha_postcmd" &&
485 ha_on $client "$ha_postcmd" >>"$log" 2>&1
486 (( ((rc == 0)) && (( mustpass != 0 )) )) ||
487 (( ((rc != 0)) && (( mustpass == 0 )) )) &&
488 ha_on $client rm -rf "$dir";
489 } >>"$log" 2>&1 || rc=$?
491 ha_info $client: rc=$rc mustpass=$mustpass
493 # mustpass=0 means that failure is expected
494 if (( rc !=0 )); then
495 if (( mustpass != 0 )); then
496 touch "$ha_fail_file"
497 touch "$ha_stop_file"
498 ha_dump_logs "${ha_clients[*]} ${ha_servers[*]}"
503 elif (( mustpass == 0 )); then
504 touch "$ha_fail_file"
505 touch "$ha_stop_file"
506 ha_dump_logs "${ha_clients[*]} ${ha_servers[*]}"
508 echo rc=$rc mustpass=$mustpass >"$status"
510 nr_loops=$((nr_loops + 1))
513 [ $nr_loops -ne 0 ] &&
514 avg_loop_time=$((($(date +%s) - start_time) / nr_loops))
516 ha_info "$tag stopped: rc=$rc mustpass=$mustpass \
517 avg loop time $avg_loop_time"
534 # ha_mpi_instances defines the number of
535 # clients start mpi loads; should be <= ${#ha_clients[@]}
537 # ha_mpi_instances = 0
539 # ${#ha_mpi_load_tags[@]} =0
540 local inst=$ha_mpi_instances
541 (( inst == 0 )) || (( ${#ha_mpi_load_tags[@]} == 0 )) &&
542 ha_info "no mpi load to start" &&
545 (( inst <= ${#ha_clients[@]} )) || inst=${#ha_clients[@]}
547 # Define names for machinefiles for each client set
548 for (( n=0; n < $ha_nclientsset; n++ )); do
549 mach[$n]=$ha_machine_file$n
552 for ((n = 0; n < ${#ha_clients[@]}; n++)); do
553 m=$(( n % ha_nclientsset))
555 ha_info machine_file=$machines
556 echo ${ha_clients[n]} >> $machines
558 local dirname=$(dirname $ha_machine_file)
559 for client in ${ha_clients[@]}; do
560 ha_on $client mkdir -p $dirname
561 scp $ha_machine_file* $client:$dirname
564 for ((n = 0; n < $inst; n++)); do
565 client=${ha_clients[n]}
566 nmpi=$((n % ${#ha_users[@]}))
567 mpiuser=${ha_users[nmpi]}
568 for ((load = 0; load < ${#ha_mpi_load_tags[@]}; load++)); do
569 tag=${ha_mpi_load_tags[$load]}
570 status=$ha_status_file_prefix-$tag-$client
573 local num=ha_nparams_$tag
575 local aref=ha_params_$tag[nparam]
576 local parameter=${!aref}
577 local nstripe=$((n % ha_nstripe_clients))
578 aref=ha_stripe_clients[nstripe]
579 local stripe=${!aref}
580 local m=$(( n % ha_nclientsset))
583 [[ $ha_ninstmustfail == 0 ]] ||
584 mustpass=$(( n % ha_ninstmustfail ))
585 ha_repeat_mpi_load $client $load $status "$parameter" \
586 $machines "$stripe" "$mpiuser" "$mustpass" \
587 "${ha_mpiopts[$mpiuser]} $ha_mpirun_options" &
588 ha_status_files+=("$status")
593 ha_repeat_nonmpi_load()
598 local tag=${ha_nonmpi_load_tags[$load]}
599 local cmd=${ha_nonmpi_load_cmds[$tag]}
600 local dir=$ha_test_dir/$client-$tag
601 local log=$ha_tmp_dir/$client-$tag
604 local avg_loop_time=0
605 local start_time=$(date +%s)
607 cmd=${cmd//"{}"/$dir}
609 ha_info "Starting $tag on $client"
611 while [ ! -e "$ha_stop_file" ] && ((rc == 0)); do
612 ha_info "$client Starts: $cmd" 2>&1 | tee -a $log
613 ha_on $client "mkdir -p $dir && \
615 rm -rf $dir" >>"$log" 2>&1 || rc=$?
618 ha_dump_logs "${ha_clients[*]} ${ha_servers[*]}"
619 touch "$ha_fail_file"
620 touch "$ha_stop_file"
624 nr_loops=$((nr_loops + 1))
627 [ $nr_loops -ne 0 ] &&
628 avg_loop_time=$((($(date +%s) - start_time) / nr_loops))
630 ha_info "$tag on $client stopped: rc $rc avg loop time ${avg_loop_time}s"
633 ha_start_nonmpi_loads()
640 for client in ${ha_clients[@]}; do
641 for ((load = 0; load < ${#ha_nonmpi_load_tags[@]}; load++)); do
642 tag=${ha_nonmpi_load_tags[$load]}
643 status=$ha_status_file_prefix-$tag-$client
644 ha_repeat_nonmpi_load $client $load $status &
645 ha_status_files+=("$status")
650 declare ha_bgcmd=${ha_bgcmd:-""}
651 declare ha_bgcmd_log=$ha_tmp_dir/bgcmdlog
654 [[ -z "$ha_bgcmd" ]] && return 0
655 ha_bgcmd=${ha_bgcmd//"{}"/$ha_test_dir}
657 ha_info "BG cmd: $ha_bgcmd"
659 [ -f $ha_stop_file ] &&
660 ha_info "$ha_stop_file found! $ha_bgcmd no started" &&
662 eval $ha_bgcmd 2>&1 | tee -a $ha_bgcmd_log
666 ha_info CMD BG PID: $CMD_BG_PID
667 ps aux | grep $CMD_BG_PID
676 [ -f $ha_lfsck_stop ] && ha_info "LFSCK stopped" && break
677 [ -f $ha_stop_file ] &&
678 ha_info "$ha_stop_file found! LFSCK not started" &&
680 ha_start_lfsck 2>&1 | tee -a $ha_lfsck_log
684 ha_info LFSCK BG PID: $LFSCK_BG_PID
687 ha_wait_lfsck_completed () {
689 local -a types=($ha_lfsck_types)
693 local nodes="${ha_servers[@]}"
696 # -A start LFSCK on all nodes
698 [ ${#types[@]} -eq 0 ] && types=(namespace layout)
699 ha_info "Waiting LFSCK completed in $ha_lfsck_wait sec: types ${types[@]}"
700 for type in ${types[@]}; do
702 for (( i=0; i<=ha_lfsck_wait; i++)); do
703 status=($(ha_on $nodes lctl get_param -n *.*.lfsck_$type 2>/dev/null | \
704 awk '/status/ { print $3 }'))
705 for (( s=0; s<${#status[@]}; s++ )); do
706 # "partial" is expected after HARD failover
707 [[ "${status[s]}" = "completed" ]] ||
708 [[ "${status[s]}" = "partial" ]] || break
710 [[ $s -eq ${#status[@]} ]] && eval var_$type=1 && break
713 ha_info "LFSCK $type status in $i sec:"
714 ha_on $nodes lctl get_param -n *.*.lfsck_$type 2>/dev/null | grep status
718 for type in ${types[@]}; do
720 ha_on $nodes lctl get_param -n *.*.lfsck_$type 2>/dev/null
721 [[ ${!var} -eq 1 ]] ||
722 { ha_info "lfsck not completed in $ha_lfsck_wait sec";
730 local -a types=($ha_lfsck_types)
733 # -A: start LFSCK on all nodes via the specified MDT device
734 # (see "-M" option) by single LFSCK command
735 local params=" -A -r $ha_lfsck_custom_params"
737 # use specified device if set
738 [ -n "$ha_lfsck_device" ] && params="-M $ha_lfsck_device $params"
740 # -t: check type(s) to be performed (default all)
741 # check only specified types if set
742 if [ ${#types[@]} -ne 0 ]; then
743 local type="${types[@]}"
744 params="$params -t ${type// /,}"
747 ha_info "LFSCK start $params"
748 ha_on $ha_lfsck_node "lctl lfsck_start $params" || rc=1
749 if [ $rc -ne 0 ]; then
750 if [ -e $ha_lfsck_lock ]; then
752 ha_wait_unlock $ha_lfsck_lock
754 ha_on $ha_lfsck_node "lctl lfsck_start $params" || rc=1
759 { touch "$ha_fail_file"; touch "$ha_stop_file";
760 touch $ha_lfsck_stop; return 1; }
762 ha_wait_lfsck_completed ||
763 { touch "$ha_fail_file"; touch "$ha_stop_file";
764 touch $ha_lfsck_stop; return 1; }
773 n=$(cat $ha_lfsck_log | awk '/repaired/ {print $3}' |\
774 awk '{sum += $1} END { print sum }')
776 { ha_info "Total repaired: $n";
777 touch "$ha_fail_file"; return 1; }
784 $ha_lfsck_bg && ha_lfsck_bg
785 trap ha_trap_stop_signals $ha_stop_signals
786 ha_start_nonmpi_loads
793 [[ -n $CMD_BG_PID ]] && wait $CMD_BG_PID || true
794 # true because of lfsck_bg could be stopped already
795 $ha_lfsck_bg && wait $LFSCK_BG_PID || true
796 trap - $ha_stop_signals
797 ha_info "Waiting for workloads to stop"
804 local end=$(($(date +%s) + ha_load_timeout))
806 ha_info "Waiting $ha_load_timeout sec for workload status..."
807 rm -f "${ha_status_files[@]}"
810 # return immediately if ha_stop_file exists,
811 # all status_files not needed to be checked
813 for file in "${ha_status_files[@]}"; do
814 if [ -e "$ha_stop_file" ]; then
815 ha_info "$ha_stop_file found! Stop."
819 # Wait status file created during ha_load_timeout.
820 # Existing file guarantees that some application
821 # is completed. If no status file was created
822 # this function guarantees that we allow
823 # applications to continue after/before
824 # failover/failback during ha_load_timeout time.
826 until [ -e "$file" ] || (($(date +%s) >= end)); do
828 # check ha_stop_file again, it could appear
829 # during ha_load_timeout
831 if [ -e "$ha_stop_file" ]; then
832 ha_info "$ha_stop_file found! Stop."
835 ha_sleep 1 >/dev/null
843 local expected_state=$2
849 # store pm -x -q $nodes results in a file to have
850 # more information about nodes statuses
851 ha_on $ha_pm_host pm -x -q $nodes | awk '{print $2 $3}' > $ha_pm_states
855 while IFS=": " read node state; do
856 [[ "$state" = "$expected_state" ]] && {
857 nodes=${nodes/$node/}
864 if [ -n "$nodes" ]; then
871 ha_power_down_cmd_fn()
876 case $ha_power_down_cmd in
877 # format is: POWER_DOWN=sysrqcrash
878 sysrqcrash) cmd="pdsh -S -w $nodes 'echo c > /proc/sysrq-trigger' &" ;;
879 *) cmd="$ha_power_down_cmd $nodes" ;;
892 case $ha_power_down_cmd in
894 sysrqcrash) state=off ;;
898 if $ha_lfsck_bg && [[ ${nodes//,/ /} =~ $ha_lfsck_node ]]; then
899 ha_info "$ha_lfsck_node down, delay start LFSCK"
900 ha_lock $ha_lfsck_lock
903 ha_info "Powering down $nodes : cmd: $ha_power_down_cmd"
904 for (( i=0; i<10; i++ )) {
905 ha_info "attempt: $i"
906 ha_power_down_cmd_fn $nodes &&
907 ha_powermanage $nodes $state && rc=0 && break
908 sleep $ha_power_delay
912 ha_info "Failed Powering down in $i attempts:" \
924 for ((i=0; i<${#ha_victims[@]}; i++)) {
925 [[ ${ha_victims[i]} == $node ]] && echo ${ha_victims_pair[i]} &&
928 [[ $i -ne ${#ha_victims[@]} ]] ||
929 ha_error "No pair found!"
935 local end=$(($(date +%s) + ha_node_up_delay))
938 if [[ ${#ha_victims_pair[@]} -eq 0 ]]; then
939 ha_sleep $ha_node_up_delay
943 # Check CRM status on failover pair
944 while (($(date +%s) <= end)); do
946 for n in ${nodes//,/ }; do
947 local pair=$(ha_get_pair $n)
948 local status=$(ha_on $pair crm_mon -1rQ | \
949 grep -w $n | head -1)
951 ha_info "$n pair: $pair status: $status"
952 [[ "$status" == *OFFLINE* ]] ||
957 if [[ $rc -eq 0 ]]; then
958 ha_info "CRM: Got all victims status OFFLINE"
964 ha_info "$nodes CRM status not OFFLINE"
965 for n in ${nodes//,/ }; do
966 local pair=$(ha_get_pair $n)
969 ha_on $pair crm_mon -1rQ
971 ha_error "CRM: some of $nodes are not OFFLINE in $ha_node_up_delay sec"
981 ha_power_up_delay $nodes
982 ha_info "Powering up $nodes : cmd: $ha_power_up_cmd"
983 for (( i=0; i<10; i++ )) {
984 ha_info "attempt: $i"
985 $ha_power_up_cmd $nodes &&
986 ha_powermanage $nodes on && rc=0 && break
987 sleep $ha_power_delay
991 ha_info "Failed Powering up in $i attempts: $ha_power_up_cmd"
1000 # Print a random integer within [0, MAX).
1007 # See "5.2 Bash Variables" from "info bash".
1009 echo -n $((RANDOM * max / 32768))
1017 if $ha_simultaneous ; then
1018 nodes=$(echo ${ha_victims[@]})
1021 i=$(ha_rand ${#ha_victims[@]})
1022 nodes=${ha_victims[$i]}
1031 local end=$(($(date +%s) + 10 * 60))
1033 ha_info "Waiting for $nodes to boot up"
1034 until ha_on $nodes hostname >/dev/null 2>&1 ||
1035 [ -e "$ha_stop_file" ] ||
1036 (($(date +%s) >= end)); do
1037 ha_sleep 1 >/dev/null
1044 ha_info "Failback resources on $nodes in $ha_failback_delay sec"
1046 ha_sleep $ha_failback_delay
1047 [ "$ha_failback_cmd" ] ||
1049 ha_info "No failback command set, skiping"
1053 $ha_failback_cmd $nodes
1054 [ -e $ha_lfsck_lock ] && ha_unlock $ha_lfsck_lock || true
1059 ha_info "---------------8<---------------"
1061 ha_info " Duration: $(($(date +%s) - $ha_start_time))s"
1062 ha_info " Loops: $ha_nr_loops"
1069 while (($(date +%s) < ha_start_time + ha_expected_duration)) &&
1070 [ ! -e "$ha_stop_file" ]; do
1071 ha_info "---------------8<---------------"
1073 $ha_workloads_only || nodes=$(ha_aim)
1075 ha_info "Failing $nodes"
1076 $ha_workloads_only && ha_info " is skipped: workload only..."
1078 ha_sleep $(ha_rand $ha_max_failover_period)
1079 $ha_workloads_only || ha_power_down $nodes
1081 ha_wait_loads || return
1083 if [ -e $ha_stop_file ]; then
1084 $ha_workloads_only || ha_power_up $nodes
1088 ha_info "Bringing $nodes back"
1089 ha_sleep $(ha_rand 10)
1090 $ha_workloads_only ||
1093 ha_wait_nodes $nodes
1098 # Wait for the failback to start.
1101 ha_wait_loads || return
1103 ha_sleep $(ha_rand 20)
1105 ha_nr_loops=$((ha_nr_loops + 1))
1106 ha_info "Loop $ha_nr_loops done"
1113 ha_process_arguments "$@"
1116 ha_log "${ha_clients[*]} ${ha_servers[*]}" \
1117 "START: $0: $(date +%H:%M:%S' '%s)"
1118 trap ha_trap_exit EXIT
1122 if $ha_test_dir_mdt_index_random &&
1123 [ $ha_test_dir_mdt_index -ne 0 ]; then
1124 mdt_index=$(ha_rand $ha_test_dir_mdt_index)
1126 mdt_index=$ha_test_dir_mdt_index
1128 ha_on ${ha_clients[0]} "$LFS mkdir -i$mdt_index \
1129 -c$ha_test_dir_stripe_count $ha_test_dir"
1130 ha_on ${ha_clients[0]} $LFS getdirstripe $ha_test_dir
1131 ha_on ${ha_clients[0]} " \
1132 $LFS setstripe $ha_stripe_params $ha_test_dir"
1137 if $ha_workloads_dry_run; then
1141 ha_dump_logs "${ha_clients[*]} ${ha_servers[*]}"
1146 $ha_lfsck_after && ha_start_lfsck | tee -a $ha_lfsck_log
1148 $ha_lfsck_fail_on_repaired && ha_lfsck_repaired
1150 if [ -e "$ha_fail_file" ]; then
1153 ha_log "${ha_clients[*]} ${ha_servers[*]}" \
1154 "END: $0: $(date +%H:%M:%S' '%s)"