3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
11 # bug number for skipped test:
12 ALWAYS_EXCEPT="$SANITY_LNET_EXCEPT "
13 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
15 # skip the grant tests for ARM until they are fixed
16 if [[ $(uname -m) = aarch64 ]]; then
17 # bug number: LU-14067
21 [ "$SLOW" = "no" ] && EXCEPT_SLOW=""
23 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
25 . $LUSTRE/tests/test-framework.sh
29 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
34 [[ -z $LNETCTL ]] && skip "Need lnetctl"
38 if is_mounted $MOUNT || is_mounted $MOUNT2; then
39 cleanupall || error "Failed cleanup prior to test execution"
44 echo "Cleaning up LNet"
45 lsmod | grep -q lnet &&
46 $LNETCTL lnet unconfigure 2>/dev/null
51 if module_loaded lnet ; then
52 cleanup_lnet || error "Failed to unload modules before test execution"
58 # Cleanup any tmp files created by the sub tests
59 rm -f $TMP/sanity-lnet-*.yaml $LNET_PARAMS_FILE
62 if $restore_mounts; then
63 setupall || error "Failed to setup Lustre after test execution"
64 elif $restore_modules; then
66 error "Couldn't load modules after test execution"
72 load_module ../libcfs/libcfs/libcfs
73 # Prevent local MODOPTS_LIBCFS being passed as part of environment
74 # variable to remote nodes
77 set_default_debug "neterror net nettrace malloc"
78 load_module ../lnet/lnet/lnet "$@"
80 LNDPATH=${LNDPATH:-"../lnet/klnds"}
81 if [ -z "$LNETLND" ]; then
83 o2ib*) LNETLND="o2iblnd/ko2iblnd" ;;
84 tcp*) LNETLND="socklnd/ksocklnd" ;;
85 *) local lnd="${NETTYPE%%[0-9]}lnd"
86 [ -f "$LNDPATH/$lnd/k$lnd.ko" ] &&
87 LNETLND="$lnd/k$lnd" ||
88 LNETLND="socklnd/ksocklnd"
91 load_module ../lnet/klnds/$LNETLND
103 echo "ip netns exec $TESTNS $@"
104 ip netns exec $TESTNS "$@"
112 netns_arg="netns $netns"
114 ip link add 'test1pl' type veth peer name $FAKE_IF $netns_arg
115 ip link set 'test1pl' up
116 if [[ -n $netns ]]; then
117 do_ns ip addr add "${FAKE_IP}/31" dev $FAKE_IF
118 do_ns ip link set $FAKE_IF up
120 ip addr add "${FAKE_IP}/31" dev $FAKE_IF
121 ip link set $FAKE_IF up
126 ip link show test1pl >& /dev/null && ip link del test1pl || return 0
137 (ip netns list | grep -q $TESTNS) && ip netns del $TESTNS
142 echo "Loading LNet and configuring DLC"
144 do_lnetctl lnet configure
147 GLOBAL_YAML_FILE=$TMP/sanity-lnet-global.yaml
148 define_global_yaml() {
149 $LNETCTL export --backup >${GLOBAL_YAML_FILE} ||
150 error "Failed to export global yaml $?"
154 if lsmod | grep -q lnet; then
155 do_lnetctl lnet unconfigure ||
156 error "lnetctl lnet unconfigure failed $?"
157 do_lnetctl lnet configure ||
158 error "lnetctl lnet configure failed $?"
160 configure_dlc || error "configure_dlc failed $?"
165 append_global_yaml() {
166 [[ ! -e ${GLOBAL_YAML_FILE} ]] &&
167 error "Missing global yaml at ${GLOBAL_YAML_FILE}"
169 cat ${GLOBAL_YAML_FILE} >> $TMP/sanity-lnet-$testnum-expected.yaml
172 create_base_yaml_file() {
176 compare_yaml_files() {
177 local expected="$TMP/sanity-lnet-$testnum-expected.yaml"
178 local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
180 ! [[ -e $expected ]] && echo "$expected not found" && return 1
181 ! [[ -e $actual ]] && echo "$actual not found" && return 1
182 diff -upN ${actual} ${expected} || rc=$?
192 local net="${nid//*@/}"
193 local addr="${nid//@*/}"
195 local num_re='[0-9]\+'
196 local ip_re="[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
198 if [[ $net =~ gni[0-9]* ]]; then
199 [[ $addr =~ ${num_re} ]] && return 0
201 [[ $addr =~ ${ip_re} ]] && return 0
206 local yfile=$TMP/sanity-lnet-$testnum-actual.yaml
207 local primary_nids=$(awk '/- primary nid:/{print $NF}' $yfile | xargs echo)
208 local secondary_nids=$(awk '/- nid:/{print $NF}' $yfile | xargs echo)
209 local gateway_nids=$(awk '/gateway:/{print $NF}' $yfile | xargs echo)
212 for nid in $primary_nids $secondary_nids; do
213 validate_nid "$nid" || error "Bad NID \"${nid}\""
218 validate_peer_nids() {
220 local nids_per_peer="$2"
222 local expect_p="$num_peers"
223 # The primary nid also shows up in the list of secondary nids
224 local expect_s="$(($num_peers + $(($nids_per_peer*$num_peers))))"
226 local actual_p=$(grep -c -- '- primary nid:' $TMP/sanity-lnet-$testnum-actual.yaml)
227 local actual_s=$(grep -c -- '- nid:' $TMP/sanity-lnet-$testnum-actual.yaml)
228 if [[ $expect_p -ne $actual_p ]]; then
230 error "Expected $expect_p but found $actual_p primary nids"
231 elif [[ $expect_s -ne $actual_s ]]; then
233 error "Expected $expect_s but found $actual_s secondary nids"
238 validate_gateway_nids() {
239 local expect_gw=$(grep -c -- 'gateway:' $TMP/sanity-lnet-$testnum-expected.yaml)
240 local actual_gw=$(grep -c -- 'gateway:' $TMP/sanity-lnet-$testnum-actual.yaml)
241 if [[ $expect_gw -ne $actual_gw ]]; then
243 error "Expected $expect_gw gateways but found $actual_gw gateways"
249 setup_netns || error "setup_netns failed with $?"
251 # Determine the local interface(s) used for LNet
252 load_modules || error "Failed to load modules"
253 NIDS=( $($LCTL list_nids | xargs echo) )
254 if [[ -z ${NIDS[@]} ]]; then
255 error "No NID configured after module load"
261 declare -a INTERFACES
262 for ((i = 0; i < ${#NIDS[@]}; i++)); do
263 ip=$(sed 's/^\(.*\)@.*$/\1/'<<<${NIDS[i]})
264 INTERFACES[i]=$(ip -o a s |
265 awk '$4 ~ /^'$ip'\//{print $2}')
266 INTERFACES=($(echo "${INTERFACES[@]}" | tr ' ' '\n' | uniq | tr '\n' ' '))
267 if [[ -z ${INTERFACES[i]} ]]; then
268 error "Can't determine interface name for NID ${NIDS[i]}"
269 elif [[ 1 -ne $(wc -w <<<${INTERFACES[i]}) ]]; then
270 error "Found $(wc -w <<<${INTERFACES[i]}) interfaces for NID ${NIDS[i]}. Expect 1"
274 cleanup_lnet || error "Failed to cleanup LNet"
276 stack_trap 'cleanup_testsuite' EXIT
279 load_module ../lnet/lnet/lnet || error "Failed to load module rc = $?"
280 do_lnetctl lnet configure || error "lnet configure failed rc = $?"
282 reinit_dlc || return $?
283 do_lnetctl import < ${GLOBAL_YAML_FILE} || error "Import failed $?"
284 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
285 create_base_yaml_file
286 compare_yaml_files || error "Configuration changed after import"
288 run_test 0 "Export empty config, import the config, compare"
291 local prim_nid="${1:+--prim_nid $1}"
292 local nid="${2:+--nid $2}"
294 local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
296 do_lnetctl peer add ${prim_nid} ${nid} || error "peer add failed $?"
297 $LNETCTL export --backup > $actual || error "export failed $?"
303 reinit_dlc || return $?
304 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
306 - primary nid: 1.1.1.1@tcp
312 compare_peer_add "1.1.1.1@tcp"
314 run_test 1 "Add peer with single nid (tcp)"
317 reinit_dlc || return $?
318 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
320 - primary nid: 2.2.2.2@o2ib
326 compare_peer_add "2.2.2.2@o2ib"
328 run_test 2 "Add peer with single nid (o2ib)"
331 reinit_dlc || return $?
332 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
334 - primary nid: 3.3.3.3@tcp
341 compare_peer_add "3.3.3.3@tcp" "3.3.3.3@o2ib"
343 run_test 3 "Add peer with tcp primary o2ib secondary"
346 reinit_dlc || return $?
347 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
349 - primary nid: 4.4.4.4@tcp
358 echo "Add peer with nidrange (tcp)"
359 compare_peer_add "4.4.4.4@tcp" "4.4.4.[1-3]@tcp"
361 echo "Add peer with nidrange that overlaps primary nid (tcp)"
362 compare_peer_add "4.4.4.4@tcp" "4.4.4.[1-4]@tcp"
364 run_test 4 "Add peer with nidrange (tcp)"
367 reinit_dlc || return $?
368 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
370 - primary nid: 5.5.5.5@o2ib
380 echo "Add peer with nidrange (o2ib)"
381 compare_peer_add "5.5.5.5@o2ib" "5.5.5.[1-4]@o2ib"
383 echo "Add peer with nidranage that overlaps primary nid (o2ib)"
384 compare_peer_add "5.5.5.5@o2ib" "5.5.5.[1-4]@o2ib"
386 run_test 5 "Add peer with nidrange (o2ib)"
389 reinit_dlc || return $?
390 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
392 - primary nid: 6.6.6.6@tcp
412 compare_peer_add "6.6.6.6@tcp" \
413 "6.6.[6-7].[0-4/2]@tcp,6.6.[1-4/2].[0-6/3]@o2ib,[6-12/4]@gni"
415 run_test 6 "Add peer with multiple nidranges"
418 local prim_nid="${1:+--prim_nid $1}"
419 local nid="${2:+--nid $2}"
421 local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
423 do_lnetctl peer del ${prim_nid} ${nid} || error "peer del failed $?"
424 $LNETCTL export --backup > $actual || error "export failed $?"
430 reinit_dlc || return $?
431 create_base_yaml_file
433 echo "Delete peer with single nid (tcp)"
434 do_lnetctl peer add --prim_nid 7.7.7.7@tcp || error "Peer add failed $?"
435 compare_peer_del "7.7.7.7@tcp"
437 echo "Delete peer with single nid (o2ib)"
438 do_lnetctl peer add --prim_nid 7.7.7.7@o2ib || error "Peer add failed $?"
439 compare_peer_del "7.7.7.7@o2ib"
441 echo "Delete peer that has multiple nids (tcp)"
442 do_lnetctl peer add --prim_nid 7.7.7.7@tcp --nid 7.7.7.[8-12]@tcp ||
443 error "Peer add failed $?"
444 compare_peer_del "7.7.7.7@tcp"
446 echo "Delete peer that has multiple nids (o2ib)"
447 do_lnetctl peer add --prim_nid 7.7.7.7@o2ib --nid 7.7.7.[8-12]@o2ib ||
448 error "Peer add failed $?"
449 compare_peer_del "7.7.7.7@o2ib"
451 echo "Delete peer that has both tcp and o2ib nids"
452 do_lnetctl peer add --prim_nid 7.7.7.7@tcp \
453 --nid 7.7.7.[9-12]@tcp,7.7.7.[13-15]@o2ib ||
454 error "Peer add failed $?"
455 compare_peer_del "7.7.7.7@tcp"
457 echo "Delete peer with single nid (gni)"
458 do_lnetctl peer add --prim_nid 7@gni || error "Peer add failed $?"
459 compare_peer_del "7@gni"
461 echo "Delete peer that has multiple nids (gni)"
462 do_lnetctl peer add --prim_nid 7@gni --nid [8-12]@gni ||
463 error "Peer add failed $?"
464 compare_peer_del "7@gni"
466 echo "Delete peer that has tcp, o2ib and gni nids"
467 do_lnetctl peer add --prim_nid 7@gni \
468 --nid [8-12]@gni,7.7.7.[9-12]@tcp,7.7.7.[13-15]@o2ib ||
469 error "Peer add failed $?"
470 compare_peer_del "7@gni"
472 run_test 7 "Various peer delete tests"
475 reinit_dlc || return $?
477 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
479 - primary nid: 8.8.8.8@tcp
491 do_lnetctl peer add --prim_nid 8.8.8.8@tcp --nid 8.8.8.[10-15]@tcp ||
492 error "Peer add failed $?"
493 compare_peer_del "8.8.8.8@tcp" "8.8.8.13@tcp"
495 run_test 8 "Delete single secondary nid from peer (tcp)"
498 reinit_dlc || return $?
500 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
502 - primary nid: 9.9.9.9@tcp
509 do_lnetctl peer add --prim_nid 9.9.9.9@tcp \
510 --nid 9.9.9.[11-16]@tcp || error "Peer add failed $?"
511 compare_peer_del "9.9.9.9@tcp" "9.9.9.[11-16]@tcp"
513 run_test 9 "Delete all secondary nids from peer (tcp)"
516 reinit_dlc || return $?
518 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
520 - primary nid: 10.10.10.10@tcp
523 - nid: 10.10.10.10@tcp
524 - nid: 10.10.10.12@tcp
525 - nid: 10.10.10.13@tcp
526 - nid: 10.10.10.15@tcp
527 - nid: 10.10.10.16@tcp
530 do_lnetctl peer add --prim_nid 10.10.10.10@tcp \
531 --nid 10.10.10.[12-16]@tcp || error "Peer add failed $?"
532 compare_peer_del "10.10.10.10@tcp" "10.10.10.14@tcp"
534 run_test 10 "Delete single secondary nid from peer (o2ib)"
537 reinit_dlc || return $?
539 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
541 - primary nid: 11.11.11.11@tcp
544 - nid: 11.11.11.11@tcp
547 do_lnetctl peer add --prim_nid 11.11.11.11@tcp \
548 --nid 11.11.11.[13-17]@tcp || error "Peer add failed $?"
549 compare_peer_del "11.11.11.11@tcp" "11.11.11.[13-17]@tcp"
551 run_test 11 "Delete all secondary nids from peer (o2ib)"
554 reinit_dlc || return $?
556 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
558 - primary nid: 12.12.12.12@o2ib
561 - nid: 12.12.12.12@o2ib
562 - nid: 13.13.13.13@o2ib
563 - nid: 14.13.13.13@o2ib
564 - nid: 14.15.13.13@o2ib
566 - nid: 15.17.1.10@tcp
567 - nid: 15.17.1.20@tcp
570 do_lnetctl peer add --prim_nid 12.12.12.12@o2ib \
571 --nid [13-14/1].[13-15/2].13.13@o2ib,[15-16/3].[17-19/4].[1].[5-20/5]@tcp ||
572 error "Peer add failed $?"
573 compare_peer_del "12.12.12.12@o2ib" "13.15.13.13@o2ib,15.17.1.15@tcp"
575 run_test 12 "Delete a secondary nid from peer (tcp and o2ib)"
578 reinit_dlc || return $?
580 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
582 - primary nid: 13.13.13.13@o2ib
585 - nid: 13.13.13.13@o2ib
588 do_lnetctl peer add --prim_nid 13.13.13.13@o2ib \
589 --nid [14-15].[1-2/1].[1].[100-254/10]@tcp,14.14.[254].14@o2ib ||
590 error "Peer add failed $?"
591 compare_peer_del "13.13.13.13@o2ib" \
592 "[14-15].[1-2/1].[1].[100-254/10]@tcp,14.14.[254].14@o2ib"
594 run_test 13 "Delete all secondary nids from peer (tcp and o2ib)"
600 if [[ $net =~ gni* ]]; then
603 echo "${num}.${num}.${num}.${num}@${net}"
607 create_mr_peer_yaml() {
609 local secondary_nids="$2"
612 echo "Generating peer yaml for $num_peers peers with $secondary_nids secondary nids"
613 echo "peer:" >> $TMP/sanity-lnet-$testnum-expected.yaml
615 local total_nids=$((num_peers + $((num_peers * secondary_nids))))
618 while [[ $created -lt $num_peers ]]; do
619 local primary=$(create_nid ${nidnum} ${net})
620 cat <<EOF >> $TMP/sanity-lnet-$testnum-expected.yaml
621 - primary nid: $primary
627 local start=$((nidnum + 1))
628 local end=$((nidnum + $secondary_nids))
629 for j in $(seq ${start} ${end}); do
630 local nid=$(create_nid $j ${net})
631 echo " - nid: $nid" >> $TMP/sanity-lnet-$testnum-expected.yaml
639 reinit_dlc || return $?
641 echo "Create single peer, single nid, using import"
642 create_mr_peer_yaml 1 0 tcp
643 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
644 error "Import failed $?"
646 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
649 echo "Delete single peer using import --del"
650 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
651 error "Import failed $?"
652 rm -f $TMP/sanity-lnet-$testnum-expected.yaml
653 create_base_yaml_file
654 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
657 run_test 14 "import peer create/delete with single nid"
660 reinit_dlc || return $?
662 echo "Create multiple peers, single nid per peer, using import"
663 create_mr_peer_yaml 5 0 o2ib
664 # The ordering of nids for this use-case is non-deterministic, so we
665 # we can't just diff the expected/actual output.
666 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
667 error "Import failed $?"
668 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
669 validate_peer_nids 5 0
671 echo "Delete multiple peers, single nid per peer, using import --del"
672 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
673 error "Import failed $?"
674 rm -f $TMP/sanity-lnet-$testnum-expected.yaml
675 create_base_yaml_file
676 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
679 run_test 15 "import multi peer create/delete with single nid per peer"
682 reinit_dlc || return $?
684 echo "Create single peer, multiple nids, using import"
685 create_mr_peer_yaml 1 5 tcp
686 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
687 error "Import failed $?"
688 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
689 validate_peer_nids 1 5
691 echo "Delete single peer, multiple nids, using import --del"
692 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
693 error "Import failed $?"
694 rm -f $TMP/sanity-lnet-$testnum-expected.yaml
695 create_base_yaml_file
696 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
699 run_test 16 "import peer create/delete with multiple nids"
702 reinit_dlc || return $?
704 echo "Create multiple peers, multiple nids per peer, using import"
705 create_mr_peer_yaml 5 7 o2ib
706 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
707 error "Import failed $?"
708 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
709 validate_peer_nids 5 7
711 echo "Delete multiple peers, multiple nids per peer, using import --del"
712 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
713 error "Import failed $?"
714 rm -f $TMP/sanity-lnet-$testnum-expected.yaml
715 create_base_yaml_file
716 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
719 run_test 17 "import multi peer create/delete with multiple nids"
722 reinit_dlc || return $?
724 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
726 - primary nid: 1.1.1.1@tcp
735 echo "Import peer with 5 nids"
736 cat $TMP/sanity-lnet-$testnum-expected.yaml
737 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
738 error "Import failed $?"
739 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
741 - primary nid: 1.1.1.1@tcp
748 echo "Delete three of the nids"
749 cat $TMP/sanity-lnet-$testnum-expected.yaml
750 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml
751 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
753 - primary nid: 1.1.1.1@tcp
759 echo "Check peer has expected nids remaining"
760 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
764 run_test 18a "Delete a subset of nids from a single peer using import --del"
767 reinit_dlc || return $?
769 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
771 - primary nid: 1.1.1.1@tcp
779 - primary nid: 6.6.6.6@o2ib
788 echo "Import two peers with 5 nids each"
789 cat $TMP/sanity-lnet-$testnum-expected.yaml
790 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
791 error "Import failed $?"
792 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
794 - primary nid: 1.1.1.1@tcp
800 - primary nid: 6.6.6.6@o2ib
807 echo "Delete three of the nids from each peer"
808 cat $TMP/sanity-lnet-$testnum-expected.yaml
809 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml
810 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
812 - primary nid: 6.6.6.6@o2ib
817 - primary nid: 1.1.1.1@tcp
824 echo "Check peers have expected nids remaining"
825 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
827 validate_peer_nids 2 1
829 run_test 18b "Delete multiple nids from multiple peers using import --del"
832 reinit_dlc || return $?
833 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
835 - primary nid: 19@gni
841 compare_peer_add "19@gni"
843 run_test 19 "Add peer with single nid (gni)"
846 reinit_dlc || return $?
847 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
849 - primary nid: 20@gni
853 - nid: 20.20.20.20@tcp
854 - nid: 20.20.20.20@o2ib
857 compare_peer_add "20@gni" "20.20.20.20@tcp,20.20.20.20@o2ib"
859 run_test 20 "Add peer with gni primary and tcp, o2ib secondary"
862 reinit_dlc || return $?
863 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
865 - primary nid: 21@gni
875 echo "Add peer with nidrange (gni)"
876 compare_peer_add "21@gni" "[22-25]@gni" || error
877 echo "Add peer with nidrange that overlaps primary nid (gni)"
878 compare_peer_add "21@gni" "[21-25]@gni"
880 run_test 21 "Add peer with nidrange (gni)"
883 reinit_dlc || return $?
884 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
886 - primary nid: 22@gni
897 do_lnetctl peer add --prim_nid 22@gni --nid [24-29]@gni ||
898 error "Peer add failed $?"
899 compare_peer_del "22@gni" "26@gni"
901 run_test 22 "Delete single secondary nid from peer (gni)"
904 reinit_dlc || return $?
905 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
907 - primary nid: 23@gni
914 do_lnetctl peer add --prim_nid 23@gni --nid [25-29]@gni ||
915 error "Peer add failed $?"
916 compare_peer_del "23@gni" "[25-29]@gni"
918 run_test 23 "Delete all secondary nids from peer (gni)"
921 reinit_dlc || return $?
922 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
924 - primary nid: 24@gni
929 - nid: 13.13.13.13@o2ib
930 - nid: 14.13.13.13@o2ib
931 - nid: 14.15.13.13@o2ib
933 - nid: 15.17.1.10@tcp
934 - nid: 15.17.1.20@tcp
937 do_lnetctl peer add --prim_nid 24@gni \
938 --nid [13-14/1].[13-15/2].13.13@o2ib,[15-16/3].[17-19/4].[1].[5-20/5]@tcp,[5-12/6]@gni ||
939 error "Peer add failed $?"
940 compare_peer_del "24@gni" "5@gni,13.15.13.13@o2ib,15.17.1.15@tcp"
942 run_test 24 "Delete a secondary nid from peer (tcp, o2ib and gni)"
945 reinit_dlc || return $?
946 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
948 - primary nid: 25@gni
954 do_lnetctl peer add --prim_nid 25@gni \
955 --nid [26-27].[4-10/3].26.26@tcp,26.26.26.26@o2ib,[30-35]@gni ||
956 error "Peer add failed $?"
957 compare_peer_del "25@gni" \
958 "[26-27].[4-10/3].26.26@tcp,26.26.26.26@o2ib,[30-35]@gni"
960 run_test 25 "Delete all secondary nids from peer (tcp, gni and o2ib)"
963 reinit_dlc || return $?
965 echo "Invalid prim_nid - peer add"
966 do_lnetctl peer add --prim_nid foobar &&
967 error "Command should have failed"
969 echo "Invalid prim_nid - peer del"
970 do_lnetctl peer del --prim_nid foobar &&
971 error "Command should have failed"
973 echo "Delete non-existing peer"
974 do_lnetctl peer del --prim_nid 1.1.1.1@o2ib &&
975 error "Command should have failed"
977 echo "Don't provide mandatory argument for peer del"
978 do_lnetctl peer del --nid 1.1.1.1@tcp &&
979 error "Command should have failed"
981 echo "Don't provide mandatory argument for peer add"
982 do_lnetctl peer add --nid 1.1.1.1@tcp &&
983 error "Command should have failed"
985 echo "Don't provide mandatory arguments peer add"
986 do_lnetctl peer add &&
987 error "Command should have failed"
989 echo "Invalid secondary nids"
990 do_lnetctl peer add --prim_nid 1.1.1.1@tcp --nid foobar &&
991 error "Command should have failed"
993 echo "Exceed max nids per peer"
994 do_lnetctl peer add --prim_nid 1.1.1.1@tcp --nid 1.1.1.[2-255]@tcp &&
995 error "Command should have failed"
997 echo "Invalid net type"
998 do_lnetctl peer add --prim_nid 1@foo &&
999 error "Command should have failed"
1001 echo "Invalid nid format"
1002 local invalid_nids="1@tcp 1@o2ib 1.1.1.1@gni"
1005 for nid in ${invalid_nids}; do
1006 echo "Check invalid primary nid - '$nid'"
1007 do_lnetctl peer add --prim_nid $nid &&
1008 error "Command should have failed"
1011 local invalid_strs="[2-1]@gni [a-f/x]@gni 256.256.256.256@tcp"
1012 invalid_strs+=" 1.1.1.1.[2-5/f]@tcp 1.]2[.3.4@o2ib"
1013 invalid_strs+="1.[2-4,[5-6],7-8].1.1@tcp foobar"
1016 for nidstr in ${invalid_strs}; do
1017 echo "Check invalid nidstring - '$nidstr'"
1018 do_lnetctl peer add --prim_nid 1.1.1.1@tcp --nid $nidstr &&
1019 error "Command should have failed"
1022 echo "Add non-local gateway"
1023 do_lnetctl route add --net tcp --gateway 1@gni &&
1024 error "Command should have failed"
1028 run_test 99a "Check various invalid inputs to lnetctl peer"
1031 reinit_dlc || return $?
1033 create_base_yaml_file
1035 cat <<EOF > $TMP/sanity-lnet-$testnum-invalid.yaml
1037 - primary nid: 99.99.99.99@tcp
1040 - nid: 99.99.99.99@tcp
1042 do_lnetctl import < $TMP/sanity-lnet-$testnum-invalid.yaml &&
1043 error "import should have failed"
1044 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
1047 run_test 99b "Invalid value for Multi-Rail in yaml import"
1051 local ip=$(ip addr show dev $if | awk '/ inet /{print $2}')
1059 if ! lsmod | grep -q ksocklnd ; then
1060 load_module ../lnet/klnds/socklnd/ksocklnd ||
1061 error "Can't load ksocklnd.ko"
1064 do_lnetctl net add --net ${net} --if ${if} ||
1065 error "Failed to add net ${net} on if ${if}"
1068 compare_route_add() {
1072 local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
1074 do_lnetctl route add --net ${rnet} --gateway ${gw} ||
1075 error "route add failed $?"
1076 # CPT configuration is pruned from the exported yaml, since the default
1077 # can vary across test systems (unlike default values for things like
1078 # peer_credits, peer_timeout, etc.)
1079 $LNETCTL export --backup | grep -v CPT > $actual ||
1080 error "export failed $?"
1081 validate_gateway_nids
1086 reinit_dlc || return $?
1087 add_net "tcp" "${INTERFACES[0]}"
1088 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
1097 peer_buffer_credits: 0
1103 gateway: 7.7.7.7@tcp
1106 health_sensitivity: 1
1108 - primary nid: 7.7.7.7@tcp
1114 compare_route_add "tcp7" "7.7.7.7@tcp" || return $?
1117 run_test 100 "Add route with single gw (tcp)"
1120 reinit_dlc || return $?
1121 add_net "tcp" "${INTERFACES[0]}"
1122 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
1131 peer_buffer_credits: 0
1137 gateway: 8.8.8.10@tcp
1140 health_sensitivity: 1
1142 gateway: 8.8.8.9@tcp
1145 health_sensitivity: 1
1147 gateway: 8.8.8.8@tcp
1150 health_sensitivity: 1
1152 - primary nid: 8.8.8.9@tcp
1156 - primary nid: 8.8.8.10@tcp
1160 - primary nid: 8.8.8.8@tcp
1166 compare_route_add "tcp8" "8.8.8.[8-10]@tcp"
1168 run_test 101 "Add route with multiple gw (tcp)"
1170 compare_route_del() {
1174 local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
1176 do_lnetctl route del --net ${rnet} --gateway ${gw} ||
1177 error "route del failed $?"
1178 $LNETCTL export --backup > $actual ||
1179 error "export failed $?"
1180 validate_gateway_nids
1184 reinit_dlc || return $?
1185 add_net "tcp" "${INTERFACES[0]}"
1186 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-expected.yaml
1187 do_lnetctl route add --net tcp102 --gateway 102.102.102.102@tcp ||
1188 error "route add failed $?"
1189 compare_route_del "tcp102" "102.102.102.102@tcp"
1191 run_test 102 "Delete route with single gw (tcp)"
1194 reinit_dlc || return $?
1195 add_net "tcp" "${INTERFACES[0]}"
1196 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-expected.yaml
1197 do_lnetctl route add --net tcp103 \
1198 --gateway 103.103.103.[103-120/4]@tcp ||
1199 error "route add failed $?"
1200 compare_route_del "tcp103" "103.103.103.[103-120/4]@tcp"
1202 run_test 103 "Delete route with multiple gw (tcp)"
1205 local tyaml="$TMP/sanity-lnet-$testnum-expected.yaml"
1207 reinit_dlc || return $?
1209 # Default value is '3'
1210 local val=$($LNETCTL global show | awk '/response_tracking/{print $NF}')
1212 error "Expect 3 found $val"
1214 echo "Set < 0; Should fail"
1215 do_lnetctl set response_tracking -1 &&
1216 error "should have failed $?"
1218 reinit_dlc || return $?
1221 response_tracking: -10
1223 do_lnetctl import < $tyaml &&
1224 error "should have failed $?"
1226 echo "Check valid values; Should succeed"
1228 for ((i = 0; i < 4; i++)); do
1229 reinit_dlc || return $?
1230 do_lnetctl set response_tracking $i ||
1231 error "should have succeeded $?"
1232 $LNETCTL global show | grep -q "response_tracking: $i" ||
1233 error "Failed to set response_tracking to $i"
1234 reinit_dlc || return $?
1237 response_tracking: $i
1239 do_lnetctl import < $tyaml ||
1240 error "should have succeeded $?"
1241 $LNETCTL global show | grep -q "response_tracking: $i" ||
1242 error "Failed to set response_tracking to $i"
1245 reinit_dlc || return $?
1246 echo "Set > 3; Should fail"
1247 do_lnetctl set response_tracking 4 &&
1248 error "should have failed $?"
1250 reinit_dlc || return $?
1253 response_tracking: 10
1255 do_lnetctl import < $tyaml &&
1256 error "should have failed $?"
1259 run_test 104 "Set/check response_tracking param"
1261 ### load lnet in default namespace, configure in target namespace
1264 cleanup_lnet || exit 1
1265 load_lnet "networks=\"\""
1266 do_ns $LNETCTL lnet configure --all || exit 1
1267 $LNETCTL net show --net tcp | grep -q "nid: ${FAKE_IP}@tcp$"
1269 run_test 200 "load lnet w/o module option, configure in a non-default namespace"
1272 cleanup_lnet || exit 1
1273 load_lnet "networks=tcp($FAKE_IF)"
1274 do_ns $LNETCTL lnet configure --all || exit 1
1275 $LNETCTL net show --net tcp | grep -q "nid: ${FAKE_IP}@tcp$"
1277 run_test 201 "load lnet using networks module options in a non-default namespace"
1280 cleanup_lnet || exit 1
1281 load_lnet "networks=\"\" ip2nets=\"tcp0($FAKE_IF) ${FAKE_IP}\""
1282 do_ns $LNETCTL lnet configure --all || exit 1
1283 $LNETCTL net show | grep -q "nid: ${FAKE_IP}@tcp$"
1285 run_test 202 "load lnet using ip2nets in a non-default namespace"
1288 ### Add the interfaces in the target namespace
1291 cleanup_lnet || exit 1
1293 do_lnetctl lnet configure || exit 1
1294 do_ns $LNETCTL net add --net tcp0 --if $FAKE_IF
1296 run_test 203 "add a network using an interface in the non-default namespace"
1298 LNET_PARAMS_FILE="$TMP/$TESTSUITE.parameters"
1299 function save_lnet_params() {
1300 $LNETCTL global show | egrep -v '^global:$' |
1301 sed 's/://' > $LNET_PARAMS_FILE
1304 function restore_lnet_params() {
1306 while read param value; do
1307 [[ $param == max_intf ]] && continue
1308 [[ $param == lnd_timeout ]] && continue
1309 $LNETCTL set ${param} ${value} ||
1310 error "Failed to restore ${param} to ${value}"
1311 done < $LNET_PARAMS_FILE
1314 function lnet_health_pre() {
1317 # Lower transaction timeout to speed up test execution
1318 $LNETCTL set transaction_timeout 10 ||
1319 error "Failed to set transaction_timeout $?"
1321 # Increase recovery interval so we have time to capture health values
1322 $LNETCTL set recovery_interval 20 ||
1323 error "Failed to set recovery_interval $?"
1325 RETRY_PARAM=$($LNETCTL global show | awk '/retry_count/{print $NF}')
1326 RSND_PRE=$($LNETCTL stats show | awk '/resend_count/{print $NF}')
1327 LO_HVAL_PRE=$($LNETCTL net show -v 2 | awk '/health value/{print $NF}' |
1328 xargs echo | sed 's/ /+/g' | bc -l)
1330 local my_nid=$($LCTL list_nids | head -n 1)
1332 RMT_HVAL_PRE=$($LNETCTL peer show --nid $my_nid -v 2 2>/dev/null |
1333 awk '/health value/{print $NF}' | xargs echo |
1334 sed 's/ /+/g' | bc -l)
1336 # Might not have any peers so initialize to zero.
1337 RMT_HVAL_PRE=${RMT_HVAL_PRE:-0}
1342 function lnet_health_post() {
1343 RSND_POST=$($LNETCTL stats show | awk '/resend_count/{print $NF}')
1344 LO_HVAL_POST=$($LNETCTL net show -v 2 |
1345 awk '/health value/{print $NF}' |
1346 xargs echo | sed 's/ /+/g' | bc -l)
1348 local my_nid=$($LCTL list_nids | head -n 1)
1350 RMT_HVAL_POST=$($LNETCTL peer show --nid $my_nid -v 2 2>/dev/null |
1351 awk '/health value/{print $NF}' | xargs echo |
1352 sed 's/ /+/g' | bc -l)
1354 # Might not have any peers so initialize to zero.
1355 RMT_HVAL_POST=${RMT_HVAL_POST:-0}
1358 echo "Pre resends: $RSND_PRE" &&
1359 echo "Post resends: $RSND_POST" &&
1360 echo "Resends delta: $((RSND_POST - RSND_PRE))" &&
1361 echo "Pre local health: $LO_HVAL_PRE" &&
1362 echo "Post local health: $LO_HVAL_POST" &&
1363 echo "Pre remote health: $RMT_HVAL_PRE" &&
1364 echo "Post remote health: $RMT_HVAL_POST"
1371 function check_no_resends() {
1372 echo "Check that no resends took place"
1373 [[ $RSND_POST -ne $RSND_PRE ]] &&
1374 error "Found resends: $RSND_POST != $RSND_PRE"
1379 function check_resends() {
1380 local delta=$((RSND_POST - RSND_PRE))
1382 echo "Check that $RETRY_PARAM resends took place"
1383 [[ $delta -ne $RETRY_PARAM ]] &&
1384 error "Expected $RETRY_PARAM resends found $delta"
1389 function check_no_local_health() {
1390 echo "Check that local NI health is unchanged"
1391 [[ $LO_HVAL_POST -ne $LO_HVAL_PRE ]] &&
1392 error "Local health changed: $LO_HVAL_POST != $LO_HVAL_PRE"
1397 function check_local_health() {
1398 echo "Check that local NI health has been changed"
1399 [[ $LO_HVAL_POST -eq $LO_HVAL_PRE ]] &&
1400 error "Local health unchanged: $LO_HVAL_POST == $LO_HVAL_PRE"
1405 function check_no_remote_health() {
1406 echo "Check that remote NI health is unchanged"
1407 [[ $RMT_HVAL_POST -ne $RMT_HVAL_PRE ]] &&
1408 error "Remote health changed: $RMT_HVAL_POST != $RMT_HVAL_PRE"
1413 function check_remote_health() {
1414 echo "Check that remote NI health has been changed"
1415 [[ $RMT_HVAL_POST -eq $RMT_HVAL_PRE ]] &&
1416 error "Remote health unchanged: $RMT_HVAL_POST == $RMT_HVAL_PRE"
1421 # See lnet/lnet/lib-msg.c:lnet_health_check()
1422 LNET_LOCAL_RESEND_STATUSES="local_interrupt local_dropped local_aborted"
1423 LNET_LOCAL_RESEND_STATUSES+=" local_no_route local_timeout"
1424 LNET_LOCAL_NO_RESEND_STATUSES="local_error"
1426 reinit_dlc || return $?
1427 add_net "tcp" "${INTERFACES[0]}" || return $?
1429 lnet_health_pre || return $?
1432 for hstatus in ${LNET_LOCAL_RESEND_STATUSES} \
1433 ${LNET_LOCAL_NO_RESEND_STATUSES}; do
1434 echo "Simulate $hstatus"
1435 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1436 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1437 error "Should have failed"
1438 $LCTL net_drop_del -a
1443 check_no_resends || return $?
1444 check_no_local_health || return $?
1448 run_test 204 "Check no health or resends for single-rail local failures"
1452 for hstatus in ${LNET_LOCAL_RESEND_STATUSES}; do
1453 reinit_dlc || return $?
1454 add_net "tcp" "${INTERFACES[0]}" || return $?
1455 add_net "tcp1" "${INTERFACES[0]}" || return $?
1457 echo "Simulate $hstatus"
1460 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1461 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e ${hstatus}
1462 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1463 error "Should have failed"
1464 $LCTL net_drop_del -a
1468 check_resends || return $?
1469 check_local_health || return $?
1472 for hstatus in ${LNET_LOCAL_NO_RESEND_STATUSES}; do
1473 reinit_dlc || return $?
1474 add_net "tcp" "${INTERFACES[0]}" || return $?
1475 add_net "tcp1" "${INTERFACES[0]}" || return $?
1477 echo "Simulate $hstatus"
1478 lnet_health_pre || return $?
1480 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1481 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e ${hstatus}
1482 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1483 error "Should have failed"
1484 $LCTL net_drop_del -a
1488 check_no_resends || return $?
1489 check_local_health || return $?
1494 run_test 205 "Check health and resends for multi-rail local failures"
1496 # See lnet/lnet/lib-msg.c:lnet_health_check()
1497 LNET_REMOTE_RESEND_STATUSES="remote_dropped"
1498 LNET_REMOTE_NO_RESEND_STATUSES="remote_error remote_timeout"
1500 reinit_dlc || return $?
1501 add_net "tcp" "${INTERFACES[0]}" || return $?
1503 do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1504 error "failed to discover myself"
1506 lnet_health_pre || return $?
1509 for hstatus in ${LNET_REMOTE_RESEND_STATUSES} \
1510 ${LNET_REMOTE_NO_RESEND_STATUSES}; do
1511 echo "Simulate $hstatus"
1512 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1513 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1514 error "Should have failed"
1515 $LCTL net_drop_del -a
1520 check_no_resends || return $?
1521 check_no_local_health || return $?
1522 check_no_remote_health || return $?
1526 run_test 206 "Check no health or resends for single-rail remote failures"
1530 for hstatus in ${LNET_REMOTE_RESEND_STATUSES}; do
1531 reinit_dlc || return $?
1532 add_net "tcp" "${INTERFACES[0]}" || return $?
1533 add_net "tcp1" "${INTERFACES[0]}" || return $?
1535 do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1536 error "failed to discover myself"
1538 echo "Simulate $hstatus"
1539 lnet_health_pre || return $?
1540 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1541 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e ${hstatus}
1542 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1543 error "Should have failed"
1544 $LCTL net_drop_del -a
1548 check_resends || return $?
1549 check_no_local_health || return $?
1550 check_remote_health || return $?
1552 for hstatus in ${LNET_REMOTE_NO_RESEND_STATUSES}; do
1553 reinit_dlc || return $?
1554 add_net "tcp" "${INTERFACES[0]}" || return $?
1555 add_net "tcp1" "${INTERFACES[0]}" || return $?
1557 do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1558 error "failed to discover myself"
1560 echo "Simulate $hstatus"
1561 lnet_health_pre || return $?
1562 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1563 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e ${hstatus}
1564 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1565 error "Should have failed"
1566 $LCTL net_drop_del -a
1570 check_no_resends || return $?
1571 check_no_local_health || return $?
1572 check_remote_health || return $?
1577 run_test 207 "Check health and resends for multi-rail remote errors"
1579 test_208_load_and_check_lnet() {
1583 local num_expected=1
1585 load_lnet "networks=\"\" ip2nets=\"${ip2nets_str}\""
1588 error "Failed to load LNet with ip2nets \"${ip2nets_str}\""
1594 nids=( $($LCTL list_nids) )
1596 [[ ${#nids[@]} -ne ${num_expected} ]] &&
1597 error "Expect ${num_expected} NIDs found ${#nids[@]}"
1599 [[ ${nids[0]} == ${p_nid} ]] ||
1600 error "Expect NID \"${p_nid}\" found \"${nids[0]}\""
1602 [[ -n $s_nid ]] && [[ ${nids[1]} != ${s_nid} ]] &&
1603 error "Expect second NID \"${s_nid}\" found \"${nids[1]}\""
1605 $LCTL net down &>/dev/null
1610 cleanup_netns || error "Failed to cleanup netns before test execution"
1611 cleanup_lnet || error "Failed to unload modules before test execution"
1612 setup_fakeif || error "Failed to add fake IF"
1614 have_interface "$FAKE_IF" ||
1615 error "Expect $FAKE_IF configured but not found"
1617 local if0_ip=$(ip --oneline addr show dev ${INTERFACES[0]} |
1618 awk '/inet /{print $4}' |
1620 if0_ip=($(echo "${if0_ip[@]}" | tr ' ' '\n' | uniq | tr '\n' ' '))
1621 local ip2nets_str="tcp(${INTERFACES[0]}) $if0_ip"
1623 echo "Configure single NID \"$ip2nets_str\""
1624 test_208_load_and_check_lnet "${ip2nets_str}" "${if0_ip}@tcp"
1626 ip2nets_str="tcp(${INTERFACES[0]}) $if0_ip; tcp1($FAKE_IF) $FAKE_IP"
1627 echo "Configure two NIDs; two NETs \"$ip2nets_str\""
1628 test_208_load_and_check_lnet "${ip2nets_str}" "${if0_ip}@tcp" \
1631 ip2nets_str="tcp(${INTERFACES[0]}) $if0_ip; tcp($FAKE_IF) $FAKE_IP"
1632 echo "Configure two NIDs; one NET \"$ip2nets_str\""
1633 test_208_load_and_check_lnet "${ip2nets_str}" "${if0_ip}@tcp" \
1635 local addr1=( ${if0_ip//./ } )
1636 local addr2=( ${FAKE_IP//./ } )
1637 local range="[${addr1[0]},${addr2[0]}]"
1640 for i in $(seq 1 3); do
1641 range+=".[${addr1[$i]},${addr2[$i]}]"
1643 ip2nets_str="tcp(${INTERFACES[0]},${FAKE_IF}) ${range}"
1645 echo "Configured two NIDs; one NET alt syntax \"$ip2nets_str\""
1646 test_208_load_and_check_lnet "${ip2nets_str}" "${if0_ip}@tcp" \
1651 echo "alt syntax with missing IF \"$ip2nets_str\""
1652 load_lnet "networks=\"\" ip2nets=\"${ip2nets_str}\""
1654 echo "$LCTL net up should fail"
1656 error "LNet bringup should have failed"
1660 run_test 208 "Test various kernel ip2nets configurations"
1663 reinit_dlc || return $?
1664 add_net "tcp" "${INTERFACES[0]}" || return $?
1666 do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1667 error "failed to discover myself"
1669 echo "Simulate network_timeout w/SR config"
1672 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e network_timeout
1673 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1674 error "Should have failed"
1675 $LCTL net_drop_del -a
1679 check_no_resends || return $?
1680 check_no_local_health || return $?
1681 check_no_remote_health || return $?
1683 reinit_dlc || return $?
1684 add_net "tcp" "${INTERFACES[0]}" || return $?
1685 add_net "tcp1" "${INTERFACES[0]}" || return $?
1687 do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1688 error "failed to discover myself"
1690 echo "Simulate network_timeout w/MR config"
1693 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e network_timeout
1694 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e network_timeout
1695 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1696 error "Should have failed"
1697 $LCTL net_drop_del -a
1701 check_no_resends || return $?
1702 check_local_health || return $?
1703 check_remote_health || return $?
1707 run_test 209 "Check health, but not resends, for network timeout"
1709 check_nid_in_recovq() {
1710 local recovq=$($LNETCTL debug recovery $1)
1712 local nids=$($LCTL list_nids | xargs echo)
1716 echo "Check recovery queue"
1718 if [[ $(grep -c 'nid-'<<<$recovq) -ne $expect ]]; then
1719 error "Expect $expect NIDs found: \"$recovq\""
1722 [[ $expect -eq 0 ]] && return 0
1724 for nid in ${nids}; do
1725 grep -q "nid-0: $nid"<<<$recovq &&
1730 error "Didn't find local NIDs in recovery queue: \"$recovq\""
1736 # First enqueue happens at time 0.
1737 # 2nd at 0 + 2^0 = 1
1738 # 3rd at 1 + 2^1 = 3
1739 # 4th at 3 + 2^2 = 7
1740 # 5th at 7 + 2^3 = 15
1741 # e.g. after 10 seconds we would expect to have seen the 4th enqueue,
1742 # (3 pings sent, 4th about to happen) and the 5th enqueue is yet to
1744 # If the recovery limit is 10 seconds, then when the 5th enqueue happens
1745 # we expect the peer NI to have aged out, so it will not actually be
1747 check_ping_count() {
1751 echo "Check ping counts:"
1753 if [[ $queue == "ni" ]]; then
1754 $LNETCTL net show -v 2 | egrep 'nid|health value|ping'
1755 ping_count=( $($LNETCTL net show -v 2 |
1756 awk '/ping_count/{print $NF}') )
1757 elif [[ $queue == "peer_ni" ]]; then
1758 $LNETCTL peer show -v 2 | egrep 'nid|health value|ping'
1759 ping_count=( $($LNETCTL peer show -v 2 |
1760 awk '/ping_count/{print $NF}') )
1762 error "Unrecognized queue \"$queue\""
1768 for count in ${ping_count[@]}; do
1769 if [[ $count -eq $expect ]]; then
1770 if [[ $expect -ne 0 ]] && $found ; then
1771 error "Found more than one interface matching \"$expect\" ping count"
1774 echo "Expect ping count \"$expect\" found \"$count\""
1777 elif [[ $count -ne 0 ]]; then
1778 error "Found interface with ping count \"$count\" but expect \"$expect\""
1787 reinit_dlc || return $?
1788 add_net "tcp" "${INTERFACES[0]}" || return $?
1789 add_net "tcp1" "${INTERFACES[0]}" || return $?
1791 local prim_nid=$($LCTL list_nids | head -n 1)
1793 do_lnetctl discover $prim_nid ||
1794 error "failed to discover myself"
1796 # Set recovery limit to 10 seconds.
1797 do_lnetctl set recovery_limit 10 ||
1798 error "failed to set recovery_limit"
1800 $LCTL set_param debug=+net
1801 # Use local_error so LNet doesn't attempt to resend the discovery ping
1802 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e local_error
1803 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e local_error
1804 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1805 error "Expected discovery to fail"
1808 check_nid_in_recovq "-l" 1
1809 check_ping_count "ni" "2"
1813 check_nid_in_recovq "-l" 1
1814 check_ping_count "ni" "3"
1816 $LCTL net_drop_del -a
1820 run_test 210 "Local NI recovery checks"
1823 reinit_dlc || return $?
1824 add_net "tcp" "${INTERFACES[0]}" || return $?
1825 add_net "tcp1" "${INTERFACES[0]}" || return $?
1827 local prim_nid=$($LCTL list_nids | head -n 1)
1829 do_lnetctl discover $prim_nid ||
1830 error "failed to discover myself"
1832 # Set recovery limit to 10 seconds.
1833 do_lnetctl set recovery_limit 10 ||
1834 error "failed to set recovery_limit"
1836 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e remote_error
1837 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e remote_error
1839 # Set health to 0 on one interface. This forces it onto the recovery
1841 $LNETCTL peer set --nid $prim_nid --health 0
1843 # After 5 seconds, we expect the peer NI to still be in recovery
1845 check_nid_in_recovq "-p" 1
1846 check_ping_count "peer_ni" "2"
1848 # After 15 seconds, the peer NI should have been fully processed out of
1849 # the recovery queue. We'll allow a total of 17 seconds to account for
1850 # differences in sleeping for whole seconds vs. the more accurate time
1851 # keeping that is done in the recovery code.
1853 check_nid_in_recovq "-p" 0
1854 check_ping_count "peer_ni" "4"
1856 $LCTL net_drop_del -a
1858 # Set health to force it back onto the recovery queue. Set to 500 means
1859 # in 5 seconds it should be back at maximum value. We'll wait a couple
1860 # more seconds than that to be safe.
1861 # NB: we reset the recovery limit to 0 (indefinite) so the peer NI is
1863 do_lnetctl set recovery_limit 0 ||
1864 error "failed to set recovery_limit"
1866 $LNETCTL peer set --nid $prim_nid --health 500
1868 check_nid_in_recovq "-p" 1
1869 check_ping_count "peer_ni" "2"
1873 check_nid_in_recovq "-p" 0
1874 check_ping_count "peer_ni" "0"
1878 run_test 211 "Remote NI recovery checks"
1881 local rnodes=$(remote_nodes_list)
1882 [[ -z $rnodes ]] && skip "Need at least 1 remote node"
1884 cleanup_lnet || error "Failed to cleanup before test execution"
1886 # Loading modules should configure LNet with the appropriate
1887 # test-framework configuration
1888 load_modules || error "Failed to load modules"
1890 local my_nid=$($LCTL list_nids | head -n 1)
1892 error "Failed to get primary NID for local host $HOSTNAME"
1894 local rnode=$(awk '{print $1}' <<<$rnodes)
1895 local rnodenids=$(do_node $rnode $LCTL list_nids | xargs echo)
1898 if [[ -z $rnodenids ]]; then
1899 do_rpc_nodes $rnode load_modules_local
1901 rnodenids=$(do_node $rnode $LCTL list_nids | xargs echo)
1904 local rnodepnid=$(awk '{print $1}' <<< $rnodenids)
1906 [[ -z $rnodepnid ]] &&
1907 error "Failed to get primary NID for remote host $rnode"
1909 log "Initial discovery"
1910 do_lnetctl discover --force $rnodepnid ||
1911 error "Failed to discover $rnodepnid"
1913 do_node $rnode "$LNETCTL discover --force $my_nid" ||
1914 error "$rnode failed to discover $my_nid"
1916 log "Fail local discover ping to set LNET_PEER_REDISCOVER flag"
1917 $LCTL net_drop_add -s "*@$NETTYPE" -d "*@$NETTYPE" -r 1 -e local_error
1918 do_lnetctl discover --force $rnodepnid &&
1919 error "Discovery should have failed"
1920 $LCTL net_drop_del -a
1923 for nid in $rnodenids; do
1924 # We need GET (PING) delay just long enough so we can trigger
1925 # discovery on the remote peer
1926 $LCTL net_delay_add -s "*@$NETTYPE" -d $nid -r 1 -m GET -l 3
1927 $LCTL net_drop_add -s "*@$NETTYPE" -d $nid -r 1 -m GET -e local_error
1928 # We need PUT (PUSH) delay just long enough so we can process
1930 $LCTL net_delay_add -s "*@$NETTYPE" -d $nid -r 1 -m PUT -l 6
1933 log "Force $HOSTNAME to discover $rnodepnid (in background)"
1934 # We want to get a PING sent that we know will eventually fail.
1935 # The delay rules we added will ensure the ping is not sent until
1936 # the PUSH is also in flight (see below), and the drop rule ensures that
1937 # when the PING is eventually sent it will error out
1938 do_lnetctl discover --force $rnodepnid &
1941 # We want a discovery PUSH from rnode to put rnode back on our
1942 # discovery queue. This should cause us to try and send a PUSH to rnode
1943 # while the PING is still outstanding.
1944 log "Force $rnode to discover $my_nid"
1945 do_node $rnode $LNETCTL discover --force $my_nid
1947 # At this point we'll have both PING_SENT and PUSH_SENT set for the
1948 # rnode peer. Wait for the PING to error out which should terminate the
1949 # discovery process that we backgrounded.
1950 log "Wait for $pid1"
1952 log "Finished wait on $pid1"
1954 # The PING send failure clears the PING_SENT flag and puts the peer back
1955 # on the discovery queue. When discovery thread processes the peer it
1956 # will mistakenly clear the PUSH_SENT flag (and set PUSH_FAILED).
1957 # Discovery will then complete for this peer even though we have an
1959 # When PUSH is actually unlinked it will be forced back onto the
1960 # discovery queue, but we no longer have a ref on the peer. When
1961 # discovery completes again, we'll trip the ASSERT in
1962 # lnet_destroy_peer_locked()
1964 # Delete the delay rules to send the PUSH
1965 $LCTL net_delay_del -a
1966 # Delete the drop rules
1967 $LCTL net_drop_del -a
1970 error "Failed to unload modules"
1972 do_rpc_nodes $rnode unload_modules_local ||
1973 error "Failed to unload modules on $rnode"
1978 run_test 212 "Check discovery refcount loss bug (LU-14627)"
1981 cleanup_netns || error "Failed to cleanup netns before test execution"
1982 cleanup_lnet || error "Failed to unload modules before test execution"
1984 setup_fakeif || error "Failed to add fake IF"
1985 have_interface "$FAKE_IF" ||
1986 error "Expect $FAKE_IF configured but not found"
1988 reinit_dlc || return $?
1990 add_net "tcp" "${INTERFACES[0]}" || return $?
1991 add_net "tcp" "$FAKE_IF" || return $?
1993 local nid1=$(lctl list_nids | head -n 1)
1994 local nid2=$(lctl list_nids | tail --lines 1)
1996 [[ $(lctl which_nid $nid1 $nid2) == $nid1 ]] ||
1997 error "Expect nid1 \"$nid1\" to be preferred"
1999 [[ $(lctl which_nid $nid2 $nid1) == $nid2 ]] ||
2000 error "Expect nid2 \"$nid2\" to be preferred"
2004 run_test 213 "Check LNetDist calculation for multiple local NIDs"
2006 function check_ni_status() {
2010 local status=$($LNETCTL net show |
2012 awk '/status/{print $NF}')
2014 echo "NI ${nid} expect status \"${expect}\" found \"${status}\""
2015 if [[ $status != $expect ]]; then
2016 error "Error: Expect NI status \"$expect\" for NID \"$nid\" but found \"$status\""
2023 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
2025 cleanup_netns || error "Failed to cleanup netns before test execution"
2026 cleanup_lnet || error "Failed to unload modules before test execution"
2028 setup_fakeif || error "Failed to add fake IF"
2029 have_interface "$FAKE_IF" ||
2030 error "Expect $FAKE_IF configured but not found"
2032 reinit_dlc || return $?
2034 add_net "tcp" "eth0" || return $?
2035 add_net "tcp" "$FAKE_IF" || return $?
2037 local nid1=$(lctl list_nids | head -n 1)
2038 local nid2=$(lctl list_nids | tail --lines 1)
2040 check_ni_status "0@lo" up
2041 check_ni_status "$nid1" up
2042 check_ni_status "$nid2" up
2044 echo "Set $FAKE_IF down"
2045 echo "ip link set dev $FAKE_IF down"
2046 ip link set dev $FAKE_IF down
2047 check_ni_status "0@lo" up
2048 check_ni_status "$nid1" up
2049 check_ni_status "$nid2" down
2051 run_test 214 "Check local NI status when link is downed"
2055 echo "Check valid values; Should succeed"
2059 for ((i = 4; i < 16; i+=1)); do
2060 reinit_dlc || return $?
2061 add_net "tcp" "${INTERFACES[0]}" || return $?
2062 do_lnetctl net set --all --conns-per-peer $i ||
2063 error "should have succeeded $?"
2064 $LNETCTL net show -v 1 | grep -q "conns_per_peer: $i" ||
2065 error "failed to set conns-per-peer to $i"
2066 lnid="$(lctl list_nids | head -n 1)"
2067 do_lnetctl ping "$lnid" ||
2068 error "failed to ping myself"
2069 # "lctl --net tcp conn_list" prints the list of active
2070 # connections. Since we're pinging ourselves, there should be
2071 # 2 Control connections plus 2*conns_per_peer connections
2072 # created (one Bulk Input, one Bulk Output in each pair).
2073 # Here's the sample output for conns_per_peer set to 1:
2074 # 12345-1.1.1.1@tcp I[0]host01->host01:988 2626560/1061296 nonagle
2075 # 12345-1.1.1.1@tcp O[0]host01->host01:1022 2626560/1061488 nonagle
2076 # 12345-1.1.1.1@tcp C[0]host01->host01:988 2626560/1061296 nonagle
2077 # 12345-1.1.1.1@tcp C[0]host01->host01:1023 2626560/1061488 nonagle
2078 cmd="printf 'network tcp\nconn_list\n' | lctl | grep -c '$lnid'"
2080 # Expect 2+conns_per_peer*2 connections. Wait no longer
2082 wait_update $HOSTNAME "$cmd" "$((2+i*2))" 2 ||
2083 error "expected number of tcp connections $((2+i*2))"
2086 reinit_dlc || return $?
2087 add_net "tcp" "${INTERFACES[0]}" || return $?
2088 echo "Set > 127; Should fail"
2089 do_lnetctl net set --all --conns-per-peer 128 &&
2090 error "should have failed $?"
2092 reinit_dlc || return $?
2093 add_net "tcp" "${INTERFACES[0]}" || return $?
2094 echo "Set < 0; Should be ignored"
2095 do_lnetctl net set --all --conns-per-peer -1 ||
2096 error "should have succeeded $?"
2097 $LNETCTL net show -v 1 | grep -q "conns_per_peer: 1" ||
2098 error "Did not stay at default"
2100 run_test 230 "Test setting conns-per-peer"
2105 local out=$TMP/$tfile
2106 local prefix=/usr/include/linux/lnet
2108 # We use a hard coded prefix so that this test will not fail
2111 if ! which $CC > /dev/null 2>&1; then
2112 skip_env "$CC is not installed"
2115 cleanup_lnet || exit 1
2118 local cc_args="-Wall -Werror -std=c99 -c -x c /dev/null -o $out"
2119 if ! [[ -d $prefix ]]; then
2120 # Assume we're running in tree and fixup the include path.
2121 prefix=$LUSTRE/../lnet/include/uapi/linux/lnet
2122 cc_args+=" -I $LUSTRE/../lnet/include/uapi"
2125 for header in $prefix/*.h; do
2126 if ! [[ -f "$header" ]]; then
2130 echo "$CC $cc_args -include $header"
2131 $CC $cc_args -include $header ||
2132 error "cannot compile '$header'"
2136 run_test 300 "packaged LNet UAPI headers can be compiled"