3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
11 # bug number for skipped test:
12 ALWAYS_EXCEPT="$SANITY_LNET_EXCEPT "
13 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
15 # skip the grant tests for ARM until they are fixed
16 if [[ $(uname -m) = aarch64 ]]; then
17 # bug number: LU-14067
21 [ "$SLOW" = "no" ] && EXCEPT_SLOW=""
23 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
25 . $LUSTRE/tests/test-framework.sh
29 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
34 [[ -z $LNETCTL ]] && skip "Need lnetctl"
38 if is_mounted $MOUNT || is_mounted $MOUNT2; then
39 cleanupall || error "Failed cleanup prior to test execution"
44 echo "Cleaning up LNet"
45 lsmod | grep -q lnet &&
46 $LNETCTL lnet unconfigure 2>/dev/null
51 if module_loaded lnet ; then
52 cleanup_lnet || error "Failed to unload modules before test execution"
58 # Cleanup any tmp files created by the sub tests
59 rm -f $TMP/sanity-lnet-*.yaml $LNET_PARAMS_FILE
62 if $restore_mounts; then
63 setupall || error "Failed to setup Lustre after test execution"
64 elif $restore_modules; then
66 error "Couldn't load modules after test execution"
72 load_module ../libcfs/libcfs/libcfs
73 # Prevent local MODOPTS_LIBCFS being passed as part of environment
74 # variable to remote nodes
77 set_default_debug "neterror net nettrace malloc"
78 load_module ../lnet/lnet/lnet "$@"
80 LNDPATH=${LNDPATH:-"../lnet/klnds"}
81 if [ -z "$LNETLND" ]; then
83 o2ib*) LNETLND="o2iblnd/ko2iblnd" ;;
84 tcp*) LNETLND="socklnd/ksocklnd" ;;
85 *) local lnd="${NETTYPE%%[0-9]}lnd"
86 [ -f "$LNDPATH/$lnd/k$lnd.ko" ] &&
87 LNETLND="$lnd/k$lnd" ||
88 LNETLND="socklnd/ksocklnd"
91 load_module ../lnet/klnds/$LNETLND
103 echo "ip netns exec $TESTNS $@"
104 ip netns exec $TESTNS "$@"
112 netns_arg="netns $netns"
114 ip link add 'test1pl' type veth peer name $FAKE_IF $netns_arg
115 ip link set 'test1pl' up
116 if [[ -n $netns ]]; then
117 do_ns ip addr add "${FAKE_IP}/31" dev $FAKE_IF
118 do_ns ip link set $FAKE_IF up
120 ip addr add "${FAKE_IP}/31" dev $FAKE_IF
121 ip link set $FAKE_IF up
126 ip link show test1pl >& /dev/null && ip link del test1pl || return 0
137 (ip netns list | grep -q $TESTNS) && ip netns del $TESTNS
142 echo "Loading LNet and configuring DLC"
144 do_lnetctl lnet configure
147 GLOBAL_YAML_FILE=$TMP/sanity-lnet-global.yaml
148 define_global_yaml() {
149 $LNETCTL export --backup >${GLOBAL_YAML_FILE} ||
150 error "Failed to export global yaml $?"
154 if lsmod | grep -q lnet; then
155 do_lnetctl lnet unconfigure ||
156 error "lnetctl lnet unconfigure failed $?"
157 do_lnetctl lnet configure ||
158 error "lnetctl lnet configure failed $?"
160 configure_dlc || error "configure_dlc failed $?"
165 append_global_yaml() {
166 [[ ! -e ${GLOBAL_YAML_FILE} ]] &&
167 error "Missing global yaml at ${GLOBAL_YAML_FILE}"
169 cat ${GLOBAL_YAML_FILE} >> $TMP/sanity-lnet-$testnum-expected.yaml
172 create_base_yaml_file() {
176 compare_yaml_files() {
177 local expected="$TMP/sanity-lnet-$testnum-expected.yaml"
178 local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
180 ! [[ -e $expected ]] && echo "$expected not found" && return 1
181 ! [[ -e $actual ]] && echo "$actual not found" && return 1
182 diff -upN ${actual} ${expected} || rc=$?
192 local net="${nid//*@/}"
193 local addr="${nid//@*/}"
195 local num_re='[0-9]\+'
196 local ip_re="[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
198 if [[ $net =~ gni[0-9]* ]]; then
199 [[ $addr =~ ${num_re} ]] && return 0
201 [[ $addr =~ ${ip_re} ]] && return 0
206 local yfile=$TMP/sanity-lnet-$testnum-actual.yaml
207 local primary_nids=$(awk '/- primary nid:/{print $NF}' $yfile | xargs echo)
208 local secondary_nids=$(awk '/- nid:/{print $NF}' $yfile | xargs echo)
209 local gateway_nids=$(awk '/gateway:/{print $NF}' $yfile | xargs echo)
212 for nid in $primary_nids $secondary_nids; do
213 validate_nid "$nid" || error "Bad NID \"${nid}\""
218 validate_peer_nids() {
220 local nids_per_peer="$2"
222 local expect_p="$num_peers"
223 # The primary nid also shows up in the list of secondary nids
224 local expect_s="$(($num_peers + $(($nids_per_peer*$num_peers))))"
226 local actual_p=$(grep -c -- '- primary nid:' $TMP/sanity-lnet-$testnum-actual.yaml)
227 local actual_s=$(grep -c -- '- nid:' $TMP/sanity-lnet-$testnum-actual.yaml)
228 if [[ $expect_p -ne $actual_p ]]; then
230 error "Expected $expect_p but found $actual_p primary nids"
231 elif [[ $expect_s -ne $actual_s ]]; then
233 error "Expected $expect_s but found $actual_s secondary nids"
238 validate_gateway_nids() {
239 local expect_gw=$(grep -c -- 'gateway:' $TMP/sanity-lnet-$testnum-expected.yaml)
240 local actual_gw=$(grep -c -- 'gateway:' $TMP/sanity-lnet-$testnum-actual.yaml)
241 if [[ $expect_gw -ne $actual_gw ]]; then
243 error "Expected $expect_gw gateways but found $actual_gw gateways"
249 setup_netns || error "setup_netns failed with $?"
251 # Determine the local interface(s) used for LNet
252 load_modules || error "Failed to load modules"
253 NIDS=( $($LCTL list_nids | xargs echo) )
254 if [[ -z ${NIDS[@]} ]]; then
255 error "No NID configured after module load"
261 declare -a INTERFACES
262 for ((i = 0; i < ${#NIDS[@]}; i++)); do
263 ip=$(sed 's/^\(.*\)@.*$/\1/'<<<${NIDS[i]})
264 INTERFACES[i]=$(ip -o a s |
265 awk '$4 ~ /^'$ip'\//{print $2}')
266 INTERFACES=($(echo "${INTERFACES[@]}" | tr ' ' '\n' | uniq | tr '\n' ' '))
267 if [[ -z ${INTERFACES[i]} ]]; then
268 error "Can't determine interface name for NID ${NIDS[i]}"
269 elif [[ 1 -ne $(wc -w <<<${INTERFACES[i]}) ]]; then
270 error "Found $(wc -w <<<${INTERFACES[i]}) interfaces for NID ${NIDS[i]}. Expect 1"
274 cleanup_lnet || error "Failed to cleanup LNet"
276 stack_trap 'cleanup_testsuite' EXIT
279 load_module ../lnet/lnet/lnet || error "Failed to load module rc = $?"
280 do_lnetctl lnet configure || error "lnet configure failed rc = $?"
282 reinit_dlc || return $?
283 do_lnetctl import < ${GLOBAL_YAML_FILE} || error "Import failed $?"
284 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
285 create_base_yaml_file
286 compare_yaml_files || error "Configuration changed after import"
288 run_test 0 "Export empty config, import the config, compare"
291 local prim_nid="${1:+--prim_nid $1}"
292 local nid="${2:+--nid $2}"
294 local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
296 do_lnetctl peer add ${prim_nid} ${nid} || error "peer add failed $?"
297 $LNETCTL export --backup > $actual || error "export failed $?"
303 reinit_dlc || return $?
304 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
306 - primary nid: 1.1.1.1@tcp
312 compare_peer_add "1.1.1.1@tcp"
314 run_test 1 "Add peer with single nid (tcp)"
317 reinit_dlc || return $?
318 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
320 - primary nid: 2.2.2.2@o2ib
326 compare_peer_add "2.2.2.2@o2ib"
328 run_test 2 "Add peer with single nid (o2ib)"
331 reinit_dlc || return $?
332 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
334 - primary nid: 3.3.3.3@tcp
341 compare_peer_add "3.3.3.3@tcp" "3.3.3.3@o2ib"
343 run_test 3 "Add peer with tcp primary o2ib secondary"
346 reinit_dlc || return $?
347 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
349 - primary nid: 4.4.4.4@tcp
358 echo "Add peer with nidrange (tcp)"
359 compare_peer_add "4.4.4.4@tcp" "4.4.4.[1-3]@tcp"
361 echo "Add peer with nidrange that overlaps primary nid (tcp)"
362 compare_peer_add "4.4.4.4@tcp" "4.4.4.[1-4]@tcp"
364 run_test 4 "Add peer with nidrange (tcp)"
367 reinit_dlc || return $?
368 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
370 - primary nid: 5.5.5.5@o2ib
380 echo "Add peer with nidrange (o2ib)"
381 compare_peer_add "5.5.5.5@o2ib" "5.5.5.[1-4]@o2ib"
383 echo "Add peer with nidranage that overlaps primary nid (o2ib)"
384 compare_peer_add "5.5.5.5@o2ib" "5.5.5.[1-4]@o2ib"
386 run_test 5 "Add peer with nidrange (o2ib)"
389 reinit_dlc || return $?
390 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
392 - primary nid: 6.6.6.6@tcp
412 compare_peer_add "6.6.6.6@tcp" \
413 "6.6.[6-7].[0-4/2]@tcp,6.6.[1-4/2].[0-6/3]@o2ib,[6-12/4]@gni"
415 run_test 6 "Add peer with multiple nidranges"
418 local prim_nid="${1:+--prim_nid $1}"
419 local nid="${2:+--nid $2}"
421 local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
423 do_lnetctl peer del ${prim_nid} ${nid} || error "peer del failed $?"
424 $LNETCTL export --backup > $actual || error "export failed $?"
430 reinit_dlc || return $?
431 create_base_yaml_file
433 echo "Delete peer with single nid (tcp)"
434 do_lnetctl peer add --prim_nid 7.7.7.7@tcp || error "Peer add failed $?"
435 compare_peer_del "7.7.7.7@tcp"
437 echo "Delete peer with single nid (o2ib)"
438 do_lnetctl peer add --prim_nid 7.7.7.7@o2ib || error "Peer add failed $?"
439 compare_peer_del "7.7.7.7@o2ib"
441 echo "Delete peer that has multiple nids (tcp)"
442 do_lnetctl peer add --prim_nid 7.7.7.7@tcp --nid 7.7.7.[8-12]@tcp ||
443 error "Peer add failed $?"
444 compare_peer_del "7.7.7.7@tcp"
446 echo "Delete peer that has multiple nids (o2ib)"
447 do_lnetctl peer add --prim_nid 7.7.7.7@o2ib --nid 7.7.7.[8-12]@o2ib ||
448 error "Peer add failed $?"
449 compare_peer_del "7.7.7.7@o2ib"
451 echo "Delete peer that has both tcp and o2ib nids"
452 do_lnetctl peer add --prim_nid 7.7.7.7@tcp \
453 --nid 7.7.7.[9-12]@tcp,7.7.7.[13-15]@o2ib ||
454 error "Peer add failed $?"
455 compare_peer_del "7.7.7.7@tcp"
457 echo "Delete peer with single nid (gni)"
458 do_lnetctl peer add --prim_nid 7@gni || error "Peer add failed $?"
459 compare_peer_del "7@gni"
461 echo "Delete peer that has multiple nids (gni)"
462 do_lnetctl peer add --prim_nid 7@gni --nid [8-12]@gni ||
463 error "Peer add failed $?"
464 compare_peer_del "7@gni"
466 echo "Delete peer that has tcp, o2ib and gni nids"
467 do_lnetctl peer add --prim_nid 7@gni \
468 --nid [8-12]@gni,7.7.7.[9-12]@tcp,7.7.7.[13-15]@o2ib ||
469 error "Peer add failed $?"
470 compare_peer_del "7@gni"
472 run_test 7 "Various peer delete tests"
475 reinit_dlc || return $?
477 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
479 - primary nid: 8.8.8.8@tcp
491 do_lnetctl peer add --prim_nid 8.8.8.8@tcp --nid 8.8.8.[10-15]@tcp ||
492 error "Peer add failed $?"
493 compare_peer_del "8.8.8.8@tcp" "8.8.8.13@tcp"
495 run_test 8 "Delete single secondary nid from peer (tcp)"
498 reinit_dlc || return $?
500 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
502 - primary nid: 9.9.9.9@tcp
509 do_lnetctl peer add --prim_nid 9.9.9.9@tcp \
510 --nid 9.9.9.[11-16]@tcp || error "Peer add failed $?"
511 compare_peer_del "9.9.9.9@tcp" "9.9.9.[11-16]@tcp"
513 run_test 9 "Delete all secondary nids from peer (tcp)"
516 reinit_dlc || return $?
518 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
520 - primary nid: 10.10.10.10@tcp
523 - nid: 10.10.10.10@tcp
524 - nid: 10.10.10.12@tcp
525 - nid: 10.10.10.13@tcp
526 - nid: 10.10.10.15@tcp
527 - nid: 10.10.10.16@tcp
530 do_lnetctl peer add --prim_nid 10.10.10.10@tcp \
531 --nid 10.10.10.[12-16]@tcp || error "Peer add failed $?"
532 compare_peer_del "10.10.10.10@tcp" "10.10.10.14@tcp"
534 run_test 10 "Delete single secondary nid from peer (o2ib)"
537 reinit_dlc || return $?
539 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
541 - primary nid: 11.11.11.11@tcp
544 - nid: 11.11.11.11@tcp
547 do_lnetctl peer add --prim_nid 11.11.11.11@tcp \
548 --nid 11.11.11.[13-17]@tcp || error "Peer add failed $?"
549 compare_peer_del "11.11.11.11@tcp" "11.11.11.[13-17]@tcp"
551 run_test 11 "Delete all secondary nids from peer (o2ib)"
554 reinit_dlc || return $?
556 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
558 - primary nid: 12.12.12.12@o2ib
561 - nid: 12.12.12.12@o2ib
562 - nid: 13.13.13.13@o2ib
563 - nid: 14.13.13.13@o2ib
564 - nid: 14.15.13.13@o2ib
566 - nid: 15.17.1.10@tcp
567 - nid: 15.17.1.20@tcp
570 do_lnetctl peer add --prim_nid 12.12.12.12@o2ib \
571 --nid [13-14/1].[13-15/2].13.13@o2ib,[15-16/3].[17-19/4].[1].[5-20/5]@tcp ||
572 error "Peer add failed $?"
573 compare_peer_del "12.12.12.12@o2ib" "13.15.13.13@o2ib,15.17.1.15@tcp"
575 run_test 12 "Delete a secondary nid from peer (tcp and o2ib)"
578 reinit_dlc || return $?
580 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
582 - primary nid: 13.13.13.13@o2ib
585 - nid: 13.13.13.13@o2ib
588 do_lnetctl peer add --prim_nid 13.13.13.13@o2ib \
589 --nid [14-15].[1-2/1].[1].[100-254/10]@tcp,14.14.[254].14@o2ib ||
590 error "Peer add failed $?"
591 compare_peer_del "13.13.13.13@o2ib" \
592 "[14-15].[1-2/1].[1].[100-254/10]@tcp,14.14.[254].14@o2ib"
594 run_test 13 "Delete all secondary nids from peer (tcp and o2ib)"
600 if [[ $net =~ gni* ]]; then
603 echo "${num}.${num}.${num}.${num}@${net}"
607 create_mr_peer_yaml() {
609 local secondary_nids="$2"
612 echo "Generating peer yaml for $num_peers peers with $secondary_nids secondary nids"
613 echo "peer:" >> $TMP/sanity-lnet-$testnum-expected.yaml
615 local total_nids=$((num_peers + $((num_peers * secondary_nids))))
618 while [[ $created -lt $num_peers ]]; do
619 local primary=$(create_nid ${nidnum} ${net})
620 cat <<EOF >> $TMP/sanity-lnet-$testnum-expected.yaml
621 - primary nid: $primary
627 local start=$((nidnum + 1))
628 local end=$((nidnum + $secondary_nids))
629 for j in $(seq ${start} ${end}); do
630 local nid=$(create_nid $j ${net})
631 echo " - nid: $nid" >> $TMP/sanity-lnet-$testnum-expected.yaml
639 reinit_dlc || return $?
641 echo "Create single peer, single nid, using import"
642 create_mr_peer_yaml 1 0 tcp
643 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
644 error "Import failed $?"
646 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
649 echo "Delete single peer using import --del"
650 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
651 error "Import failed $?"
652 rm -f $TMP/sanity-lnet-$testnum-expected.yaml
653 create_base_yaml_file
654 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
657 run_test 14 "import peer create/delete with single nid"
660 reinit_dlc || return $?
662 echo "Create multiple peers, single nid per peer, using import"
663 create_mr_peer_yaml 5 0 o2ib
664 # The ordering of nids for this use-case is non-deterministic, so we
665 # we can't just diff the expected/actual output.
666 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
667 error "Import failed $?"
668 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
669 validate_peer_nids 5 0
671 echo "Delete multiple peers, single nid per peer, using import --del"
672 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
673 error "Import failed $?"
674 rm -f $TMP/sanity-lnet-$testnum-expected.yaml
675 create_base_yaml_file
676 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
679 run_test 15 "import multi peer create/delete with single nid per peer"
682 reinit_dlc || return $?
684 echo "Create single peer, multiple nids, using import"
685 create_mr_peer_yaml 1 5 tcp
686 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
687 error "Import failed $?"
688 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
689 validate_peer_nids 1 5
691 echo "Delete single peer, multiple nids, using import --del"
692 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
693 error "Import failed $?"
694 rm -f $TMP/sanity-lnet-$testnum-expected.yaml
695 create_base_yaml_file
696 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
699 run_test 16 "import peer create/delete with multiple nids"
702 reinit_dlc || return $?
704 echo "Create multiple peers, multiple nids per peer, using import"
705 create_mr_peer_yaml 5 7 o2ib
706 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
707 error "Import failed $?"
708 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
709 validate_peer_nids 5 7
711 echo "Delete multiple peers, multiple nids per peer, using import --del"
712 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
713 error "Import failed $?"
714 rm -f $TMP/sanity-lnet-$testnum-expected.yaml
715 create_base_yaml_file
716 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
719 run_test 17 "import multi peer create/delete with multiple nids"
722 reinit_dlc || return $?
724 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
726 - primary nid: 1.1.1.1@tcp
735 echo "Import peer with 5 nids"
736 cat $TMP/sanity-lnet-$testnum-expected.yaml
737 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
738 error "Import failed $?"
739 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
741 - primary nid: 1.1.1.1@tcp
748 echo "Delete three of the nids"
749 cat $TMP/sanity-lnet-$testnum-expected.yaml
750 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml
751 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
753 - primary nid: 1.1.1.1@tcp
759 echo "Check peer has expected nids remaining"
760 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
764 run_test 18a "Delete a subset of nids from a single peer using import --del"
767 reinit_dlc || return $?
769 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
771 - primary nid: 1.1.1.1@tcp
779 - primary nid: 6.6.6.6@o2ib
788 echo "Import two peers with 5 nids each"
789 cat $TMP/sanity-lnet-$testnum-expected.yaml
790 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
791 error "Import failed $?"
792 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
794 - primary nid: 1.1.1.1@tcp
800 - primary nid: 6.6.6.6@o2ib
807 echo "Delete three of the nids from each peer"
808 cat $TMP/sanity-lnet-$testnum-expected.yaml
809 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml
810 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
812 - primary nid: 6.6.6.6@o2ib
817 - primary nid: 1.1.1.1@tcp
824 echo "Check peers have expected nids remaining"
825 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
827 validate_peer_nids 2 1
829 run_test 18b "Delete multiple nids from multiple peers using import --del"
832 reinit_dlc || return $?
833 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
835 - primary nid: 19@gni
841 compare_peer_add "19@gni"
843 run_test 19 "Add peer with single nid (gni)"
846 reinit_dlc || return $?
847 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
849 - primary nid: 20@gni
853 - nid: 20.20.20.20@tcp
854 - nid: 20.20.20.20@o2ib
857 compare_peer_add "20@gni" "20.20.20.20@tcp,20.20.20.20@o2ib"
859 run_test 20 "Add peer with gni primary and tcp, o2ib secondary"
862 reinit_dlc || return $?
863 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
865 - primary nid: 21@gni
875 echo "Add peer with nidrange (gni)"
876 compare_peer_add "21@gni" "[22-25]@gni" || error
877 echo "Add peer with nidrange that overlaps primary nid (gni)"
878 compare_peer_add "21@gni" "[21-25]@gni"
880 run_test 21 "Add peer with nidrange (gni)"
883 reinit_dlc || return $?
884 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
886 - primary nid: 22@gni
897 do_lnetctl peer add --prim_nid 22@gni --nid [24-29]@gni ||
898 error "Peer add failed $?"
899 compare_peer_del "22@gni" "26@gni"
901 run_test 22 "Delete single secondary nid from peer (gni)"
904 reinit_dlc || return $?
905 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
907 - primary nid: 23@gni
914 do_lnetctl peer add --prim_nid 23@gni --nid [25-29]@gni ||
915 error "Peer add failed $?"
916 compare_peer_del "23@gni" "[25-29]@gni"
918 run_test 23 "Delete all secondary nids from peer (gni)"
921 reinit_dlc || return $?
922 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
924 - primary nid: 24@gni
929 - nid: 13.13.13.13@o2ib
930 - nid: 14.13.13.13@o2ib
931 - nid: 14.15.13.13@o2ib
933 - nid: 15.17.1.10@tcp
934 - nid: 15.17.1.20@tcp
937 do_lnetctl peer add --prim_nid 24@gni \
938 --nid [13-14/1].[13-15/2].13.13@o2ib,[15-16/3].[17-19/4].[1].[5-20/5]@tcp,[5-12/6]@gni ||
939 error "Peer add failed $?"
940 compare_peer_del "24@gni" "5@gni,13.15.13.13@o2ib,15.17.1.15@tcp"
942 run_test 24 "Delete a secondary nid from peer (tcp, o2ib and gni)"
945 reinit_dlc || return $?
946 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
948 - primary nid: 25@gni
954 do_lnetctl peer add --prim_nid 25@gni \
955 --nid [26-27].[4-10/3].26.26@tcp,26.26.26.26@o2ib,[30-35]@gni ||
956 error "Peer add failed $?"
957 compare_peer_del "25@gni" \
958 "[26-27].[4-10/3].26.26@tcp,26.26.26.26@o2ib,[30-35]@gni"
960 run_test 25 "Delete all secondary nids from peer (tcp, gni and o2ib)"
963 reinit_dlc || return $?
965 echo "Invalid prim_nid - peer add"
966 do_lnetctl peer add --prim_nid foobar &&
967 error "Command should have failed"
969 echo "Invalid prim_nid - peer del"
970 do_lnetctl peer del --prim_nid foobar &&
971 error "Command should have failed"
973 echo "Delete non-existing peer"
974 do_lnetctl peer del --prim_nid 1.1.1.1@o2ib &&
975 error "Command should have failed"
977 echo "Don't provide mandatory argument for peer del"
978 do_lnetctl peer del --nid 1.1.1.1@tcp &&
979 error "Command should have failed"
981 echo "Don't provide mandatory argument for peer add"
982 do_lnetctl peer add --nid 1.1.1.1@tcp &&
983 error "Command should have failed"
985 echo "Don't provide mandatory arguments peer add"
986 do_lnetctl peer add &&
987 error "Command should have failed"
989 echo "Invalid secondary nids"
990 do_lnetctl peer add --prim_nid 1.1.1.1@tcp --nid foobar &&
991 error "Command should have failed"
993 echo "Exceed max nids per peer"
994 do_lnetctl peer add --prim_nid 1.1.1.1@tcp --nid 1.1.1.[2-255]@tcp &&
995 error "Command should have failed"
997 echo "Invalid net type"
998 do_lnetctl peer add --prim_nid 1@foo &&
999 error "Command should have failed"
1001 echo "Invalid nid format"
1002 local invalid_nids="1@tcp 1@o2ib 1.1.1.1@gni"
1005 for nid in ${invalid_nids}; do
1006 echo "Check invalid primary nid - '$nid'"
1007 do_lnetctl peer add --prim_nid $nid &&
1008 error "Command should have failed"
1011 local invalid_strs="[2-1]@gni [a-f/x]@gni 256.256.256.256@tcp"
1012 invalid_strs+=" 1.1.1.1.[2-5/f]@tcp 1.]2[.3.4@o2ib"
1013 invalid_strs+="1.[2-4,[5-6],7-8].1.1@tcp foobar"
1016 for nidstr in ${invalid_strs}; do
1017 echo "Check invalid nidstring - '$nidstr'"
1018 do_lnetctl peer add --prim_nid 1.1.1.1@tcp --nid $nidstr &&
1019 error "Command should have failed"
1022 echo "Add non-local gateway"
1023 do_lnetctl route add --net tcp --gateway 1@gni &&
1024 error "Command should have failed"
1028 run_test 99a "Check various invalid inputs to lnetctl peer"
1031 reinit_dlc || return $?
1033 create_base_yaml_file
1035 cat <<EOF > $TMP/sanity-lnet-$testnum-invalid.yaml
1037 - primary nid: 99.99.99.99@tcp
1040 - nid: 99.99.99.99@tcp
1042 do_lnetctl import < $TMP/sanity-lnet-$testnum-invalid.yaml &&
1043 error "import should have failed"
1044 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
1047 run_test 99b "Invalid value for Multi-Rail in yaml import"
1051 local ip=$(ip addr show dev $if | awk '/ inet /{print $2}')
1059 if ! lsmod | grep -q ksocklnd ; then
1060 load_module ../lnet/klnds/socklnd/ksocklnd ||
1061 error "Can't load ksocklnd.ko"
1064 do_lnetctl net add --net ${net} --if ${if} ||
1065 error "Failed to add net ${net} on if ${if}"
1068 compare_route_add() {
1072 local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
1074 do_lnetctl route add --net ${rnet} --gateway ${gw} ||
1075 error "route add failed $?"
1076 # CPT configuration is pruned from the exported yaml, since the default
1077 # can vary across test systems (unlike default values for things like
1078 # peer_credits, peer_timeout, etc.)
1079 $LNETCTL export --backup | grep -v CPT > $actual ||
1080 error "export failed $?"
1081 validate_gateway_nids
1086 reinit_dlc || return $?
1087 add_net "tcp" "${INTERFACES[0]}"
1088 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
1097 peer_buffer_credits: 0
1103 gateway: 7.7.7.7@tcp
1106 health_sensitivity: 1
1108 - primary nid: 7.7.7.7@tcp
1114 compare_route_add "tcp7" "7.7.7.7@tcp" || return $?
1117 run_test 100 "Add route with single gw (tcp)"
1120 reinit_dlc || return $?
1121 add_net "tcp" "${INTERFACES[0]}"
1122 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
1131 peer_buffer_credits: 0
1137 gateway: 8.8.8.10@tcp
1140 health_sensitivity: 1
1142 gateway: 8.8.8.9@tcp
1145 health_sensitivity: 1
1147 gateway: 8.8.8.8@tcp
1150 health_sensitivity: 1
1152 - primary nid: 8.8.8.9@tcp
1156 - primary nid: 8.8.8.10@tcp
1160 - primary nid: 8.8.8.8@tcp
1166 compare_route_add "tcp8" "8.8.8.[8-10]@tcp"
1168 run_test 101 "Add route with multiple gw (tcp)"
1170 compare_route_del() {
1174 local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
1176 do_lnetctl route del --net ${rnet} --gateway ${gw} ||
1177 error "route del failed $?"
1178 $LNETCTL export --backup > $actual ||
1179 error "export failed $?"
1180 validate_gateway_nids
1184 reinit_dlc || return $?
1185 add_net "tcp" "${INTERFACES[0]}"
1186 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-expected.yaml
1187 do_lnetctl route add --net tcp102 --gateway 102.102.102.102@tcp ||
1188 error "route add failed $?"
1189 compare_route_del "tcp102" "102.102.102.102@tcp"
1191 run_test 102 "Delete route with single gw (tcp)"
1194 reinit_dlc || return $?
1195 add_net "tcp" "${INTERFACES[0]}"
1196 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-expected.yaml
1197 do_lnetctl route add --net tcp103 \
1198 --gateway 103.103.103.[103-120/4]@tcp ||
1199 error "route add failed $?"
1200 compare_route_del "tcp103" "103.103.103.[103-120/4]@tcp"
1202 run_test 103 "Delete route with multiple gw (tcp)"
1205 local tyaml="$TMP/sanity-lnet-$testnum-expected.yaml"
1207 reinit_dlc || return $?
1209 # Default value is '3'
1210 local val=$($LNETCTL global show | awk '/response_tracking/{print $NF}')
1212 error "Expect 3 found $val"
1214 echo "Set < 0; Should fail"
1215 do_lnetctl set response_tracking -1 &&
1216 error "should have failed $?"
1218 reinit_dlc || return $?
1221 response_tracking: -10
1223 do_lnetctl import < $tyaml &&
1224 error "should have failed $?"
1226 echo "Check valid values; Should succeed"
1228 for ((i = 0; i < 4; i++)); do
1229 reinit_dlc || return $?
1230 do_lnetctl set response_tracking $i ||
1231 error "should have succeeded $?"
1232 $LNETCTL global show | grep -q "response_tracking: $i" ||
1233 error "Failed to set response_tracking to $i"
1234 reinit_dlc || return $?
1237 response_tracking: $i
1239 do_lnetctl import < $tyaml ||
1240 error "should have succeeded $?"
1241 $LNETCTL global show | grep -q "response_tracking: $i" ||
1242 error "Failed to set response_tracking to $i"
1245 reinit_dlc || return $?
1246 echo "Set > 3; Should fail"
1247 do_lnetctl set response_tracking 4 &&
1248 error "should have failed $?"
1250 reinit_dlc || return $?
1253 response_tracking: 10
1255 do_lnetctl import < $tyaml &&
1256 error "should have failed $?"
1259 run_test 104 "Set/check response_tracking param"
1262 reinit_dlc || return $?
1263 add_net "tcp" "${INTERFACES[0]}"
1264 do_lnetctl route add --net tcp105 --gateway 105.105.105.105@tcp ||
1265 error "route add failed $?"
1266 do_lnetctl peer add --prim 105.105.105.105@tcp &&
1267 error "peer add should fail"
1271 run_test 105 "Adding duplicate GW peer should fail"
1274 reinit_dlc || return $?
1275 add_net "tcp" "${INTERFACES[0]}"
1276 do_lnetctl route add --net tcp106 --gateway 106.106.106.106@tcp ||
1277 error "route add failed $?"
1278 do_lnetctl peer del --prim 106.106.106.106@tcp &&
1279 error "peer del should fail"
1283 run_test 106 "Deleting GW peer should fail"
1286 cleanup_lnet || exit 1
1287 load_lnet "networks=\"\""
1288 do_ns $LNETCTL lnet configure --all || exit 1
1289 $LNETCTL net show --net tcp | grep -q "nid: ${FAKE_IP}@tcp$"
1291 run_test 200 "load lnet w/o module option, configure in a non-default namespace"
1294 cleanup_lnet || exit 1
1295 load_lnet "networks=tcp($FAKE_IF)"
1296 do_ns $LNETCTL lnet configure --all || exit 1
1297 $LNETCTL net show --net tcp | grep -q "nid: ${FAKE_IP}@tcp$"
1299 run_test 201 "load lnet using networks module options in a non-default namespace"
1302 cleanup_lnet || exit 1
1303 load_lnet "networks=\"\" ip2nets=\"tcp0($FAKE_IF) ${FAKE_IP}\""
1304 do_ns $LNETCTL lnet configure --all || exit 1
1305 $LNETCTL net show | grep -q "nid: ${FAKE_IP}@tcp$"
1307 run_test 202 "load lnet using ip2nets in a non-default namespace"
1310 ### Add the interfaces in the target namespace
1313 cleanup_lnet || exit 1
1315 do_lnetctl lnet configure || exit 1
1316 do_ns $LNETCTL net add --net tcp0 --if $FAKE_IF
1318 run_test 203 "add a network using an interface in the non-default namespace"
1320 LNET_PARAMS_FILE="$TMP/$TESTSUITE.parameters"
1321 function save_lnet_params() {
1322 $LNETCTL global show | egrep -v '^global:$' |
1323 sed 's/://' > $LNET_PARAMS_FILE
1326 function restore_lnet_params() {
1328 while read param value; do
1329 [[ $param == max_intf ]] && continue
1330 [[ $param == lnd_timeout ]] && continue
1331 $LNETCTL set ${param} ${value} ||
1332 error "Failed to restore ${param} to ${value}"
1333 done < $LNET_PARAMS_FILE
1336 function lnet_health_pre() {
1339 # Lower transaction timeout to speed up test execution
1340 $LNETCTL set transaction_timeout 10 ||
1341 error "Failed to set transaction_timeout $?"
1343 # Increase recovery interval so we have time to capture health values
1344 $LNETCTL set recovery_interval 20 ||
1345 error "Failed to set recovery_interval $?"
1347 RETRY_PARAM=$($LNETCTL global show | awk '/retry_count/{print $NF}')
1348 RSND_PRE=$($LNETCTL stats show | awk '/resend_count/{print $NF}')
1349 LO_HVAL_PRE=$($LNETCTL net show -v 2 | awk '/health value/{print $NF}' |
1350 xargs echo | sed 's/ /+/g' | bc -l)
1352 local my_nid=$($LCTL list_nids | head -n 1)
1354 RMT_HVAL_PRE=$($LNETCTL peer show --nid $my_nid -v 2 2>/dev/null |
1355 awk '/health value/{print $NF}' | xargs echo |
1356 sed 's/ /+/g' | bc -l)
1358 # Might not have any peers so initialize to zero.
1359 RMT_HVAL_PRE=${RMT_HVAL_PRE:-0}
1364 function lnet_health_post() {
1365 RSND_POST=$($LNETCTL stats show | awk '/resend_count/{print $NF}')
1366 LO_HVAL_POST=$($LNETCTL net show -v 2 |
1367 awk '/health value/{print $NF}' |
1368 xargs echo | sed 's/ /+/g' | bc -l)
1370 local my_nid=$($LCTL list_nids | head -n 1)
1372 RMT_HVAL_POST=$($LNETCTL peer show --nid $my_nid -v 2 2>/dev/null |
1373 awk '/health value/{print $NF}' | xargs echo |
1374 sed 's/ /+/g' | bc -l)
1376 # Might not have any peers so initialize to zero.
1377 RMT_HVAL_POST=${RMT_HVAL_POST:-0}
1380 echo "Pre resends: $RSND_PRE" &&
1381 echo "Post resends: $RSND_POST" &&
1382 echo "Resends delta: $((RSND_POST - RSND_PRE))" &&
1383 echo "Pre local health: $LO_HVAL_PRE" &&
1384 echo "Post local health: $LO_HVAL_POST" &&
1385 echo "Pre remote health: $RMT_HVAL_PRE" &&
1386 echo "Post remote health: $RMT_HVAL_POST"
1393 function check_no_resends() {
1394 echo "Check that no resends took place"
1395 [[ $RSND_POST -ne $RSND_PRE ]] &&
1396 error "Found resends: $RSND_POST != $RSND_PRE"
1401 function check_resends() {
1402 local delta=$((RSND_POST - RSND_PRE))
1404 echo "Check that $RETRY_PARAM resends took place"
1405 [[ $delta -ne $RETRY_PARAM ]] &&
1406 error "Expected $RETRY_PARAM resends found $delta"
1411 function check_no_local_health() {
1412 echo "Check that local NI health is unchanged"
1413 [[ $LO_HVAL_POST -ne $LO_HVAL_PRE ]] &&
1414 error "Local health changed: $LO_HVAL_POST != $LO_HVAL_PRE"
1419 function check_local_health() {
1420 echo "Check that local NI health has been changed"
1421 [[ $LO_HVAL_POST -eq $LO_HVAL_PRE ]] &&
1422 error "Local health unchanged: $LO_HVAL_POST == $LO_HVAL_PRE"
1427 function check_no_remote_health() {
1428 echo "Check that remote NI health is unchanged"
1429 [[ $RMT_HVAL_POST -ne $RMT_HVAL_PRE ]] &&
1430 error "Remote health changed: $RMT_HVAL_POST != $RMT_HVAL_PRE"
1435 function check_remote_health() {
1436 echo "Check that remote NI health has been changed"
1437 [[ $RMT_HVAL_POST -eq $RMT_HVAL_PRE ]] &&
1438 error "Remote health unchanged: $RMT_HVAL_POST == $RMT_HVAL_PRE"
1443 # See lnet/lnet/lib-msg.c:lnet_health_check()
1444 LNET_LOCAL_RESEND_STATUSES="local_interrupt local_dropped local_aborted"
1445 LNET_LOCAL_RESEND_STATUSES+=" local_no_route local_timeout"
1446 LNET_LOCAL_NO_RESEND_STATUSES="local_error"
1448 reinit_dlc || return $?
1449 add_net "tcp" "${INTERFACES[0]}" || return $?
1451 lnet_health_pre || return $?
1454 for hstatus in ${LNET_LOCAL_RESEND_STATUSES} \
1455 ${LNET_LOCAL_NO_RESEND_STATUSES}; do
1456 echo "Simulate $hstatus"
1457 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1458 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1459 error "Should have failed"
1460 $LCTL net_drop_del -a
1465 check_no_resends || return $?
1466 check_no_local_health || return $?
1470 run_test 204 "Check no health or resends for single-rail local failures"
1474 for hstatus in ${LNET_LOCAL_RESEND_STATUSES}; do
1475 reinit_dlc || return $?
1476 add_net "tcp" "${INTERFACES[0]}" || return $?
1477 add_net "tcp1" "${INTERFACES[0]}" || return $?
1479 echo "Simulate $hstatus"
1482 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1483 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e ${hstatus}
1484 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1485 error "Should have failed"
1486 $LCTL net_drop_del -a
1490 check_resends || return $?
1491 check_local_health || return $?
1494 for hstatus in ${LNET_LOCAL_NO_RESEND_STATUSES}; do
1495 reinit_dlc || return $?
1496 add_net "tcp" "${INTERFACES[0]}" || return $?
1497 add_net "tcp1" "${INTERFACES[0]}" || return $?
1499 echo "Simulate $hstatus"
1500 lnet_health_pre || return $?
1502 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1503 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e ${hstatus}
1504 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1505 error "Should have failed"
1506 $LCTL net_drop_del -a
1510 check_no_resends || return $?
1511 check_local_health || return $?
1516 run_test 205 "Check health and resends for multi-rail local failures"
1518 # See lnet/lnet/lib-msg.c:lnet_health_check()
1519 LNET_REMOTE_RESEND_STATUSES="remote_dropped"
1520 LNET_REMOTE_NO_RESEND_STATUSES="remote_error remote_timeout"
1522 reinit_dlc || return $?
1523 add_net "tcp" "${INTERFACES[0]}" || return $?
1525 do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1526 error "failed to discover myself"
1528 lnet_health_pre || return $?
1531 for hstatus in ${LNET_REMOTE_RESEND_STATUSES} \
1532 ${LNET_REMOTE_NO_RESEND_STATUSES}; do
1533 echo "Simulate $hstatus"
1534 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1535 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1536 error "Should have failed"
1537 $LCTL net_drop_del -a
1542 check_no_resends || return $?
1543 check_no_local_health || return $?
1544 check_no_remote_health || return $?
1548 run_test 206 "Check no health or resends for single-rail remote failures"
1552 for hstatus in ${LNET_REMOTE_RESEND_STATUSES}; do
1553 reinit_dlc || return $?
1554 add_net "tcp" "${INTERFACES[0]}" || return $?
1555 add_net "tcp1" "${INTERFACES[0]}" || return $?
1557 do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1558 error "failed to discover myself"
1560 echo "Simulate $hstatus"
1561 lnet_health_pre || return $?
1562 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1563 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e ${hstatus}
1564 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1565 error "Should have failed"
1566 $LCTL net_drop_del -a
1570 check_resends || return $?
1571 check_no_local_health || return $?
1572 check_remote_health || return $?
1574 for hstatus in ${LNET_REMOTE_NO_RESEND_STATUSES}; do
1575 reinit_dlc || return $?
1576 add_net "tcp" "${INTERFACES[0]}" || return $?
1577 add_net "tcp1" "${INTERFACES[0]}" || return $?
1579 do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1580 error "failed to discover myself"
1582 echo "Simulate $hstatus"
1583 lnet_health_pre || return $?
1584 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1585 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e ${hstatus}
1586 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1587 error "Should have failed"
1588 $LCTL net_drop_del -a
1592 check_no_resends || return $?
1593 check_no_local_health || return $?
1594 check_remote_health || return $?
1599 run_test 207 "Check health and resends for multi-rail remote errors"
1601 test_208_load_and_check_lnet() {
1605 local num_expected=1
1607 load_lnet "networks=\"\" ip2nets=\"${ip2nets_str}\""
1610 error "Failed to load LNet with ip2nets \"${ip2nets_str}\""
1616 nids=( $($LCTL list_nids) )
1618 [[ ${#nids[@]} -ne ${num_expected} ]] &&
1619 error "Expect ${num_expected} NIDs found ${#nids[@]}"
1621 [[ ${nids[0]} == ${p_nid} ]] ||
1622 error "Expect NID \"${p_nid}\" found \"${nids[0]}\""
1624 [[ -n $s_nid ]] && [[ ${nids[1]} != ${s_nid} ]] &&
1625 error "Expect second NID \"${s_nid}\" found \"${nids[1]}\""
1627 $LCTL net down &>/dev/null
1632 cleanup_netns || error "Failed to cleanup netns before test execution"
1633 cleanup_lnet || error "Failed to unload modules before test execution"
1634 setup_fakeif || error "Failed to add fake IF"
1636 have_interface "$FAKE_IF" ||
1637 error "Expect $FAKE_IF configured but not found"
1639 local if0_ip=$(ip --oneline addr show dev ${INTERFACES[0]} |
1640 awk '/inet /{print $4}' |
1642 if0_ip=($(echo "${if0_ip[@]}" | tr ' ' '\n' | uniq | tr '\n' ' '))
1643 local ip2nets_str="tcp(${INTERFACES[0]}) $if0_ip"
1645 echo "Configure single NID \"$ip2nets_str\""
1646 test_208_load_and_check_lnet "${ip2nets_str}" "${if0_ip}@tcp"
1648 ip2nets_str="tcp(${INTERFACES[0]}) $if0_ip; tcp1($FAKE_IF) $FAKE_IP"
1649 echo "Configure two NIDs; two NETs \"$ip2nets_str\""
1650 test_208_load_and_check_lnet "${ip2nets_str}" "${if0_ip}@tcp" \
1653 ip2nets_str="tcp(${INTERFACES[0]}) $if0_ip; tcp($FAKE_IF) $FAKE_IP"
1654 echo "Configure two NIDs; one NET \"$ip2nets_str\""
1655 test_208_load_and_check_lnet "${ip2nets_str}" "${if0_ip}@tcp" \
1657 local addr1=( ${if0_ip//./ } )
1658 local addr2=( ${FAKE_IP//./ } )
1659 local range="[${addr1[0]},${addr2[0]}]"
1662 for i in $(seq 1 3); do
1663 range+=".[${addr1[$i]},${addr2[$i]}]"
1665 ip2nets_str="tcp(${INTERFACES[0]},${FAKE_IF}) ${range}"
1667 echo "Configured two NIDs; one NET alt syntax \"$ip2nets_str\""
1668 test_208_load_and_check_lnet "${ip2nets_str}" "${if0_ip}@tcp" \
1673 echo "alt syntax with missing IF \"$ip2nets_str\""
1674 load_lnet "networks=\"\" ip2nets=\"${ip2nets_str}\""
1676 echo "$LCTL net up should fail"
1678 error "LNet bringup should have failed"
1682 run_test 208 "Test various kernel ip2nets configurations"
1685 reinit_dlc || return $?
1686 add_net "tcp" "${INTERFACES[0]}" || return $?
1688 do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1689 error "failed to discover myself"
1691 echo "Simulate network_timeout w/SR config"
1694 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e network_timeout
1695 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1696 error "Should have failed"
1697 $LCTL net_drop_del -a
1701 check_no_resends || return $?
1702 check_no_local_health || return $?
1703 check_no_remote_health || return $?
1705 reinit_dlc || return $?
1706 add_net "tcp" "${INTERFACES[0]}" || return $?
1707 add_net "tcp1" "${INTERFACES[0]}" || return $?
1709 do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1710 error "failed to discover myself"
1712 echo "Simulate network_timeout w/MR config"
1715 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e network_timeout
1716 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e network_timeout
1717 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1718 error "Should have failed"
1719 $LCTL net_drop_del -a
1723 check_no_resends || return $?
1724 check_local_health || return $?
1725 check_remote_health || return $?
1729 run_test 209 "Check health, but not resends, for network timeout"
1731 check_nid_in_recovq() {
1732 local recovq=$($LNETCTL debug recovery $1)
1734 local nids=$($LCTL list_nids | xargs echo)
1738 echo "Check recovery queue"
1740 if [[ $(grep -c 'nid-'<<<$recovq) -ne $expect ]]; then
1741 error "Expect $expect NIDs found: \"$recovq\""
1744 [[ $expect -eq 0 ]] && return 0
1746 for nid in ${nids}; do
1747 grep -q "nid-0: $nid"<<<$recovq &&
1752 error "Didn't find local NIDs in recovery queue: \"$recovq\""
1758 # First enqueue happens at time 0.
1759 # 2nd at 0 + 2^0 = 1
1760 # 3rd at 1 + 2^1 = 3
1761 # 4th at 3 + 2^2 = 7
1762 # 5th at 7 + 2^3 = 15
1763 # e.g. after 10 seconds we would expect to have seen the 4th enqueue,
1764 # (3 pings sent, 4th about to happen) and the 5th enqueue is yet to
1766 # If the recovery limit is 10 seconds, then when the 5th enqueue happens
1767 # we expect the peer NI to have aged out, so it will not actually be
1769 check_ping_count() {
1773 echo "Check ping counts:"
1775 if [[ $queue == "ni" ]]; then
1776 $LNETCTL net show -v 2 | egrep 'nid|health value|ping'
1777 ping_count=( $($LNETCTL net show -v 2 |
1778 awk '/ping_count/{print $NF}') )
1779 elif [[ $queue == "peer_ni" ]]; then
1780 $LNETCTL peer show -v 2 | egrep 'nid|health value|ping'
1781 ping_count=( $($LNETCTL peer show -v 2 |
1782 awk '/ping_count/{print $NF}') )
1784 error "Unrecognized queue \"$queue\""
1790 for count in ${ping_count[@]}; do
1791 if [[ $count -eq $expect ]]; then
1792 if [[ $expect -ne 0 ]] && $found ; then
1793 error "Found more than one interface matching \"$expect\" ping count"
1796 echo "Expect ping count \"$expect\" found \"$count\""
1799 elif [[ $count -ne 0 ]]; then
1800 error "Found interface with ping count \"$count\" but expect \"$expect\""
1809 reinit_dlc || return $?
1810 add_net "tcp" "${INTERFACES[0]}" || return $?
1811 add_net "tcp1" "${INTERFACES[0]}" || return $?
1813 local prim_nid=$($LCTL list_nids | head -n 1)
1815 do_lnetctl discover $prim_nid ||
1816 error "failed to discover myself"
1818 # Set recovery limit to 10 seconds.
1819 do_lnetctl set recovery_limit 10 ||
1820 error "failed to set recovery_limit"
1822 $LCTL set_param debug=+net
1823 # Use local_error so LNet doesn't attempt to resend the discovery ping
1824 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e local_error
1825 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e local_error
1826 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1827 error "Expected discovery to fail"
1830 check_nid_in_recovq "-l" 1
1831 check_ping_count "ni" "2"
1835 check_nid_in_recovq "-l" 1
1836 check_ping_count "ni" "3"
1838 $LCTL net_drop_del -a
1842 run_test 210 "Local NI recovery checks"
1845 reinit_dlc || return $?
1846 add_net "tcp" "${INTERFACES[0]}" || return $?
1847 add_net "tcp1" "${INTERFACES[0]}" || return $?
1849 local prim_nid=$($LCTL list_nids | head -n 1)
1851 do_lnetctl discover $prim_nid ||
1852 error "failed to discover myself"
1854 # Set recovery limit to 10 seconds.
1855 do_lnetctl set recovery_limit 10 ||
1856 error "failed to set recovery_limit"
1858 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e remote_error
1859 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e remote_error
1861 # Set health to 0 on one interface. This forces it onto the recovery
1863 $LNETCTL peer set --nid $prim_nid --health 0
1865 # After 5 seconds, we expect the peer NI to still be in recovery
1867 check_nid_in_recovq "-p" 1
1868 check_ping_count "peer_ni" "2"
1870 # After 15 seconds, the peer NI should have been fully processed out of
1871 # the recovery queue. We'll allow a total of 17 seconds to account for
1872 # differences in sleeping for whole seconds vs. the more accurate time
1873 # keeping that is done in the recovery code.
1875 check_nid_in_recovq "-p" 0
1876 check_ping_count "peer_ni" "4"
1878 $LCTL net_drop_del -a
1880 # Set health to force it back onto the recovery queue. Set to 500 means
1881 # in 5 seconds it should be back at maximum value. We'll wait a couple
1882 # more seconds than that to be safe.
1883 # NB: we reset the recovery limit to 0 (indefinite) so the peer NI is
1885 do_lnetctl set recovery_limit 0 ||
1886 error "failed to set recovery_limit"
1888 $LNETCTL peer set --nid $prim_nid --health 500
1890 check_nid_in_recovq "-p" 1
1891 check_ping_count "peer_ni" "2"
1895 check_nid_in_recovq "-p" 0
1896 check_ping_count "peer_ni" "0"
1900 run_test 211 "Remote NI recovery checks"
1903 local rnodes=$(remote_nodes_list)
1904 [[ -z $rnodes ]] && skip "Need at least 1 remote node"
1906 cleanup_lnet || error "Failed to cleanup before test execution"
1908 # Loading modules should configure LNet with the appropriate
1909 # test-framework configuration
1910 load_modules || error "Failed to load modules"
1912 local my_nid=$($LCTL list_nids | head -n 1)
1914 error "Failed to get primary NID for local host $HOSTNAME"
1916 local rnode=$(awk '{print $1}' <<<$rnodes)
1917 local rnodenids=$(do_node $rnode $LCTL list_nids | xargs echo)
1920 if [[ -z $rnodenids ]]; then
1921 do_rpc_nodes $rnode load_modules_local
1923 rnodenids=$(do_node $rnode $LCTL list_nids | xargs echo)
1926 local rnodepnid=$(awk '{print $1}' <<< $rnodenids)
1928 [[ -z $rnodepnid ]] &&
1929 error "Failed to get primary NID for remote host $rnode"
1931 log "Initial discovery"
1932 do_lnetctl discover --force $rnodepnid ||
1933 error "Failed to discover $rnodepnid"
1935 do_node $rnode "$LNETCTL discover --force $my_nid" ||
1936 error "$rnode failed to discover $my_nid"
1938 log "Fail local discover ping to set LNET_PEER_REDISCOVER flag"
1939 $LCTL net_drop_add -s "*@$NETTYPE" -d "*@$NETTYPE" -r 1 -e local_error
1940 do_lnetctl discover --force $rnodepnid &&
1941 error "Discovery should have failed"
1942 $LCTL net_drop_del -a
1945 for nid in $rnodenids; do
1946 # We need GET (PING) delay just long enough so we can trigger
1947 # discovery on the remote peer
1948 $LCTL net_delay_add -s "*@$NETTYPE" -d $nid -r 1 -m GET -l 3
1949 $LCTL net_drop_add -s "*@$NETTYPE" -d $nid -r 1 -m GET -e local_error
1950 # We need PUT (PUSH) delay just long enough so we can process
1952 $LCTL net_delay_add -s "*@$NETTYPE" -d $nid -r 1 -m PUT -l 6
1955 log "Force $HOSTNAME to discover $rnodepnid (in background)"
1956 # We want to get a PING sent that we know will eventually fail.
1957 # The delay rules we added will ensure the ping is not sent until
1958 # the PUSH is also in flight (see below), and the drop rule ensures that
1959 # when the PING is eventually sent it will error out
1960 do_lnetctl discover --force $rnodepnid &
1963 # We want a discovery PUSH from rnode to put rnode back on our
1964 # discovery queue. This should cause us to try and send a PUSH to rnode
1965 # while the PING is still outstanding.
1966 log "Force $rnode to discover $my_nid"
1967 do_node $rnode $LNETCTL discover --force $my_nid
1969 # At this point we'll have both PING_SENT and PUSH_SENT set for the
1970 # rnode peer. Wait for the PING to error out which should terminate the
1971 # discovery process that we backgrounded.
1972 log "Wait for $pid1"
1974 log "Finished wait on $pid1"
1976 # The PING send failure clears the PING_SENT flag and puts the peer back
1977 # on the discovery queue. When discovery thread processes the peer it
1978 # will mistakenly clear the PUSH_SENT flag (and set PUSH_FAILED).
1979 # Discovery will then complete for this peer even though we have an
1981 # When PUSH is actually unlinked it will be forced back onto the
1982 # discovery queue, but we no longer have a ref on the peer. When
1983 # discovery completes again, we'll trip the ASSERT in
1984 # lnet_destroy_peer_locked()
1986 # Delete the delay rules to send the PUSH
1987 $LCTL net_delay_del -a
1988 # Delete the drop rules
1989 $LCTL net_drop_del -a
1992 error "Failed to unload modules"
1994 do_rpc_nodes $rnode unload_modules_local ||
1995 error "Failed to unload modules on $rnode"
2000 run_test 212 "Check discovery refcount loss bug (LU-14627)"
2003 cleanup_netns || error "Failed to cleanup netns before test execution"
2004 cleanup_lnet || error "Failed to unload modules before test execution"
2006 setup_fakeif || error "Failed to add fake IF"
2007 have_interface "$FAKE_IF" ||
2008 error "Expect $FAKE_IF configured but not found"
2010 reinit_dlc || return $?
2012 add_net "tcp" "${INTERFACES[0]}" || return $?
2013 add_net "tcp" "$FAKE_IF" || return $?
2015 local nid1=$(lctl list_nids | head -n 1)
2016 local nid2=$(lctl list_nids | tail --lines 1)
2018 [[ $(lctl which_nid $nid1 $nid2) == $nid1 ]] ||
2019 error "Expect nid1 \"$nid1\" to be preferred"
2021 [[ $(lctl which_nid $nid2 $nid1) == $nid2 ]] ||
2022 error "Expect nid2 \"$nid2\" to be preferred"
2026 run_test 213 "Check LNetDist calculation for multiple local NIDs"
2028 function check_ni_status() {
2032 local status=$($LNETCTL net show |
2034 awk '/status/{print $NF}')
2036 echo "NI ${nid} expect status \"${expect}\" found \"${status}\""
2037 if [[ $status != $expect ]]; then
2038 error "Error: Expect NI status \"$expect\" for NID \"$nid\" but found \"$status\""
2045 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
2047 cleanup_netns || error "Failed to cleanup netns before test execution"
2048 cleanup_lnet || error "Failed to unload modules before test execution"
2050 setup_fakeif || error "Failed to add fake IF"
2051 have_interface "$FAKE_IF" ||
2052 error "Expect $FAKE_IF configured but not found"
2054 reinit_dlc || return $?
2056 add_net "tcp" "eth0" || return $?
2057 add_net "tcp" "$FAKE_IF" || return $?
2059 local nid1=$(lctl list_nids | head -n 1)
2060 local nid2=$(lctl list_nids | tail --lines 1)
2062 check_ni_status "0@lo" up
2063 check_ni_status "$nid1" up
2064 check_ni_status "$nid2" up
2066 echo "Set $FAKE_IF down"
2067 echo "ip link set dev $FAKE_IF down"
2068 ip link set dev $FAKE_IF down
2069 check_ni_status "0@lo" up
2070 check_ni_status "$nid1" up
2071 check_ni_status "$nid2" down
2073 run_test 214 "Check local NI status when link is downed"
2079 $LNETCTL net show -v 2 |
2080 egrep -e nid -e $stat |
2082 awk '/'$stat':/{print $NF}'
2087 for nidvar in nid1 nid2; do
2088 for stat in send_count recv_count; do
2089 s=$(get_ni_stat ${!nidvar} $stat)
2090 eval ${nidvar}_pre_${stat}=$s
2097 for nidvar in nid1 nid2; do
2098 for stat in send_count recv_count; do
2099 s=$(get_ni_stat ${!nidvar} $stat)
2100 eval ${nidvar}_post_${stat}=$s
2110 eval pre=\${${nidvar}_pre_${stat}}
2111 eval post=\${${nidvar}_post_${stat}}
2113 echo "${!nidvar} pre ${stat} $pre post ${stat} $post"
2115 [[ $pre -ne $post ]]
2119 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
2121 cleanup_netns || error "Failed to cleanup netns before test execution"
2122 cleanup_lnet || error "Failed to unload modules before test execution"
2124 reinit_dlc || return $?
2126 add_net "tcp1" "eth0" || return $?
2127 add_net "tcp2" "eth0" || return $?
2129 local nid1=$($LCTL list_nids | head -n 1)
2130 local nid2=$($LCTL list_nids | tail --lines 1)
2132 do_lnetctl peer add --prim $nid1 --nid $nid2 ||
2133 error "Failed to add peer"
2137 for nidvarA in nid1 nid2; do
2140 for nidvarB in nid1 nid2; do
2141 [[ $nidvarA == $nidvarB ]] && continue
2145 echo "$LNETCTL ping $dst x $npings"
2146 for i in $(seq 1 $npings); do
2147 $LNETCTL ping $dst &>/dev/null ||
2148 error "$LNETCTL ping $dst failed"
2153 # No source specified, sends to either NID should cause
2154 # counts to increase across both NIs
2155 for nidvar in nid1 nid2; do
2156 for stat in send_count recv_count; do
2157 ni_stat_changed $nidvar $stat ||
2158 error "$stat unchanged for ${!nidvar}"
2164 echo "$LNETCTL ping --source $src $dst x $npings"
2165 for i in $(seq 1 $npings); do
2166 $LNETCTL ping --source $src $dst &>/dev/null ||
2167 error "$LNETCTL ping --source $src $dst failed"
2172 # src nid == dest nid means stats for the _other_ NI
2173 # should be unchanged
2174 for nidvar in nid1 nid2; do
2175 for stat in send_count recv_count; do
2176 if [[ ${!nidvar} == $src ]]; then
2177 ni_stat_changed $nidvar $stat ||
2178 error "$stat unchanged for ${!nidvar}"
2180 ni_stat_changed $nidvar $stat &&
2181 error "$stat changed for ${!nidvar}"
2186 # Double number of pings for next iteration because the net
2187 # sequence numbers will have diverged
2188 npings=$(($npings * 2))
2193 run_test 215 "Test lnetctl ping --source option"
2197 echo "Check valid values; Should succeed"
2201 for ((i = 4; i < 16; i+=1)); do
2202 reinit_dlc || return $?
2203 add_net "tcp" "${INTERFACES[0]}" || return $?
2204 do_lnetctl net set --all --conns-per-peer $i ||
2205 error "should have succeeded $?"
2206 $LNETCTL net show -v 1 | grep -q "conns_per_peer: $i" ||
2207 error "failed to set conns-per-peer to $i"
2208 lnid="$(lctl list_nids | head -n 1)"
2209 do_lnetctl ping "$lnid" ||
2210 error "failed to ping myself"
2212 # "lctl --net tcp conn_list" prints the list of active
2213 # connections. Since we're pinging ourselves, there should be
2214 # 2 Control connections plus 2*conns_per_peer connections
2215 # created (one Bulk Input, one Bulk Output in each pair).
2216 # Here's the sample output for conns_per_peer set to 1:
2217 # 12345-1.1.1.1@tcp I[0]host01->host01:988 2626560/1061296 nonagle
2218 # 12345-1.1.1.1@tcp O[0]host01->host01:1022 2626560/1061488 nonagle
2219 # 12345-1.1.1.1@tcp C[0]host01->host01:988 2626560/1061296 nonagle
2220 # 12345-1.1.1.1@tcp C[0]host01->host01:1023 2626560/1061488 nonagle
2221 cmd="printf 'network tcp\nconn_list\n' | lctl | grep -c '$lnid'"
2223 # Expect 2+conns_per_peer*2 connections. Wait no longer
2225 wait_update $HOSTNAME "$cmd" "$((2+i*2))" 2 ||
2226 error "expected number of tcp connections $((2+i*2))"
2229 reinit_dlc || return $?
2230 add_net "tcp" "${INTERFACES[0]}" || return $?
2231 echo "Set > 127; Should fail"
2232 do_lnetctl net set --all --conns-per-peer 128 &&
2233 error "should have failed $?"
2235 reinit_dlc || return $?
2236 add_net "tcp" "${INTERFACES[0]}" || return $?
2237 echo "Set < 0; Should be ignored"
2238 do_lnetctl net set --all --conns-per-peer -1 ||
2239 error "should have succeeded $?"
2240 $LNETCTL net show -v 1 | grep -q "conns_per_peer: 1" ||
2241 error "Did not stay at default"
2243 run_test 230 "Test setting conns-per-peer"
2245 ### Test that linux route is added for each ni
2247 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
2248 reinit_dlc || return $?
2249 add_net "tcp" "eth0" || return $?
2250 ip route show table eth0 | grep -q "eth0"
2252 run_test 250 "test that linux routes are added"
2257 local out=$TMP/$tfile
2258 local prefix=/usr/include/linux/lnet
2260 # We use a hard coded prefix so that this test will not fail
2263 if ! which $CC > /dev/null 2>&1; then
2264 skip_env "$CC is not installed"
2267 cleanup_lnet || exit 1
2270 local cc_args="-Wall -Werror -std=c99 -c -x c /dev/null -o $out"
2271 if ! [[ -d $prefix ]]; then
2272 # Assume we're running in tree and fixup the include path.
2273 prefix=$LUSTRE/../lnet/include/uapi/linux/lnet
2274 cc_args+=" -I $LUSTRE/../lnet/include/uapi"
2277 for header in $prefix/*.h; do
2278 if ! [[ -f "$header" ]]; then
2282 echo "$CC $cc_args -include $header"
2283 $CC $cc_args -include $header ||
2284 error "cannot compile '$header'"
2288 run_test 300 "packaged LNet UAPI headers can be compiled"