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*
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 stack_trap 'cleanup_testsuite' EXIT
254 load_module ../lnet/lnet/lnet || error "Failed to load module rc = $?"
255 do_lnetctl lnet configure || error "lnet configure failed rc = $?"
257 reinit_dlc || return $?
258 do_lnetctl import < ${GLOBAL_YAML_FILE} || error "Import failed $?"
259 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
260 create_base_yaml_file
261 compare_yaml_files || error "Configuration changed after import"
263 run_test 0 "Export empty config, import the config, compare"
266 local prim_nid="${1:+--prim_nid $1}"
267 local nid="${2:+--nid $2}"
269 local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
271 do_lnetctl peer add ${prim_nid} ${nid} || error "peer add failed $?"
272 $LNETCTL export --backup > $actual || error "export failed $?"
278 reinit_dlc || return $?
279 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
281 - primary nid: 1.1.1.1@tcp
287 compare_peer_add "1.1.1.1@tcp"
289 run_test 1 "Add peer with single nid (tcp)"
292 reinit_dlc || return $?
293 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
295 - primary nid: 2.2.2.2@o2ib
301 compare_peer_add "2.2.2.2@o2ib"
303 run_test 2 "Add peer with single nid (o2ib)"
306 reinit_dlc || return $?
307 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
309 - primary nid: 3.3.3.3@tcp
316 compare_peer_add "3.3.3.3@tcp" "3.3.3.3@o2ib"
318 run_test 3 "Add peer with tcp primary o2ib secondary"
321 reinit_dlc || return $?
322 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
324 - primary nid: 4.4.4.4@tcp
333 echo "Add peer with nidrange (tcp)"
334 compare_peer_add "4.4.4.4@tcp" "4.4.4.[1-3]@tcp"
336 echo "Add peer with nidrange that overlaps primary nid (tcp)"
337 compare_peer_add "4.4.4.4@tcp" "4.4.4.[1-4]@tcp"
339 run_test 4 "Add peer with nidrange (tcp)"
342 reinit_dlc || return $?
343 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
345 - primary nid: 5.5.5.5@o2ib
355 echo "Add peer with nidrange (o2ib)"
356 compare_peer_add "5.5.5.5@o2ib" "5.5.5.[1-4]@o2ib"
358 echo "Add peer with nidranage that overlaps primary nid (o2ib)"
359 compare_peer_add "5.5.5.5@o2ib" "5.5.5.[1-4]@o2ib"
361 run_test 5 "Add peer with nidrange (o2ib)"
364 reinit_dlc || return $?
365 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
367 - primary nid: 6.6.6.6@tcp
387 compare_peer_add "6.6.6.6@tcp" \
388 "6.6.[6-7].[0-4/2]@tcp,6.6.[1-4/2].[0-6/3]@o2ib,[6-12/4]@gni"
390 run_test 6 "Add peer with multiple nidranges"
393 local prim_nid="${1:+--prim_nid $1}"
394 local nid="${2:+--nid $2}"
396 local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
398 do_lnetctl peer del ${prim_nid} ${nid} || error "peer del failed $?"
399 $LNETCTL export --backup > $actual || error "export failed $?"
405 reinit_dlc || return $?
406 create_base_yaml_file
408 echo "Delete peer with single nid (tcp)"
409 do_lnetctl peer add --prim_nid 7.7.7.7@tcp || error "Peer add failed $?"
410 compare_peer_del "7.7.7.7@tcp"
412 echo "Delete peer with single nid (o2ib)"
413 do_lnetctl peer add --prim_nid 7.7.7.7@o2ib || error "Peer add failed $?"
414 compare_peer_del "7.7.7.7@o2ib"
416 echo "Delete peer that has multiple nids (tcp)"
417 do_lnetctl peer add --prim_nid 7.7.7.7@tcp --nid 7.7.7.[8-12]@tcp ||
418 error "Peer add failed $?"
419 compare_peer_del "7.7.7.7@tcp"
421 echo "Delete peer that has multiple nids (o2ib)"
422 do_lnetctl peer add --prim_nid 7.7.7.7@o2ib --nid 7.7.7.[8-12]@o2ib ||
423 error "Peer add failed $?"
424 compare_peer_del "7.7.7.7@o2ib"
426 echo "Delete peer that has both tcp and o2ib nids"
427 do_lnetctl peer add --prim_nid 7.7.7.7@tcp \
428 --nid 7.7.7.[9-12]@tcp,7.7.7.[13-15]@o2ib ||
429 error "Peer add failed $?"
430 compare_peer_del "7.7.7.7@tcp"
432 echo "Delete peer with single nid (gni)"
433 do_lnetctl peer add --prim_nid 7@gni || error "Peer add failed $?"
434 compare_peer_del "7@gni"
436 echo "Delete peer that has multiple nids (gni)"
437 do_lnetctl peer add --prim_nid 7@gni --nid [8-12]@gni ||
438 error "Peer add failed $?"
439 compare_peer_del "7@gni"
441 echo "Delete peer that has tcp, o2ib and gni nids"
442 do_lnetctl peer add --prim_nid 7@gni \
443 --nid [8-12]@gni,7.7.7.[9-12]@tcp,7.7.7.[13-15]@o2ib ||
444 error "Peer add failed $?"
445 compare_peer_del "7@gni"
447 run_test 7 "Various peer delete tests"
450 reinit_dlc || return $?
452 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
454 - primary nid: 8.8.8.8@tcp
466 do_lnetctl peer add --prim_nid 8.8.8.8@tcp --nid 8.8.8.[10-15]@tcp ||
467 error "Peer add failed $?"
468 compare_peer_del "8.8.8.8@tcp" "8.8.8.13@tcp"
470 run_test 8 "Delete single secondary nid from peer (tcp)"
473 reinit_dlc || return $?
475 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
477 - primary nid: 9.9.9.9@tcp
484 do_lnetctl peer add --prim_nid 9.9.9.9@tcp \
485 --nid 9.9.9.[11-16]@tcp || error "Peer add failed $?"
486 compare_peer_del "9.9.9.9@tcp" "9.9.9.[11-16]@tcp"
488 run_test 9 "Delete all secondary nids from peer (tcp)"
491 reinit_dlc || return $?
493 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
495 - primary nid: 10.10.10.10@tcp
498 - nid: 10.10.10.10@tcp
499 - nid: 10.10.10.12@tcp
500 - nid: 10.10.10.13@tcp
501 - nid: 10.10.10.15@tcp
502 - nid: 10.10.10.16@tcp
505 do_lnetctl peer add --prim_nid 10.10.10.10@tcp \
506 --nid 10.10.10.[12-16]@tcp || error "Peer add failed $?"
507 compare_peer_del "10.10.10.10@tcp" "10.10.10.14@tcp"
509 run_test 10 "Delete single secondary nid from peer (o2ib)"
512 reinit_dlc || return $?
514 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
516 - primary nid: 11.11.11.11@tcp
519 - nid: 11.11.11.11@tcp
522 do_lnetctl peer add --prim_nid 11.11.11.11@tcp \
523 --nid 11.11.11.[13-17]@tcp || error "Peer add failed $?"
524 compare_peer_del "11.11.11.11@tcp" "11.11.11.[13-17]@tcp"
526 run_test 11 "Delete all secondary nids from peer (o2ib)"
529 reinit_dlc || return $?
531 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
533 - primary nid: 12.12.12.12@o2ib
536 - nid: 12.12.12.12@o2ib
537 - nid: 13.13.13.13@o2ib
538 - nid: 14.13.13.13@o2ib
539 - nid: 14.15.13.13@o2ib
541 - nid: 15.17.1.10@tcp
542 - nid: 15.17.1.20@tcp
545 do_lnetctl peer add --prim_nid 12.12.12.12@o2ib \
546 --nid [13-14/1].[13-15/2].13.13@o2ib,[15-16/3].[17-19/4].[1].[5-20/5]@tcp ||
547 error "Peer add failed $?"
548 compare_peer_del "12.12.12.12@o2ib" "13.15.13.13@o2ib,15.17.1.15@tcp"
550 run_test 12 "Delete a secondary nid from peer (tcp and o2ib)"
553 reinit_dlc || return $?
555 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
557 - primary nid: 13.13.13.13@o2ib
560 - nid: 13.13.13.13@o2ib
563 do_lnetctl peer add --prim_nid 13.13.13.13@o2ib \
564 --nid [14-15].[1-2/1].[1].[100-254/10]@tcp,14.14.[254].14@o2ib ||
565 error "Peer add failed $?"
566 compare_peer_del "13.13.13.13@o2ib" \
567 "[14-15].[1-2/1].[1].[100-254/10]@tcp,14.14.[254].14@o2ib"
569 run_test 13 "Delete all secondary nids from peer (tcp and o2ib)"
575 if [[ $net =~ gni* ]]; then
578 echo "${num}.${num}.${num}.${num}@${net}"
582 create_mr_peer_yaml() {
584 local secondary_nids="$2"
587 echo "Generating peer yaml for $num_peers peers with $secondary_nids secondary nids"
588 echo "peer:" >> $TMP/sanity-lnet-$testnum-expected.yaml
590 local total_nids=$((num_peers + $((num_peers * secondary_nids))))
593 while [[ $created -lt $num_peers ]]; do
594 local primary=$(create_nid ${nidnum} ${net})
595 cat <<EOF >> $TMP/sanity-lnet-$testnum-expected.yaml
596 - primary nid: $primary
602 local start=$((nidnum + 1))
603 local end=$((nidnum + $secondary_nids))
604 for j in $(seq ${start} ${end}); do
605 local nid=$(create_nid $j ${net})
606 echo " - nid: $nid" >> $TMP/sanity-lnet-$testnum-expected.yaml
614 reinit_dlc || return $?
616 echo "Create single peer, single nid, using import"
617 create_mr_peer_yaml 1 0 tcp
618 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
619 error "Import failed $?"
621 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
624 echo "Delete single peer using import --del"
625 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
626 error "Import failed $?"
627 rm -f $TMP/sanity-lnet-$testnum-expected.yaml
628 create_base_yaml_file
629 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
632 run_test 14 "import peer create/delete with single nid"
635 reinit_dlc || return $?
637 echo "Create multiple peers, single nid per peer, using import"
638 create_mr_peer_yaml 5 0 o2ib
639 # The ordering of nids for this use-case is non-deterministic, so we
640 # we can't just diff the expected/actual output.
641 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
642 error "Import failed $?"
643 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
644 validate_peer_nids 5 0
646 echo "Delete multiple peers, single nid per peer, using import --del"
647 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
648 error "Import failed $?"
649 rm -f $TMP/sanity-lnet-$testnum-expected.yaml
650 create_base_yaml_file
651 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
654 run_test 15 "import multi peer create/delete with single nid per peer"
657 reinit_dlc || return $?
659 echo "Create single peer, multiple nids, using import"
660 create_mr_peer_yaml 1 5 tcp
661 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
662 error "Import failed $?"
663 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
664 validate_peer_nids 1 5
666 echo "Delete single peer, multiple nids, using import --del"
667 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
668 error "Import failed $?"
669 rm -f $TMP/sanity-lnet-$testnum-expected.yaml
670 create_base_yaml_file
671 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
674 run_test 16 "import peer create/delete with multiple nids"
677 reinit_dlc || return $?
679 echo "Create multiple peers, multiple nids per peer, using import"
680 create_mr_peer_yaml 5 7 o2ib
681 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
682 error "Import failed $?"
683 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
684 validate_peer_nids 5 7
686 echo "Delete multiple peers, multiple nids per peer, using import --del"
687 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
688 error "Import failed $?"
689 rm -f $TMP/sanity-lnet-$testnum-expected.yaml
690 create_base_yaml_file
691 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
694 run_test 17 "import multi peer create/delete with multiple nids"
697 reinit_dlc || return $?
699 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
701 - primary nid: 1.1.1.1@tcp
710 echo "Import peer with 5 nids"
711 cat $TMP/sanity-lnet-$testnum-expected.yaml
712 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
713 error "Import failed $?"
714 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
716 - primary nid: 1.1.1.1@tcp
723 echo "Delete three of the nids"
724 cat $TMP/sanity-lnet-$testnum-expected.yaml
725 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml
726 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
728 - primary nid: 1.1.1.1@tcp
734 echo "Check peer has expected nids remaining"
735 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
739 run_test 18a "Delete a subset of nids from a single peer using import --del"
742 reinit_dlc || return $?
744 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
746 - primary nid: 1.1.1.1@tcp
754 - primary nid: 6.6.6.6@o2ib
763 echo "Import two peers with 5 nids each"
764 cat $TMP/sanity-lnet-$testnum-expected.yaml
765 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
766 error "Import failed $?"
767 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
769 - primary nid: 1.1.1.1@tcp
775 - primary nid: 6.6.6.6@o2ib
782 echo "Delete three of the nids from each peer"
783 cat $TMP/sanity-lnet-$testnum-expected.yaml
784 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml
785 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
787 - primary nid: 6.6.6.6@o2ib
792 - primary nid: 1.1.1.1@tcp
799 echo "Check peers have expected nids remaining"
800 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
802 validate_peer_nids 2 1
804 run_test 18b "Delete multiple nids from multiple peers using import --del"
807 reinit_dlc || return $?
808 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
810 - primary nid: 19@gni
816 compare_peer_add "19@gni"
818 run_test 19 "Add peer with single nid (gni)"
821 reinit_dlc || return $?
822 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
824 - primary nid: 20@gni
828 - nid: 20.20.20.20@tcp
829 - nid: 20.20.20.20@o2ib
832 compare_peer_add "20@gni" "20.20.20.20@tcp,20.20.20.20@o2ib"
834 run_test 20 "Add peer with gni primary and tcp, o2ib secondary"
837 reinit_dlc || return $?
838 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
840 - primary nid: 21@gni
850 echo "Add peer with nidrange (gni)"
851 compare_peer_add "21@gni" "[22-25]@gni" || error
852 echo "Add peer with nidrange that overlaps primary nid (gni)"
853 compare_peer_add "21@gni" "[21-25]@gni"
855 run_test 21 "Add peer with nidrange (gni)"
858 reinit_dlc || return $?
859 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
861 - primary nid: 22@gni
872 do_lnetctl peer add --prim_nid 22@gni --nid [24-29]@gni ||
873 error "Peer add failed $?"
874 compare_peer_del "22@gni" "26@gni"
876 run_test 22 "Delete single secondary nid from peer (gni)"
879 reinit_dlc || return $?
880 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
882 - primary nid: 23@gni
889 do_lnetctl peer add --prim_nid 23@gni --nid [25-29]@gni ||
890 error "Peer add failed $?"
891 compare_peer_del "23@gni" "[25-29]@gni"
893 run_test 23 "Delete all secondary nids from peer (gni)"
896 reinit_dlc || return $?
897 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
899 - primary nid: 24@gni
904 - nid: 13.13.13.13@o2ib
905 - nid: 14.13.13.13@o2ib
906 - nid: 14.15.13.13@o2ib
908 - nid: 15.17.1.10@tcp
909 - nid: 15.17.1.20@tcp
912 do_lnetctl peer add --prim_nid 24@gni \
913 --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 ||
914 error "Peer add failed $?"
915 compare_peer_del "24@gni" "5@gni,13.15.13.13@o2ib,15.17.1.15@tcp"
917 run_test 24 "Delete a secondary nid from peer (tcp, o2ib and gni)"
920 reinit_dlc || return $?
921 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
923 - primary nid: 25@gni
929 do_lnetctl peer add --prim_nid 25@gni \
930 --nid [26-27].[4-10/3].26.26@tcp,26.26.26.26@o2ib,[30-35]@gni ||
931 error "Peer add failed $?"
932 compare_peer_del "25@gni" \
933 "[26-27].[4-10/3].26.26@tcp,26.26.26.26@o2ib,[30-35]@gni"
935 run_test 25 "Delete all secondary nids from peer (tcp, gni and o2ib)"
938 reinit_dlc || return $?
940 echo "Invalid prim_nid - peer add"
941 do_lnetctl peer add --prim_nid foobar &&
942 error "Command should have failed"
944 echo "Invalid prim_nid - peer del"
945 do_lnetctl peer del --prim_nid foobar &&
946 error "Command should have failed"
948 echo "Delete non-existing peer"
949 do_lnetctl peer del --prim_nid 1.1.1.1@o2ib &&
950 error "Command should have failed"
952 echo "Don't provide mandatory argument for peer del"
953 do_lnetctl peer del --nid 1.1.1.1@tcp &&
954 error "Command should have failed"
956 echo "Don't provide mandatory argument for peer add"
957 do_lnetctl peer add --nid 1.1.1.1@tcp &&
958 error "Command should have failed"
960 echo "Don't provide mandatory arguments peer add"
961 do_lnetctl peer add &&
962 error "Command should have failed"
964 echo "Invalid secondary nids"
965 do_lnetctl peer add --prim_nid 1.1.1.1@tcp --nid foobar &&
966 error "Command should have failed"
968 echo "Exceed max nids per peer"
969 do_lnetctl peer add --prim_nid 1.1.1.1@tcp --nid 1.1.1.[2-255]@tcp &&
970 error "Command should have failed"
972 echo "Invalid net type"
973 do_lnetctl peer add --prim_nid 1@foo &&
974 error "Command should have failed"
976 echo "Invalid nid format"
977 local invalid_nids="1@tcp 1@o2ib 1.1.1.1@gni"
980 for nid in ${invalid_nids}; do
981 echo "Check invalid primary nid - '$nid'"
982 do_lnetctl peer add --prim_nid $nid &&
983 error "Command should have failed"
986 local invalid_strs="[2-1]@gni [a-f/x]@gni 256.256.256.256@tcp"
987 invalid_strs+=" 1.1.1.1.[2-5/f]@tcp 1.]2[.3.4@o2ib"
988 invalid_strs+="1.[2-4,[5-6],7-8].1.1@tcp foobar"
991 for nidstr in ${invalid_strs}; do
992 echo "Check invalid nidstring - '$nidstr'"
993 do_lnetctl peer add --prim_nid 1.1.1.1@tcp --nid $nidstr &&
994 error "Command should have failed"
997 echo "Add non-local gateway"
998 do_lnetctl route add --net tcp --gateway 1@gni &&
999 error "Command should have failed"
1003 run_test 99a "Check various invalid inputs to lnetctl peer"
1006 reinit_dlc || return $?
1008 create_base_yaml_file
1010 cat <<EOF > $TMP/sanity-lnet-$testnum-invalid.yaml
1012 - primary nid: 99.99.99.99@tcp
1015 - nid: 99.99.99.99@tcp
1017 do_lnetctl import < $TMP/sanity-lnet-$testnum-invalid.yaml &&
1018 error "import should have failed"
1019 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
1022 run_test 99b "Invalid value for Multi-Rail in yaml import"
1026 local ip=$(ip addr show dev $if | awk '/ inet /{print $2}')
1034 if ! lsmod | grep -q ksocklnd ; then
1035 load_module ../lnet/klnds/socklnd/ksocklnd ||
1036 error "Can't load ksocklnd.ko"
1039 do_lnetctl net add --net ${net} --if ${if} ||
1040 error "Failed to add net ${net} on if ${if}"
1043 compare_route_add() {
1047 local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
1049 do_lnetctl route add --net ${rnet} --gateway ${gw} ||
1050 error "route add failed $?"
1051 # CPT configuration is pruned from the exported yaml, since the default
1052 # can vary across test systems (unlike default values for things like
1053 # peer_credits, peer_timeout, etc.)
1054 $LNETCTL export --backup | grep -v CPT > $actual ||
1055 error "export failed $?"
1056 validate_gateway_nids
1061 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1062 reinit_dlc || return $?
1063 add_net "tcp" "eth0"
1064 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
1073 peer_buffer_credits: 0
1077 gateway: 7.7.7.7@tcp
1080 health_sensitivity: 1
1082 - primary nid: 7.7.7.7@tcp
1088 compare_route_add "tcp7" "7.7.7.7@tcp" || return $?
1091 run_test 100 "Add route with single gw (tcp)"
1094 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1095 reinit_dlc || return $?
1096 add_net "tcp" "eth0"
1097 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
1106 peer_buffer_credits: 0
1110 gateway: 8.8.8.10@tcp
1113 health_sensitivity: 1
1115 gateway: 8.8.8.9@tcp
1118 health_sensitivity: 1
1120 gateway: 8.8.8.8@tcp
1123 health_sensitivity: 1
1125 - primary nid: 8.8.8.9@tcp
1129 - primary nid: 8.8.8.10@tcp
1133 - primary nid: 8.8.8.8@tcp
1139 compare_route_add "tcp8" "8.8.8.[8-10]@tcp"
1141 run_test 101 "Add route with multiple gw (tcp)"
1143 compare_route_del() {
1147 local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
1149 do_lnetctl route del --net ${rnet} --gateway ${gw} ||
1150 error "route del failed $?"
1151 $LNETCTL export --backup > $actual ||
1152 error "export failed $?"
1153 validate_gateway_nids
1157 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1158 reinit_dlc || return $?
1159 add_net "tcp" "eth0"
1160 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-expected.yaml
1161 do_lnetctl route add --net tcp102 --gateway 102.102.102.102@tcp ||
1162 error "route add failed $?"
1163 compare_route_del "tcp102" "102.102.102.102@tcp"
1165 run_test 102 "Delete route with single gw (tcp)"
1168 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1169 reinit_dlc || return $?
1170 add_net "tcp" "eth0"
1171 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-expected.yaml
1172 do_lnetctl route add --net tcp103 \
1173 --gateway 103.103.103.[103-120/4]@tcp ||
1174 error "route add failed $?"
1175 compare_route_del "tcp103" "103.103.103.[103-120/4]@tcp"
1177 run_test 103 "Delete route with multiple gw (tcp)"
1180 local tyaml="$TMP/sanity-lnet-$testnum-expected.yaml"
1182 reinit_dlc || return $?
1184 # Default value is '3'
1185 local val=$($LNETCTL global show | awk '/response_tracking/{print $NF}')
1187 error "Expect 3 found $val"
1189 echo "Set < 0; Should fail"
1190 do_lnetctl set response_tracking -1 &&
1191 error "should have failed $?"
1193 reinit_dlc || return $?
1196 response_tracking: -10
1198 do_lnetctl import < $tyaml &&
1199 error "should have failed $?"
1201 echo "Check valid values; Should succeed"
1203 for ((i = 0; i < 4; i++)); do
1204 reinit_dlc || return $?
1205 do_lnetctl set response_tracking $i ||
1206 error "should have succeeded $?"
1207 $LNETCTL global show | grep -q "response_tracking: $i" ||
1208 error "Failed to set response_tracking to $i"
1209 reinit_dlc || return $?
1212 response_tracking: $i
1214 do_lnetctl import < $tyaml ||
1215 error "should have succeeded $?"
1216 $LNETCTL global show | grep -q "response_tracking: $i" ||
1217 error "Failed to set response_tracking to $i"
1220 reinit_dlc || return $?
1221 echo "Set > 3; Should fail"
1222 do_lnetctl set response_tracking 4 &&
1223 error "should have failed $?"
1225 reinit_dlc || return $?
1228 response_tracking: 10
1230 do_lnetctl import < $tyaml &&
1231 error "should have failed $?"
1234 run_test 104 "Set/check response_tracking param"
1236 ### load lnet in default namespace, configure in target namespace
1239 cleanup_lnet || exit 1
1240 load_lnet "networks=\"\""
1241 do_ns $LNETCTL lnet configure --all || exit 1
1242 $LNETCTL net show --net tcp | grep -q "nid: ${FAKE_IP}@tcp$"
1244 run_test 200 "load lnet w/o module option, configure in a non-default namespace"
1247 cleanup_lnet || exit 1
1248 load_lnet "networks=tcp($FAKE_IF)"
1249 do_ns $LNETCTL lnet configure --all || exit 1
1250 $LNETCTL net show --net tcp | grep -q "nid: ${FAKE_IP}@tcp$"
1252 run_test 201 "load lnet using networks module options in a non-default namespace"
1255 cleanup_lnet || exit 1
1256 load_lnet "networks=\"\" ip2nets=\"tcp0($FAKE_IF) ${FAKE_IP}\""
1257 do_ns $LNETCTL lnet configure --all || exit 1
1258 $LNETCTL net show | grep -q "nid: ${FAKE_IP}@tcp$"
1260 run_test 202 "load lnet using ip2nets in a non-default namespace"
1263 ### Add the interfaces in the target namespace
1266 cleanup_lnet || exit 1
1268 do_lnetctl lnet configure || exit 1
1269 do_ns $LNETCTL net add --net tcp0 --if $FAKE_IF
1271 run_test 203 "add a network using an interface in the non-default namespace"
1273 LNET_PARAMS_FILE="$TMP/$TESTSUITE.parameters"
1274 function save_lnet_params() {
1275 $LNETCTL global show | egrep -v '^global:$' |
1276 sed 's/://' > $LNET_PARAMS_FILE
1279 function restore_lnet_params() {
1281 while read param value; do
1282 [[ $param == max_intf ]] && continue
1283 [[ $param == lnd_timeout ]] && continue
1284 $LNETCTL set ${param} ${value} ||
1285 error "Failed to restore ${param} to ${value}"
1286 done < $LNET_PARAMS_FILE
1289 function lnet_health_pre() {
1292 # Lower transaction timeout to speed up test execution
1293 $LNETCTL set transaction_timeout 10 ||
1294 error "Failed to set transaction_timeout $?"
1296 # Increase recovery interval so we have time to capture health values
1297 $LNETCTL set recovery_interval 20 ||
1298 error "Failed to set recovery_interval $?"
1300 RETRY_PARAM=$($LNETCTL global show | awk '/retry_count/{print $NF}')
1301 RSND_PRE=$($LNETCTL stats show | awk '/resend_count/{print $NF}')
1302 LO_HVAL_PRE=$($LNETCTL net show -v 2 | awk '/health value/{print $NF}' |
1303 xargs echo | sed 's/ /+/g' | bc -l)
1305 local my_nid=$($LCTL list_nids | head -n 1)
1307 RMT_HVAL_PRE=$($LNETCTL peer show --nid $my_nid -v 2 2>/dev/null |
1308 awk '/health value/{print $NF}' | xargs echo |
1309 sed 's/ /+/g' | bc -l)
1311 # Might not have any peers so initialize to zero.
1312 RMT_HVAL_PRE=${RMT_HVAL_PRE:-0}
1317 function lnet_health_post() {
1318 RSND_POST=$($LNETCTL stats show | awk '/resend_count/{print $NF}')
1319 LO_HVAL_POST=$($LNETCTL net show -v 2 |
1320 awk '/health value/{print $NF}' |
1321 xargs echo | sed 's/ /+/g' | bc -l)
1323 local my_nid=$($LCTL list_nids | head -n 1)
1325 RMT_HVAL_POST=$($LNETCTL peer show --nid $my_nid -v 2 2>/dev/null |
1326 awk '/health value/{print $NF}' | xargs echo |
1327 sed 's/ /+/g' | bc -l)
1329 # Might not have any peers so initialize to zero.
1330 RMT_HVAL_POST=${RMT_HVAL_POST:-0}
1333 echo "Pre resends: $RSND_PRE" &&
1334 echo "Post resends: $RSND_POST" &&
1335 echo "Resends delta: $((RSND_POST - RSND_PRE))" &&
1336 echo "Pre local health: $LO_HVAL_PRE" &&
1337 echo "Post local health: $LO_HVAL_POST" &&
1338 echo "Pre remote health: $RMT_HVAL_PRE" &&
1339 echo "Post remote health: $RMT_HVAL_POST"
1346 function check_no_resends() {
1347 echo "Check that no resends took place"
1348 [[ $RSND_POST -ne $RSND_PRE ]] &&
1349 error "Found resends: $RSND_POST != $RSND_PRE"
1354 function check_resends() {
1355 local delta=$((RSND_POST - RSND_PRE))
1357 echo "Check that $RETRY_PARAM resends took place"
1358 [[ $delta -ne $RETRY_PARAM ]] &&
1359 error "Expected $RETRY_PARAM resends found $delta"
1364 function check_no_local_health() {
1365 echo "Check that local NI health is unchanged"
1366 [[ $LO_HVAL_POST -ne $LO_HVAL_PRE ]] &&
1367 error "Local health changed: $LO_HVAL_POST != $LO_HVAL_PRE"
1372 function check_local_health() {
1373 echo "Check that local NI health has been changed"
1374 [[ $LO_HVAL_POST -eq $LO_HVAL_PRE ]] &&
1375 error "Local health unchanged: $LO_HVAL_POST == $LO_HVAL_PRE"
1380 function check_no_remote_health() {
1381 echo "Check that remote NI health is unchanged"
1382 [[ $RMT_HVAL_POST -ne $RMT_HVAL_PRE ]] &&
1383 error "Remote health changed: $RMT_HVAL_POST != $RMT_HVAL_PRE"
1388 function check_remote_health() {
1389 echo "Check that remote NI health has been changed"
1390 [[ $RMT_HVAL_POST -eq $RMT_HVAL_PRE ]] &&
1391 error "Remote health unchanged: $RMT_HVAL_POST == $RMT_HVAL_PRE"
1396 # See lnet/lnet/lib-msg.c:lnet_health_check()
1397 LNET_LOCAL_RESEND_STATUSES="local_interrupt local_dropped local_aborted"
1398 LNET_LOCAL_RESEND_STATUSES+=" local_no_route local_timeout"
1399 LNET_LOCAL_NO_RESEND_STATUSES="local_error"
1401 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1402 reinit_dlc || return $?
1403 add_net "tcp" "eth0" || return $?
1405 lnet_health_pre || return $?
1408 for hstatus in ${LNET_LOCAL_RESEND_STATUSES} \
1409 ${LNET_LOCAL_NO_RESEND_STATUSES}; do
1410 echo "Simulate $hstatus"
1411 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1412 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1413 error "Should have failed"
1414 $LCTL net_drop_del -a
1419 check_no_resends || return $?
1420 check_no_local_health || return $?
1424 run_test 204 "Check no health or resends for single-rail local failures"
1427 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1430 for hstatus in ${LNET_LOCAL_RESEND_STATUSES}; do
1431 reinit_dlc || return $?
1432 add_net "tcp" "eth0" || return $?
1433 add_net "tcp1" "eth0" || return $?
1435 echo "Simulate $hstatus"
1438 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1439 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e ${hstatus}
1440 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1441 error "Should have failed"
1442 $LCTL net_drop_del -a
1446 check_resends || return $?
1447 check_local_health || return $?
1450 for hstatus in ${LNET_LOCAL_NO_RESEND_STATUSES}; do
1451 reinit_dlc || return $?
1452 add_net "tcp" "eth0" || return $?
1453 add_net "tcp1" "eth0" || return $?
1455 echo "Simulate $hstatus"
1456 lnet_health_pre || return $?
1458 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1459 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e ${hstatus}
1460 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1461 error "Should have failed"
1462 $LCTL net_drop_del -a
1466 check_no_resends || return $?
1467 check_local_health || return $?
1472 run_test 205 "Check health and resends for multi-rail local failures"
1474 # See lnet/lnet/lib-msg.c:lnet_health_check()
1475 LNET_REMOTE_RESEND_STATUSES="remote_dropped"
1476 LNET_REMOTE_NO_RESEND_STATUSES="remote_error remote_timeout"
1478 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1479 reinit_dlc || return $?
1480 add_net "tcp" "eth0" || return $?
1482 do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1483 error "failed to discover myself"
1485 lnet_health_pre || return $?
1488 for hstatus in ${LNET_REMOTE_RESEND_STATUSES} \
1489 ${LNET_REMOTE_NO_RESEND_STATUSES}; do
1490 echo "Simulate $hstatus"
1491 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1492 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1493 error "Should have failed"
1494 $LCTL net_drop_del -a
1499 check_no_resends || return $?
1500 check_no_local_health || return $?
1501 check_no_remote_health || return $?
1505 run_test 206 "Check no health or resends for single-rail remote failures"
1508 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1511 for hstatus in ${LNET_REMOTE_RESEND_STATUSES}; do
1512 reinit_dlc || return $?
1513 add_net "tcp" "eth0" || return $?
1514 add_net "tcp1" "eth0" || return $?
1516 do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1517 error "failed to discover myself"
1519 echo "Simulate $hstatus"
1520 lnet_health_pre || return $?
1521 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1522 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e ${hstatus}
1523 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1524 error "Should have failed"
1525 $LCTL net_drop_del -a
1529 check_resends || return $?
1530 check_no_local_health || return $?
1531 check_remote_health || return $?
1533 for hstatus in ${LNET_REMOTE_NO_RESEND_STATUSES}; do
1534 reinit_dlc || return $?
1535 add_net "tcp" "eth0" || return $?
1536 add_net "tcp1" "eth0" || return $?
1538 do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1539 error "failed to discover myself"
1541 echo "Simulate $hstatus"
1542 lnet_health_pre || return $?
1543 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1544 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e ${hstatus}
1545 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1546 error "Should have failed"
1547 $LCTL net_drop_del -a
1551 check_no_resends || return $?
1552 check_no_local_health || return $?
1553 check_remote_health || return $?
1558 run_test 207 "Check health and resends for multi-rail remote errors"
1560 test_208_load_and_check_lnet() {
1564 local num_expected=1
1566 load_lnet "networks=\"\" ip2nets=\"${ip2nets_str}\""
1569 error "Failed to load LNet with ip2nets \"${ip2nets_str}\""
1575 nids=( $($LCTL list_nids) )
1577 [[ ${#nids[@]} -ne ${num_expected} ]] &&
1578 error "Expect ${num_expected} NIDs found ${#nids[@]}"
1580 [[ ${nids[0]} == ${p_nid} ]] ||
1581 error "Expect NID \"${p_nid}\" found \"${nids[0]}\""
1583 [[ -n $s_nid ]] && [[ ${nids[1]} != ${s_nid} ]] &&
1584 error "Expect second NID \"${s_nid}\" found \"${nids[1]}\""
1586 $LCTL net down &>/dev/null
1591 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1593 cleanup_netns || error "Failed to cleanup netns before test execution"
1594 cleanup_lnet || error "Failed to unload modules before test execution"
1595 setup_fakeif || error "Failed to add fake IF"
1597 have_interface "$FAKE_IF" ||
1598 error "Expect $FAKE_IF configured but not found"
1600 local eth0_ip=$(ip --oneline addr show dev eth0 |
1601 awk '/inet /{print $4}' |
1603 local ip2nets_str="tcp(eth0) $eth0_ip"
1605 echo "Configure single NID \"$ip2nets_str\""
1606 test_208_load_and_check_lnet "${ip2nets_str}" "${eth0_ip}@tcp"
1608 ip2nets_str="tcp(eth0) $eth0_ip; tcp1($FAKE_IF) $FAKE_IP"
1609 echo "Configure two NIDs; two NETs \"$ip2nets_str\""
1610 test_208_load_and_check_lnet "${ip2nets_str}" "${eth0_ip}@tcp" \
1613 ip2nets_str="tcp(eth0) $eth0_ip; tcp($FAKE_IF) $FAKE_IP"
1614 echo "Configure two NIDs; one NET \"$ip2nets_str\""
1615 test_208_load_and_check_lnet "${ip2nets_str}" "${eth0_ip}@tcp" \
1617 local addr1=( ${eth0_ip//./ } )
1618 local addr2=( ${FAKE_IP//./ } )
1619 local range="[${addr1[0]},${addr2[0]}]"
1622 for i in $(seq 1 3); do
1623 range+=".[${addr1[$i]},${addr2[$i]}]"
1625 ip2nets_str="tcp(eth0,${FAKE_IF}) ${range}"
1627 echo "Configured two NIDs; one NET alt syntax \"$ip2nets_str\""
1628 test_208_load_and_check_lnet "${ip2nets_str}" "${eth0_ip}@tcp" \
1633 echo "alt syntax with missing IF \"$ip2nets_str\""
1634 load_lnet "networks=\"\" ip2nets=\"${ip2nets_str}\""
1636 echo "$LCTL net up should fail"
1638 error "LNet bringup should have failed"
1642 run_test 208 "Test various kernel ip2nets configurations"
1645 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1647 reinit_dlc || return $?
1648 add_net "tcp" "eth0" || return $?
1650 do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1651 error "failed to discover myself"
1653 echo "Simulate network_timeout w/SR config"
1656 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e network_timeout
1657 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1658 error "Should have failed"
1659 $LCTL net_drop_del -a
1663 check_no_resends || return $?
1664 check_no_local_health || return $?
1665 check_no_remote_health || return $?
1667 reinit_dlc || return $?
1668 add_net "tcp" "eth0" || return $?
1669 add_net "tcp1" "eth0" || return $?
1671 do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1672 error "failed to discover myself"
1674 echo "Simulate network_timeout w/MR config"
1677 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e network_timeout
1678 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e network_timeout
1679 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1680 error "Should have failed"
1681 $LCTL net_drop_del -a
1685 check_no_resends || return $?
1686 check_local_health || return $?
1687 check_remote_health || return $?
1691 run_test 209 "Check health, but not resends, for network timeout"
1693 check_nid_in_recovq() {
1694 local recovq=$($LNETCTL debug recovery $1)
1696 local nids=$($LCTL list_nids | xargs echo)
1700 echo "Check recovery queue"
1702 if [[ $(grep -c 'nid-'<<<$recovq) -ne $expect ]]; then
1703 error "Expect $expect NIDs found: \"$recovq\""
1706 [[ $expect -eq 0 ]] && return 0
1708 for nid in ${nids}; do
1709 grep -q "nid-0: $nid"<<<$recovq &&
1714 error "Didn't find local NIDs in recovery queue: \"$recovq\""
1720 # First enqueue happens at time 0.
1721 # 2nd at 0 + 2^0 = 1
1722 # 3rd at 1 + 2^1 = 3
1723 # 4th at 3 + 2^2 = 7
1724 # 5th at 7 + 2^3 = 15
1725 # e.g. after 10 seconds we would expect to have seen the 4th enqueue,
1726 # (3 pings sent, 4th about to happen) and the 5th enqueue is yet to
1728 # If the recovery limit is 10 seconds, then when the 5th enqueue happens
1729 # we expect the peer NI to have aged out, so it will not actually be
1731 check_ping_count() {
1735 echo "Check ping counts:"
1737 if [[ $queue == "ni" ]]; then
1738 $LNETCTL net show -v 2 | egrep 'nid|health value|ping'
1739 ping_count=( $($LNETCTL net show -v 2 |
1740 awk '/ping_count/{print $NF}') )
1741 elif [[ $queue == "peer_ni" ]]; then
1742 $LNETCTL peer show -v 2 | egrep 'nid|health value|ping'
1743 ping_count=( $($LNETCTL peer show -v 2 |
1744 awk '/ping_count/{print $NF}') )
1746 error "Unrecognized queue \"$queue\""
1752 for count in ${ping_count[@]}; do
1753 if [[ $count -eq $expect ]]; then
1754 if [[ $expect -ne 0 ]] && $found ; then
1755 error "Found more than one interface matching \"$expect\" ping count"
1758 echo "Expect ping count \"$expect\" found \"$count\""
1761 elif [[ $count -ne 0 ]]; then
1762 error "Found interface with ping count \"$count\" but expect \"$expect\""
1771 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1772 reinit_dlc || return $?
1773 add_net "tcp" "eth0" || return $?
1774 add_net "tcp1" "eth0" || return $?
1776 local prim_nid=$($LCTL list_nids | head -n 1)
1778 do_lnetctl discover $prim_nid ||
1779 error "failed to discover myself"
1781 # Set recovery limit to 10 seconds.
1782 do_lnetctl set recovery_limit 10 ||
1783 error "failed to set recovery_limit"
1785 $LCTL set_param debug=+net
1786 # Use local_error so LNet doesn't attempt to resend the discovery ping
1787 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e local_error
1788 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e local_error
1789 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1790 error "Expected discovery to fail"
1793 check_nid_in_recovq "-l" 1
1794 check_ping_count "ni" "2"
1798 check_nid_in_recovq "-l" 1
1799 check_ping_count "ni" "3"
1801 $LCTL net_drop_del -a
1805 run_test 210 "Local NI recovery checks"
1808 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1809 reinit_dlc || return $?
1810 add_net "tcp" "eth0" || return $?
1811 add_net "tcp1" "eth0" || 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 net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e remote_error
1823 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e remote_error
1825 # Set health to 0 on one interface. This forces it onto the recovery
1827 $LNETCTL peer set --nid $prim_nid --health 0
1829 # After 5 seconds, we expect the peer NI to still be in recovery
1831 check_nid_in_recovq "-p" 1
1832 check_ping_count "peer_ni" "2"
1834 # After 15 seconds, the peer NI should have been fully processed out of
1835 # the recovery queue. We'll allow a total of 17 seconds to account for
1836 # differences in sleeping for whole seconds vs. the more accurate time
1837 # keeping that is done in the recovery code.
1839 check_nid_in_recovq "-p" 0
1840 check_ping_count "peer_ni" "4"
1842 $LCTL net_drop_del -a
1844 # Set health to force it back onto the recovery queue. Set to 500 means
1845 # in 5 seconds it should be back at maximum value. We'll wait a couple
1846 # more seconds than that to be safe.
1847 # NB: we reset the recovery limit to 0 (indefinite) so the peer NI is
1849 do_lnetctl set recovery_limit 0 ||
1850 error "failed to set recovery_limit"
1852 $LNETCTL peer set --nid $prim_nid --health 500
1854 check_nid_in_recovq "-p" 1
1855 check_ping_count "peer_ni" "2"
1859 check_nid_in_recovq "-p" 0
1860 check_ping_count "peer_ni" "0"
1864 run_test 211 "Remote NI recovery checks"
1867 local rnodes=$(remote_nodes_list)
1868 [[ -z $rnodes ]] && skip "Need at least 1 remote node"
1870 cleanup_lnet || error "Failed to cleanup before test execution"
1872 # Loading modules should configure LNet with the appropriate
1873 # test-framework configuration
1874 load_modules || error "Failed to load modules"
1876 local my_nid=$($LCTL list_nids | head -n 1)
1878 error "Failed to get primary NID for local host $HOSTNAME"
1880 local rnode=$(awk '{print $1}' <<<$rnodes)
1881 local rnodenids=$(do_node $rnode $LCTL list_nids | xargs echo)
1884 if [[ -z $rnodenids ]]; then
1885 do_rpc_nodes $rnode load_modules_local
1887 rnodenids=$(do_node $rnode $LCTL list_nids | xargs echo)
1890 local rnodepnid=$(awk '{print $1}' <<< $rnodenids)
1892 [[ -z $rnodepnid ]] &&
1893 error "Failed to get primary NID for remote host $rnode"
1895 log "Initial discovery"
1896 do_lnetctl discover --force $rnodepnid ||
1897 error "Failed to discover $rnodepnid"
1899 do_node $rnode "$LNETCTL discover --force $my_nid" ||
1900 error "$rnode failed to discover $my_nid"
1902 log "Fail local discover ping to set LNET_PEER_REDISCOVER flag"
1903 $LCTL net_drop_add -s "*@$NETTYPE" -d "*@$NETTYPE" -r 1 -e local_error
1904 do_lnetctl discover --force $rnodepnid &&
1905 error "Discovery should have failed"
1906 $LCTL net_drop_del -a
1909 for nid in $rnodenids; do
1910 # We need GET (PING) delay just long enough so we can trigger
1911 # discovery on the remote peer
1912 $LCTL net_delay_add -s "*@$NETTYPE" -d $nid -r 1 -m GET -l 3
1913 $LCTL net_drop_add -s "*@$NETTYPE" -d $nid -r 1 -m GET -e local_error
1914 # We need PUT (PUSH) delay just long enough so we can process
1916 $LCTL net_delay_add -s "*@$NETTYPE" -d $nid -r 1 -m PUT -l 6
1919 log "Force $HOSTNAME to discover $rnodepnid (in background)"
1920 # We want to get a PING sent that we know will eventually fail.
1921 # The delay rules we added will ensure the ping is not sent until
1922 # the PUSH is also in flight (see below), and the drop rule ensures that
1923 # when the PING is eventually sent it will error out
1924 do_lnetctl discover --force $rnodepnid &
1927 # We want a discovery PUSH from rnode to put rnode back on our
1928 # discovery queue. This should cause us to try and send a PUSH to rnode
1929 # while the PING is still outstanding.
1930 log "Force $rnode to discover $my_nid"
1931 do_node $rnode $LNETCTL discover --force $my_nid
1933 # At this point we'll have both PING_SENT and PUSH_SENT set for the
1934 # rnode peer. Wait for the PING to error out which should terminate the
1935 # discovery process that we backgrounded.
1936 log "Wait for $pid1"
1938 log "Finished wait on $pid1"
1940 # The PING send failure clears the PING_SENT flag and puts the peer back
1941 # on the discovery queue. When discovery thread processes the peer it
1942 # will mistakenly clear the PUSH_SENT flag (and set PUSH_FAILED).
1943 # Discovery will then complete for this peer even though we have an
1945 # When PUSH is actually unlinked it will be forced back onto the
1946 # discovery queue, but we no longer have a ref on the peer. When
1947 # discovery completes again, we'll trip the ASSERT in
1948 # lnet_destroy_peer_locked()
1950 # Delete the delay rules to send the PUSH
1951 $LCTL net_delay_del -a
1952 # Delete the drop rules
1953 $LCTL net_drop_del -a
1956 error "Failed to unload modules"
1958 do_rpc_nodes $rnode unload_modules_local ||
1959 error "Failed to unload modules on $rnode"
1964 run_test 212 "Check discovery refcount loss bug (LU-14627)"
1967 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1969 cleanup_netns || error "Failed to cleanup netns before test execution"
1970 cleanup_lnet || error "Failed to unload modules before test execution"
1972 setup_fakeif || error "Failed to add fake IF"
1973 have_interface "$FAKE_IF" ||
1974 error "Expect $FAKE_IF configured but not found"
1976 reinit_dlc || return $?
1978 add_net "tcp" "eth0" || return $?
1979 add_net "tcp" "$FAKE_IF" || return $?
1981 local nid1=$(lctl list_nids | head -n 1)
1982 local nid2=$(lctl list_nids | tail --lines 1)
1984 [[ $(lctl which_nid $nid1 $nid2) == $nid1 ]] ||
1985 error "Expect nid1 \"$nid1\" to be preferred"
1987 [[ $(lctl which_nid $nid2 $nid1) == $nid2 ]] ||
1988 error "Expect nid2 \"$nid2\" to be preferred"
1992 run_test 213 "Check LNetDist calculation for multiple local NIDs"
1997 local out=$TMP/$tfile
1998 local prefix=/usr/include/linux/lnet
2000 # We use a hard coded prefix so that this test will not fail
2003 if ! which $CC > /dev/null 2>&1; then
2004 skip_env "$CC is not installed"
2007 cleanup_lnet || exit 1
2010 local cc_args="-Wall -Werror -std=c99 -c -x c /dev/null -o $out"
2011 if ! [[ -d $prefix ]]; then
2012 # Assume we're running in tree and fixup the include path.
2013 prefix=$LUSTRE/../lnet/include/uapi/linux/lnet
2014 cc_args+=" -I $LUSTRE/../lnet/include/uapi"
2017 for header in $prefix/*.h; do
2018 if ! [[ -f "$header" ]]; then
2022 echo "$CC $cc_args -include $header"
2023 $CC $cc_args -include $header ||
2024 error "cannot compile '$header'"
2028 run_test 300 "packaged LNet UAPI headers can be compiled"