Whamcloud - gitweb
LU-14627 lnet: Ensure ref taken when queueing for discovery
[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 route:
1076     - net: tcp7
1077       gateway: 7.7.7.7@tcp
1078       hop: -1
1079       priority: 0
1080       health_sensitivity: 1
1081 peer:
1082     - primary nid: 7.7.7.7@tcp
1083       Multi-Rail: False
1084       peer ni:
1085         - nid: 7.7.7.7@tcp
1086 EOF
1087         append_global_yaml
1088         compare_route_add "tcp7" "7.7.7.7@tcp" || return $?
1089         compare_yaml_files
1090 }
1091 run_test 100 "Add route with single gw (tcp)"
1092
1093 test_101() {
1094         have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1095         reinit_dlc || return $?
1096         add_net "tcp" "eth0"
1097         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
1098 net:
1099     - net type: tcp
1100       local NI(s):
1101         - interfaces:
1102               0: eth0
1103           tunables:
1104               peer_timeout: 180
1105               peer_credits: 8
1106               peer_buffer_credits: 0
1107               credits: 256
1108 route:
1109     - net: tcp8
1110       gateway: 8.8.8.10@tcp
1111       hop: -1
1112       priority: 0
1113       health_sensitivity: 1
1114     - net: tcp8
1115       gateway: 8.8.8.9@tcp
1116       hop: -1
1117       priority: 0
1118       health_sensitivity: 1
1119     - net: tcp8
1120       gateway: 8.8.8.8@tcp
1121       hop: -1
1122       priority: 0
1123       health_sensitivity: 1
1124 peer:
1125     - primary nid: 8.8.8.9@tcp
1126       Multi-Rail: False
1127       peer ni:
1128         - nid: 8.8.8.9@tcp
1129     - primary nid: 8.8.8.10@tcp
1130       Multi-Rail: False
1131       peer ni:
1132         - nid: 8.8.8.10@tcp
1133     - primary nid: 8.8.8.8@tcp
1134       Multi-Rail: False
1135       peer ni:
1136         - nid: 8.8.8.8@tcp
1137 EOF
1138         append_global_yaml
1139         compare_route_add "tcp8" "8.8.8.[8-10]@tcp"
1140 }
1141 run_test 101 "Add route with multiple gw (tcp)"
1142
1143 compare_route_del() {
1144         local rnet="$1"
1145         local gw="$2"
1146
1147         local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
1148
1149         do_lnetctl route del --net ${rnet} --gateway ${gw} ||
1150                 error "route del failed $?"
1151         $LNETCTL export --backup > $actual ||
1152                 error "export failed $?"
1153         validate_gateway_nids
1154 }
1155
1156 test_102() {
1157         have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1158         reinit_dlc || return $?
1159         add_net "tcp" "eth0"
1160         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-expected.yaml
1161         do_lnetctl route add --net tcp102 --gateway 102.102.102.102@tcp ||
1162                 error "route add failed $?"
1163         compare_route_del "tcp102" "102.102.102.102@tcp"
1164 }
1165 run_test 102 "Delete route with single gw (tcp)"
1166
1167 test_103() {
1168         have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1169         reinit_dlc || return $?
1170         add_net "tcp" "eth0"
1171         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-expected.yaml
1172         do_lnetctl route add --net tcp103 \
1173                 --gateway 103.103.103.[103-120/4]@tcp ||
1174                 error "route add failed $?"
1175         compare_route_del "tcp103" "103.103.103.[103-120/4]@tcp"
1176 }
1177 run_test 103 "Delete route with multiple gw (tcp)"
1178
1179 test_104() {
1180         local tyaml="$TMP/sanity-lnet-$testnum-expected.yaml"
1181
1182         reinit_dlc || return $?
1183
1184         # Default value is '3'
1185         local val=$($LNETCTL global show | awk '/response_tracking/{print $NF}')
1186         [[ $val -ne 3 ]] &&
1187                 error "Expect 3 found $val"
1188
1189         echo "Set < 0;  Should fail"
1190         do_lnetctl set response_tracking -1 &&
1191                 error "should have failed $?"
1192
1193         reinit_dlc || return $?
1194         cat <<EOF > $tyaml
1195 global:
1196     response_tracking: -10
1197 EOF
1198         do_lnetctl import < $tyaml &&
1199                 error "should have failed $?"
1200
1201         echo "Check valid values; Should succeed"
1202         local i
1203         for ((i = 0; i < 4; i++)); do
1204                 reinit_dlc || return $?
1205                 do_lnetctl set response_tracking $i ||
1206                         error "should have succeeded $?"
1207                 $LNETCTL global show | grep -q "response_tracking: $i" ||
1208                         error "Failed to set response_tracking to $i"
1209                 reinit_dlc || return $?
1210                 cat <<EOF > $tyaml
1211 global:
1212     response_tracking: $i
1213 EOF
1214                 do_lnetctl import < $tyaml ||
1215                         error "should have succeeded $?"
1216                 $LNETCTL global show | grep -q "response_tracking: $i" ||
1217                         error "Failed to set response_tracking to $i"
1218         done
1219
1220         reinit_dlc || return $?
1221         echo "Set > 3; Should fail"
1222         do_lnetctl set response_tracking 4 &&
1223                 error "should have failed $?"
1224
1225         reinit_dlc || return $?
1226         cat <<EOF > $tyaml
1227 global:
1228     response_tracking: 10
1229 EOF
1230         do_lnetctl import < $tyaml &&
1231                 error "should have failed $?"
1232         return 0
1233 }
1234 run_test 104 "Set/check response_tracking param"
1235
1236 ### load lnet in default namespace, configure in target namespace
1237
1238 test_200() {
1239         cleanup_lnet || exit 1
1240         load_lnet "networks=\"\""
1241         do_ns $LNETCTL lnet configure --all || exit 1
1242         $LNETCTL net show --net tcp | grep -q "nid: ${FAKE_IP}@tcp$"
1243 }
1244 run_test 200 "load lnet w/o module option, configure in a non-default namespace"
1245
1246 test_201() {
1247         cleanup_lnet || exit 1
1248         load_lnet "networks=tcp($FAKE_IF)"
1249         do_ns $LNETCTL lnet configure --all || exit 1
1250         $LNETCTL net show --net tcp | grep -q "nid: ${FAKE_IP}@tcp$"
1251 }
1252 run_test 201 "load lnet using networks module options in a non-default namespace"
1253
1254 test_202() {
1255         cleanup_lnet || exit 1
1256         load_lnet "networks=\"\" ip2nets=\"tcp0($FAKE_IF) ${FAKE_IP}\""
1257         do_ns $LNETCTL lnet configure --all || exit 1
1258         $LNETCTL net show | grep -q "nid: ${FAKE_IP}@tcp$"
1259 }
1260 run_test 202 "load lnet using ip2nets in a non-default namespace"
1261
1262
1263 ### Add the interfaces in the target namespace
1264
1265 test_203() {
1266         cleanup_lnet || exit 1
1267         load_lnet
1268         do_lnetctl lnet configure || exit 1
1269         do_ns $LNETCTL net add --net tcp0 --if $FAKE_IF
1270 }
1271 run_test 203 "add a network using an interface in the non-default namespace"
1272
1273 LNET_PARAMS_FILE="$TMP/$TESTSUITE.parameters"
1274 function save_lnet_params() {
1275         $LNETCTL global show | egrep -v '^global:$' |
1276                                sed 's/://' > $LNET_PARAMS_FILE
1277 }
1278
1279 function restore_lnet_params() {
1280         local param value
1281         while read param value; do
1282                 [[ $param == max_intf ]] && continue
1283                 [[ $param == lnd_timeout ]] && continue
1284                 $LNETCTL set ${param} ${value} ||
1285                         error "Failed to restore ${param} to ${value}"
1286         done < $LNET_PARAMS_FILE
1287 }
1288
1289 function lnet_health_pre() {
1290         save_lnet_params
1291
1292         # Lower transaction timeout to speed up test execution
1293         $LNETCTL set transaction_timeout 10 ||
1294                 error "Failed to set transaction_timeout $?"
1295
1296         # Increase recovery interval so we have time to capture health values
1297         $LNETCTL set recovery_interval 20 ||
1298                 error "Failed to set recovery_interval $?"
1299
1300         RETRY_PARAM=$($LNETCTL global show | awk '/retry_count/{print $NF}')
1301         RSND_PRE=$($LNETCTL stats show | awk '/resend_count/{print $NF}')
1302         LO_HVAL_PRE=$($LNETCTL net show -v 2 | awk '/health value/{print $NF}' |
1303                       xargs echo | sed 's/ /+/g' | bc -l)
1304
1305         local my_nid=$($LCTL list_nids | head -n 1)
1306
1307         RMT_HVAL_PRE=$($LNETCTL peer show --nid $my_nid -v 2 2>/dev/null |
1308                        awk '/health value/{print $NF}' | xargs echo |
1309                        sed 's/ /+/g' | bc -l)
1310
1311         # Might not have any peers so initialize to zero.
1312         RMT_HVAL_PRE=${RMT_HVAL_PRE:-0}
1313
1314         return 0
1315 }
1316
1317 function lnet_health_post() {
1318         RSND_POST=$($LNETCTL stats show | awk '/resend_count/{print $NF}')
1319         LO_HVAL_POST=$($LNETCTL net show -v 2 |
1320                        awk '/health value/{print $NF}' |
1321                        xargs echo | sed 's/ /+/g' | bc -l)
1322
1323         local my_nid=$($LCTL list_nids | head -n 1)
1324
1325         RMT_HVAL_POST=$($LNETCTL peer show --nid $my_nid -v 2 2>/dev/null |
1326                         awk '/health value/{print $NF}' | xargs echo |
1327                         sed 's/ /+/g' | bc -l)
1328
1329         # Might not have any peers so initialize to zero.
1330         RMT_HVAL_POST=${RMT_HVAL_POST:-0}
1331
1332         ${VERBOSE} &&
1333         echo "Pre resends: $RSND_PRE" &&
1334         echo "Post resends: $RSND_POST" &&
1335         echo "Resends delta: $((RSND_POST - RSND_PRE))" &&
1336         echo "Pre local health: $LO_HVAL_PRE" &&
1337         echo "Post local health: $LO_HVAL_POST" &&
1338         echo "Pre remote health: $RMT_HVAL_PRE" &&
1339         echo "Post remote health: $RMT_HVAL_POST"
1340
1341         restore_lnet_params
1342
1343         return 0
1344 }
1345
1346 function check_no_resends() {
1347         echo "Check that no resends took place"
1348         [[ $RSND_POST -ne $RSND_PRE ]] &&
1349                 error "Found resends: $RSND_POST != $RSND_PRE"
1350
1351         return 0
1352 }
1353
1354 function check_resends() {
1355         local delta=$((RSND_POST - RSND_PRE))
1356
1357         echo "Check that $RETRY_PARAM resends took place"
1358         [[ $delta -ne $RETRY_PARAM ]] &&
1359                 error "Expected $RETRY_PARAM resends found $delta"
1360
1361         return 0
1362 }
1363
1364 function check_no_local_health() {
1365         echo "Check that local NI health is unchanged"
1366         [[ $LO_HVAL_POST -ne $LO_HVAL_PRE ]] &&
1367                 error "Local health changed: $LO_HVAL_POST != $LO_HVAL_PRE"
1368
1369         return 0
1370 }
1371
1372 function check_local_health() {
1373         echo "Check that local NI health has been changed"
1374         [[ $LO_HVAL_POST -eq $LO_HVAL_PRE ]] &&
1375                 error "Local health unchanged: $LO_HVAL_POST == $LO_HVAL_PRE"
1376
1377         return 0
1378 }
1379
1380 function check_no_remote_health() {
1381         echo "Check that remote NI health is unchanged"
1382         [[ $RMT_HVAL_POST -ne $RMT_HVAL_PRE ]] &&
1383                 error "Remote health changed: $RMT_HVAL_POST != $RMT_HVAL_PRE"
1384
1385         return 0
1386 }
1387
1388 function check_remote_health() {
1389         echo "Check that remote NI health has been changed"
1390         [[ $RMT_HVAL_POST -eq $RMT_HVAL_PRE ]] &&
1391                 error "Remote health unchanged: $RMT_HVAL_POST == $RMT_HVAL_PRE"
1392
1393         return 0
1394 }
1395
1396 # See lnet/lnet/lib-msg.c:lnet_health_check()
1397 LNET_LOCAL_RESEND_STATUSES="local_interrupt local_dropped local_aborted"
1398 LNET_LOCAL_RESEND_STATUSES+=" local_no_route local_timeout"
1399 LNET_LOCAL_NO_RESEND_STATUSES="local_error"
1400 test_204() {
1401         have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1402         reinit_dlc || return $?
1403         add_net "tcp" "eth0" || return $?
1404
1405         lnet_health_pre || return $?
1406
1407         local hstatus
1408         for hstatus in ${LNET_LOCAL_RESEND_STATUSES} \
1409                        ${LNET_LOCAL_NO_RESEND_STATUSES}; do
1410                 echo "Simulate $hstatus"
1411                 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1412                 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1413                         error "Should have failed"
1414                 $LCTL net_drop_del -a
1415         done
1416
1417         lnet_health_post
1418
1419         check_no_resends || return $?
1420         check_no_local_health || return $?
1421
1422         return 0
1423 }
1424 run_test 204 "Check no health or resends for single-rail local failures"
1425
1426 test_205() {
1427         have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1428
1429         local hstatus
1430         for hstatus in ${LNET_LOCAL_RESEND_STATUSES}; do
1431                 reinit_dlc || return $?
1432                 add_net "tcp" "eth0" || return $?
1433                 add_net "tcp1" "eth0" || return $?
1434
1435                 echo "Simulate $hstatus"
1436                 lnet_health_pre
1437
1438                 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1439                 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e ${hstatus}
1440                 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1441                         error "Should have failed"
1442                 $LCTL net_drop_del -a
1443
1444                 lnet_health_post
1445
1446                 check_resends || return $?
1447                 check_local_health || return $?
1448         done
1449
1450         for hstatus in ${LNET_LOCAL_NO_RESEND_STATUSES}; do
1451                 reinit_dlc || return $?
1452                 add_net "tcp" "eth0" || return $?
1453                 add_net "tcp1" "eth0" || return $?
1454
1455                 echo "Simulate $hstatus"
1456                 lnet_health_pre || return $?
1457
1458                 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1459                 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e ${hstatus}
1460                 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1461                         error "Should have failed"
1462                 $LCTL net_drop_del -a
1463
1464                 lnet_health_post
1465
1466                 check_no_resends || return $?
1467                 check_local_health || return $?
1468         done
1469
1470         return 0
1471 }
1472 run_test 205 "Check health and resends for multi-rail local failures"
1473
1474 # See lnet/lnet/lib-msg.c:lnet_health_check()
1475 LNET_REMOTE_RESEND_STATUSES="remote_dropped"
1476 LNET_REMOTE_NO_RESEND_STATUSES="remote_error remote_timeout"
1477 test_206() {
1478         have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1479         reinit_dlc || return $?
1480         add_net "tcp" "eth0" || return $?
1481
1482         do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1483                 error "failed to discover myself"
1484
1485         lnet_health_pre || return $?
1486
1487         local hstatus
1488         for hstatus in ${LNET_REMOTE_RESEND_STATUSES} \
1489                        ${LNET_REMOTE_NO_RESEND_STATUSES}; do
1490                 echo "Simulate $hstatus"
1491                 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1492                 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1493                         error "Should have failed"
1494                 $LCTL net_drop_del -a
1495         done
1496
1497         lnet_health_post
1498
1499         check_no_resends || return $?
1500         check_no_local_health || return $?
1501         check_no_remote_health || return $?
1502
1503         return 0
1504 }
1505 run_test 206 "Check no health or resends for single-rail remote failures"
1506
1507 test_207() {
1508         have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1509
1510         local hstatus
1511         for hstatus in ${LNET_REMOTE_RESEND_STATUSES}; do
1512                 reinit_dlc || return $?
1513                 add_net "tcp" "eth0" || return $?
1514                 add_net "tcp1" "eth0" || return $?
1515
1516                 do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1517                         error "failed to discover myself"
1518
1519                 echo "Simulate $hstatus"
1520                 lnet_health_pre || return $?
1521                 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1522                 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e ${hstatus}
1523                 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1524                         error "Should have failed"
1525                 $LCTL net_drop_del -a
1526
1527                 lnet_health_post
1528
1529                 check_resends || return $?
1530                 check_no_local_health || return $?
1531                 check_remote_health || return $?
1532         done
1533         for hstatus in ${LNET_REMOTE_NO_RESEND_STATUSES}; do
1534                 reinit_dlc || return $?
1535                 add_net "tcp" "eth0" || return $?
1536                 add_net "tcp1" "eth0" || return $?
1537
1538                 do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1539                         error "failed to discover myself"
1540
1541                 echo "Simulate $hstatus"
1542                 lnet_health_pre || return $?
1543                 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1544                 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e ${hstatus}
1545                 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1546                         error "Should have failed"
1547                 $LCTL net_drop_del -a
1548
1549                 lnet_health_post
1550
1551                 check_no_resends || return $?
1552                 check_no_local_health || return $?
1553                 check_remote_health || return $?
1554         done
1555
1556         return 0
1557 }
1558 run_test 207 "Check health and resends for multi-rail remote errors"
1559
1560 test_208_load_and_check_lnet() {
1561         local ip2nets="$1"
1562         local p_nid="$2"
1563         local s_nid="$3"
1564         local num_expected=1
1565
1566         load_lnet "networks=\"\" ip2nets=\"${ip2nets_str}\""
1567
1568         $LCTL net up ||
1569                 error "Failed to load LNet with ip2nets \"${ip2nets_str}\""
1570
1571         [[ -n $s_nid ]] &&
1572                 num_expected=2
1573
1574         declare -a nids
1575         nids=( $($LCTL list_nids) )
1576
1577         [[ ${#nids[@]} -ne ${num_expected} ]] &&
1578                 error "Expect ${num_expected} NIDs found ${#nids[@]}"
1579
1580         [[ ${nids[0]} == ${p_nid} ]] ||
1581                 error "Expect NID \"${p_nid}\" found \"${nids[0]}\""
1582
1583         [[ -n $s_nid ]] && [[ ${nids[1]} != ${s_nid} ]] &&
1584                 error "Expect second NID \"${s_nid}\" found \"${nids[1]}\""
1585
1586         $LCTL net down &>/dev/null
1587         cleanup_lnet
1588 }
1589
1590 test_208() {
1591         have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1592
1593         cleanup_netns || error "Failed to cleanup netns before test execution"
1594         cleanup_lnet || error "Failed to unload modules before test execution"
1595         setup_fakeif || error "Failed to add fake IF"
1596
1597         have_interface "$FAKE_IF" ||
1598                 error "Expect $FAKE_IF configured but not found"
1599
1600         local eth0_ip=$(ip --oneline addr show dev eth0 |
1601                         awk '/inet /{print $4}' |
1602                         sed 's:/.*::')
1603         local ip2nets_str="tcp(eth0) $eth0_ip"
1604
1605         echo "Configure single NID \"$ip2nets_str\""
1606         test_208_load_and_check_lnet "${ip2nets_str}" "${eth0_ip}@tcp"
1607
1608         ip2nets_str="tcp(eth0) $eth0_ip; tcp1($FAKE_IF) $FAKE_IP"
1609         echo "Configure two NIDs; two NETs \"$ip2nets_str\""
1610         test_208_load_and_check_lnet "${ip2nets_str}" "${eth0_ip}@tcp" \
1611                                      "${FAKE_IP}@tcp1"
1612
1613         ip2nets_str="tcp(eth0) $eth0_ip; tcp($FAKE_IF) $FAKE_IP"
1614         echo "Configure two NIDs; one NET \"$ip2nets_str\""
1615         test_208_load_and_check_lnet "${ip2nets_str}" "${eth0_ip}@tcp" \
1616                                      "${FAKE_IP}@tcp"
1617         local addr1=( ${eth0_ip//./ } )
1618         local addr2=( ${FAKE_IP//./ } )
1619         local range="[${addr1[0]},${addr2[0]}]"
1620
1621         local i
1622         for i in $(seq 1 3); do
1623                 range+=".[${addr1[$i]},${addr2[$i]}]"
1624         done
1625         ip2nets_str="tcp(eth0,${FAKE_IF}) ${range}"
1626
1627         echo "Configured two NIDs; one NET alt syntax \"$ip2nets_str\""
1628         test_208_load_and_check_lnet "${ip2nets_str}" "${eth0_ip}@tcp" \
1629                                      "${FAKE_IP}@tcp"
1630
1631         cleanup_fakeif
1632
1633         echo "alt syntax with missing IF \"$ip2nets_str\""
1634         load_lnet "networks=\"\" ip2nets=\"${ip2nets_str}\""
1635
1636         echo "$LCTL net up should fail"
1637         $LCTL net up &&
1638                 error "LNet bringup should have failed"
1639
1640         cleanup_lnet
1641 }
1642 run_test 208 "Test various kernel ip2nets configurations"
1643
1644 test_209() {
1645         have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1646
1647         reinit_dlc || return $?
1648         add_net "tcp" "eth0" || return $?
1649
1650         do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1651                 error "failed to discover myself"
1652
1653         echo "Simulate network_timeout w/SR config"
1654         lnet_health_pre
1655
1656         $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e network_timeout
1657         do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1658                 error "Should have failed"
1659         $LCTL net_drop_del -a
1660
1661         lnet_health_post
1662
1663         check_no_resends || return $?
1664         check_no_local_health || return $?
1665         check_no_remote_health || return $?
1666
1667         reinit_dlc || return $?
1668         add_net "tcp" "eth0" || return $?
1669         add_net "tcp1" "eth0" || return $?
1670
1671         do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1672                 error "failed to discover myself"
1673
1674         echo "Simulate network_timeout w/MR config"
1675         lnet_health_pre
1676
1677         $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e network_timeout
1678         $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e network_timeout
1679         do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1680                 error "Should have failed"
1681         $LCTL net_drop_del -a
1682
1683         lnet_health_post
1684
1685         check_no_resends || return $?
1686         check_local_health || return $?
1687         check_remote_health || return $?
1688
1689         return 0
1690 }
1691 run_test 209 "Check health, but not resends, for network timeout"
1692
1693 check_nid_in_recovq() {
1694         local recovq=$($LNETCTL debug recovery $1)
1695         local expect="$2"
1696         local nids=$($LCTL list_nids | xargs echo)
1697         local found=false
1698         local nid=""
1699
1700         echo "Check recovery queue"
1701         echo "$recovq"
1702         if [[ $(grep -c 'nid-'<<<$recovq) -ne $expect ]]; then
1703                 error "Expect $expect NIDs found: \"$recovq\""
1704         fi
1705
1706         [[ $expect -eq 0 ]] && return 0
1707
1708         for nid in ${nids}; do
1709                 grep -q "nid-0: $nid"<<<$recovq &&
1710                         found=true
1711         done
1712
1713         if ! $found; then
1714                 error "Didn't find local NIDs in recovery queue: \"$recovq\""
1715         fi
1716
1717         return 0
1718 }
1719
1720 # First enqueue happens at time 0.
1721 # 2nd at 0 + 2^0 = 1
1722 # 3rd at 1 + 2^1 = 3
1723 # 4th at 3 + 2^2 = 7
1724 # 5th at 7 + 2^3 = 15
1725 # e.g. after 10 seconds we would expect to have seen the 4th enqueue,
1726 # (3 pings sent, 4th about to happen) and the 5th enqueue is yet to
1727 # happen
1728 # If the recovery limit is 10 seconds, then when the 5th enqueue happens
1729 # we expect the peer NI to have aged out, so it will not actually be
1730 # queued.
1731 check_ping_count() {
1732         local queue="$1"
1733         local expect="$2"
1734
1735         echo "Check ping counts:"
1736         local ping_count
1737         if [[ $queue == "ni" ]]; then
1738                 $LNETCTL net show -v 2 | egrep 'nid|health value|ping'
1739                 ping_count=( $($LNETCTL net show -v 2 |
1740                                 awk '/ping_count/{print $NF}') )
1741         elif [[ $queue == "peer_ni" ]]; then
1742                 $LNETCTL peer show -v 2 | egrep 'nid|health value|ping'
1743                 ping_count=( $($LNETCTL peer show -v 2 |
1744                                 awk '/ping_count/{print $NF}') )
1745         else
1746                 error "Unrecognized queue \"$queue\""
1747                 return 1
1748         fi
1749
1750         local count
1751         local found=false
1752         for count in ${ping_count[@]}; do
1753                 if [[ $count -eq $expect ]]; then
1754                         if [[ $expect -ne 0 ]] && $found ; then
1755                                 error "Found more than one interface matching \"$expect\" ping count"
1756                                 return 1
1757                         else
1758                                 echo "Expect ping count \"$expect\" found \"$count\""
1759                                 found=true;
1760                         fi
1761                 elif [[ $count -ne 0 ]]; then
1762                         error "Found interface with ping count \"$count\" but expect \"$expect\""
1763                         return 1
1764                 fi
1765         done
1766
1767         return 0
1768 }
1769
1770 test_210() {
1771         have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1772         reinit_dlc || return $?
1773         add_net "tcp" "eth0" || return $?
1774         add_net "tcp1" "eth0" || return $?
1775
1776         local prim_nid=$($LCTL list_nids | head -n 1)
1777
1778         do_lnetctl discover $prim_nid ||
1779                 error "failed to discover myself"
1780
1781         # Set recovery limit to 10 seconds.
1782         do_lnetctl set recovery_limit 10 ||
1783                 error "failed to set recovery_limit"
1784
1785         $LCTL set_param debug=+net
1786         # Use local_error so LNet doesn't attempt to resend the discovery ping
1787         $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e local_error
1788         $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e local_error
1789         do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1790                 error "Expected discovery to fail"
1791
1792         sleep 5
1793         check_nid_in_recovq "-l" 1
1794         check_ping_count "ni" "2"
1795
1796         sleep 5
1797
1798         check_nid_in_recovq "-l" 1
1799         check_ping_count "ni" "3"
1800
1801         $LCTL net_drop_del -a
1802
1803         return 0
1804 }
1805 run_test 210 "Local NI recovery checks"
1806
1807 test_211() {
1808         have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1809         reinit_dlc || return $?
1810         add_net "tcp" "eth0" || return $?
1811         add_net "tcp1" "eth0" || return $?
1812
1813         local prim_nid=$($LCTL list_nids | head -n 1)
1814
1815         do_lnetctl discover $prim_nid ||
1816                 error "failed to discover myself"
1817
1818         # Set recovery limit to 10 seconds.
1819         do_lnetctl set recovery_limit 10 ||
1820                 error "failed to set recovery_limit"
1821
1822         $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e remote_error
1823         $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e remote_error
1824
1825         # Set health to 0 on one interface. This forces it onto the recovery
1826         # queue.
1827         $LNETCTL peer set --nid $prim_nid --health 0
1828
1829         # After 5 seconds, we expect the peer NI to still be in recovery
1830         sleep 5
1831         check_nid_in_recovq "-p" 1
1832         check_ping_count "peer_ni" "2"
1833
1834         # After 15 seconds, the peer NI should have been fully processed out of
1835         # the recovery queue. We'll allow a total of 17 seconds to account for
1836         # differences in sleeping for whole seconds vs. the more accurate time
1837         # keeping that is done in the recovery code.
1838         sleep 12
1839         check_nid_in_recovq "-p" 0
1840         check_ping_count "peer_ni" "4"
1841
1842         $LCTL net_drop_del -a
1843
1844         # Set health to force it back onto the recovery queue. Set to 500 means
1845         # in 5 seconds it should be back at maximum value. We'll wait a couple
1846         # more seconds than that to be safe.
1847         # NB: we need to increase the recovery limit so the peer NI is
1848         # eligible again
1849         do_lnetctl set recovery_limit 50 ||
1850                 error "failed to set recovery_limit"
1851
1852         $LNETCTL peer set --nid $prim_nid --health 500
1853
1854         sleep 7
1855
1856         check_nid_in_recovq "-p" 0
1857         check_ping_count "peer_ni" "0"
1858
1859         return 0
1860 }
1861 run_test 211 "Remote NI recovery checks"
1862
1863 test_212() {
1864         local rnodes=$(remote_nodes_list)
1865         [[ -z $rnodes ]] && skip "Need at least 1 remote node"
1866
1867         cleanup_lnet || error "Failed to cleanup before test execution"
1868
1869         # Loading modules should configure LNet with the appropriate
1870         # test-framework configuration
1871         load_modules || error "Failed to load modules"
1872
1873         local my_nid=$($LCTL list_nids | head -n 1)
1874         [[ -z $my_nid ]] &&
1875                 error "Failed to get primary NID for local host $HOSTNAME"
1876
1877         local rnode=$(awk '{print $1}' <<<$rnodes)
1878         local rnodenids=$(do_node $rnode $LCTL list_nids | xargs echo)
1879         local rloaded=false
1880
1881         if [[ -z $rnodenids ]]; then
1882                 do_rpc_nodes $rnode load_modules_local
1883                 rloaded=true
1884                 rnodenids=$(do_node $rnode $LCTL list_nids | xargs echo)
1885         fi
1886
1887         local rnodepnid=$(awk '{print $1}' <<< $rnodenids)
1888
1889         [[ -z $rnodepnid ]] &&
1890                 error "Failed to get primary NID for remote host $rnode"
1891
1892         log "Initial discovery"
1893         do_lnetctl discover --force $rnodepnid ||
1894                 error "Failed to discover $rnodepnid"
1895
1896         do_node $rnode "$LNETCTL discover --force $my_nid" ||
1897                 error "$rnode failed to discover $my_nid"
1898
1899         log "Fail local discover ping to set LNET_PEER_REDISCOVER flag"
1900         $LCTL net_drop_add -s "*@$NETTYPE" -d "*@$NETTYPE" -r 1 -e local_error
1901         do_lnetctl discover --force $rnodepnid &&
1902                 error "Discovery should have failed"
1903         $LCTL net_drop_del -a
1904
1905         local nid
1906         for nid in $rnodenids; do
1907                 # We need GET (PING) delay just long enough so we can trigger
1908                 # discovery on the remote peer
1909                 $LCTL net_delay_add -s "*@$NETTYPE" -d $nid -r 1 -m GET -l 3
1910                 $LCTL net_drop_add -s "*@$NETTYPE" -d $nid -r 1 -m GET -e local_error
1911                 # We need PUT (PUSH) delay just long enough so we can process
1912                 # the PING failure
1913                 $LCTL net_delay_add -s "*@$NETTYPE" -d $nid -r 1 -m PUT -l 6
1914         done
1915
1916         log "Force $HOSTNAME to discover $rnodepnid (in background)"
1917         # We want to get a PING sent that we know will eventually fail.
1918         # The delay rules we added will ensure the ping is not sent until
1919         # the PUSH is also in flight (see below), and the drop rule ensures that
1920         # when the PING is eventually sent it will error out
1921         do_lnetctl discover --force $rnodepnid &
1922         local pid1=$!
1923
1924         # We want a discovery PUSH from rnode to put rnode back on our
1925         # discovery queue. This should cause us to try and send a PUSH to rnode
1926         # while the PING is still outstanding.
1927         log "Force $rnode to discover $my_nid"
1928         do_node $rnode $LNETCTL discover --force $my_nid
1929
1930         # At this point we'll have both PING_SENT and PUSH_SENT set for the
1931         # rnode peer. Wait for the PING to error out which should terminate the
1932         # discovery process that we backgrounded.
1933         log "Wait for $pid1"
1934         wait $pid1
1935         log "Finished wait on $pid1"
1936
1937         # The PING send failure clears the PING_SENT flag and puts the peer back
1938         # on the discovery queue. When discovery thread processes the peer it
1939         # will mistakenly clear the PUSH_SENT flag (and set PUSH_FAILED).
1940         # Discovery will then complete for this peer even though we have an
1941         # outstanding PUSH.
1942         # When PUSH is actually unlinked it will be forced back onto the
1943         # discovery queue, but we no longer have a ref on the peer. When
1944         # discovery completes again, we'll trip the ASSERT in
1945         # lnet_destroy_peer_locked()
1946
1947         # Delete the delay rules to send the PUSH
1948         $LCTL net_delay_del -a
1949         # Delete the drop rules
1950         $LCTL net_drop_del -a
1951
1952         unload_modules ||
1953                 error "Failed to unload modules"
1954         if $rloaded; then
1955                 do_rpc_nodes $rnode unload_modules_local ||
1956                         error "Failed to unload modules on $rnode"
1957         fi
1958
1959         return 0
1960 }
1961 run_test 212 "Check discovery refcount loss bug (LU-14627)"
1962
1963 test_300() {
1964         # LU-13274
1965         local header
1966         local out=$TMP/$tfile
1967         local prefix=/usr/include/linux/lnet
1968
1969         # We use a hard coded prefix so that this test will not fail
1970         # when run in tree.
1971         CC=${CC:-cc}
1972         if ! which $CC > /dev/null 2>&1; then
1973                 skip_env "$CC is not installed"
1974         fi
1975
1976         cleanup_lnet || exit 1
1977         load_lnet
1978
1979         if ! [[ -d $prefix ]]; then
1980                 # Assume we're running in tree and fixup the include path.
1981                 prefix=$LUSTRE/../lnet/include/uapi/linux/lnet
1982         fi
1983
1984         for header in $prefix/*.h; do
1985                 if ! [[ -f "$header" ]]; then
1986                         continue
1987                 fi
1988
1989                 $CC -Wall -Werror -std=c99 -include $header -c -x c /dev/null -o $out ||
1990                         error "cannot compile '$header'"
1991         done
1992         rm -f $out
1993 }
1994 run_test 300 "packaged LNet UAPI headers can be compiled"
1995
1996 complete $SECONDS
1997
1998 cleanup_testsuite
1999 exit_status