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
1079 gateway: 7.7.7.7@tcp
1082 health_sensitivity: 1
1084 - primary nid: 7.7.7.7@tcp
1090 compare_route_add "tcp7" "7.7.7.7@tcp" || return $?
1093 run_test 100 "Add route with single gw (tcp)"
1096 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1097 reinit_dlc || return $?
1098 add_net "tcp" "eth0"
1099 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
1108 peer_buffer_credits: 0
1114 gateway: 8.8.8.10@tcp
1117 health_sensitivity: 1
1119 gateway: 8.8.8.9@tcp
1122 health_sensitivity: 1
1124 gateway: 8.8.8.8@tcp
1127 health_sensitivity: 1
1129 - primary nid: 8.8.8.9@tcp
1133 - primary nid: 8.8.8.10@tcp
1137 - primary nid: 8.8.8.8@tcp
1143 compare_route_add "tcp8" "8.8.8.[8-10]@tcp"
1145 run_test 101 "Add route with multiple gw (tcp)"
1147 compare_route_del() {
1151 local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
1153 do_lnetctl route del --net ${rnet} --gateway ${gw} ||
1154 error "route del failed $?"
1155 $LNETCTL export --backup > $actual ||
1156 error "export failed $?"
1157 validate_gateway_nids
1161 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1162 reinit_dlc || return $?
1163 add_net "tcp" "eth0"
1164 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-expected.yaml
1165 do_lnetctl route add --net tcp102 --gateway 102.102.102.102@tcp ||
1166 error "route add failed $?"
1167 compare_route_del "tcp102" "102.102.102.102@tcp"
1169 run_test 102 "Delete route with single gw (tcp)"
1172 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1173 reinit_dlc || return $?
1174 add_net "tcp" "eth0"
1175 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-expected.yaml
1176 do_lnetctl route add --net tcp103 \
1177 --gateway 103.103.103.[103-120/4]@tcp ||
1178 error "route add failed $?"
1179 compare_route_del "tcp103" "103.103.103.[103-120/4]@tcp"
1181 run_test 103 "Delete route with multiple gw (tcp)"
1184 local tyaml="$TMP/sanity-lnet-$testnum-expected.yaml"
1186 reinit_dlc || return $?
1188 # Default value is '3'
1189 local val=$($LNETCTL global show | awk '/response_tracking/{print $NF}')
1191 error "Expect 3 found $val"
1193 echo "Set < 0; Should fail"
1194 do_lnetctl set response_tracking -1 &&
1195 error "should have failed $?"
1197 reinit_dlc || return $?
1200 response_tracking: -10
1202 do_lnetctl import < $tyaml &&
1203 error "should have failed $?"
1205 echo "Check valid values; Should succeed"
1207 for ((i = 0; i < 4; i++)); do
1208 reinit_dlc || return $?
1209 do_lnetctl set response_tracking $i ||
1210 error "should have succeeded $?"
1211 $LNETCTL global show | grep -q "response_tracking: $i" ||
1212 error "Failed to set response_tracking to $i"
1213 reinit_dlc || return $?
1216 response_tracking: $i
1218 do_lnetctl import < $tyaml ||
1219 error "should have succeeded $?"
1220 $LNETCTL global show | grep -q "response_tracking: $i" ||
1221 error "Failed to set response_tracking to $i"
1224 reinit_dlc || return $?
1225 echo "Set > 3; Should fail"
1226 do_lnetctl set response_tracking 4 &&
1227 error "should have failed $?"
1229 reinit_dlc || return $?
1232 response_tracking: 10
1234 do_lnetctl import < $tyaml &&
1235 error "should have failed $?"
1238 run_test 104 "Set/check response_tracking param"
1240 ### load lnet in default namespace, configure in target namespace
1243 cleanup_lnet || exit 1
1244 load_lnet "networks=\"\""
1245 do_ns $LNETCTL lnet configure --all || exit 1
1246 $LNETCTL net show --net tcp | grep -q "nid: ${FAKE_IP}@tcp$"
1248 run_test 200 "load lnet w/o module option, configure in a non-default namespace"
1251 cleanup_lnet || exit 1
1252 load_lnet "networks=tcp($FAKE_IF)"
1253 do_ns $LNETCTL lnet configure --all || exit 1
1254 $LNETCTL net show --net tcp | grep -q "nid: ${FAKE_IP}@tcp$"
1256 run_test 201 "load lnet using networks module options in a non-default namespace"
1259 cleanup_lnet || exit 1
1260 load_lnet "networks=\"\" ip2nets=\"tcp0($FAKE_IF) ${FAKE_IP}\""
1261 do_ns $LNETCTL lnet configure --all || exit 1
1262 $LNETCTL net show | grep -q "nid: ${FAKE_IP}@tcp$"
1264 run_test 202 "load lnet using ip2nets in a non-default namespace"
1267 ### Add the interfaces in the target namespace
1270 cleanup_lnet || exit 1
1272 do_lnetctl lnet configure || exit 1
1273 do_ns $LNETCTL net add --net tcp0 --if $FAKE_IF
1275 run_test 203 "add a network using an interface in the non-default namespace"
1277 LNET_PARAMS_FILE="$TMP/$TESTSUITE.parameters"
1278 function save_lnet_params() {
1279 $LNETCTL global show | egrep -v '^global:$' |
1280 sed 's/://' > $LNET_PARAMS_FILE
1283 function restore_lnet_params() {
1285 while read param value; do
1286 [[ $param == max_intf ]] && continue
1287 [[ $param == lnd_timeout ]] && continue
1288 $LNETCTL set ${param} ${value} ||
1289 error "Failed to restore ${param} to ${value}"
1290 done < $LNET_PARAMS_FILE
1293 function lnet_health_pre() {
1296 # Lower transaction timeout to speed up test execution
1297 $LNETCTL set transaction_timeout 10 ||
1298 error "Failed to set transaction_timeout $?"
1300 # Increase recovery interval so we have time to capture health values
1301 $LNETCTL set recovery_interval 20 ||
1302 error "Failed to set recovery_interval $?"
1304 RETRY_PARAM=$($LNETCTL global show | awk '/retry_count/{print $NF}')
1305 RSND_PRE=$($LNETCTL stats show | awk '/resend_count/{print $NF}')
1306 LO_HVAL_PRE=$($LNETCTL net show -v 2 | awk '/health value/{print $NF}' |
1307 xargs echo | sed 's/ /+/g' | bc -l)
1309 local my_nid=$($LCTL list_nids | head -n 1)
1311 RMT_HVAL_PRE=$($LNETCTL peer show --nid $my_nid -v 2 2>/dev/null |
1312 awk '/health value/{print $NF}' | xargs echo |
1313 sed 's/ /+/g' | bc -l)
1315 # Might not have any peers so initialize to zero.
1316 RMT_HVAL_PRE=${RMT_HVAL_PRE:-0}
1321 function lnet_health_post() {
1322 RSND_POST=$($LNETCTL stats show | awk '/resend_count/{print $NF}')
1323 LO_HVAL_POST=$($LNETCTL net show -v 2 |
1324 awk '/health value/{print $NF}' |
1325 xargs echo | sed 's/ /+/g' | bc -l)
1327 local my_nid=$($LCTL list_nids | head -n 1)
1329 RMT_HVAL_POST=$($LNETCTL peer show --nid $my_nid -v 2 2>/dev/null |
1330 awk '/health value/{print $NF}' | xargs echo |
1331 sed 's/ /+/g' | bc -l)
1333 # Might not have any peers so initialize to zero.
1334 RMT_HVAL_POST=${RMT_HVAL_POST:-0}
1337 echo "Pre resends: $RSND_PRE" &&
1338 echo "Post resends: $RSND_POST" &&
1339 echo "Resends delta: $((RSND_POST - RSND_PRE))" &&
1340 echo "Pre local health: $LO_HVAL_PRE" &&
1341 echo "Post local health: $LO_HVAL_POST" &&
1342 echo "Pre remote health: $RMT_HVAL_PRE" &&
1343 echo "Post remote health: $RMT_HVAL_POST"
1350 function check_no_resends() {
1351 echo "Check that no resends took place"
1352 [[ $RSND_POST -ne $RSND_PRE ]] &&
1353 error "Found resends: $RSND_POST != $RSND_PRE"
1358 function check_resends() {
1359 local delta=$((RSND_POST - RSND_PRE))
1361 echo "Check that $RETRY_PARAM resends took place"
1362 [[ $delta -ne $RETRY_PARAM ]] &&
1363 error "Expected $RETRY_PARAM resends found $delta"
1368 function check_no_local_health() {
1369 echo "Check that local NI health is unchanged"
1370 [[ $LO_HVAL_POST -ne $LO_HVAL_PRE ]] &&
1371 error "Local health changed: $LO_HVAL_POST != $LO_HVAL_PRE"
1376 function check_local_health() {
1377 echo "Check that local NI health has been changed"
1378 [[ $LO_HVAL_POST -eq $LO_HVAL_PRE ]] &&
1379 error "Local health unchanged: $LO_HVAL_POST == $LO_HVAL_PRE"
1384 function check_no_remote_health() {
1385 echo "Check that remote NI health is unchanged"
1386 [[ $RMT_HVAL_POST -ne $RMT_HVAL_PRE ]] &&
1387 error "Remote health changed: $RMT_HVAL_POST != $RMT_HVAL_PRE"
1392 function check_remote_health() {
1393 echo "Check that remote NI health has been changed"
1394 [[ $RMT_HVAL_POST -eq $RMT_HVAL_PRE ]] &&
1395 error "Remote health unchanged: $RMT_HVAL_POST == $RMT_HVAL_PRE"
1400 # See lnet/lnet/lib-msg.c:lnet_health_check()
1401 LNET_LOCAL_RESEND_STATUSES="local_interrupt local_dropped local_aborted"
1402 LNET_LOCAL_RESEND_STATUSES+=" local_no_route local_timeout"
1403 LNET_LOCAL_NO_RESEND_STATUSES="local_error"
1405 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1406 reinit_dlc || return $?
1407 add_net "tcp" "eth0" || return $?
1409 lnet_health_pre || return $?
1412 for hstatus in ${LNET_LOCAL_RESEND_STATUSES} \
1413 ${LNET_LOCAL_NO_RESEND_STATUSES}; do
1414 echo "Simulate $hstatus"
1415 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1416 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1417 error "Should have failed"
1418 $LCTL net_drop_del -a
1423 check_no_resends || return $?
1424 check_no_local_health || return $?
1428 run_test 204 "Check no health or resends for single-rail local failures"
1431 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1434 for hstatus in ${LNET_LOCAL_RESEND_STATUSES}; do
1435 reinit_dlc || return $?
1436 add_net "tcp" "eth0" || return $?
1437 add_net "tcp1" "eth0" || return $?
1439 echo "Simulate $hstatus"
1442 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1443 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e ${hstatus}
1444 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1445 error "Should have failed"
1446 $LCTL net_drop_del -a
1450 check_resends || return $?
1451 check_local_health || return $?
1454 for hstatus in ${LNET_LOCAL_NO_RESEND_STATUSES}; do
1455 reinit_dlc || return $?
1456 add_net "tcp" "eth0" || return $?
1457 add_net "tcp1" "eth0" || return $?
1459 echo "Simulate $hstatus"
1460 lnet_health_pre || return $?
1462 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1463 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e ${hstatus}
1464 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1465 error "Should have failed"
1466 $LCTL net_drop_del -a
1470 check_no_resends || return $?
1471 check_local_health || return $?
1476 run_test 205 "Check health and resends for multi-rail local failures"
1478 # See lnet/lnet/lib-msg.c:lnet_health_check()
1479 LNET_REMOTE_RESEND_STATUSES="remote_dropped"
1480 LNET_REMOTE_NO_RESEND_STATUSES="remote_error remote_timeout"
1482 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1483 reinit_dlc || return $?
1484 add_net "tcp" "eth0" || return $?
1486 do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1487 error "failed to discover myself"
1489 lnet_health_pre || return $?
1492 for hstatus in ${LNET_REMOTE_RESEND_STATUSES} \
1493 ${LNET_REMOTE_NO_RESEND_STATUSES}; do
1494 echo "Simulate $hstatus"
1495 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1496 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1497 error "Should have failed"
1498 $LCTL net_drop_del -a
1503 check_no_resends || return $?
1504 check_no_local_health || return $?
1505 check_no_remote_health || return $?
1509 run_test 206 "Check no health or resends for single-rail remote failures"
1512 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1515 for hstatus in ${LNET_REMOTE_RESEND_STATUSES}; do
1516 reinit_dlc || return $?
1517 add_net "tcp" "eth0" || return $?
1518 add_net "tcp1" "eth0" || return $?
1520 do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1521 error "failed to discover myself"
1523 echo "Simulate $hstatus"
1524 lnet_health_pre || return $?
1525 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1526 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e ${hstatus}
1527 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1528 error "Should have failed"
1529 $LCTL net_drop_del -a
1533 check_resends || return $?
1534 check_no_local_health || return $?
1535 check_remote_health || return $?
1537 for hstatus in ${LNET_REMOTE_NO_RESEND_STATUSES}; do
1538 reinit_dlc || return $?
1539 add_net "tcp" "eth0" || return $?
1540 add_net "tcp1" "eth0" || return $?
1542 do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1543 error "failed to discover myself"
1545 echo "Simulate $hstatus"
1546 lnet_health_pre || return $?
1547 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1548 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e ${hstatus}
1549 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1550 error "Should have failed"
1551 $LCTL net_drop_del -a
1555 check_no_resends || return $?
1556 check_no_local_health || return $?
1557 check_remote_health || return $?
1562 run_test 207 "Check health and resends for multi-rail remote errors"
1564 test_208_load_and_check_lnet() {
1568 local num_expected=1
1570 load_lnet "networks=\"\" ip2nets=\"${ip2nets_str}\""
1573 error "Failed to load LNet with ip2nets \"${ip2nets_str}\""
1579 nids=( $($LCTL list_nids) )
1581 [[ ${#nids[@]} -ne ${num_expected} ]] &&
1582 error "Expect ${num_expected} NIDs found ${#nids[@]}"
1584 [[ ${nids[0]} == ${p_nid} ]] ||
1585 error "Expect NID \"${p_nid}\" found \"${nids[0]}\""
1587 [[ -n $s_nid ]] && [[ ${nids[1]} != ${s_nid} ]] &&
1588 error "Expect second NID \"${s_nid}\" found \"${nids[1]}\""
1590 $LCTL net down &>/dev/null
1595 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1597 cleanup_netns || error "Failed to cleanup netns before test execution"
1598 cleanup_lnet || error "Failed to unload modules before test execution"
1599 setup_fakeif || error "Failed to add fake IF"
1601 have_interface "$FAKE_IF" ||
1602 error "Expect $FAKE_IF configured but not found"
1604 local eth0_ip=$(ip --oneline addr show dev eth0 |
1605 awk '/inet /{print $4}' |
1607 local ip2nets_str="tcp(eth0) $eth0_ip"
1609 echo "Configure single NID \"$ip2nets_str\""
1610 test_208_load_and_check_lnet "${ip2nets_str}" "${eth0_ip}@tcp"
1612 ip2nets_str="tcp(eth0) $eth0_ip; tcp1($FAKE_IF) $FAKE_IP"
1613 echo "Configure two NIDs; two NETs \"$ip2nets_str\""
1614 test_208_load_and_check_lnet "${ip2nets_str}" "${eth0_ip}@tcp" \
1617 ip2nets_str="tcp(eth0) $eth0_ip; tcp($FAKE_IF) $FAKE_IP"
1618 echo "Configure two NIDs; one NET \"$ip2nets_str\""
1619 test_208_load_and_check_lnet "${ip2nets_str}" "${eth0_ip}@tcp" \
1621 local addr1=( ${eth0_ip//./ } )
1622 local addr2=( ${FAKE_IP//./ } )
1623 local range="[${addr1[0]},${addr2[0]}]"
1626 for i in $(seq 1 3); do
1627 range+=".[${addr1[$i]},${addr2[$i]}]"
1629 ip2nets_str="tcp(eth0,${FAKE_IF}) ${range}"
1631 echo "Configured two NIDs; one NET alt syntax \"$ip2nets_str\""
1632 test_208_load_and_check_lnet "${ip2nets_str}" "${eth0_ip}@tcp" \
1637 echo "alt syntax with missing IF \"$ip2nets_str\""
1638 load_lnet "networks=\"\" ip2nets=\"${ip2nets_str}\""
1640 echo "$LCTL net up should fail"
1642 error "LNet bringup should have failed"
1646 run_test 208 "Test various kernel ip2nets configurations"
1649 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1651 reinit_dlc || return $?
1652 add_net "tcp" "eth0" || return $?
1654 do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1655 error "failed to discover myself"
1657 echo "Simulate network_timeout w/SR config"
1660 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e network_timeout
1661 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1662 error "Should have failed"
1663 $LCTL net_drop_del -a
1667 check_no_resends || return $?
1668 check_no_local_health || return $?
1669 check_no_remote_health || return $?
1671 reinit_dlc || return $?
1672 add_net "tcp" "eth0" || return $?
1673 add_net "tcp1" "eth0" || return $?
1675 do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1676 error "failed to discover myself"
1678 echo "Simulate network_timeout w/MR config"
1681 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e network_timeout
1682 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e network_timeout
1683 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1684 error "Should have failed"
1685 $LCTL net_drop_del -a
1689 check_no_resends || return $?
1690 check_local_health || return $?
1691 check_remote_health || return $?
1695 run_test 209 "Check health, but not resends, for network timeout"
1697 check_nid_in_recovq() {
1698 local recovq=$($LNETCTL debug recovery $1)
1700 local nids=$($LCTL list_nids | xargs echo)
1704 echo "Check recovery queue"
1706 if [[ $(grep -c 'nid-'<<<$recovq) -ne $expect ]]; then
1707 error "Expect $expect NIDs found: \"$recovq\""
1710 [[ $expect -eq 0 ]] && return 0
1712 for nid in ${nids}; do
1713 grep -q "nid-0: $nid"<<<$recovq &&
1718 error "Didn't find local NIDs in recovery queue: \"$recovq\""
1724 # First enqueue happens at time 0.
1725 # 2nd at 0 + 2^0 = 1
1726 # 3rd at 1 + 2^1 = 3
1727 # 4th at 3 + 2^2 = 7
1728 # 5th at 7 + 2^3 = 15
1729 # e.g. after 10 seconds we would expect to have seen the 4th enqueue,
1730 # (3 pings sent, 4th about to happen) and the 5th enqueue is yet to
1732 # If the recovery limit is 10 seconds, then when the 5th enqueue happens
1733 # we expect the peer NI to have aged out, so it will not actually be
1735 check_ping_count() {
1739 echo "Check ping counts:"
1741 if [[ $queue == "ni" ]]; then
1742 $LNETCTL net show -v 2 | egrep 'nid|health value|ping'
1743 ping_count=( $($LNETCTL net show -v 2 |
1744 awk '/ping_count/{print $NF}') )
1745 elif [[ $queue == "peer_ni" ]]; then
1746 $LNETCTL peer show -v 2 | egrep 'nid|health value|ping'
1747 ping_count=( $($LNETCTL peer show -v 2 |
1748 awk '/ping_count/{print $NF}') )
1750 error "Unrecognized queue \"$queue\""
1756 for count in ${ping_count[@]}; do
1757 if [[ $count -eq $expect ]]; then
1758 if [[ $expect -ne 0 ]] && $found ; then
1759 error "Found more than one interface matching \"$expect\" ping count"
1762 echo "Expect ping count \"$expect\" found \"$count\""
1765 elif [[ $count -ne 0 ]]; then
1766 error "Found interface with ping count \"$count\" but expect \"$expect\""
1775 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1776 reinit_dlc || return $?
1777 add_net "tcp" "eth0" || return $?
1778 add_net "tcp1" "eth0" || return $?
1780 local prim_nid=$($LCTL list_nids | head -n 1)
1782 do_lnetctl discover $prim_nid ||
1783 error "failed to discover myself"
1785 # Set recovery limit to 10 seconds.
1786 do_lnetctl set recovery_limit 10 ||
1787 error "failed to set recovery_limit"
1789 $LCTL set_param debug=+net
1790 # Use local_error so LNet doesn't attempt to resend the discovery ping
1791 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e local_error
1792 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e local_error
1793 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1794 error "Expected discovery to fail"
1797 check_nid_in_recovq "-l" 1
1798 check_ping_count "ni" "2"
1802 check_nid_in_recovq "-l" 1
1803 check_ping_count "ni" "3"
1805 $LCTL net_drop_del -a
1809 run_test 210 "Local NI recovery checks"
1812 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1813 reinit_dlc || return $?
1814 add_net "tcp" "eth0" || return $?
1815 add_net "tcp1" "eth0" || return $?
1817 local prim_nid=$($LCTL list_nids | head -n 1)
1819 do_lnetctl discover $prim_nid ||
1820 error "failed to discover myself"
1822 # Set recovery limit to 10 seconds.
1823 do_lnetctl set recovery_limit 10 ||
1824 error "failed to set recovery_limit"
1826 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e remote_error
1827 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e remote_error
1829 # Set health to 0 on one interface. This forces it onto the recovery
1831 $LNETCTL peer set --nid $prim_nid --health 0
1833 # After 5 seconds, we expect the peer NI to still be in recovery
1835 check_nid_in_recovq "-p" 1
1836 check_ping_count "peer_ni" "2"
1838 # After 15 seconds, the peer NI should have been fully processed out of
1839 # the recovery queue. We'll allow a total of 17 seconds to account for
1840 # differences in sleeping for whole seconds vs. the more accurate time
1841 # keeping that is done in the recovery code.
1843 check_nid_in_recovq "-p" 0
1844 check_ping_count "peer_ni" "4"
1846 $LCTL net_drop_del -a
1848 # Set health to force it back onto the recovery queue. Set to 500 means
1849 # in 5 seconds it should be back at maximum value. We'll wait a couple
1850 # more seconds than that to be safe.
1851 # NB: we reset the recovery limit to 0 (indefinite) so the peer NI is
1853 do_lnetctl set recovery_limit 0 ||
1854 error "failed to set recovery_limit"
1856 $LNETCTL peer set --nid $prim_nid --health 500
1858 check_nid_in_recovq "-p" 1
1859 check_ping_count "peer_ni" "2"
1863 check_nid_in_recovq "-p" 0
1864 check_ping_count "peer_ni" "0"
1868 run_test 211 "Remote NI recovery checks"
1871 local rnodes=$(remote_nodes_list)
1872 [[ -z $rnodes ]] && skip "Need at least 1 remote node"
1874 cleanup_lnet || error "Failed to cleanup before test execution"
1876 # Loading modules should configure LNet with the appropriate
1877 # test-framework configuration
1878 load_modules || error "Failed to load modules"
1880 local my_nid=$($LCTL list_nids | head -n 1)
1882 error "Failed to get primary NID for local host $HOSTNAME"
1884 local rnode=$(awk '{print $1}' <<<$rnodes)
1885 local rnodenids=$(do_node $rnode $LCTL list_nids | xargs echo)
1888 if [[ -z $rnodenids ]]; then
1889 do_rpc_nodes $rnode load_modules_local
1891 rnodenids=$(do_node $rnode $LCTL list_nids | xargs echo)
1894 local rnodepnid=$(awk '{print $1}' <<< $rnodenids)
1896 [[ -z $rnodepnid ]] &&
1897 error "Failed to get primary NID for remote host $rnode"
1899 log "Initial discovery"
1900 do_lnetctl discover --force $rnodepnid ||
1901 error "Failed to discover $rnodepnid"
1903 do_node $rnode "$LNETCTL discover --force $my_nid" ||
1904 error "$rnode failed to discover $my_nid"
1906 log "Fail local discover ping to set LNET_PEER_REDISCOVER flag"
1907 $LCTL net_drop_add -s "*@$NETTYPE" -d "*@$NETTYPE" -r 1 -e local_error
1908 do_lnetctl discover --force $rnodepnid &&
1909 error "Discovery should have failed"
1910 $LCTL net_drop_del -a
1913 for nid in $rnodenids; do
1914 # We need GET (PING) delay just long enough so we can trigger
1915 # discovery on the remote peer
1916 $LCTL net_delay_add -s "*@$NETTYPE" -d $nid -r 1 -m GET -l 3
1917 $LCTL net_drop_add -s "*@$NETTYPE" -d $nid -r 1 -m GET -e local_error
1918 # We need PUT (PUSH) delay just long enough so we can process
1920 $LCTL net_delay_add -s "*@$NETTYPE" -d $nid -r 1 -m PUT -l 6
1923 log "Force $HOSTNAME to discover $rnodepnid (in background)"
1924 # We want to get a PING sent that we know will eventually fail.
1925 # The delay rules we added will ensure the ping is not sent until
1926 # the PUSH is also in flight (see below), and the drop rule ensures that
1927 # when the PING is eventually sent it will error out
1928 do_lnetctl discover --force $rnodepnid &
1931 # We want a discovery PUSH from rnode to put rnode back on our
1932 # discovery queue. This should cause us to try and send a PUSH to rnode
1933 # while the PING is still outstanding.
1934 log "Force $rnode to discover $my_nid"
1935 do_node $rnode $LNETCTL discover --force $my_nid
1937 # At this point we'll have both PING_SENT and PUSH_SENT set for the
1938 # rnode peer. Wait for the PING to error out which should terminate the
1939 # discovery process that we backgrounded.
1940 log "Wait for $pid1"
1942 log "Finished wait on $pid1"
1944 # The PING send failure clears the PING_SENT flag and puts the peer back
1945 # on the discovery queue. When discovery thread processes the peer it
1946 # will mistakenly clear the PUSH_SENT flag (and set PUSH_FAILED).
1947 # Discovery will then complete for this peer even though we have an
1949 # When PUSH is actually unlinked it will be forced back onto the
1950 # discovery queue, but we no longer have a ref on the peer. When
1951 # discovery completes again, we'll trip the ASSERT in
1952 # lnet_destroy_peer_locked()
1954 # Delete the delay rules to send the PUSH
1955 $LCTL net_delay_del -a
1956 # Delete the drop rules
1957 $LCTL net_drop_del -a
1960 error "Failed to unload modules"
1962 do_rpc_nodes $rnode unload_modules_local ||
1963 error "Failed to unload modules on $rnode"
1968 run_test 212 "Check discovery refcount loss bug (LU-14627)"
1971 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1973 cleanup_netns || error "Failed to cleanup netns before test execution"
1974 cleanup_lnet || error "Failed to unload modules before test execution"
1976 setup_fakeif || error "Failed to add fake IF"
1977 have_interface "$FAKE_IF" ||
1978 error "Expect $FAKE_IF configured but not found"
1980 reinit_dlc || return $?
1982 add_net "tcp" "eth0" || return $?
1983 add_net "tcp" "$FAKE_IF" || return $?
1985 local nid1=$(lctl list_nids | head -n 1)
1986 local nid2=$(lctl list_nids | tail --lines 1)
1988 [[ $(lctl which_nid $nid1 $nid2) == $nid1 ]] ||
1989 error "Expect nid1 \"$nid1\" to be preferred"
1991 [[ $(lctl which_nid $nid2 $nid1) == $nid2 ]] ||
1992 error "Expect nid2 \"$nid2\" to be preferred"
1996 run_test 213 "Check LNetDist calculation for multiple local NIDs"
2000 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
2002 echo "Check valid values; Should succeed"
2005 for ((i = 4; i < 16; i+=4)); do
2006 reinit_dlc || return $?
2007 add_net "tcp" "eth0" || return $?
2008 do_lnetctl net set --all --conns-per-peer $i ||
2009 error "should have succeeded $?"
2010 $LNETCTL net show -v 1 | grep -q "conns_per_peer: $i" ||
2011 error "failed to set conns-per-peer to $i"
2012 lnid="$(lctl list_nids | head -n 1)"
2013 do_lnetctl ping "$lnid" ||
2014 error "failed to ping myself"
2015 printf 'network tcp\nconn_list\n' | lctl | grep -c "$lnid" | grep -q $((2+i*2)) ||
2016 error "expected number of tcp connections $((2+i*2))"
2019 reinit_dlc || return $?
2020 add_net "tcp" "eth0" || return $?
2021 echo "Set > 127; Should fail"
2022 do_lnetctl net set --all --conns-per-peer 128 &&
2023 error "should have failed $?"
2025 reinit_dlc || return $?
2026 add_net "tcp" "eth0" || return $?
2027 echo "Set < 0; Should be ignored"
2028 do_lnetctl net set --all --conns-per-peer -1 ||
2029 error "should have succeeded $?"
2030 $LNETCTL net show -v 1 | grep -q "conns_per_peer: 1" ||
2031 error "Did not stay at default"
2033 run_test 230 "Test setting conns-per-peer"
2038 local out=$TMP/$tfile
2039 local prefix=/usr/include/linux/lnet
2041 # We use a hard coded prefix so that this test will not fail
2044 if ! which $CC > /dev/null 2>&1; then
2045 skip_env "$CC is not installed"
2048 cleanup_lnet || exit 1
2051 local cc_args="-Wall -Werror -std=c99 -c -x c /dev/null -o $out"
2052 if ! [[ -d $prefix ]]; then
2053 # Assume we're running in tree and fixup the include path.
2054 prefix=$LUSTRE/../lnet/include/uapi/linux/lnet
2055 cc_args+=" -I $LUSTRE/../lnet/include/uapi"
2058 for header in $prefix/*.h; do
2059 if ! [[ -f "$header" ]]; then
2063 echo "$CC $cc_args -include $header"
2064 $CC $cc_args -include $header ||
2065 error "cannot compile '$header'"
2069 run_test 300 "packaged LNet UAPI headers can be compiled"