Whamcloud - gitweb
LU-12815 socklnd: allow dynamic setting of conns_per_peer
[fs/lustre-release.git] / lustre / tests / sanity-lnet.sh
1 #!/bin/bash
2 #
3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
5 #
6
7 set -e
8
9 ONLY=${ONLY:-"$*"}
10
11 # bug number for skipped test:
12 ALWAYS_EXCEPT="$SANITY_LNET_EXCEPT "
13 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
14
15 # skip the grant tests for ARM until they are fixed
16 if [[ $(uname -m) = aarch64 ]]; then
17         # bug number:    LU-14067
18         ALWAYS_EXCEPT+=" 300"
19 fi
20
21 [ "$SLOW" = "no" ] && EXCEPT_SLOW=""
22
23 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
24
25 . $LUSTRE/tests/test-framework.sh
26 CLEANUP=${CLEANUP:-:}
27 SETUP=${SETUP:-:}
28 init_test_env $@
29 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
30 init_logging
31
32 build_test_filter
33
34 [[ -z $LNETCTL ]] && skip "Need lnetctl"
35
36 restore_mounts=false
37
38 if is_mounted $MOUNT || is_mounted $MOUNT2; then
39         cleanupall || error "Failed cleanup prior to test execution"
40         restore_mounts=true
41 fi
42
43 cleanup_lnet() {
44         echo "Cleaning up LNet"
45         lsmod | grep -q lnet &&
46                 $LNETCTL lnet unconfigure 2>/dev/null
47         unload_modules
48 }
49
50 restore_modules=false
51 if module_loaded lnet ; then
52         cleanup_lnet || error "Failed to unload modules before test execution"
53         restore_modules=true
54 fi
55
56 cleanup_testsuite() {
57         trap "" EXIT
58         # Cleanup any tmp files created by the sub tests
59         rm -f $TMP/sanity-lnet*
60         cleanup_netns
61         cleanup_lnet
62         if $restore_mounts; then
63                 setupall || error "Failed to setup Lustre after test execution"
64         elif $restore_modules; then
65                 load_modules ||
66                         error "Couldn't load modules after test execution"
67         fi
68         return 0
69 }
70
71 load_lnet() {
72         load_module ../libcfs/libcfs/libcfs
73         # Prevent local MODOPTS_LIBCFS being passed as part of environment
74         # variable to remote nodes
75         unset MODOPTS_LIBCFS
76
77         set_default_debug "neterror net nettrace malloc"
78         load_module ../lnet/lnet/lnet "$@"
79
80         LNDPATH=${LNDPATH:-"../lnet/klnds"}
81         if [ -z "$LNETLND" ]; then
82                 case $NETTYPE in
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"
89                 esac
90         fi
91         load_module ../lnet/klnds/$LNETLND
92 }
93
94 do_lnetctl() {
95         echo "$LNETCTL $@"
96         $LNETCTL "$@"
97 }
98
99 TESTNS='test_ns'
100 FAKE_IF="test1pg"
101 FAKE_IP="10.1.2.3"
102 do_ns() {
103         echo "ip netns exec $TESTNS $@"
104         ip netns exec $TESTNS "$@"
105 }
106
107 setup_fakeif() {
108         local netns="$1"
109
110         local netns_arg=""
111         [[ -n $netns ]] &&
112                 netns_arg="netns $netns"
113
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
119         else
120                 ip addr add "${FAKE_IP}/31" dev $FAKE_IF
121                 ip link set $FAKE_IF up
122         fi
123 }
124
125 cleanup_fakeif() {
126         ip link show test1pl >& /dev/null && ip link del test1pl || return 0
127 }
128
129 setup_netns() {
130         cleanup_netns
131
132         ip netns add $TESTNS
133         setup_fakeif $TESTNS
134 }
135
136 cleanup_netns() {
137         (ip netns list | grep -q $TESTNS) && ip netns del $TESTNS
138         cleanup_fakeif
139 }
140
141 configure_dlc() {
142         echo "Loading LNet and configuring DLC"
143         load_lnet
144         do_lnetctl lnet configure
145 }
146
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 $?"
151 }
152
153 reinit_dlc() {
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 $?"
159         else
160                 configure_dlc || error "configure_dlc failed $?"
161         fi
162         define_global_yaml
163 }
164
165 append_global_yaml() {
166         [[ ! -e ${GLOBAL_YAML_FILE} ]] &&
167                 error "Missing global yaml at ${GLOBAL_YAML_FILE}"
168
169         cat ${GLOBAL_YAML_FILE} >> $TMP/sanity-lnet-$testnum-expected.yaml
170 }
171
172 create_base_yaml_file() {
173         append_global_yaml
174 }
175
176 compare_yaml_files() {
177         local expected="$TMP/sanity-lnet-$testnum-expected.yaml"
178         local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
179         local rc=0
180         ! [[ -e $expected ]] && echo "$expected not found" && return 1
181         ! [[ -e $actual ]] && echo "$actual not found" && return 1
182         diff -upN ${actual} ${expected} || rc=$?
183         echo "Expected:"
184         cat $expected
185         echo "Actual:"
186         cat $actual
187         return $rc
188 }
189
190 validate_nid() {
191         local nid="$1"
192         local net="${nid//*@/}"
193         local addr="${nid//@*/}"
194
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}"
197
198         if [[ $net =~ gni[0-9]* ]]; then
199                 [[ $addr =~ ${num_re} ]] && return 0
200         else
201                 [[ $addr =~ ${ip_re} ]] && return 0
202         fi
203 }
204
205 validate_nids() {
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)
210
211         local nid
212         for nid in $primary_nids $secondary_nids; do
213                 validate_nid "$nid" || error "Bad NID \"${nid}\""
214         done
215         return 0
216 }
217
218 validate_peer_nids() {
219         local num_peers="$1"
220         local nids_per_peer="$2"
221
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))))"
225
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
229                 compare_yaml_files
230                 error "Expected $expect_p but found $actual_p primary nids"
231         elif [[ $expect_s -ne $actual_s ]]; then
232                 compare_yaml_files
233                 error "Expected $expect_s but found $actual_s secondary nids"
234         fi
235         validate_nids
236 }
237
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
242                 compare_yaml_files
243                 error "Expected $expect_gw gateways but found $actual_gw gateways"
244         fi
245         validate_nids
246 }
247
248 cleanupall -f
249 setup_netns || error "setup_netns failed with $?"
250
251 stack_trap 'cleanup_testsuite' EXIT
252
253 test_0() {
254         load_module ../lnet/lnet/lnet || error "Failed to load module rc = $?"
255         do_lnetctl lnet configure || error "lnet configure failed rc = $?"
256         define_global_yaml
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"
262 }
263 run_test 0 "Export empty config, import the config, compare"
264
265 compare_peer_add() {
266         local prim_nid="${1:+--prim_nid $1}"
267         local nid="${2:+--nid $2}"
268
269         local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
270
271         do_lnetctl peer add ${prim_nid} ${nid} || error "peer add failed $?"
272         $LNETCTL export --backup > $actual || error "export failed $?"
273         compare_yaml_files
274         return $?
275 }
276
277 test_1() {
278         reinit_dlc || return $?
279         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
280 peer:
281     - primary nid: 1.1.1.1@tcp
282       Multi-Rail: True
283       peer ni:
284         - nid: 1.1.1.1@tcp
285 EOF
286         append_global_yaml
287         compare_peer_add "1.1.1.1@tcp"
288 }
289 run_test 1 "Add peer with single nid (tcp)"
290
291 test_2() {
292         reinit_dlc || return $?
293         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
294 peer:
295     - primary nid: 2.2.2.2@o2ib
296       Multi-Rail: True
297       peer ni:
298         - nid: 2.2.2.2@o2ib
299 EOF
300         append_global_yaml
301         compare_peer_add "2.2.2.2@o2ib"
302 }
303 run_test 2 "Add peer with single nid (o2ib)"
304
305 test_3() {
306         reinit_dlc || return $?
307         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
308 peer:
309     - primary nid: 3.3.3.3@tcp
310       Multi-Rail: True
311       peer ni:
312         - nid: 3.3.3.3@tcp
313         - nid: 3.3.3.3@o2ib
314 EOF
315         append_global_yaml
316         compare_peer_add "3.3.3.3@tcp" "3.3.3.3@o2ib"
317 }
318 run_test 3 "Add peer with tcp primary o2ib secondary"
319
320 test_4() {
321         reinit_dlc || return $?
322         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
323 peer:
324     - primary nid: 4.4.4.4@tcp
325       Multi-Rail: True
326       peer ni:
327         - nid: 4.4.4.4@tcp
328         - nid: 4.4.4.1@tcp
329         - nid: 4.4.4.2@tcp
330         - nid: 4.4.4.3@tcp
331 EOF
332         append_global_yaml
333         echo "Add peer with nidrange (tcp)"
334         compare_peer_add "4.4.4.4@tcp" "4.4.4.[1-3]@tcp"
335
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"
338 }
339 run_test 4 "Add peer with nidrange (tcp)"
340
341 test_5() {
342         reinit_dlc || return $?
343         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
344 peer:
345     - primary nid: 5.5.5.5@o2ib
346       Multi-Rail: True
347       peer ni:
348         - nid: 5.5.5.5@o2ib
349         - nid: 5.5.5.1@o2ib
350         - nid: 5.5.5.2@o2ib
351         - nid: 5.5.5.3@o2ib
352         - nid: 5.5.5.4@o2ib
353 EOF
354         append_global_yaml
355         echo "Add peer with nidrange (o2ib)"
356         compare_peer_add "5.5.5.5@o2ib" "5.5.5.[1-4]@o2ib"
357
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"
360 }
361 run_test 5 "Add peer with nidrange (o2ib)"
362
363 test_6() {
364         reinit_dlc || return $?
365         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
366 peer:
367     - primary nid: 6.6.6.6@tcp
368       Multi-Rail: True
369       peer ni:
370         - nid: 6.6.6.6@tcp
371         - nid: 6.6.6.0@tcp
372         - nid: 6.6.6.2@tcp
373         - nid: 6.6.6.4@tcp
374         - nid: 6.6.7.0@tcp
375         - nid: 6.6.7.2@tcp
376         - nid: 6.6.7.4@tcp
377         - nid: 6.6.1.0@o2ib
378         - nid: 6.6.1.3@o2ib
379         - nid: 6.6.1.6@o2ib
380         - nid: 6.6.3.0@o2ib
381         - nid: 6.6.3.3@o2ib
382         - nid: 6.6.3.6@o2ib
383         - nid: 6@gni
384         - nid: 10@gni
385 EOF
386         append_global_yaml
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"
389 }
390 run_test 6 "Add peer with multiple nidranges"
391
392 compare_peer_del() {
393         local prim_nid="${1:+--prim_nid $1}"
394         local nid="${2:+--nid $2}"
395
396         local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
397
398         do_lnetctl peer del ${prim_nid} ${nid} || error "peer del failed $?"
399         $LNETCTL export --backup > $actual || error "export failed $?"
400         compare_yaml_files
401         return $?
402 }
403
404 test_7() {
405         reinit_dlc || return $?
406         create_base_yaml_file
407
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"
411
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"
415
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"
420
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"
425
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"
431
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"
435
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"
440
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"
446 }
447 run_test 7 "Various peer delete tests"
448
449 test_8() {
450         reinit_dlc || return $?
451
452         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
453 peer:
454     - primary nid: 8.8.8.8@tcp
455       Multi-Rail: True
456       peer ni:
457         - nid: 8.8.8.8@tcp
458         - nid: 8.8.8.10@tcp
459         - nid: 8.8.8.11@tcp
460         - nid: 8.8.8.12@tcp
461         - nid: 8.8.8.14@tcp
462         - nid: 8.8.8.15@tcp
463 EOF
464         append_global_yaml
465
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"
469 }
470 run_test 8 "Delete single secondary nid from peer (tcp)"
471
472 test_9() {
473         reinit_dlc || return $?
474
475         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
476 peer:
477     - primary nid: 9.9.9.9@tcp
478       Multi-Rail: True
479       peer ni:
480         - nid: 9.9.9.9@tcp
481 EOF
482         append_global_yaml
483
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"
487 }
488 run_test 9 "Delete all secondary nids from peer (tcp)"
489
490 test_10() {
491         reinit_dlc || return $?
492
493         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
494 peer:
495     - primary nid: 10.10.10.10@tcp
496       Multi-Rail: True
497       peer ni:
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
503 EOF
504         append_global_yaml
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"
508 }
509 run_test 10 "Delete single secondary nid from peer (o2ib)"
510
511 test_11() {
512         reinit_dlc || return $?
513
514         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
515 peer:
516     - primary nid: 11.11.11.11@tcp
517       Multi-Rail: True
518       peer ni:
519         - nid: 11.11.11.11@tcp
520 EOF
521         append_global_yaml
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"
525 }
526 run_test 11 "Delete all secondary nids from peer (o2ib)"
527
528 test_12() {
529         reinit_dlc || return $?
530
531         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
532 peer:
533     - primary nid: 12.12.12.12@o2ib
534       Multi-Rail: True
535       peer ni:
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
540         - nid: 15.17.1.5@tcp
541         - nid: 15.17.1.10@tcp
542         - nid: 15.17.1.20@tcp
543 EOF
544         append_global_yaml
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"
549 }
550 run_test 12 "Delete a secondary nid from peer (tcp and o2ib)"
551
552 test_13() {
553         reinit_dlc || return $?
554
555         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
556 peer:
557     - primary nid: 13.13.13.13@o2ib
558       Multi-Rail: True
559       peer ni:
560         - nid: 13.13.13.13@o2ib
561 EOF
562         append_global_yaml
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"
568 }
569 run_test 13 "Delete all secondary nids from peer (tcp and o2ib)"
570
571 create_nid() {
572         local num="$1"
573         local net="$2"
574
575         if [[ $net =~ gni* ]]; then
576                 echo "${num}@${net}"
577         else
578                 echo "${num}.${num}.${num}.${num}@${net}"
579         fi
580 }
581
582 create_mr_peer_yaml() {
583         local num_peers="$1"
584         local secondary_nids="$2"
585         local net="$3"
586
587         echo "Generating peer yaml for $num_peers peers with $secondary_nids secondary nids"
588         echo "peer:" >> $TMP/sanity-lnet-$testnum-expected.yaml
589         local i
590         local total_nids=$((num_peers + $((num_peers * secondary_nids))))
591         local created=0
592         local nidnum=1
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
597       Multi-Rail: True
598       peer ni:
599         - nid: $primary
600 EOF
601                 local j
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
607                 done
608                 nidnum=$((end + 1))
609                 ((created++))
610         done
611 }
612
613 test_14() {
614         reinit_dlc || return $?
615
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 $?"
620         append_global_yaml
621         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
622         compare_yaml_files
623
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
630         compare_yaml_files
631 }
632 run_test 14 "import peer create/delete with single nid"
633
634 test_15() {
635         reinit_dlc || return $?
636
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
645
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
652         compare_yaml_files
653 }
654 run_test 15 "import multi peer create/delete with single nid per peer"
655
656 test_16() {
657         reinit_dlc || return $?
658
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
665
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
672         compare_yaml_files
673 }
674 run_test 16 "import peer create/delete with multiple nids"
675
676 test_17() {
677         reinit_dlc || return $?
678
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
685
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
692         compare_yaml_files
693 }
694 run_test 17 "import multi peer create/delete with multiple nids"
695
696 test_18a() {
697         reinit_dlc || return $?
698
699         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
700 peer:
701     - primary nid: 1.1.1.1@tcp
702       Multi-Rail: True
703       peer ni:
704         - nid: 1.1.1.1@tcp
705         - nid: 2.2.2.2@tcp
706         - nid: 4.4.4.4@tcp
707         - nid: 3.3.3.3@o2ib
708         - nid: 5@gni
709 EOF
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
715 peer:
716     - primary nid: 1.1.1.1@tcp
717       Multi-Rail: True
718       peer ni:
719         - nid: 2.2.2.2@tcp
720         - nid: 3.3.3.3@o2ib
721         - nid: 5@gni
722 EOF
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
727 peer:
728     - primary nid: 1.1.1.1@tcp
729       Multi-Rail: True
730       peer ni:
731         - nid: 1.1.1.1@tcp
732         - nid: 4.4.4.4@tcp
733 EOF
734         echo "Check peer has expected nids remaining"
735         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
736         append_global_yaml
737         compare_yaml_files
738 }
739 run_test 18a "Delete a subset of nids from a single peer using import --del"
740
741 test_18b() {
742         reinit_dlc || return $?
743
744         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
745 peer:
746     - primary nid: 1.1.1.1@tcp
747       Multi-Rail: True
748       peer ni:
749         - nid: 1.1.1.1@tcp
750         - nid: 2.2.2.2@tcp
751         - nid: 4.4.4.4@tcp
752         - nid: 3.3.3.3@o2ib
753         - nid: 5@gni
754     - primary nid: 6.6.6.6@o2ib
755       Multi-Rail: True
756       peer ni:
757         - nid: 6.6.6.6@o2ib
758         - nid: 7.7.7.7@tcp
759         - nid: 8.8.8.8@tcp
760         - nid: 9.9.9.9@tcp
761         - nid: 10@gni
762 EOF
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
768 peer:
769     - primary nid: 1.1.1.1@tcp
770       Multi-Rail: True
771       peer ni:
772         - nid: 2.2.2.2@tcp
773         - nid: 3.3.3.3@o2ib
774         - nid: 5@gni
775     - primary nid: 6.6.6.6@o2ib
776       Multi-Rail: True
777       peer ni:
778         - nid: 7.7.7.7@tcp
779         - nid: 8.8.8.8@tcp
780         - nid: 10@gni
781 EOF
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
786 peer:
787     - primary nid: 6.6.6.6@o2ib
788       Multi-Rail: True
789       peer ni:
790         - nid: 6.6.6.6@o2ib
791         - nid: 7.7.7.7@tcp
792     - primary nid: 1.1.1.1@tcp
793       Multi-Rail: True
794       peer ni:
795         - nid: 1.1.1.1@tcp
796         - nid: 4.4.4.4@tcp
797 EOF
798         append_global_yaml
799         echo "Check peers have expected nids remaining"
800         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
801         compare_yaml_files
802         validate_peer_nids 2 1
803 }
804 run_test 18b "Delete multiple nids from multiple peers using import --del"
805
806 test_19() {
807         reinit_dlc || return $?
808         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
809 peer:
810     - primary nid: 19@gni
811       Multi-Rail: True
812       peer ni:
813         - nid: 19@gni
814 EOF
815         append_global_yaml
816         compare_peer_add "19@gni"
817 }
818 run_test 19 "Add peer with single nid (gni)"
819
820 test_20() {
821         reinit_dlc || return $?
822         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
823 peer:
824     - primary nid: 20@gni
825       Multi-Rail: True
826       peer ni:
827         - nid: 20@gni
828         - nid: 20.20.20.20@tcp
829         - nid: 20.20.20.20@o2ib
830 EOF
831         append_global_yaml
832         compare_peer_add "20@gni" "20.20.20.20@tcp,20.20.20.20@o2ib"
833 }
834 run_test 20 "Add peer with gni primary and tcp, o2ib secondary"
835
836 test_21() {
837         reinit_dlc || return $?
838         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
839 peer:
840     - primary nid: 21@gni
841       Multi-Rail: True
842       peer ni:
843         - nid: 21@gni
844         - nid: 22@gni
845         - nid: 23@gni
846         - nid: 24@gni
847         - nid: 25@gni
848 EOF
849         append_global_yaml
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"
854 }
855 run_test 21 "Add peer with nidrange (gni)"
856
857 test_22() {
858         reinit_dlc || return $?
859         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
860 peer:
861     - primary nid: 22@gni
862       Multi-Rail: True
863       peer ni:
864         - nid: 22@gni
865         - nid: 24@gni
866         - nid: 25@gni
867         - nid: 27@gni
868         - nid: 28@gni
869         - nid: 29@gni
870 EOF
871         append_global_yaml
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"
875 }
876 run_test 22 "Delete single secondary nid from peer (gni)"
877
878 test_23() {
879         reinit_dlc || return $?
880         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
881 peer:
882     - primary nid: 23@gni
883       Multi-Rail: True
884       peer ni:
885         - nid: 23@gni
886 EOF
887         append_global_yaml
888
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"
892 }
893 run_test 23 "Delete all secondary nids from peer (gni)"
894
895 test_24() {
896         reinit_dlc || return $?
897         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
898 peer:
899     - primary nid: 24@gni
900       Multi-Rail: True
901       peer ni:
902         - nid: 24@gni
903         - nid: 11@gni
904         - nid: 13.13.13.13@o2ib
905         - nid: 14.13.13.13@o2ib
906         - nid: 14.15.13.13@o2ib
907         - nid: 15.17.1.5@tcp
908         - nid: 15.17.1.10@tcp
909         - nid: 15.17.1.20@tcp
910 EOF
911         append_global_yaml
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"
916 }
917 run_test 24 "Delete a secondary nid from peer (tcp, o2ib and gni)"
918
919 test_25() {
920         reinit_dlc || return $?
921         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
922 peer:
923     - primary nid: 25@gni
924       Multi-Rail: True
925       peer ni:
926         - nid: 25@gni
927 EOF
928         append_global_yaml
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"
934 }
935 run_test 25 "Delete all secondary nids from peer (tcp, gni and o2ib)"
936
937 test_99a() {
938         reinit_dlc || return $?
939
940         echo "Invalid prim_nid - peer add"
941         do_lnetctl peer add --prim_nid foobar &&
942                 error "Command should have failed"
943
944         echo "Invalid prim_nid - peer del"
945         do_lnetctl peer del --prim_nid foobar &&
946                 error "Command should have failed"
947
948         echo "Delete non-existing peer"
949         do_lnetctl peer del --prim_nid 1.1.1.1@o2ib &&
950                 error "Command should have failed"
951
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"
955
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"
959
960         echo "Don't provide mandatory arguments peer add"
961         do_lnetctl peer add &&
962                 error "Command should have failed"
963
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"
967
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"
971
972         echo "Invalid net type"
973         do_lnetctl peer add --prim_nid 1@foo &&
974                 error "Command should have failed"
975
976         echo "Invalid nid format"
977         local invalid_nids="1@tcp 1@o2ib 1.1.1.1@gni"
978
979         local nid
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"
984         done
985
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"
989
990         local nidstr
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"
995         done
996
997         echo "Add non-local gateway"
998         do_lnetctl route add --net tcp --gateway 1@gni &&
999                 error "Command should have failed"
1000
1001         return 0
1002 }
1003 run_test 99a "Check various invalid inputs to lnetctl peer"
1004
1005 test_99b() {
1006         reinit_dlc || return $?
1007
1008         create_base_yaml_file
1009
1010         cat <<EOF > $TMP/sanity-lnet-$testnum-invalid.yaml
1011 peer:
1012     - primary nid: 99.99.99.99@tcp
1013       Multi-Rail: Foobar
1014       peer ni:
1015         - nid: 99.99.99.99@tcp
1016 EOF
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
1020         compare_yaml_files
1021 }
1022 run_test 99b "Invalid value for Multi-Rail in yaml import"
1023
1024 have_interface() {
1025         local if="$1"
1026         local ip=$(ip addr show dev $if | awk '/ inet /{print $2}')
1027         [[ -n $ip ]]
1028 }
1029
1030 add_net() {
1031         local net="$1"
1032         local if="$2"
1033
1034         if ! lsmod | grep -q ksocklnd ; then
1035                 load_module ../lnet/klnds/socklnd/ksocklnd ||
1036                         error "Can't load ksocklnd.ko"
1037         fi
1038
1039         do_lnetctl net add --net ${net} --if ${if} ||
1040                 error "Failed to add net ${net} on if ${if}"
1041 }
1042
1043 compare_route_add() {
1044         local rnet="$1"
1045         local gw="$2"
1046
1047         local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
1048
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
1057         return $?
1058 }
1059
1060 test_100() {
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
1065 net:
1066     - net type: tcp
1067       local NI(s):
1068         - interfaces:
1069               0: eth0
1070           tunables:
1071               peer_timeout: 180
1072               peer_credits: 8
1073               peer_buffer_credits: 0
1074               credits: 256
1075           lnd tunables:
1076               conns_per_peer: 1
1077 route:
1078     - net: tcp7
1079       gateway: 7.7.7.7@tcp
1080       hop: -1
1081       priority: 0
1082       health_sensitivity: 1
1083 peer:
1084     - primary nid: 7.7.7.7@tcp
1085       Multi-Rail: False
1086       peer ni:
1087         - nid: 7.7.7.7@tcp
1088 EOF
1089         append_global_yaml
1090         compare_route_add "tcp7" "7.7.7.7@tcp" || return $?
1091         compare_yaml_files
1092 }
1093 run_test 100 "Add route with single gw (tcp)"
1094
1095 test_101() {
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
1100 net:
1101     - net type: tcp
1102       local NI(s):
1103         - interfaces:
1104               0: eth0
1105           tunables:
1106               peer_timeout: 180
1107               peer_credits: 8
1108               peer_buffer_credits: 0
1109               credits: 256
1110           lnd tunables:
1111               conns_per_peer: 1
1112 route:
1113     - net: tcp8
1114       gateway: 8.8.8.10@tcp
1115       hop: -1
1116       priority: 0
1117       health_sensitivity: 1
1118     - net: tcp8
1119       gateway: 8.8.8.9@tcp
1120       hop: -1
1121       priority: 0
1122       health_sensitivity: 1
1123     - net: tcp8
1124       gateway: 8.8.8.8@tcp
1125       hop: -1
1126       priority: 0
1127       health_sensitivity: 1
1128 peer:
1129     - primary nid: 8.8.8.9@tcp
1130       Multi-Rail: False
1131       peer ni:
1132         - nid: 8.8.8.9@tcp
1133     - primary nid: 8.8.8.10@tcp
1134       Multi-Rail: False
1135       peer ni:
1136         - nid: 8.8.8.10@tcp
1137     - primary nid: 8.8.8.8@tcp
1138       Multi-Rail: False
1139       peer ni:
1140         - nid: 8.8.8.8@tcp
1141 EOF
1142         append_global_yaml
1143         compare_route_add "tcp8" "8.8.8.[8-10]@tcp"
1144 }
1145 run_test 101 "Add route with multiple gw (tcp)"
1146
1147 compare_route_del() {
1148         local rnet="$1"
1149         local gw="$2"
1150
1151         local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
1152
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
1158 }
1159
1160 test_102() {
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"
1168 }
1169 run_test 102 "Delete route with single gw (tcp)"
1170
1171 test_103() {
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"
1180 }
1181 run_test 103 "Delete route with multiple gw (tcp)"
1182
1183 test_104() {
1184         local tyaml="$TMP/sanity-lnet-$testnum-expected.yaml"
1185
1186         reinit_dlc || return $?
1187
1188         # Default value is '3'
1189         local val=$($LNETCTL global show | awk '/response_tracking/{print $NF}')
1190         [[ $val -ne 3 ]] &&
1191                 error "Expect 3 found $val"
1192
1193         echo "Set < 0;  Should fail"
1194         do_lnetctl set response_tracking -1 &&
1195                 error "should have failed $?"
1196
1197         reinit_dlc || return $?
1198         cat <<EOF > $tyaml
1199 global:
1200     response_tracking: -10
1201 EOF
1202         do_lnetctl import < $tyaml &&
1203                 error "should have failed $?"
1204
1205         echo "Check valid values; Should succeed"
1206         local i
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 $?
1214                 cat <<EOF > $tyaml
1215 global:
1216     response_tracking: $i
1217 EOF
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"
1222         done
1223
1224         reinit_dlc || return $?
1225         echo "Set > 3; Should fail"
1226         do_lnetctl set response_tracking 4 &&
1227                 error "should have failed $?"
1228
1229         reinit_dlc || return $?
1230         cat <<EOF > $tyaml
1231 global:
1232     response_tracking: 10
1233 EOF
1234         do_lnetctl import < $tyaml &&
1235                 error "should have failed $?"
1236         return 0
1237 }
1238 run_test 104 "Set/check response_tracking param"
1239
1240 ### load lnet in default namespace, configure in target namespace
1241
1242 test_200() {
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$"
1247 }
1248 run_test 200 "load lnet w/o module option, configure in a non-default namespace"
1249
1250 test_201() {
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$"
1255 }
1256 run_test 201 "load lnet using networks module options in a non-default namespace"
1257
1258 test_202() {
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$"
1263 }
1264 run_test 202 "load lnet using ip2nets in a non-default namespace"
1265
1266
1267 ### Add the interfaces in the target namespace
1268
1269 test_203() {
1270         cleanup_lnet || exit 1
1271         load_lnet
1272         do_lnetctl lnet configure || exit 1
1273         do_ns $LNETCTL net add --net tcp0 --if $FAKE_IF
1274 }
1275 run_test 203 "add a network using an interface in the non-default namespace"
1276
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
1281 }
1282
1283 function restore_lnet_params() {
1284         local param value
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
1291 }
1292
1293 function lnet_health_pre() {
1294         save_lnet_params
1295
1296         # Lower transaction timeout to speed up test execution
1297         $LNETCTL set transaction_timeout 10 ||
1298                 error "Failed to set transaction_timeout $?"
1299
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 $?"
1303
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)
1308
1309         local my_nid=$($LCTL list_nids | head -n 1)
1310
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)
1314
1315         # Might not have any peers so initialize to zero.
1316         RMT_HVAL_PRE=${RMT_HVAL_PRE:-0}
1317
1318         return 0
1319 }
1320
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)
1326
1327         local my_nid=$($LCTL list_nids | head -n 1)
1328
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)
1332
1333         # Might not have any peers so initialize to zero.
1334         RMT_HVAL_POST=${RMT_HVAL_POST:-0}
1335
1336         ${VERBOSE} &&
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"
1344
1345         restore_lnet_params
1346
1347         return 0
1348 }
1349
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"
1354
1355         return 0
1356 }
1357
1358 function check_resends() {
1359         local delta=$((RSND_POST - RSND_PRE))
1360
1361         echo "Check that $RETRY_PARAM resends took place"
1362         [[ $delta -ne $RETRY_PARAM ]] &&
1363                 error "Expected $RETRY_PARAM resends found $delta"
1364
1365         return 0
1366 }
1367
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"
1372
1373         return 0
1374 }
1375
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"
1380
1381         return 0
1382 }
1383
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"
1388
1389         return 0
1390 }
1391
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"
1396
1397         return 0
1398 }
1399
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"
1404 test_204() {
1405         have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1406         reinit_dlc || return $?
1407         add_net "tcp" "eth0" || return $?
1408
1409         lnet_health_pre || return $?
1410
1411         local hstatus
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
1419         done
1420
1421         lnet_health_post
1422
1423         check_no_resends || return $?
1424         check_no_local_health || return $?
1425
1426         return 0
1427 }
1428 run_test 204 "Check no health or resends for single-rail local failures"
1429
1430 test_205() {
1431         have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1432
1433         local hstatus
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 $?
1438
1439                 echo "Simulate $hstatus"
1440                 lnet_health_pre
1441
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
1447
1448                 lnet_health_post
1449
1450                 check_resends || return $?
1451                 check_local_health || return $?
1452         done
1453
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 $?
1458
1459                 echo "Simulate $hstatus"
1460                 lnet_health_pre || return $?
1461
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
1467
1468                 lnet_health_post
1469
1470                 check_no_resends || return $?
1471                 check_local_health || return $?
1472         done
1473
1474         return 0
1475 }
1476 run_test 205 "Check health and resends for multi-rail local failures"
1477
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"
1481 test_206() {
1482         have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1483         reinit_dlc || return $?
1484         add_net "tcp" "eth0" || return $?
1485
1486         do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1487                 error "failed to discover myself"
1488
1489         lnet_health_pre || return $?
1490
1491         local hstatus
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
1499         done
1500
1501         lnet_health_post
1502
1503         check_no_resends || return $?
1504         check_no_local_health || return $?
1505         check_no_remote_health || return $?
1506
1507         return 0
1508 }
1509 run_test 206 "Check no health or resends for single-rail remote failures"
1510
1511 test_207() {
1512         have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1513
1514         local hstatus
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 $?
1519
1520                 do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1521                         error "failed to discover myself"
1522
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
1530
1531                 lnet_health_post
1532
1533                 check_resends || return $?
1534                 check_no_local_health || return $?
1535                 check_remote_health || return $?
1536         done
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 $?
1541
1542                 do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1543                         error "failed to discover myself"
1544
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
1552
1553                 lnet_health_post
1554
1555                 check_no_resends || return $?
1556                 check_no_local_health || return $?
1557                 check_remote_health || return $?
1558         done
1559
1560         return 0
1561 }
1562 run_test 207 "Check health and resends for multi-rail remote errors"
1563
1564 test_208_load_and_check_lnet() {
1565         local ip2nets="$1"
1566         local p_nid="$2"
1567         local s_nid="$3"
1568         local num_expected=1
1569
1570         load_lnet "networks=\"\" ip2nets=\"${ip2nets_str}\""
1571
1572         $LCTL net up ||
1573                 error "Failed to load LNet with ip2nets \"${ip2nets_str}\""
1574
1575         [[ -n $s_nid ]] &&
1576                 num_expected=2
1577
1578         declare -a nids
1579         nids=( $($LCTL list_nids) )
1580
1581         [[ ${#nids[@]} -ne ${num_expected} ]] &&
1582                 error "Expect ${num_expected} NIDs found ${#nids[@]}"
1583
1584         [[ ${nids[0]} == ${p_nid} ]] ||
1585                 error "Expect NID \"${p_nid}\" found \"${nids[0]}\""
1586
1587         [[ -n $s_nid ]] && [[ ${nids[1]} != ${s_nid} ]] &&
1588                 error "Expect second NID \"${s_nid}\" found \"${nids[1]}\""
1589
1590         $LCTL net down &>/dev/null
1591         cleanup_lnet
1592 }
1593
1594 test_208() {
1595         have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1596
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"
1600
1601         have_interface "$FAKE_IF" ||
1602                 error "Expect $FAKE_IF configured but not found"
1603
1604         local eth0_ip=$(ip --oneline addr show dev eth0 |
1605                         awk '/inet /{print $4}' |
1606                         sed 's:/.*::')
1607         local ip2nets_str="tcp(eth0) $eth0_ip"
1608
1609         echo "Configure single NID \"$ip2nets_str\""
1610         test_208_load_and_check_lnet "${ip2nets_str}" "${eth0_ip}@tcp"
1611
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" \
1615                                      "${FAKE_IP}@tcp1"
1616
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" \
1620                                      "${FAKE_IP}@tcp"
1621         local addr1=( ${eth0_ip//./ } )
1622         local addr2=( ${FAKE_IP//./ } )
1623         local range="[${addr1[0]},${addr2[0]}]"
1624
1625         local i
1626         for i in $(seq 1 3); do
1627                 range+=".[${addr1[$i]},${addr2[$i]}]"
1628         done
1629         ip2nets_str="tcp(eth0,${FAKE_IF}) ${range}"
1630
1631         echo "Configured two NIDs; one NET alt syntax \"$ip2nets_str\""
1632         test_208_load_and_check_lnet "${ip2nets_str}" "${eth0_ip}@tcp" \
1633                                      "${FAKE_IP}@tcp"
1634
1635         cleanup_fakeif
1636
1637         echo "alt syntax with missing IF \"$ip2nets_str\""
1638         load_lnet "networks=\"\" ip2nets=\"${ip2nets_str}\""
1639
1640         echo "$LCTL net up should fail"
1641         $LCTL net up &&
1642                 error "LNet bringup should have failed"
1643
1644         cleanup_lnet
1645 }
1646 run_test 208 "Test various kernel ip2nets configurations"
1647
1648 test_209() {
1649         have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1650
1651         reinit_dlc || return $?
1652         add_net "tcp" "eth0" || return $?
1653
1654         do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1655                 error "failed to discover myself"
1656
1657         echo "Simulate network_timeout w/SR config"
1658         lnet_health_pre
1659
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
1664
1665         lnet_health_post
1666
1667         check_no_resends || return $?
1668         check_no_local_health || return $?
1669         check_no_remote_health || return $?
1670
1671         reinit_dlc || return $?
1672         add_net "tcp" "eth0" || return $?
1673         add_net "tcp1" "eth0" || return $?
1674
1675         do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1676                 error "failed to discover myself"
1677
1678         echo "Simulate network_timeout w/MR config"
1679         lnet_health_pre
1680
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
1686
1687         lnet_health_post
1688
1689         check_no_resends || return $?
1690         check_local_health || return $?
1691         check_remote_health || return $?
1692
1693         return 0
1694 }
1695 run_test 209 "Check health, but not resends, for network timeout"
1696
1697 check_nid_in_recovq() {
1698         local recovq=$($LNETCTL debug recovery $1)
1699         local expect="$2"
1700         local nids=$($LCTL list_nids | xargs echo)
1701         local found=false
1702         local nid=""
1703
1704         echo "Check recovery queue"
1705         echo "$recovq"
1706         if [[ $(grep -c 'nid-'<<<$recovq) -ne $expect ]]; then
1707                 error "Expect $expect NIDs found: \"$recovq\""
1708         fi
1709
1710         [[ $expect -eq 0 ]] && return 0
1711
1712         for nid in ${nids}; do
1713                 grep -q "nid-0: $nid"<<<$recovq &&
1714                         found=true
1715         done
1716
1717         if ! $found; then
1718                 error "Didn't find local NIDs in recovery queue: \"$recovq\""
1719         fi
1720
1721         return 0
1722 }
1723
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
1731 # happen
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
1734 # queued.
1735 check_ping_count() {
1736         local queue="$1"
1737         local expect="$2"
1738
1739         echo "Check ping counts:"
1740         local ping_count
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}') )
1749         else
1750                 error "Unrecognized queue \"$queue\""
1751                 return 1
1752         fi
1753
1754         local count
1755         local found=false
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"
1760                                 return 1
1761                         else
1762                                 echo "Expect ping count \"$expect\" found \"$count\""
1763                                 found=true;
1764                         fi
1765                 elif [[ $count -ne 0 ]]; then
1766                         error "Found interface with ping count \"$count\" but expect \"$expect\""
1767                         return 1
1768                 fi
1769         done
1770
1771         return 0
1772 }
1773
1774 test_210() {
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 $?
1779
1780         local prim_nid=$($LCTL list_nids | head -n 1)
1781
1782         do_lnetctl discover $prim_nid ||
1783                 error "failed to discover myself"
1784
1785         # Set recovery limit to 10 seconds.
1786         do_lnetctl set recovery_limit 10 ||
1787                 error "failed to set recovery_limit"
1788
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"
1795
1796         sleep 5
1797         check_nid_in_recovq "-l" 1
1798         check_ping_count "ni" "2"
1799
1800         sleep 5
1801
1802         check_nid_in_recovq "-l" 1
1803         check_ping_count "ni" "3"
1804
1805         $LCTL net_drop_del -a
1806
1807         return 0
1808 }
1809 run_test 210 "Local NI recovery checks"
1810
1811 test_211() {
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 $?
1816
1817         local prim_nid=$($LCTL list_nids | head -n 1)
1818
1819         do_lnetctl discover $prim_nid ||
1820                 error "failed to discover myself"
1821
1822         # Set recovery limit to 10 seconds.
1823         do_lnetctl set recovery_limit 10 ||
1824                 error "failed to set recovery_limit"
1825
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
1828
1829         # Set health to 0 on one interface. This forces it onto the recovery
1830         # queue.
1831         $LNETCTL peer set --nid $prim_nid --health 0
1832
1833         # After 5 seconds, we expect the peer NI to still be in recovery
1834         sleep 5
1835         check_nid_in_recovq "-p" 1
1836         check_ping_count "peer_ni" "2"
1837
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.
1842         sleep 12
1843         check_nid_in_recovq "-p" 0
1844         check_ping_count "peer_ni" "4"
1845
1846         $LCTL net_drop_del -a
1847
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
1852         # eligible again
1853         do_lnetctl set recovery_limit 0 ||
1854                 error "failed to set recovery_limit"
1855
1856         $LNETCTL peer set --nid $prim_nid --health 500
1857
1858         check_nid_in_recovq "-p" 1
1859         check_ping_count "peer_ni" "2"
1860
1861         sleep 7
1862
1863         check_nid_in_recovq "-p" 0
1864         check_ping_count "peer_ni" "0"
1865
1866         return 0
1867 }
1868 run_test 211 "Remote NI recovery checks"
1869
1870 test_212() {
1871         local rnodes=$(remote_nodes_list)
1872         [[ -z $rnodes ]] && skip "Need at least 1 remote node"
1873
1874         cleanup_lnet || error "Failed to cleanup before test execution"
1875
1876         # Loading modules should configure LNet with the appropriate
1877         # test-framework configuration
1878         load_modules || error "Failed to load modules"
1879
1880         local my_nid=$($LCTL list_nids | head -n 1)
1881         [[ -z $my_nid ]] &&
1882                 error "Failed to get primary NID for local host $HOSTNAME"
1883
1884         local rnode=$(awk '{print $1}' <<<$rnodes)
1885         local rnodenids=$(do_node $rnode $LCTL list_nids | xargs echo)
1886         local rloaded=false
1887
1888         if [[ -z $rnodenids ]]; then
1889                 do_rpc_nodes $rnode load_modules_local
1890                 rloaded=true
1891                 rnodenids=$(do_node $rnode $LCTL list_nids | xargs echo)
1892         fi
1893
1894         local rnodepnid=$(awk '{print $1}' <<< $rnodenids)
1895
1896         [[ -z $rnodepnid ]] &&
1897                 error "Failed to get primary NID for remote host $rnode"
1898
1899         log "Initial discovery"
1900         do_lnetctl discover --force $rnodepnid ||
1901                 error "Failed to discover $rnodepnid"
1902
1903         do_node $rnode "$LNETCTL discover --force $my_nid" ||
1904                 error "$rnode failed to discover $my_nid"
1905
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
1911
1912         local nid
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
1919                 # the PING failure
1920                 $LCTL net_delay_add -s "*@$NETTYPE" -d $nid -r 1 -m PUT -l 6
1921         done
1922
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 &
1929         local pid1=$!
1930
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
1936
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"
1941         wait $pid1
1942         log "Finished wait on $pid1"
1943
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
1948         # outstanding PUSH.
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()
1953
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
1958
1959         unload_modules ||
1960                 error "Failed to unload modules"
1961         if $rloaded; then
1962                 do_rpc_nodes $rnode unload_modules_local ||
1963                         error "Failed to unload modules on $rnode"
1964         fi
1965
1966         return 0
1967 }
1968 run_test 212 "Check discovery refcount loss bug (LU-14627)"
1969
1970 test_213() {
1971         have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1972
1973         cleanup_netns || error "Failed to cleanup netns before test execution"
1974         cleanup_lnet || error "Failed to unload modules before test execution"
1975
1976         setup_fakeif || error "Failed to add fake IF"
1977         have_interface "$FAKE_IF" ||
1978                 error "Expect $FAKE_IF configured but not found"
1979
1980         reinit_dlc || return $?
1981
1982         add_net "tcp" "eth0" || return $?
1983         add_net "tcp" "$FAKE_IF" || return $?
1984
1985         local nid1=$(lctl list_nids | head -n 1)
1986         local nid2=$(lctl list_nids | tail --lines 1)
1987
1988         [[ $(lctl which_nid $nid1 $nid2) == $nid1 ]] ||
1989                 error "Expect nid1 \"$nid1\" to be preferred"
1990
1991         [[ $(lctl which_nid $nid2 $nid1) == $nid2 ]] ||
1992                 error "Expect nid2 \"$nid2\" to be preferred"
1993
1994         return 0
1995 }
1996 run_test 213 "Check LNetDist calculation for multiple local NIDs"
1997
1998 test_230() {
1999         # LU-12815
2000         have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
2001
2002         echo "Check valid values; Should succeed"
2003         local i
2004         local lnid
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))"
2017         done
2018
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 $?"
2024
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"
2032 }
2033 run_test 230 "Test setting conns-per-peer"
2034
2035 test_300() {
2036         # LU-13274
2037         local header
2038         local out=$TMP/$tfile
2039         local prefix=/usr/include/linux/lnet
2040
2041         # We use a hard coded prefix so that this test will not fail
2042         # when run in tree.
2043         CC=${CC:-cc}
2044         if ! which $CC > /dev/null 2>&1; then
2045                 skip_env "$CC is not installed"
2046         fi
2047
2048         cleanup_lnet || exit 1
2049         load_lnet
2050
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"
2056         fi
2057
2058         for header in $prefix/*.h; do
2059                 if ! [[ -f "$header" ]]; then
2060                         continue
2061                 fi
2062
2063                 echo "$CC $cc_args -include $header"
2064                 $CC $cc_args -include $header ||
2065                         error "cannot compile '$header'"
2066         done
2067         rm -f $out
2068 }
2069 run_test 300 "packaged LNet UAPI headers can be compiled"
2070
2071 complete $SECONDS
2072
2073 cleanup_testsuite
2074 exit_status