Whamcloud - gitweb
LU-14067 tests: re-enable gcc compile test for PPC + ARM
[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 [ "$SLOW" = "no" ] && EXCEPT_SLOW=""
16
17 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
18
19 . $LUSTRE/tests/test-framework.sh
20 CLEANUP=${CLEANUP:-:}
21 SETUP=${SETUP:-:}
22 init_test_env "$@"
23 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
24 init_logging
25
26 build_test_filter
27
28 [[ -z $LNETCTL ]] && skip "Need lnetctl"
29
30 restore_mounts=false
31
32 if is_mounted $MOUNT || is_mounted $MOUNT2; then
33         cleanupall || error "Failed cleanup prior to test execution"
34         restore_mounts=true
35 fi
36
37 cleanup_lnet() {
38         echo "Cleaning up LNet"
39         lsmod | grep -q lnet &&
40                 $LNETCTL lnet unconfigure 2>/dev/null
41         unload_modules
42 }
43
44 restore_modules=false
45 if module_loaded lnet ; then
46         cleanup_lnet || error "Failed to unload modules before test execution"
47         restore_modules=true
48 fi
49
50 cleanup_testsuite() {
51         trap "" EXIT
52         # Cleanup any tmp files created by the sub tests
53         rm -f $TMP/sanity-lnet-*.yaml $LNET_PARAMS_FILE
54         cleanup_netns
55         cleanup_lnet
56         if $restore_mounts; then
57                 setupall || error "Failed to setup Lustre after test execution"
58         elif $restore_modules; then
59                 load_modules ||
60                         error "Couldn't load modules after test execution"
61         fi
62         return 0
63 }
64
65 TESTNS='test_ns'
66 FAKE_IF="test1pg"
67 FAKE_IP="10.1.2.3"
68 do_ns() {
69         echo "ip netns exec $TESTNS $*"
70         ip netns exec $TESTNS "$@"
71 }
72
73 setup_fakeif() {
74         local netns="$1"
75
76         local netns_arg=""
77         [[ -n $netns ]] &&
78                 netns_arg="netns $netns"
79
80         ip link add 'test1pl' type veth peer name $FAKE_IF $netns_arg
81         ip link set 'test1pl' up
82         if [[ -n $netns ]]; then
83                 do_ns ip addr add "${FAKE_IP}/31" dev $FAKE_IF
84                 do_ns ip link set $FAKE_IF up
85         else
86                 ip addr add "${FAKE_IP}/31" dev $FAKE_IF
87                 ip link set $FAKE_IF up
88         fi
89 }
90
91 cleanup_fakeif() {
92         ip link show test1pl >& /dev/null && ip link del test1pl || return 0
93 }
94
95 setup_netns() {
96         cleanup_netns
97
98         ip netns add $TESTNS
99         setup_fakeif $TESTNS
100 }
101
102 cleanup_netns() {
103         (ip netns list | grep -q $TESTNS) && ip netns del $TESTNS
104         cleanup_fakeif
105 }
106
107 configure_dlc() {
108         echo "Loading LNet and configuring DLC"
109         load_lnet
110         do_lnetctl lnet configure
111 }
112
113 GLOBAL_YAML_FILE=$TMP/sanity-lnet-global.yaml
114 define_global_yaml() {
115         $LNETCTL export --backup >${GLOBAL_YAML_FILE} ||
116                 error "Failed to export global yaml $?"
117 }
118
119 reinit_dlc() {
120         if lsmod | grep -q lnet; then
121                 do_lnetctl lnet unconfigure ||
122                         error "lnetctl lnet unconfigure failed $?"
123                 do_lnetctl lnet configure ||
124                         error "lnetctl lnet configure failed $?"
125         else
126                 configure_dlc || error "configure_dlc failed $?"
127         fi
128         define_global_yaml
129 }
130
131 append_global_yaml() {
132         [[ ! -e ${GLOBAL_YAML_FILE} ]] &&
133                 error "Missing global yaml at ${GLOBAL_YAML_FILE}"
134
135         cat ${GLOBAL_YAML_FILE} >> $TMP/sanity-lnet-$testnum-expected.yaml
136 }
137
138 create_base_yaml_file() {
139         append_global_yaml
140 }
141
142 compare_yaml_files() {
143         local expected="$TMP/sanity-lnet-$testnum-expected.yaml"
144         local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
145         local rc=0
146         ! [[ -e $expected ]] && echo "$expected not found" && return 1
147         ! [[ -e $actual ]] && echo "$actual not found" && return 1
148         diff -upN ${actual} ${expected} || rc=$?
149         echo "Expected:"
150         cat $expected
151         echo "Actual:"
152         cat $actual
153         return $rc
154 }
155
156 validate_nid() {
157         local nid="$1"
158         local net="${nid//*@/}"
159         local addr="${nid//@*/}"
160
161         local num_re='[0-9]\+'
162         local ip_re="[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
163
164         if [[ $net =~ gni[0-9]* ]]; then
165                 [[ $addr =~ ${num_re} ]] && return 0
166         else
167                 [[ $addr =~ ${ip_re} ]] && return 0
168         fi
169 }
170
171 validate_nids() {
172         local yfile=$TMP/sanity-lnet-$testnum-actual.yaml
173         local primary_nids=$(awk '/- primary nid:/{print $NF}' $yfile | xargs echo)
174         local secondary_nids=$(awk '/- nid:/{print $NF}' $yfile | xargs echo)
175         local gateway_nids=$(awk '/gateway:/{print $NF}' $yfile | xargs echo)
176
177         local nid
178         for nid in $primary_nids $secondary_nids; do
179                 validate_nid "$nid" || error "Bad NID \"${nid}\""
180         done
181         return 0
182 }
183
184 validate_peer_nids() {
185         local num_peers="$1"
186         local nids_per_peer="$2"
187
188         local expect_p="$num_peers"
189         # The primary nid also shows up in the list of secondary nids
190         local expect_s="$(($num_peers + $(($nids_per_peer*$num_peers))))"
191
192         local actual_p=$(grep -c -- '- primary nid:' $TMP/sanity-lnet-$testnum-actual.yaml)
193         local actual_s=$(grep -c -- '- nid:' $TMP/sanity-lnet-$testnum-actual.yaml)
194         if [[ $expect_p -ne $actual_p ]]; then
195                 compare_yaml_files
196                 error "Expected $expect_p but found $actual_p primary nids"
197         elif [[ $expect_s -ne $actual_s ]]; then
198                 compare_yaml_files
199                 error "Expected $expect_s but found $actual_s secondary nids"
200         fi
201         validate_nids
202 }
203
204 validate_gateway_nids() {
205         local expect_gw=$(grep -c -- 'gateway:' $TMP/sanity-lnet-$testnum-expected.yaml)
206         local actual_gw=$(grep -c -- 'gateway:' $TMP/sanity-lnet-$testnum-actual.yaml)
207         if [[ $expect_gw -ne $actual_gw ]]; then
208                 compare_yaml_files
209                 error "Expected $expect_gw gateways but found $actual_gw gateways"
210         fi
211         validate_nids
212 }
213
214 cleanupall -f
215 setup_netns || error "setup_netns failed with $?"
216
217 # Determine the local interface(s) used for LNet
218 load_lnet "config_on_load=1" || error "Failed to load modules"
219
220 do_lnetctl net show
221 ip a
222
223 INTERFACES=( $(lnet_if_list) )
224
225 cleanup_lnet || error "Failed to cleanup LNet"
226
227 stack_trap 'cleanup_testsuite' EXIT
228
229 test_0() {
230         load_module ../lnet/lnet/lnet || error "Failed to load module rc = $?"
231         do_lnetctl lnet configure || error "lnet configure failed rc = $?"
232         define_global_yaml
233         reinit_dlc || return $?
234         do_lnetctl import <  ${GLOBAL_YAML_FILE} || error "Import failed $?"
235         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
236         create_base_yaml_file
237         compare_yaml_files || error "Configuration changed after import"
238 }
239 run_test 0 "Export empty config, import the config, compare"
240
241 compare_peer_add() {
242         local prim_nid="${1:+--prim_nid $1}"
243         local nid="${2:+--nid $2}"
244
245         local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
246
247         do_lnetctl peer add ${prim_nid} ${nid} || error "peer add failed $?"
248         $LNETCTL export --backup > $actual || error "export failed $?"
249         compare_yaml_files
250         return $?
251 }
252
253 test_1() {
254         reinit_dlc || return $?
255         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
256 peer:
257     - primary nid: 1.1.1.1@tcp
258       Multi-Rail: True
259       peer ni:
260         - nid: 1.1.1.1@tcp
261 EOF
262         append_global_yaml
263         compare_peer_add "1.1.1.1@tcp"
264 }
265 run_test 1 "Add peer with single nid (tcp)"
266
267 test_2() {
268         reinit_dlc || return $?
269         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
270 peer:
271     - primary nid: 2.2.2.2@o2ib
272       Multi-Rail: True
273       peer ni:
274         - nid: 2.2.2.2@o2ib
275 EOF
276         append_global_yaml
277         compare_peer_add "2.2.2.2@o2ib"
278 }
279 run_test 2 "Add peer with single nid (o2ib)"
280
281 test_3() {
282         reinit_dlc || return $?
283         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
284 peer:
285     - primary nid: 3.3.3.3@tcp
286       Multi-Rail: True
287       peer ni:
288         - nid: 3.3.3.3@tcp
289         - nid: 3.3.3.3@o2ib
290 EOF
291         append_global_yaml
292         compare_peer_add "3.3.3.3@tcp" "3.3.3.3@o2ib"
293 }
294 run_test 3 "Add peer with tcp primary o2ib secondary"
295
296 test_4() {
297         reinit_dlc || return $?
298         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
299 peer:
300     - primary nid: 4.4.4.4@tcp
301       Multi-Rail: True
302       peer ni:
303         - nid: 4.4.4.4@tcp
304         - nid: 4.4.4.1@tcp
305         - nid: 4.4.4.2@tcp
306         - nid: 4.4.4.3@tcp
307 EOF
308         append_global_yaml
309         echo "Add peer with nidrange (tcp)"
310         compare_peer_add "4.4.4.4@tcp" "4.4.4.[1-3]@tcp"
311
312         echo "Add peer with nidrange that overlaps primary nid (tcp)"
313         compare_peer_add "4.4.4.4@tcp" "4.4.4.[1-4]@tcp"
314 }
315 run_test 4 "Add peer with nidrange (tcp)"
316
317 test_5() {
318         reinit_dlc || return $?
319         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
320 peer:
321     - primary nid: 5.5.5.5@o2ib
322       Multi-Rail: True
323       peer ni:
324         - nid: 5.5.5.5@o2ib
325         - nid: 5.5.5.1@o2ib
326         - nid: 5.5.5.2@o2ib
327         - nid: 5.5.5.3@o2ib
328         - nid: 5.5.5.4@o2ib
329 EOF
330         append_global_yaml
331         echo "Add peer with nidrange (o2ib)"
332         compare_peer_add "5.5.5.5@o2ib" "5.5.5.[1-4]@o2ib"
333
334         echo "Add peer with nidranage that overlaps primary nid (o2ib)"
335         compare_peer_add "5.5.5.5@o2ib" "5.5.5.[1-4]@o2ib"
336 }
337 run_test 5 "Add peer with nidrange (o2ib)"
338
339 test_6() {
340         reinit_dlc || return $?
341         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
342 peer:
343     - primary nid: 6.6.6.6@tcp
344       Multi-Rail: True
345       peer ni:
346         - nid: 6.6.6.6@tcp
347         - nid: 6.6.6.0@tcp
348         - nid: 6.6.6.2@tcp
349         - nid: 6.6.6.4@tcp
350         - nid: 6.6.7.0@tcp
351         - nid: 6.6.7.2@tcp
352         - nid: 6.6.7.4@tcp
353         - nid: 6.6.1.0@o2ib
354         - nid: 6.6.1.3@o2ib
355         - nid: 6.6.1.6@o2ib
356         - nid: 6.6.3.0@o2ib
357         - nid: 6.6.3.3@o2ib
358         - nid: 6.6.3.6@o2ib
359         - nid: 6@gni
360         - nid: 10@gni
361 EOF
362         append_global_yaml
363         compare_peer_add "6.6.6.6@tcp" \
364                 "6.6.[6-7].[0-4/2]@tcp,6.6.[1-4/2].[0-6/3]@o2ib,[6-12/4]@gni"
365 }
366 run_test 6 "Add peer with multiple nidranges"
367
368 compare_peer_del() {
369         local prim_nid="${1:+--prim_nid $1}"
370         local nid="${2:+--nid $2}"
371
372         local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
373
374         do_lnetctl peer del ${prim_nid} ${nid} || error "peer del failed $?"
375         $LNETCTL export --backup > $actual || error "export failed $?"
376         compare_yaml_files
377         return $?
378 }
379
380 test_7() {
381         reinit_dlc || return $?
382         create_base_yaml_file
383
384         echo "Delete peer with single nid (tcp)"
385         do_lnetctl peer add --prim_nid 7.7.7.7@tcp || error "Peer add failed $?"
386         compare_peer_del "7.7.7.7@tcp"
387
388         echo "Delete peer with single nid (o2ib)"
389         do_lnetctl peer add --prim_nid 7.7.7.7@o2ib || error "Peer add failed $?"
390         compare_peer_del "7.7.7.7@o2ib"
391
392         echo "Delete peer that has multiple nids (tcp)"
393         do_lnetctl peer add --prim_nid 7.7.7.7@tcp --nid 7.7.7.[8-12]@tcp ||
394                 error "Peer add failed $?"
395         compare_peer_del "7.7.7.7@tcp"
396
397         echo "Delete peer that has multiple nids (o2ib)"
398         do_lnetctl peer add --prim_nid 7.7.7.7@o2ib --nid 7.7.7.[8-12]@o2ib ||
399                 error "Peer add failed $?"
400         compare_peer_del "7.7.7.7@o2ib"
401
402         echo "Delete peer that has both tcp and o2ib nids"
403         do_lnetctl peer add --prim_nid 7.7.7.7@tcp \
404                 --nid 7.7.7.[9-12]@tcp,7.7.7.[13-15]@o2ib ||
405                 error "Peer add failed $?"
406         compare_peer_del "7.7.7.7@tcp"
407
408         echo "Delete peer with single nid (gni)"
409         do_lnetctl peer add --prim_nid 7@gni || error "Peer add failed $?"
410         compare_peer_del "7@gni"
411
412         echo "Delete peer that has multiple nids (gni)"
413         do_lnetctl peer add --prim_nid 7@gni --nid [8-12]@gni ||
414                 error "Peer add failed $?"
415         compare_peer_del "7@gni"
416
417         echo "Delete peer that has tcp, o2ib and gni nids"
418         do_lnetctl peer add --prim_nid 7@gni \
419                 --nid [8-12]@gni,7.7.7.[9-12]@tcp,7.7.7.[13-15]@o2ib ||
420                 error "Peer add failed $?"
421         compare_peer_del "7@gni"
422 }
423 run_test 7 "Various peer delete tests"
424
425 test_8() {
426         reinit_dlc || return $?
427
428         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
429 peer:
430     - primary nid: 8.8.8.8@tcp
431       Multi-Rail: True
432       peer ni:
433         - nid: 8.8.8.8@tcp
434         - nid: 8.8.8.10@tcp
435         - nid: 8.8.8.11@tcp
436         - nid: 8.8.8.12@tcp
437         - nid: 8.8.8.14@tcp
438         - nid: 8.8.8.15@tcp
439 EOF
440         append_global_yaml
441
442         do_lnetctl peer add --prim_nid 8.8.8.8@tcp --nid 8.8.8.[10-15]@tcp ||
443                 error "Peer add failed $?"
444         compare_peer_del "8.8.8.8@tcp" "8.8.8.13@tcp"
445 }
446 run_test 8 "Delete single secondary nid from peer (tcp)"
447
448 test_9() {
449         reinit_dlc || return $?
450
451         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
452 peer:
453     - primary nid: 9.9.9.9@tcp
454       Multi-Rail: True
455       peer ni:
456         - nid: 9.9.9.9@tcp
457 EOF
458         append_global_yaml
459
460         do_lnetctl peer add --prim_nid 9.9.9.9@tcp \
461                 --nid 9.9.9.[11-16]@tcp || error "Peer add failed $?"
462         compare_peer_del "9.9.9.9@tcp" "9.9.9.[11-16]@tcp"
463 }
464 run_test 9 "Delete all secondary nids from peer (tcp)"
465
466 test_10() {
467         reinit_dlc || return $?
468
469         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
470 peer:
471     - primary nid: 10.10.10.10@tcp
472       Multi-Rail: True
473       peer ni:
474         - nid: 10.10.10.10@tcp
475         - nid: 10.10.10.12@tcp
476         - nid: 10.10.10.13@tcp
477         - nid: 10.10.10.15@tcp
478         - nid: 10.10.10.16@tcp
479 EOF
480         append_global_yaml
481         do_lnetctl peer add --prim_nid 10.10.10.10@tcp \
482                 --nid 10.10.10.[12-16]@tcp || error "Peer add failed $?"
483         compare_peer_del "10.10.10.10@tcp" "10.10.10.14@tcp"
484 }
485 run_test 10 "Delete single secondary nid from peer (o2ib)"
486
487 test_11() {
488         reinit_dlc || return $?
489
490         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
491 peer:
492     - primary nid: 11.11.11.11@tcp
493       Multi-Rail: True
494       peer ni:
495         - nid: 11.11.11.11@tcp
496 EOF
497         append_global_yaml
498         do_lnetctl peer add --prim_nid 11.11.11.11@tcp \
499                 --nid 11.11.11.[13-17]@tcp || error "Peer add failed $?"
500         compare_peer_del "11.11.11.11@tcp" "11.11.11.[13-17]@tcp"
501 }
502 run_test 11 "Delete all secondary nids from peer (o2ib)"
503
504 test_12() {
505         reinit_dlc || return $?
506
507         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
508 peer:
509     - primary nid: 12.12.12.12@o2ib
510       Multi-Rail: True
511       peer ni:
512         - nid: 12.12.12.12@o2ib
513         - nid: 13.13.13.13@o2ib
514         - nid: 14.13.13.13@o2ib
515         - nid: 14.15.13.13@o2ib
516         - nid: 15.17.1.5@tcp
517         - nid: 15.17.1.10@tcp
518         - nid: 15.17.1.20@tcp
519 EOF
520         append_global_yaml
521         do_lnetctl peer add --prim_nid 12.12.12.12@o2ib \
522                 --nid [13-14/1].[13-15/2].13.13@o2ib,[15-16/3].[17-19/4].[1].[5-20/5]@tcp ||
523                 error "Peer add failed $?"
524         compare_peer_del "12.12.12.12@o2ib" "13.15.13.13@o2ib,15.17.1.15@tcp"
525 }
526 run_test 12 "Delete a secondary nid from peer (tcp and o2ib)"
527
528 test_13() {
529         reinit_dlc || return $?
530
531         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
532 peer:
533     - primary nid: 13.13.13.13@o2ib
534       Multi-Rail: True
535       peer ni:
536         - nid: 13.13.13.13@o2ib
537 EOF
538         append_global_yaml
539         do_lnetctl peer add --prim_nid 13.13.13.13@o2ib \
540                 --nid [14-15].[1-2/1].[1].[100-254/10]@tcp,14.14.[254].14@o2ib ||
541                 error "Peer add failed $?"
542         compare_peer_del "13.13.13.13@o2ib" \
543                 "[14-15].[1-2/1].[1].[100-254/10]@tcp,14.14.[254].14@o2ib"
544 }
545 run_test 13 "Delete all secondary nids from peer (tcp and o2ib)"
546
547 create_nid() {
548         local num="$1"
549         local net="$2"
550
551         if [[ $net =~ gni* ]]; then
552                 echo "${num}@${net}"
553         else
554                 echo "${num}.${num}.${num}.${num}@${net}"
555         fi
556 }
557
558 create_mr_peer_yaml() {
559         local num_peers="$1"
560         local secondary_nids="$2"
561         local net="$3"
562
563         echo "Generating peer yaml for $num_peers peers with $secondary_nids secondary nids"
564         echo "peer:" >> $TMP/sanity-lnet-$testnum-expected.yaml
565         local i
566         local total_nids=$((num_peers + $((num_peers * secondary_nids))))
567         local created=0
568         local nidnum=1
569         while [[ $created -lt $num_peers ]]; do
570                 local primary=$(create_nid ${nidnum} ${net})
571         cat <<EOF >> $TMP/sanity-lnet-$testnum-expected.yaml
572     - primary nid: $primary
573       Multi-Rail: True
574       peer ni:
575         - nid: $primary
576 EOF
577                 local j
578                 local start=$((nidnum + 1))
579                 local end=$((nidnum + $secondary_nids))
580                 for j in $(seq ${start} ${end}); do
581                         local nid=$(create_nid $j ${net})
582                         echo "        - nid: $nid" >> $TMP/sanity-lnet-$testnum-expected.yaml
583                 done
584                 nidnum=$((end + 1))
585                 ((created++))
586         done
587 }
588
589 test_14() {
590         reinit_dlc || return $?
591
592         echo "Create single peer, single nid, using import"
593         create_mr_peer_yaml 1 0 tcp
594         do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
595                 error "Import failed $?"
596         append_global_yaml
597         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
598         compare_yaml_files
599
600         echo "Delete single peer using import --del"
601         do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
602                 error "Import failed $?"
603         rm -f $TMP/sanity-lnet-$testnum-expected.yaml
604         create_base_yaml_file
605         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
606         compare_yaml_files
607 }
608 run_test 14 "import peer create/delete with single nid"
609
610 test_15() {
611         reinit_dlc || return $?
612
613         echo "Create multiple peers, single nid per peer, using import"
614         create_mr_peer_yaml 5 0 o2ib
615         # The ordering of nids for this use-case is non-deterministic, so we
616         # we can't just diff the expected/actual output.
617         do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
618                 error "Import failed $?"
619         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
620         validate_peer_nids 5 0
621
622         echo "Delete multiple peers, single nid per peer, using import --del"
623         do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
624                 error "Import failed $?"
625         rm -f $TMP/sanity-lnet-$testnum-expected.yaml
626         create_base_yaml_file
627         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
628         compare_yaml_files
629 }
630 run_test 15 "import multi peer create/delete with single nid per peer"
631
632 test_16() {
633         reinit_dlc || return $?
634
635         echo "Create single peer, multiple nids, using import"
636         create_mr_peer_yaml 1 5 tcp
637         do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
638                 error "Import failed $?"
639         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
640         validate_peer_nids 1 5
641
642         echo "Delete single peer, multiple nids, using import --del"
643         do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
644                 error "Import failed $?"
645         rm -f $TMP/sanity-lnet-$testnum-expected.yaml
646         create_base_yaml_file
647         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
648         compare_yaml_files
649 }
650 run_test 16 "import peer create/delete with multiple nids"
651
652 test_17() {
653         reinit_dlc || return $?
654
655         echo "Create multiple peers, multiple nids per peer, using import"
656         create_mr_peer_yaml 5 7 o2ib
657         do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
658                 error "Import failed $?"
659         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
660         validate_peer_nids 5 7
661
662         echo "Delete multiple peers, multiple nids per peer, using import --del"
663         do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
664                 error "Import failed $?"
665         rm -f $TMP/sanity-lnet-$testnum-expected.yaml
666         create_base_yaml_file
667         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
668         compare_yaml_files
669 }
670 run_test 17 "import multi peer create/delete with multiple nids"
671
672 test_18a() {
673         reinit_dlc || return $?
674
675         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
676 peer:
677     - primary nid: 1.1.1.1@tcp
678       Multi-Rail: True
679       peer ni:
680         - nid: 1.1.1.1@tcp
681         - nid: 2.2.2.2@tcp
682         - nid: 4.4.4.4@tcp
683         - nid: 3.3.3.3@o2ib
684         - nid: 5@gni
685 EOF
686         echo "Import peer with 5 nids"
687         cat $TMP/sanity-lnet-$testnum-expected.yaml
688         do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
689                 error "Import failed $?"
690         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
691 peer:
692     - primary nid: 1.1.1.1@tcp
693       Multi-Rail: True
694       peer ni:
695         - nid: 2.2.2.2@tcp
696         - nid: 3.3.3.3@o2ib
697         - nid: 5@gni
698 EOF
699         echo "Delete three of the nids"
700         cat $TMP/sanity-lnet-$testnum-expected.yaml
701         do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml
702         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
703 peer:
704     - primary nid: 1.1.1.1@tcp
705       Multi-Rail: True
706       peer ni:
707         - nid: 1.1.1.1@tcp
708         - nid: 4.4.4.4@tcp
709 EOF
710         echo "Check peer has expected nids remaining"
711         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
712         append_global_yaml
713         compare_yaml_files
714 }
715 run_test 18a "Delete a subset of nids from a single peer using import --del"
716
717 test_18b() {
718         reinit_dlc || return $?
719
720         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
721 peer:
722     - primary nid: 1.1.1.1@tcp
723       Multi-Rail: True
724       peer ni:
725         - nid: 1.1.1.1@tcp
726         - nid: 2.2.2.2@tcp
727         - nid: 4.4.4.4@tcp
728         - nid: 3.3.3.3@o2ib
729         - nid: 5@gni
730     - primary nid: 6.6.6.6@o2ib
731       Multi-Rail: True
732       peer ni:
733         - nid: 6.6.6.6@o2ib
734         - nid: 7.7.7.7@tcp
735         - nid: 8.8.8.8@tcp
736         - nid: 9.9.9.9@tcp
737         - nid: 10@gni
738 EOF
739         echo "Import two peers with 5 nids each"
740         cat $TMP/sanity-lnet-$testnum-expected.yaml
741         do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
742                 error "Import failed $?"
743         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
744 peer:
745     - primary nid: 1.1.1.1@tcp
746       Multi-Rail: True
747       peer ni:
748         - nid: 2.2.2.2@tcp
749         - nid: 3.3.3.3@o2ib
750         - nid: 5@gni
751     - primary nid: 6.6.6.6@o2ib
752       Multi-Rail: True
753       peer ni:
754         - nid: 7.7.7.7@tcp
755         - nid: 8.8.8.8@tcp
756         - nid: 10@gni
757 EOF
758         echo "Delete three of the nids from each peer"
759         cat $TMP/sanity-lnet-$testnum-expected.yaml
760         do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml
761         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
762 peer:
763     - primary nid: 6.6.6.6@o2ib
764       Multi-Rail: True
765       peer ni:
766         - nid: 6.6.6.6@o2ib
767         - nid: 7.7.7.7@tcp
768     - primary nid: 1.1.1.1@tcp
769       Multi-Rail: True
770       peer ni:
771         - nid: 1.1.1.1@tcp
772         - nid: 4.4.4.4@tcp
773 EOF
774         append_global_yaml
775         echo "Check peers have expected nids remaining"
776         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
777         compare_yaml_files
778         validate_peer_nids 2 1
779 }
780 run_test 18b "Delete multiple nids from multiple peers using import --del"
781
782 test_19() {
783         reinit_dlc || return $?
784         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
785 peer:
786     - primary nid: 19@gni
787       Multi-Rail: True
788       peer ni:
789         - nid: 19@gni
790 EOF
791         append_global_yaml
792         compare_peer_add "19@gni"
793 }
794 run_test 19 "Add peer with single nid (gni)"
795
796 test_20() {
797         reinit_dlc || return $?
798         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
799 peer:
800     - primary nid: 20@gni
801       Multi-Rail: True
802       peer ni:
803         - nid: 20@gni
804         - nid: 20.20.20.20@tcp
805         - nid: 20.20.20.20@o2ib
806 EOF
807         append_global_yaml
808         compare_peer_add "20@gni" "20.20.20.20@tcp,20.20.20.20@o2ib"
809 }
810 run_test 20 "Add peer with gni primary and tcp, o2ib secondary"
811
812 test_21() {
813         reinit_dlc || return $?
814         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
815 peer:
816     - primary nid: 21@gni
817       Multi-Rail: True
818       peer ni:
819         - nid: 21@gni
820         - nid: 22@gni
821         - nid: 23@gni
822         - nid: 24@gni
823         - nid: 25@gni
824 EOF
825         append_global_yaml
826         echo "Add peer with nidrange (gni)"
827         compare_peer_add "21@gni" "[22-25]@gni" || error
828         echo "Add peer with nidrange that overlaps primary nid (gni)"
829         compare_peer_add "21@gni" "[21-25]@gni"
830 }
831 run_test 21 "Add peer with nidrange (gni)"
832
833 test_22() {
834         reinit_dlc || return $?
835         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
836 peer:
837     - primary nid: 22@gni
838       Multi-Rail: True
839       peer ni:
840         - nid: 22@gni
841         - nid: 24@gni
842         - nid: 25@gni
843         - nid: 27@gni
844         - nid: 28@gni
845         - nid: 29@gni
846 EOF
847         append_global_yaml
848         do_lnetctl peer add --prim_nid 22@gni --nid [24-29]@gni ||
849                 error "Peer add failed $?"
850         compare_peer_del "22@gni" "26@gni"
851 }
852 run_test 22 "Delete single secondary nid from peer (gni)"
853
854 test_23() {
855         reinit_dlc || return $?
856         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
857 peer:
858     - primary nid: 23@gni
859       Multi-Rail: True
860       peer ni:
861         - nid: 23@gni
862 EOF
863         append_global_yaml
864
865         do_lnetctl peer add --prim_nid 23@gni --nid [25-29]@gni ||
866                 error "Peer add failed $?"
867         compare_peer_del "23@gni" "[25-29]@gni"
868 }
869 run_test 23 "Delete all secondary nids from peer (gni)"
870
871 test_24() {
872         reinit_dlc || return $?
873         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
874 peer:
875     - primary nid: 24@gni
876       Multi-Rail: True
877       peer ni:
878         - nid: 24@gni
879         - nid: 11@gni
880         - nid: 13.13.13.13@o2ib
881         - nid: 14.13.13.13@o2ib
882         - nid: 14.15.13.13@o2ib
883         - nid: 15.17.1.5@tcp
884         - nid: 15.17.1.10@tcp
885         - nid: 15.17.1.20@tcp
886 EOF
887         append_global_yaml
888         do_lnetctl peer add --prim_nid 24@gni \
889                 --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 ||
890                 error "Peer add failed $?"
891         compare_peer_del "24@gni" "5@gni,13.15.13.13@o2ib,15.17.1.15@tcp"
892 }
893 run_test 24 "Delete a secondary nid from peer (tcp, o2ib and gni)"
894
895 test_25() {
896         reinit_dlc || return $?
897         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
898 peer:
899     - primary nid: 25@gni
900       Multi-Rail: True
901       peer ni:
902         - nid: 25@gni
903 EOF
904         append_global_yaml
905         do_lnetctl peer add --prim_nid 25@gni \
906                 --nid [26-27].[4-10/3].26.26@tcp,26.26.26.26@o2ib,[30-35]@gni ||
907                 error "Peer add failed $?"
908         compare_peer_del "25@gni" \
909                 "[26-27].[4-10/3].26.26@tcp,26.26.26.26@o2ib,[30-35]@gni"
910 }
911 run_test 25 "Delete all secondary nids from peer (tcp, gni and o2ib)"
912
913 test_99a() {
914         reinit_dlc || return $?
915
916         echo "Invalid prim_nid - peer add"
917         do_lnetctl peer add --prim_nid foobar &&
918                 error "Command should have failed"
919
920         echo "Invalid prim_nid - peer del"
921         do_lnetctl peer del --prim_nid foobar &&
922                 error "Command should have failed"
923
924         echo "Delete non-existing peer"
925         do_lnetctl peer del --prim_nid 1.1.1.1@o2ib &&
926                 error "Command should have failed"
927
928         echo "Don't provide mandatory argument for peer del"
929         do_lnetctl peer del --nid 1.1.1.1@tcp &&
930                 error "Command should have failed"
931
932         echo "Don't provide mandatory argument for peer add"
933         do_lnetctl peer add --nid 1.1.1.1@tcp &&
934                 error "Command should have failed"
935
936         echo "Don't provide mandatory arguments peer add"
937         do_lnetctl peer add &&
938                 error "Command should have failed"
939
940         echo "Invalid secondary nids"
941         do_lnetctl peer add --prim_nid 1.1.1.1@tcp --nid foobar &&
942                 error "Command should have failed"
943
944         echo "Exceed max nids per peer"
945         do_lnetctl peer add --prim_nid 1.1.1.1@tcp --nid 1.1.1.[2-255]@tcp &&
946                 error "Command should have failed"
947
948         echo "Invalid net type"
949         do_lnetctl peer add --prim_nid 1@foo &&
950                 error "Command should have failed"
951
952         echo "Invalid nid format"
953         local invalid_nids="1@tcp 1@o2ib 1.1.1.1@gni"
954
955         local nid
956         for nid in ${invalid_nids}; do
957                 echo "Check invalid primary nid - '$nid'"
958                 do_lnetctl peer add --prim_nid $nid &&
959                         error "Command should have failed"
960         done
961
962         local invalid_strs="[2-1]@gni [a-f/x]@gni 256.256.256.256@tcp"
963         invalid_strs+=" 1.1.1.1.[2-5/f]@tcp 1.]2[.3.4@o2ib"
964         invalid_strs+="1.[2-4,[5-6],7-8].1.1@tcp foobar"
965
966         local nidstr
967         for nidstr in ${invalid_strs}; do
968                 echo "Check invalid nidstring - '$nidstr'"
969                 do_lnetctl peer add --prim_nid 1.1.1.1@tcp --nid $nidstr &&
970                         error "Command should have failed"
971         done
972
973         echo "Add non-local gateway"
974         do_lnetctl route add --net tcp --gateway 1@gni &&
975                 error "Command should have failed"
976
977         return 0
978 }
979 run_test 99a "Check various invalid inputs to lnetctl peer"
980
981 test_99b() {
982         reinit_dlc || return $?
983
984         create_base_yaml_file
985
986         cat <<EOF > $TMP/sanity-lnet-$testnum-invalid.yaml
987 peer:
988     - primary nid: 99.99.99.99@tcp
989       Multi-Rail: Foobar
990       peer ni:
991         - nid: 99.99.99.99@tcp
992 EOF
993         do_lnetctl import < $TMP/sanity-lnet-$testnum-invalid.yaml &&
994                 error "import should have failed"
995         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
996         compare_yaml_files
997 }
998 run_test 99b "Invalid value for Multi-Rail in yaml import"
999
1000 have_interface() {
1001         local if="$1"
1002         local ip=$(ip addr show dev $if | awk '/ inet /{print $2}')
1003         [[ -n $ip ]]
1004 }
1005
1006 add_net() {
1007         local net="$1"
1008         local if="$2"
1009
1010         if ! lsmod | grep -q ksocklnd ; then
1011                 load_module ../lnet/klnds/socklnd/ksocklnd ||
1012                         error "Can't load ksocklnd.ko"
1013         fi
1014
1015         do_lnetctl net add --net ${net} --if ${if} ||
1016                 error "Failed to add net ${net} on if ${if}"
1017 }
1018
1019 compare_route_add() {
1020         local rnet="$1"
1021         local gw="$2"
1022
1023         local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
1024
1025         do_lnetctl route add --net ${rnet} --gateway ${gw} ||
1026                 error "route add failed $?"
1027         # CPT configuration is pruned from the exported yaml, since the default
1028         # can vary across test systems (unlike default values for things like
1029         # peer_credits, peer_timeout, etc.)
1030         $LNETCTL export --backup | grep -v CPT > $actual ||
1031                 error "export failed $?"
1032         validate_gateway_nids
1033         return $?
1034 }
1035
1036 test_100() {
1037         reinit_dlc || return $?
1038         add_net "tcp" "${INTERFACES[0]}"
1039         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
1040 net:
1041     - net type: tcp
1042       local NI(s):
1043         - interfaces:
1044               0: ${INTERFACES[0]}
1045           tunables:
1046               peer_timeout: 180
1047               peer_credits: 8
1048               peer_buffer_credits: 0
1049               credits: 256
1050           lnd tunables:
1051               conns_per_peer: 1
1052 route:
1053     - net: tcp7
1054       gateway: 7.7.7.7@tcp
1055       hop: -1
1056       priority: 0
1057       health_sensitivity: 1
1058 peer:
1059     - primary nid: 7.7.7.7@tcp
1060       Multi-Rail: False
1061       peer ni:
1062         - nid: 7.7.7.7@tcp
1063 EOF
1064         append_global_yaml
1065         compare_route_add "tcp7" "7.7.7.7@tcp" || return $?
1066         compare_yaml_files
1067 }
1068 run_test 100 "Add route with single gw (tcp)"
1069
1070 test_101() {
1071         reinit_dlc || return $?
1072         add_net "tcp" "${INTERFACES[0]}"
1073         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
1074 net:
1075     - net type: tcp
1076       local NI(s):
1077         - interfaces:
1078               0: ${INTERFACES[0]}
1079           tunables:
1080               peer_timeout: 180
1081               peer_credits: 8
1082               peer_buffer_credits: 0
1083               credits: 256
1084           lnd tunables:
1085               conns_per_peer: 1
1086 route:
1087     - net: tcp8
1088       gateway: 8.8.8.10@tcp
1089       hop: -1
1090       priority: 0
1091       health_sensitivity: 1
1092     - net: tcp8
1093       gateway: 8.8.8.9@tcp
1094       hop: -1
1095       priority: 0
1096       health_sensitivity: 1
1097     - net: tcp8
1098       gateway: 8.8.8.8@tcp
1099       hop: -1
1100       priority: 0
1101       health_sensitivity: 1
1102 peer:
1103     - primary nid: 8.8.8.9@tcp
1104       Multi-Rail: False
1105       peer ni:
1106         - nid: 8.8.8.9@tcp
1107     - primary nid: 8.8.8.10@tcp
1108       Multi-Rail: False
1109       peer ni:
1110         - nid: 8.8.8.10@tcp
1111     - primary nid: 8.8.8.8@tcp
1112       Multi-Rail: False
1113       peer ni:
1114         - nid: 8.8.8.8@tcp
1115 EOF
1116         append_global_yaml
1117         compare_route_add "tcp8" "8.8.8.[8-10]@tcp"
1118 }
1119 run_test 101 "Add route with multiple gw (tcp)"
1120
1121 compare_route_del() {
1122         local rnet="$1"
1123         local gw="$2"
1124
1125         local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
1126
1127         do_lnetctl route del --net ${rnet} --gateway ${gw} ||
1128                 error "route del failed $?"
1129         $LNETCTL export --backup > $actual ||
1130                 error "export failed $?"
1131         validate_gateway_nids
1132 }
1133
1134 test_102() {
1135         reinit_dlc || return $?
1136         add_net "tcp" "${INTERFACES[0]}"
1137         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-expected.yaml
1138         do_lnetctl route add --net tcp102 --gateway 102.102.102.102@tcp ||
1139                 error "route add failed $?"
1140         compare_route_del "tcp102" "102.102.102.102@tcp"
1141 }
1142 run_test 102 "Delete route with single gw (tcp)"
1143
1144 test_103() {
1145         reinit_dlc || return $?
1146         add_net "tcp" "${INTERFACES[0]}"
1147         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-expected.yaml
1148         do_lnetctl route add --net tcp103 \
1149                 --gateway 103.103.103.[103-120/4]@tcp ||
1150                 error "route add failed $?"
1151         compare_route_del "tcp103" "103.103.103.[103-120/4]@tcp"
1152 }
1153 run_test 103 "Delete route with multiple gw (tcp)"
1154
1155 test_104() {
1156         local tyaml="$TMP/sanity-lnet-$testnum-expected.yaml"
1157
1158         reinit_dlc || return $?
1159
1160         # Default value is '3'
1161         local val=$($LNETCTL global show | awk '/response_tracking/{print $NF}')
1162         [[ $val -ne 3 ]] &&
1163                 error "Expect 3 found $val"
1164
1165         echo "Set < 0;  Should fail"
1166         do_lnetctl set response_tracking -1 &&
1167                 error "should have failed $?"
1168
1169         reinit_dlc || return $?
1170         cat <<EOF > $tyaml
1171 global:
1172     response_tracking: -10
1173 EOF
1174         do_lnetctl import < $tyaml &&
1175                 error "should have failed $?"
1176
1177         echo "Check valid values; Should succeed"
1178         local i
1179         for ((i = 0; i < 4; i++)); do
1180                 reinit_dlc || return $?
1181                 do_lnetctl set response_tracking $i ||
1182                         error "should have succeeded $?"
1183                 $LNETCTL global show | grep -q "response_tracking: $i" ||
1184                         error "Failed to set response_tracking to $i"
1185                 reinit_dlc || return $?
1186                 cat <<EOF > $tyaml
1187 global:
1188     response_tracking: $i
1189 EOF
1190                 do_lnetctl import < $tyaml ||
1191                         error "should have succeeded $?"
1192                 $LNETCTL global show | grep -q "response_tracking: $i" ||
1193                         error "Failed to set response_tracking to $i"
1194         done
1195
1196         reinit_dlc || return $?
1197         echo "Set > 3; Should fail"
1198         do_lnetctl set response_tracking 4 &&
1199                 error "should have failed $?"
1200
1201         reinit_dlc || return $?
1202         cat <<EOF > $tyaml
1203 global:
1204     response_tracking: 10
1205 EOF
1206         do_lnetctl import < $tyaml &&
1207                 error "should have failed $?"
1208         return 0
1209 }
1210 run_test 104 "Set/check response_tracking param"
1211
1212 test_105() {
1213         reinit_dlc || return $?
1214         add_net "tcp" "${INTERFACES[0]}"
1215         do_lnetctl route add --net tcp105 --gateway 105.105.105.105@tcp ||
1216                 error "route add failed $?"
1217         do_lnetctl peer add --prim 105.105.105.105@tcp &&
1218                 error "peer add should fail"
1219
1220         return 0
1221 }
1222 run_test 105 "Adding duplicate GW peer should fail"
1223
1224 test_106() {
1225         reinit_dlc || return $?
1226         add_net "tcp" "${INTERFACES[0]}"
1227         do_lnetctl route add --net tcp106 --gateway 106.106.106.106@tcp ||
1228                 error "route add failed $?"
1229         do_lnetctl peer del --prim 106.106.106.106@tcp &&
1230                 error "peer del should fail"
1231
1232         return 0
1233 }
1234 run_test 106 "Deleting GW peer should fail"
1235
1236 test_200() {
1237         cleanup_lnet || exit 1
1238         load_lnet "networks=\"\""
1239         do_ns $LNETCTL lnet configure --all || exit 1
1240         $LNETCTL net show --net tcp | grep -q "nid: ${FAKE_IP}@tcp$"
1241 }
1242 run_test 200 "load lnet w/o module option, configure in a non-default namespace"
1243
1244 test_201() {
1245         cleanup_lnet || exit 1
1246         load_lnet "networks=tcp($FAKE_IF)"
1247         do_ns $LNETCTL lnet configure --all || exit 1
1248         $LNETCTL net show --net tcp | grep -q "nid: ${FAKE_IP}@tcp$"
1249 }
1250 run_test 201 "load lnet using networks module options in a non-default namespace"
1251
1252 test_202() {
1253         cleanup_lnet || exit 1
1254         load_lnet "networks=\"\" ip2nets=\"tcp0($FAKE_IF) ${FAKE_IP}\""
1255         do_ns $LNETCTL lnet configure --all || exit 1
1256         $LNETCTL net show | grep -q "nid: ${FAKE_IP}@tcp$"
1257 }
1258 run_test 202 "load lnet using ip2nets in a non-default namespace"
1259
1260
1261 ### Add the interfaces in the target namespace
1262
1263 test_203() {
1264         cleanup_lnet || exit 1
1265         load_lnet
1266         do_lnetctl lnet configure || exit 1
1267         do_ns $LNETCTL net add --net tcp0 --if $FAKE_IF
1268 }
1269 run_test 203 "add a network using an interface in the non-default namespace"
1270
1271 LNET_PARAMS_FILE="$TMP/$TESTSUITE.parameters"
1272 function save_lnet_params() {
1273         $LNETCTL global show | egrep -v '^global:$' |
1274                                sed 's/://' > $LNET_PARAMS_FILE
1275 }
1276
1277 function restore_lnet_params() {
1278         local param value
1279         while read param value; do
1280                 [[ $param == max_intf ]] && continue
1281                 [[ $param == lnd_timeout ]] && continue
1282                 $LNETCTL set ${param} ${value} ||
1283                         error "Failed to restore ${param} to ${value}"
1284         done < $LNET_PARAMS_FILE
1285 }
1286
1287 function lnet_health_pre() {
1288         save_lnet_params
1289
1290         # Lower transaction timeout to speed up test execution
1291         $LNETCTL set transaction_timeout 10 ||
1292                 error "Failed to set transaction_timeout $?"
1293
1294         RETRY_PARAM=$($LNETCTL global show | awk '/retry_count/{print $NF}')
1295         RSND_PRE=$($LNETCTL stats show | awk '/resend_count/{print $NF}')
1296         LO_HVAL_PRE=$($LNETCTL net show -v 2 | awk '/health value/{print $NF}' |
1297                       xargs echo | sed 's/ /+/g' | bc -l)
1298
1299         RMT_HVAL_PRE=$($LNETCTL peer show --nid ${RNIDS[0]} -v 2 2>/dev/null |
1300                        awk '/health value/{print $NF}' | xargs echo |
1301                        sed 's/ /+/g' | bc -l)
1302
1303         # Might not have any peers so initialize to zero.
1304         RMT_HVAL_PRE=${RMT_HVAL_PRE:-0}
1305
1306         return 0
1307 }
1308
1309 function lnet_health_post() {
1310         RSND_POST=$($LNETCTL stats show | awk '/resend_count/{print $NF}')
1311         LO_HVAL_POST=$($LNETCTL net show -v 2 |
1312                        awk '/health value/{print $NF}' |
1313                        xargs echo | sed 's/ /+/g' | bc -l)
1314
1315         RMT_HVAL_POST=$($LNETCTL peer show --nid ${RNIDS[0]} -v 2 2>/dev/null |
1316                         awk '/health value/{print $NF}' | xargs echo |
1317                         sed 's/ /+/g' | bc -l)
1318
1319         # Might not have any peers so initialize to zero.
1320         RMT_HVAL_POST=${RMT_HVAL_POST:-0}
1321
1322         ${VERBOSE} &&
1323         echo "Pre resends: $RSND_PRE" &&
1324         echo "Post resends: $RSND_POST" &&
1325         echo "Resends delta: $((RSND_POST - RSND_PRE))" &&
1326         echo "Pre local health: $LO_HVAL_PRE" &&
1327         echo "Post local health: $LO_HVAL_POST" &&
1328         echo "Pre remote health: $RMT_HVAL_PRE" &&
1329         echo "Post remote health: $RMT_HVAL_POST"
1330
1331         restore_lnet_params
1332
1333         do_lnetctl peer set --health 1000 --all
1334         do_lnetctl net set --health 1000 --all
1335
1336         return 0
1337 }
1338
1339 function check_no_resends() {
1340         echo "Check that no resends took place"
1341         [[ $RSND_POST -ne $RSND_PRE ]] &&
1342                 error "Found resends: $RSND_POST != $RSND_PRE"
1343
1344         return 0
1345 }
1346
1347 function check_resends() {
1348         local delta=$((RSND_POST - RSND_PRE))
1349
1350         echo "Check that $RETRY_PARAM resends took place"
1351         [[ $delta -ne $RETRY_PARAM ]] &&
1352                 error "Expected $RETRY_PARAM resends found $delta"
1353
1354         return 0
1355 }
1356
1357 function check_no_local_health() {
1358         echo "Check that local NI health is unchanged"
1359         [[ $LO_HVAL_POST -ne $LO_HVAL_PRE ]] &&
1360                 error "Local health changed: $LO_HVAL_POST != $LO_HVAL_PRE"
1361
1362         return 0
1363 }
1364
1365 function check_local_health() {
1366         echo "Check that local NI health has been changed"
1367         [[ $LO_HVAL_POST -eq $LO_HVAL_PRE ]] &&
1368                 error "Local health unchanged: $LO_HVAL_POST == $LO_HVAL_PRE"
1369
1370         return 0
1371 }
1372
1373 function check_no_remote_health() {
1374         echo "Check that remote NI health is unchanged"
1375         [[ $RMT_HVAL_POST -ne $RMT_HVAL_PRE ]] &&
1376                 error "Remote health changed: $RMT_HVAL_POST != $RMT_HVAL_PRE"
1377
1378         return 0
1379 }
1380
1381 function check_remote_health() {
1382         echo "Check that remote NI health has been changed"
1383         [[ $RMT_HVAL_POST -eq $RMT_HVAL_PRE ]] &&
1384                 error "Remote health unchanged: $RMT_HVAL_POST == $RMT_HVAL_PRE"
1385
1386         return 0
1387 }
1388
1389 RNODE=""
1390 RLOADED=false
1391 NET_DEL_ARGS=""
1392 RNIDS=( )
1393 LNIDS=( )
1394 setup_health_test() {
1395         local need_mr=$1
1396         local rc=0
1397
1398         local rnodes=$(remote_nodes_list)
1399         [[ -z $rnodes ]] && skip "Need at least 1 remote node"
1400
1401         cleanup_lnet || error "Failed to cleanup before test execution"
1402
1403         # Loading modules should configure LNet with the appropriate
1404         # test-framework configuration
1405         load_lnet "config_on_load=1" || error "Failed to load modules"
1406
1407         LNIDS=( $($LCTL list_nids | xargs echo) )
1408
1409         RNODE=$(awk '{print $1}' <<<$rnodes)
1410         RNIDS=( $(do_node $RNODE $LCTL list_nids | xargs echo) )
1411
1412         if [[ -z ${RNIDS[@]} ]]; then
1413                 do_rpc_nodes $RNODE load_lnet "config_on_load=1"
1414                 RLOADED=true
1415                 RNIDS=( $(do_node $RNODE $LCTL list_nids | xargs echo) )
1416         fi
1417
1418         [[ ${#LNIDS[@]} -lt 1 ]] &&
1419                 error "No NIDs configured for local host $HOSTNAME"
1420         [[ ${#RNIDS[@]} -lt 1 ]] &&
1421                 error "No NIDs configured for remote host $RNODE"
1422
1423         do_lnetctl discover ${RNIDS[0]} ||
1424                 error "Unable to discover ${RNIDS[0]}"
1425
1426         local mr=$($LNETCTL peer show --nid ${RNIDS[0]} |
1427                    awk '/Multi-Rail/{print $NF}')
1428
1429         if ${need_mr} && [[ $mr == False ]]; then
1430                 cleanup_health_test || return $?
1431                 skip "Need MR peer"
1432         fi
1433
1434         if ( ! ${need_mr} && [[ ${#RNIDS[@]} -gt 1 ]] ) ||
1435            ( ! ${need_mr} && [[ ${#LNIDS[@]} -gt 1 ]] ); then
1436                 cleanup_health_test || return $?
1437                 skip "Need SR peer"
1438         fi
1439
1440         if ${need_mr} && [[ ${#RNIDS[@]} -lt 2 ]]; then
1441                 # Add a second, reachable NID to rnode.
1442                 local net=${RNIDS[0]}
1443
1444                 net="${net//*@/}1"
1445
1446                 local if=$(do_rpc_nodes --quiet $RNODE lnet_if_list)
1447                 [[ -z $if ]] &&
1448                         error "Failed to determine interface for $RNODE"
1449
1450                 do_rpc_nodes $RNODE "$LNETCTL lnet configure"
1451                 do_rpc_nodes $RNODE "$LNETCTL net add --net $net --if $if" ||
1452                         rc=$?
1453                 if [[ $rc -ne 0 ]]; then
1454                         error "Failed to add interface to $RNODE rc=$?"
1455                 else
1456                         RNIDS[1]="${RNIDS[0]}1"
1457                         NET_DEL_ARGS="--net $net --if $if"
1458                 fi
1459         fi
1460
1461         if ${need_mr} && [[ ${#LNIDS[@]} -lt 2 ]]; then
1462                 local net=${LNIDS[0]}
1463                 net="${net//*@/}1"
1464
1465                 do_lnetctl lnet configure &&
1466                         do_lnetctl net add --net $net --if ${INTERFACES[0]} ||
1467                         rc=$?
1468                 if [[ $rc -ne 0 ]]; then
1469                         error "Failed to add interface rc=$?"
1470                 else
1471                         LNIDS[1]="${LNIDS[0]}1"
1472                 fi
1473         fi
1474
1475         $LNETCTL net show
1476
1477         $LNETCTL peer show -v 2 | egrep -e nid -e health
1478
1479         $LCTL set_param debug=+net
1480
1481         return 0
1482
1483 }
1484
1485 cleanup_health_test() {
1486         local rc=0
1487
1488         if [[ -n $NET_DEL_ARGS ]]; then
1489                 do_rpc_nodes $RNODE \
1490                         "$LNETCTL net del $NET_DEL_ARGS" ||
1491                         rc=$((rc + $?))
1492                 NET_DEL_ARGS=""
1493         fi
1494
1495         unload_modules || rc=$?
1496
1497         if $RLOADED; then
1498                 do_rpc_nodes $RNODE unload_modules_local ||
1499                         rc=$((rc + $?))
1500                 RLOADED=false
1501         fi
1502
1503         [[ $rc -ne 0 ]] &&
1504                 error "Failed cleanup"
1505
1506         return $rc
1507 }
1508
1509 add_health_test_drop_rules() {
1510         local hstatus=$1
1511         local lnid rnid
1512
1513         for lnid in "${LNIDS[@]}"; do
1514                 for rnid in "${RNIDS[@]}"; do
1515                         $LCTL net_drop_add -s $lnid -d $rnid -m GET -r 1 -e ${hstatus}
1516                 done
1517         done
1518 }
1519
1520 # See lnet/lnet/lib-msg.c:lnet_health_check()
1521 LNET_LOCAL_RESEND_STATUSES="local_interrupt local_dropped local_aborted"
1522 LNET_LOCAL_RESEND_STATUSES+=" local_no_route local_timeout"
1523 LNET_LOCAL_NO_RESEND_STATUSES="local_error"
1524 test_204() {
1525         setup_health_test false || return $?
1526
1527         local hstatus
1528         for hstatus in ${LNET_LOCAL_RESEND_STATUSES} \
1529                        ${LNET_LOCAL_NO_RESEND_STATUSES}; do
1530                 echo "Simulate $hstatus"
1531                 lnet_health_pre || return $?
1532
1533                 add_health_test_drop_rules ${hstatus}
1534                 do_lnetctl discover ${RNIDS[0]} &&
1535                         error "Should have failed"
1536                 $LCTL net_drop_del -a
1537
1538                 lnet_health_post
1539
1540                 check_no_resends || return $?
1541                 check_no_local_health || return $?
1542         done
1543
1544         cleanup_health_test || return $?
1545
1546         return 0
1547 }
1548 run_test 204 "Check no health or resends for single-rail local failures"
1549
1550 test_205() {
1551         setup_health_test true || return $?
1552
1553         local hstatus
1554         for hstatus in ${LNET_LOCAL_RESEND_STATUSES}; do
1555                 echo "Simulate $hstatus"
1556                 lnet_health_pre || return $?
1557
1558                 add_health_test_drop_rules ${hstatus}
1559                 do_lnetctl discover ${RNIDS[0]} &&
1560                         error "Should have failed"
1561                 $LCTL net_drop_del -a
1562
1563                 lnet_health_post
1564
1565                 check_resends || return $?
1566                 check_local_health || return $?
1567         done
1568
1569         for hstatus in ${LNET_LOCAL_NO_RESEND_STATUSES}; do
1570                 echo "Simulate $hstatus"
1571                 lnet_health_pre || return $?
1572
1573                 add_health_test_drop_rules ${hstatus}
1574                 do_lnetctl discover ${RNIDS[0]} &&
1575                         error "Should have failed"
1576                 $LCTL net_drop_del -a
1577
1578                 lnet_health_post
1579
1580                 check_no_resends || return $?
1581                 check_local_health || return $?
1582         done
1583
1584         cleanup_health_test || return $?
1585
1586         return 0
1587 }
1588 run_test 205 "Check health and resends for multi-rail local failures"
1589
1590 # See lnet/lnet/lib-msg.c:lnet_health_check()
1591 LNET_REMOTE_RESEND_STATUSES="remote_dropped"
1592 LNET_REMOTE_NO_RESEND_STATUSES="remote_error remote_timeout"
1593 test_206() {
1594         setup_health_test false || return $?
1595
1596         local hstatus
1597         for hstatus in ${LNET_REMOTE_RESEND_STATUSES} \
1598                        ${LNET_REMOTE_NO_RESEND_STATUSES}; do
1599                 echo "Simulate $hstatus"
1600                 lnet_health_pre || return $?
1601
1602                 add_health_test_drop_rules ${hstatus}
1603                 do_lnetctl discover ${RNIDS[0]} &&
1604                         error "Should have failed"
1605                 $LCTL net_drop_del -a
1606
1607                 lnet_health_post
1608
1609                 check_no_resends || return $?
1610                 check_no_local_health || return $?
1611                 check_no_remote_health || return $?
1612         done
1613
1614         cleanup_health_test || return $?
1615
1616         return 0
1617 }
1618 run_test 206 "Check no health or resends for single-rail remote failures"
1619
1620 test_207() {
1621         setup_health_test true || return $?
1622
1623         local hstatus
1624         for hstatus in ${LNET_REMOTE_RESEND_STATUSES}; do
1625                 echo "Simulate $hstatus"
1626                 lnet_health_pre || return $?
1627
1628                 add_health_test_drop_rules ${hstatus}
1629
1630                 do_lnetctl discover ${RNIDS[0]} &&
1631                         error "Should have failed"
1632
1633                 lnet_health_post
1634
1635                 $LCTL net_drop_del -a
1636
1637                 check_resends || return $?
1638                 check_no_local_health || return $?
1639                 check_remote_health || return $?
1640                 do_lnetctl peer set --health 1000 --all ||
1641                         error "Unable to reset health rc=$?"
1642         done
1643         for hstatus in ${LNET_REMOTE_NO_RESEND_STATUSES}; do
1644                 echo "Simulate $hstatus"
1645                 lnet_health_pre || return $?
1646
1647                 add_health_test_drop_rules ${hstatus}
1648
1649                 do_lnetctl discover ${RNIDS[0]} &&
1650                         error "Should have failed"
1651
1652                 lnet_health_post
1653
1654                 $LCTL net_drop_del -a
1655
1656                 check_no_resends || return $?
1657                 check_no_local_health || return $?
1658                 check_remote_health || return $?
1659                 do_lnetctl peer set --health 1000 --all ||
1660                         error "Unable to reset health rc=$?"
1661         done
1662
1663         cleanup_health_test || return $?
1664
1665         return 0
1666 }
1667 run_test 207 "Check health and resends for multi-rail remote errors"
1668
1669 test_208_load_and_check_lnet() {
1670         local ip2nets="$1"
1671         local p_nid="$2"
1672         local s_nid="$3"
1673         local num_expected=1
1674
1675         load_lnet "networks=\"\" ip2nets=\"${ip2nets_str}\""
1676
1677         $LCTL net up ||
1678                 error "Failed to load LNet with ip2nets \"${ip2nets_str}\""
1679
1680         [[ -n $s_nid ]] &&
1681                 num_expected=2
1682
1683         declare -a nids
1684         nids=( $($LCTL list_nids) )
1685
1686         [[ ${#nids[@]} -ne ${num_expected} ]] &&
1687                 error "Expect ${num_expected} NIDs found ${#nids[@]}"
1688
1689         [[ ${nids[0]} == ${p_nid} ]] ||
1690                 error "Expect NID \"${p_nid}\" found \"${nids[0]}\""
1691
1692         [[ -n $s_nid ]] && [[ ${nids[1]} != ${s_nid} ]] &&
1693                 error "Expect second NID \"${s_nid}\" found \"${nids[1]}\""
1694
1695         $LCTL net down &>/dev/null
1696         cleanup_lnet
1697 }
1698
1699 test_208() {
1700         cleanup_netns || error "Failed to cleanup netns before test execution"
1701         cleanup_lnet || error "Failed to unload modules before test execution"
1702         setup_fakeif || error "Failed to add fake IF"
1703
1704         have_interface "$FAKE_IF" ||
1705                 error "Expect $FAKE_IF configured but not found"
1706
1707         local if0_ip=$(ip --oneline addr show dev ${INTERFACES[0]} |
1708                        awk '/inet /{print $4}' |
1709                        sed 's:/.*::')
1710         if0_ip=($(echo "${if0_ip[@]}" | tr ' ' '\n' | uniq | tr '\n' ' '))
1711         local ip2nets_str="tcp(${INTERFACES[0]}) $if0_ip"
1712
1713         echo "Configure single NID \"$ip2nets_str\""
1714         test_208_load_and_check_lnet "${ip2nets_str}" "${if0_ip}@tcp"
1715
1716         ip2nets_str="tcp(${INTERFACES[0]}) $if0_ip; tcp1($FAKE_IF) $FAKE_IP"
1717         echo "Configure two NIDs; two NETs \"$ip2nets_str\""
1718         test_208_load_and_check_lnet "${ip2nets_str}" "${if0_ip}@tcp" \
1719                                      "${FAKE_IP}@tcp1"
1720
1721         ip2nets_str="tcp(${INTERFACES[0]}) $if0_ip; tcp($FAKE_IF) $FAKE_IP"
1722         echo "Configure two NIDs; one NET \"$ip2nets_str\""
1723         test_208_load_and_check_lnet "${ip2nets_str}" "${if0_ip}@tcp" \
1724                                      "${FAKE_IP}@tcp"
1725         local addr1=( ${if0_ip//./ } )
1726         local addr2=( ${FAKE_IP//./ } )
1727         local range="[${addr1[0]},${addr2[0]}]"
1728
1729         local i
1730         for i in $(seq 1 3); do
1731                 range+=".[${addr1[$i]},${addr2[$i]}]"
1732         done
1733         ip2nets_str="tcp(${INTERFACES[0]},${FAKE_IF}) ${range}"
1734
1735         echo "Configured two NIDs; one NET alt syntax \"$ip2nets_str\""
1736         test_208_load_and_check_lnet "${ip2nets_str}" "${if0_ip}@tcp" \
1737                                      "${FAKE_IP}@tcp"
1738
1739         cleanup_fakeif
1740
1741         echo "alt syntax with missing IF \"$ip2nets_str\""
1742         load_lnet "networks=\"\" ip2nets=\"${ip2nets_str}\""
1743
1744         echo "$LCTL net up should fail"
1745         $LCTL net up &&
1746                 error "LNet bringup should have failed"
1747
1748         cleanup_lnet
1749 }
1750 run_test 208 "Test various kernel ip2nets configurations"
1751
1752 test_209() {
1753         setup_health_test false || return $?
1754
1755         echo "Simulate network_timeout w/SR config"
1756         lnet_health_pre
1757
1758         add_health_test_drop_rules network_timeout
1759
1760         do_lnetctl discover ${RNIDS[0]} &&
1761                 error "Should have failed"
1762         $LCTL net_drop_del -a
1763
1764         lnet_health_post
1765
1766         check_no_resends || return $?
1767         check_no_local_health || return $?
1768         check_no_remote_health || return $?
1769
1770         cleanup_health_test || return $?
1771
1772         setup_health_test true || return $?
1773
1774         echo "Simulate network_timeout w/MR config"
1775
1776         lnet_health_pre
1777
1778         add_health_test_drop_rules network_timeout
1779
1780         do_lnetctl discover ${RNIDS[0]} &&
1781                 error "Should have failed"
1782         $LCTL net_drop_del -a
1783
1784         lnet_health_post
1785
1786         check_no_resends || return $?
1787         check_local_health || return $?
1788         check_remote_health || return $?
1789
1790         cleanup_health_test || return $?
1791
1792         return 0
1793 }
1794 run_test 209 "Check health, but not resends, for network timeout"
1795
1796 check_nid_in_recovq() {
1797         local recovq=$($LNETCTL debug recovery $1)
1798         local expect="$2"
1799         local nids=$($LCTL list_nids | xargs echo)
1800         local found=false
1801         local nid=""
1802
1803         echo "Check \"$1\" recovery queue"
1804         echo "$recovq"
1805         if [[ $(grep -c 'nid-'<<<$recovq) -ne $expect ]]; then
1806                 error "Expect $expect NIDs found: \"$recovq\""
1807         fi
1808
1809         [[ $expect -eq 0 ]] && return 0
1810
1811         for nid in ${nids}; do
1812                 grep -q "nid-0: $nid"<<<$recovq &&
1813                         found=true
1814         done
1815
1816         if ! $found; then
1817                 error "Didn't find local NIDs in recovery queue: \"$recovq\""
1818         fi
1819
1820         return 0
1821 }
1822
1823 # First enqueue happens at time 0.
1824 # 2nd at 0 + 2^0 = 1
1825 # 3rd at 1 + 2^1 = 3
1826 # 4th at 3 + 2^2 = 7
1827 # 5th at 7 + 2^3 = 15
1828 # e.g. after 10 seconds we would expect to have seen the 4th enqueue,
1829 # (3 pings sent, 4th about to happen) and the 5th enqueue is yet to
1830 # happen
1831 # If the recovery limit is 10 seconds, then when the 5th enqueue happens
1832 # we expect the peer NI to have aged out, so it will not actually be
1833 # queued.
1834 # If max_recovery_ping_interval is set to 2 then:
1835 #  First enqueue happens at time 0.
1836 #  2nd at 0 + 2^0 = 1
1837 #  3rd at 1 + 2^1 = 3
1838 #  4th at 3 + 2^1 = 5
1839 #  5th at 5 + 2^1 = 7
1840 #  6th at 7 + 2^1 = 9
1841 #  7th at 9 + 2^1 = 11
1842 # e.g. after 4 seconds we would expect to have seen the 3th enqueue,
1843 # (2 pings sent, 3rd about to happen), and the 4th enqueue is yet to happen
1844 # e.g. after 10 seconds we would expect to have seen the 6th enqueue,
1845 # (5 pings sent, 6th about to happen), and the 8th enqueue is yet to happen
1846 check_ping_count() {
1847         local queue="$1"
1848         local expect="$2"
1849
1850         echo "Check ping counts:"
1851         local ping_count
1852         if [[ $queue == "ni" ]]; then
1853                 $LNETCTL net show -v 2 | egrep 'nid|health value|ping'
1854                 ping_count=( $($LNETCTL net show -v 2 |
1855                                 awk '/ping_count/{print $NF}') )
1856         elif [[ $queue == "peer_ni" ]]; then
1857                 $LNETCTL peer show -v 2 | egrep 'nid|health value|ping'
1858                 ping_count=( $($LNETCTL peer show -v 2 |
1859                                 awk '/ping_count/{print $NF}') )
1860         else
1861                 error "Unrecognized queue \"$queue\""
1862                 return 1
1863         fi
1864
1865         local count
1866         local found=false
1867         for count in "${ping_count[@]}"; do
1868                 if [[ $count -eq $expect ]]; then
1869                         if [[ $expect -ne 0 ]] && $found ; then
1870                                 error "Found more than one interface matching \"$expect\" ping count"
1871                                 return 1
1872                         else
1873                                 echo "Expect ping count \"$expect\" found \"$count\""
1874                                 found=true;
1875                         fi
1876                 elif [[ $count -ne 0 ]]; then
1877                         error "Found interface with ping count \"$count\" but expect \"$expect\""
1878                         return 1
1879                 fi
1880         done
1881
1882         return 0
1883 }
1884
1885 test_210() {
1886         reinit_dlc || return $?
1887         add_net "tcp" "${INTERFACES[0]}" || return $?
1888         add_net "tcp1" "${INTERFACES[0]}" || return $?
1889
1890         local prim_nid=$($LCTL list_nids | head -n 1)
1891
1892         do_lnetctl discover $prim_nid ||
1893                 error "failed to discover myself"
1894
1895         local default=$($LNETCTL global show |
1896                         awk '/recovery_limit/{print $NF}')
1897         # Set recovery limit to 10 seconds.
1898         do_lnetctl set recovery_limit 10 ||
1899                 error "failed to set recovery_limit"
1900
1901         $LCTL set_param debug=+net
1902         # Use local_error so LNet doesn't attempt to resend the discovery ping
1903         $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e local_error
1904         $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e local_error
1905         do_lnetctl discover $prim_nid &&
1906                 error "Expected discovery to fail"
1907
1908         # See comment for check_ping_count()
1909         sleep 5
1910         check_nid_in_recovq "-l" "1"
1911         check_ping_count "ni" "2"
1912
1913         sleep 5
1914
1915         check_nid_in_recovq "-l" "1"
1916         check_ping_count "ni" "3"
1917
1918         $LCTL net_drop_del -a
1919
1920         reinit_dlc || return $?
1921         add_net "tcp" "${INTERFACES[0]}" || return $?
1922         add_net "tcp1" "${INTERFACES[0]}" || return $?
1923
1924         local prim_nid=$($LCTL list_nids | head -n 1)
1925
1926         do_lnetctl discover $prim_nid ||
1927                 error "failed to discover myself"
1928
1929         do_lnetctl set recovery_limit $default ||
1930                 error "failed to set recovery_limit"
1931
1932         default=$($LNETCTL global show |
1933                   awk '/max_recovery_ping_interval/{print $NF}')
1934         do_lnetctl set max_recovery_ping_interval 2 ||
1935                 error "failed to set max_recovery_ping_interval"
1936
1937         $LCTL set_param debug=+net
1938         # Use local_error so LNet doesn't attempt to resend the discovery ping
1939         $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e local_error
1940         $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e local_error
1941         do_lnetctl discover $prim_nid &&
1942                 error "Expected discovery to fail"
1943
1944         # See comment for check_ping_count()
1945         sleep 4
1946         check_nid_in_recovq "-l" "1"
1947         check_ping_count "ni" "2"
1948
1949         sleep 6
1950         check_nid_in_recovq "-l" "1"
1951         check_ping_count "ni" "5"
1952
1953         $LCTL net_drop_del -a
1954
1955         do_lnetctl set max_recovery_ping_interval $default ||
1956                 error "failed to set max_recovery_ping_interval"
1957
1958         return 0
1959 }
1960 run_test 210 "Local NI recovery checks"
1961
1962 test_211() {
1963         reinit_dlc || return $?
1964         add_net "tcp" "${INTERFACES[0]}" || return $?
1965         add_net "tcp1" "${INTERFACES[0]}" || return $?
1966
1967         local prim_nid=$($LCTL list_nids | head -n 1)
1968
1969         do_lnetctl discover $prim_nid ||
1970                 error "failed to discover myself"
1971
1972         local default=$($LNETCTL global show |
1973                         awk '/recovery_limit/{print $NF}')
1974         # Set recovery limit to 10 seconds.
1975         do_lnetctl set recovery_limit 10 ||
1976                 error "failed to set recovery_limit"
1977
1978         $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e remote_error
1979         $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e remote_error
1980
1981         # Set health to 0 on one interface. This forces it onto the recovery
1982         # queue.
1983         $LNETCTL peer set --nid $prim_nid --health 0
1984
1985         # After 5 seconds, we expect the peer NI to still be in recovery
1986         sleep 5
1987         check_nid_in_recovq "-p" 1
1988         check_ping_count "peer_ni" "2"
1989
1990         # After 15 seconds, the peer NI should have been fully processed out of
1991         # the recovery queue. We'll allow a total of 17 seconds to account for
1992         # differences in sleeping for whole seconds vs. the more accurate time
1993         # keeping that is done in the recovery code.
1994         sleep 12
1995         check_nid_in_recovq "-p" 0
1996         check_ping_count "peer_ni" "4"
1997
1998         $LCTL net_drop_del -a
1999
2000         # Set health to force it back onto the recovery queue. Set to 500 means
2001         # in 5 seconds it should be back at maximum value. We'll wait a couple
2002         # more seconds than that to be safe.
2003         # NB: we reset the recovery limit to 0 (indefinite) so the peer NI is
2004         # eligible again
2005         do_lnetctl set recovery_limit 0 ||
2006                 error "failed to set recovery_limit"
2007
2008         $LNETCTL peer set --nid $prim_nid --health 500
2009
2010         check_nid_in_recovq "-p" 1
2011         check_ping_count "peer_ni" "2"
2012
2013         sleep 7
2014
2015         check_nid_in_recovq "-p" 0
2016         check_ping_count "peer_ni" "0"
2017
2018         reinit_dlc || return $?
2019         add_net "tcp" "${INTERFACES[0]}" || return $?
2020         add_net "tcp1" "${INTERFACES[0]}" || return $?
2021
2022         local prim_nid=$($LCTL list_nids | head -n 1)
2023
2024         do_lnetctl discover $prim_nid ||
2025                 error "failed to discover myself"
2026
2027         do_lnetctl set recovery_limit $default ||
2028                 error "failed to set recovery_limit"
2029
2030         default=$($LNETCTL global show |
2031                   awk '/max_recovery_ping_interval/{print $NF}')
2032         do_lnetctl set max_recovery_ping_interval 2 ||
2033                 error "failed to set max_recovery_ping_interval"
2034
2035         $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e remote_error
2036         $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e remote_error
2037
2038         # Set health to 0 on one interface. This forces it onto the recovery
2039         # queue.
2040         $LNETCTL peer set --nid $prim_nid --health 0
2041
2042         # See comment for check_ping_count()
2043         sleep 4
2044         check_nid_in_recovq "-p" "1"
2045         check_ping_count "peer_ni" "2"
2046
2047         sleep 6
2048         check_nid_in_recovq "-p" "1"
2049         check_ping_count "peer_ni" "5"
2050
2051         $LCTL net_drop_del -a
2052
2053         do_lnetctl set max_recovery_ping_interval $default ||
2054                 error "failed to set max_recovery_ping_interval"
2055
2056         return 0
2057 }
2058 run_test 211 "Remote NI recovery checks"
2059
2060 test_212() {
2061         local rnodes=$(remote_nodes_list)
2062         [[ -z $rnodes ]] && skip "Need at least 1 remote node"
2063
2064         cleanup_lnet || error "Failed to cleanup before test execution"
2065
2066         # Loading modules should configure LNet with the appropriate
2067         # test-framework configuration
2068         load_lnet "config_on_load=1" || error "Failed to load modules"
2069
2070         local my_nid=$($LCTL list_nids | head -n 1)
2071         [[ -z $my_nid ]] &&
2072                 error "Failed to get primary NID for local host $HOSTNAME"
2073
2074         local rnode=$(awk '{print $1}' <<<$rnodes)
2075         local rnodenids=$(do_node $rnode $LCTL list_nids | xargs echo)
2076         local rloaded=false
2077
2078         if [[ -z $rnodenids ]]; then
2079                 do_rpc_nodes $rnode load_lnet "config_on_load=1"
2080                 rloaded=true
2081                 rnodenids=$(do_node $rnode $LCTL list_nids | xargs echo)
2082         fi
2083
2084         local rnodepnid=$(awk '{print $1}' <<< $rnodenids)
2085
2086         [[ -z $rnodepnid ]] &&
2087                 error "Failed to get primary NID for remote host $rnode"
2088
2089         log "Initial discovery"
2090         do_lnetctl discover --force $rnodepnid ||
2091                 error "Failed to discover $rnodepnid"
2092
2093         do_node $rnode "$LNETCTL discover --force $my_nid" ||
2094                 error "$rnode failed to discover $my_nid"
2095
2096         log "Fail local discover ping to set LNET_PEER_REDISCOVER flag"
2097         $LCTL net_drop_add -s "*@$NETTYPE" -d "*@$NETTYPE" -r 1 -e local_error
2098         do_lnetctl discover --force $rnodepnid &&
2099                 error "Discovery should have failed"
2100         $LCTL net_drop_del -a
2101
2102         local nid
2103         for nid in $rnodenids; do
2104                 # We need GET (PING) delay just long enough so we can trigger
2105                 # discovery on the remote peer
2106                 $LCTL net_delay_add -s "*@$NETTYPE" -d $nid -r 1 -m GET -l 3
2107                 $LCTL net_drop_add -s "*@$NETTYPE" -d $nid -r 1 -m GET -e local_error
2108                 # We need PUT (PUSH) delay just long enough so we can process
2109                 # the PING failure
2110                 $LCTL net_delay_add -s "*@$NETTYPE" -d $nid -r 1 -m PUT -l 6
2111         done
2112
2113         log "Force $HOSTNAME to discover $rnodepnid (in background)"
2114         # We want to get a PING sent that we know will eventually fail.
2115         # The delay rules we added will ensure the ping is not sent until
2116         # the PUSH is also in flight (see below), and the drop rule ensures that
2117         # when the PING is eventually sent it will error out
2118         do_lnetctl discover --force $rnodepnid &
2119         local pid1=$!
2120
2121         # We want a discovery PUSH from rnode to put rnode back on our
2122         # discovery queue. This should cause us to try and send a PUSH to rnode
2123         # while the PING is still outstanding.
2124         log "Force $rnode to discover $my_nid"
2125         do_node $rnode $LNETCTL discover --force $my_nid
2126
2127         # At this point we'll have both PING_SENT and PUSH_SENT set for the
2128         # rnode peer. Wait for the PING to error out which should terminate the
2129         # discovery process that we backgrounded.
2130         log "Wait for $pid1"
2131         wait $pid1
2132         log "Finished wait on $pid1"
2133
2134         # The PING send failure clears the PING_SENT flag and puts the peer back
2135         # on the discovery queue. When discovery thread processes the peer it
2136         # will mistakenly clear the PUSH_SENT flag (and set PUSH_FAILED).
2137         # Discovery will then complete for this peer even though we have an
2138         # outstanding PUSH.
2139         # When PUSH is actually unlinked it will be forced back onto the
2140         # discovery queue, but we no longer have a ref on the peer. When
2141         # discovery completes again, we'll trip the ASSERT in
2142         # lnet_destroy_peer_locked()
2143
2144         # Delete the delay rules to send the PUSH
2145         $LCTL net_delay_del -a
2146         # Delete the drop rules
2147         $LCTL net_drop_del -a
2148
2149         unload_modules ||
2150                 error "Failed to unload modules"
2151         if $rloaded; then
2152                 do_rpc_nodes $rnode unload_modules_local ||
2153                         error "Failed to unload modules on $rnode"
2154         fi
2155
2156         return 0
2157 }
2158 run_test 212 "Check discovery refcount loss bug (LU-14627)"
2159
2160 test_213() {
2161         cleanup_netns || error "Failed to cleanup netns before test execution"
2162         cleanup_lnet || error "Failed to unload modules before test execution"
2163
2164         setup_fakeif || error "Failed to add fake IF"
2165         have_interface "$FAKE_IF" ||
2166                 error "Expect $FAKE_IF configured but not found"
2167
2168         reinit_dlc || return $?
2169
2170         add_net "tcp" "${INTERFACES[0]}" || return $?
2171         add_net "tcp" "$FAKE_IF" || return $?
2172
2173         local nid1=$(lctl list_nids | head -n 1)
2174         local nid2=$(lctl list_nids | tail --lines 1)
2175
2176         [[ $(lctl which_nid $nid1 $nid2) == $nid1 ]] ||
2177                 error "Expect nid1 \"$nid1\" to be preferred"
2178
2179         [[ $(lctl which_nid $nid2 $nid1) == $nid2 ]] ||
2180                 error "Expect nid2 \"$nid2\" to be preferred"
2181
2182         return 0
2183 }
2184 run_test 213 "Check LNetDist calculation for multiple local NIDs"
2185
2186 function check_ni_status() {
2187         local nid="$1"
2188         local expect="$2"
2189
2190         local status=$($LNETCTL net show |
2191                        grep -A 1 ${nid} |
2192                        awk '/status/{print $NF}')
2193
2194         echo "NI ${nid} expect status \"${expect}\" found \"${status}\""
2195         if [[ $status != $expect ]]; then
2196                 error "Error: Expect NI status \"$expect\" for NID \"$nid\" but found \"$status\""
2197         fi
2198
2199         return 0
2200 }
2201
2202 test_214() {
2203         cleanup_netns || error "Failed to cleanup netns before test execution"
2204         cleanup_lnet || error "Failed to unload modules before test execution"
2205
2206         setup_fakeif || error "Failed to add fake IF"
2207         have_interface "$FAKE_IF" ||
2208                 error "Expect $FAKE_IF configured but not found"
2209
2210         reinit_dlc || return $?
2211
2212         add_net "tcp" "${INTERFACES[0]}" || return $?
2213         add_net "tcp" "$FAKE_IF" || return $?
2214
2215         local nid1=$(lctl list_nids | head -n 1)
2216         local nid2=$(lctl list_nids | tail --lines 1)
2217
2218         check_ni_status "0@lo" up
2219         check_ni_status "$nid1" up
2220         check_ni_status "$nid2" up
2221
2222         echo "Set $FAKE_IF down"
2223         echo "ip link set dev $FAKE_IF down"
2224         ip link set dev $FAKE_IF down
2225         check_ni_status "0@lo" up
2226         check_ni_status "$nid1" up
2227         check_ni_status "$nid2" down
2228 }
2229 run_test 214 "Check local NI status when link is downed"
2230
2231 get_ni_stat() {
2232         local nid=$1
2233         local stat=$2
2234
2235         $LNETCTL net show -v 2 |
2236                 egrep -e nid -e $stat |
2237                 grep -wA 1 $nid |
2238                 awk '/'$stat':/{print $NF}'
2239 }
2240
2241 ni_stats_pre() {
2242         local nidvar s
2243         for nidvar in nid1 nid2; do
2244                 for stat in send_count recv_count; do
2245                         s=$(get_ni_stat ${!nidvar} $stat)
2246                         eval ${nidvar}_pre_${stat}=$s
2247                 done
2248         done
2249 }
2250
2251 ni_stats_post() {
2252         local nidvar s
2253         for nidvar in nid1 nid2; do
2254                 for stat in send_count recv_count; do
2255                         s=$(get_ni_stat ${!nidvar} $stat)
2256                         eval ${nidvar}_post_${stat}=$s
2257                 done
2258         done
2259 }
2260
2261 ni_stat_changed() {
2262         local nidvar=$1
2263         local stat=$2
2264
2265         local pre post
2266         eval pre=\${${nidvar}_pre_${stat}}
2267         eval post=\${${nidvar}_post_${stat}}
2268
2269         echo "${!nidvar} pre ${stat} $pre post ${stat} $post"
2270
2271         [[ $pre -ne $post ]]
2272 }
2273
2274 test_215() {
2275         cleanup_netns || error "Failed to cleanup netns before test execution"
2276         cleanup_lnet || error "Failed to unload modules before test execution"
2277
2278         reinit_dlc || return $?
2279
2280         add_net "tcp1" "${INTERFACES[0]}" || return $?
2281         add_net "tcp2" "${INTERFACES[0]}" || return $?
2282
2283         local nid1=$($LCTL list_nids | head -n 1)
2284         local nid2=$($LCTL list_nids | tail --lines 1)
2285
2286         do_lnetctl peer add --prim $nid1 --nid $nid2 ||
2287                 error "Failed to add peer"
2288
2289         local npings=25
2290
2291         for nidvarA in nid1 nid2; do
2292                 src=${!nidvarA}
2293                 dst=${!nidvarA}
2294                 for nidvarB in nid1 nid2; do
2295                         [[ $nidvarA == $nidvarB ]] && continue
2296
2297                         ni_stats_pre
2298
2299                         echo "$LNETCTL ping $dst x $npings"
2300                         for i in $(seq 1 $npings); do
2301                                 $LNETCTL ping $dst &>/dev/null ||
2302                                         error "$LNETCTL ping $dst failed"
2303                         done
2304
2305                         ni_stats_post
2306
2307                         # No source specified, sends to either NID should cause
2308                         # counts to increase across both NIs
2309                         for nidvar in nid1 nid2; do
2310                                 for stat in send_count recv_count; do
2311                                         ni_stat_changed $nidvar $stat ||
2312                                                 error "$stat unchanged for ${!nidvar}"
2313                                 done
2314                         done
2315
2316                         ni_stats_pre
2317
2318                         echo "$LNETCTL ping --source $src $dst x $npings"
2319                         for i in $(seq 1 $npings); do
2320                                 $LNETCTL ping --source $src $dst &>/dev/null ||
2321                                         error "$LNETCTL ping --source $src $dst failed"
2322                         done
2323
2324                         ni_stats_post
2325
2326                         # src nid == dest nid means stats for the _other_ NI
2327                         # should be unchanged
2328                         for nidvar in nid1 nid2; do
2329                                 for stat in send_count recv_count; do
2330                                         if [[ ${!nidvar} == $src ]]; then
2331                                                 ni_stat_changed $nidvar $stat ||
2332                                                         error "$stat unchanged for ${!nidvar}"
2333                                         else
2334                                                 ni_stat_changed $nidvar $stat &&
2335                                                         error "$stat changed for ${!nidvar}"
2336                                         fi
2337                                 done
2338                         done
2339                 done
2340                 # Double number of pings for next iteration because the net
2341                 # sequence numbers will have diverged
2342                 npings=$(($npings * 2))
2343         done
2344
2345         # Ping from nid1 to nid2 should fail
2346         do_lnetctl ping --source $nid1 $nid2 &&
2347                 error "ping from $nid1 to $nid2 should fail"
2348
2349         # Ping from nid2 to nid1 should fail
2350         do_lnetctl ping --source $nid2 $nid1 &&
2351                 error "ping from $nid2 to $nid1 should fail"
2352
2353         return 0
2354 }
2355 run_test 215 "Test lnetctl ping --source option"
2356
2357 test_216() {
2358         local rc=0
2359
2360         reinit_dlc || return $?
2361
2362         add_net "tcp" "${INTERFACES[0]}" || return $?
2363         add_net "tcp1" "${INTERFACES[0]}" || return $?
2364
2365         local nids=( $($LCTL list_nids | xargs echo) )
2366
2367         do_lnetctl discover ${nids[0]} ||
2368                 error "Initial discovery failed"
2369
2370         do_lnetctl ping --source ${nids[0]} ${nids[0]} ||
2371                 error "Initial ping failed $?"
2372
2373         do_lnetctl ping --source ${nids[1]} ${nids[1]} ||
2374                 error "Initial ping failed $?"
2375
2376         local src dst
2377         for src in "${nids[@]}"; do
2378                 for dst in "${nids[@]}"; do
2379                         $LCTL net_drop_add -r 1 -s $src -d $dst -e network_timeout
2380                 done
2381         done
2382
2383         do_lnetctl ping ${nids[0]} || rc=$?
2384
2385         $LCTL net_drop_del -a
2386
2387         [[ $rc -eq 0 ]] &&
2388                 error "expected ping to fail"
2389
2390         check_nid_in_recovq "-p" 0
2391         check_nid_in_recovq "-l" 1
2392
2393         return 0
2394 }
2395 run_test 216 "Failed send to peer NI owned by local host should not trigger peer NI recovery"
2396
2397 test_217() {
2398         reinit_dlc || return $?
2399
2400         [[ $($LNETCTL net show | grep -c nid) -ne 1 ]] &&
2401                 error "Unexpected number of NIs after initalizing DLC"
2402
2403         do_lnetctl discover 0@lo ||
2404                 error "Failed to discover 0@lo"
2405
2406         unload_modules
2407 }
2408 run_test 217 "Don't leak memory when discovering peer with nnis <= 1"
2409
2410 test_218() {
2411         reinit_dlc || return $?
2412
2413         [[ ${#INTERFACES[@]} -lt 2 ]] &&
2414                 skip "Need two LNet interfaces"
2415
2416         add_net "tcp" "${INTERFACES[0]}" || return $?
2417
2418         local nid1=$($LCTL list_nids | head -n 1)
2419
2420         do_lnetctl ping $nid1 ||
2421                 error "ping failed"
2422
2423         add_net "tcp" "${INTERFACES[1]}" || return $?
2424
2425         local nid2=$($LCTL list_nids | tail --lines 1)
2426
2427         do_lnetctl ping $nid2 ||
2428                 error "ping failed"
2429
2430         $LCTL net_drop_add -s $nid1 -d $nid1 -e local_error -r 1
2431
2432         do_lnetctl ping $nid1 &&
2433                 error "ping should have failed"
2434
2435         local health_recovered
2436         local i
2437
2438         for i in $(seq 1 5); do
2439                 health_recovered=$($LNETCTL net show -v 2 |
2440                                    grep -c 'health value: 1000')
2441
2442                 if [[ $health_recovered -ne 2 ]]; then
2443                         echo "Wait 1 second for health to recover"
2444                         sleep 1
2445                 else
2446                         break
2447                 fi
2448         done
2449
2450         health_recovered=$($LNETCTL net show -v 2 |
2451                            grep -c 'health value: 1000')
2452
2453         $LCTL net_drop_del -a
2454
2455         [[ $health_recovered -ne 2 ]] &&
2456                 do_lnetctl net show -v 2 | egrep -e nid -e health &&
2457                 error "Health hasn't recovered"
2458
2459         return 0
2460 }
2461 run_test 218 "Local recovery pings should exercise all available paths"
2462
2463 test_219() {
2464         reinit_dlc || return $?
2465         add_net "tcp" "${INTERFACES[0]}" || return $?
2466         add_net "tcp1" "${INTERFACES[0]}" || return $?
2467
2468         local nid1=$(lctl list_nids | head -n 1)
2469         local nid2=$(lctl list_nids | tail --lines 1)
2470
2471         do_lnetctl ping $nid1 ||
2472                 error "Ping failed $?"
2473         do_lnetctl ping $nid2 ||
2474                 error "Ping failed $?"
2475
2476         do_lnetctl discover $nid2 ||
2477                 error "Discovery failed"
2478
2479         $LNETCTL peer show --nid $nid1 | grep -q $nid2 ||
2480                 error "$nid2 is not listed under $nid1"
2481 }
2482 run_test 219 "Consolidate peer entries"
2483
2484 test_230() {
2485         # LU-12815
2486         echo "Check valid values; Should succeed"
2487         local i
2488         local lnid
2489         local cmd
2490         for ((i = 4; i < 16; i+=1)); do
2491                 reinit_dlc || return $?
2492                 add_net "tcp" "${INTERFACES[0]}" || return $?
2493                 do_lnetctl net set --all --conns-per-peer $i ||
2494                         error "should have succeeded $?"
2495                 $LNETCTL net show -v 1 | grep -q "conns_per_peer: $i" ||
2496                         error "failed to set conns-per-peer to $i"
2497                 lnid="$(lctl list_nids | head -n 1)"
2498                 do_lnetctl ping "$lnid" ||
2499                         error "failed to ping myself"
2500
2501                 # "lctl --net tcp conn_list" prints the list of active
2502                 # connections. Since we're pinging ourselves, there should be
2503                 # 2 Control connections plus 2*conns_per_peer connections
2504                 # created (one Bulk Input, one Bulk Output in each pair).
2505                 # Here's the sample output for conns_per_peer set to 1:
2506                 # 12345-1.1.1.1@tcp I[0]host01->host01:988 2626560/1061296 nonagle
2507                 # 12345-1.1.1.1@tcp O[0]host01->host01:1022 2626560/1061488 nonagle
2508                 # 12345-1.1.1.1@tcp C[0]host01->host01:988 2626560/1061296 nonagle
2509                 # 12345-1.1.1.1@tcp C[0]host01->host01:1023 2626560/1061488 nonagle
2510                 cmd="printf 'network tcp\nconn_list\n' | lctl | grep -c '$lnid'"
2511
2512                 # Expect 2+conns_per_peer*2 connections. Wait no longer
2513                 # than 2 seconds.
2514                 wait_update $HOSTNAME "$cmd" "$((2+i*2))" 2 ||
2515                         error "expected number of tcp connections $((2+i*2))"
2516         done
2517
2518         reinit_dlc || return $?
2519         add_net "tcp" "${INTERFACES[0]}" || return $?
2520         echo "Set > 127; Should fail"
2521         do_lnetctl net set --all --conns-per-peer 128 &&
2522                 error "should have failed $?"
2523
2524         reinit_dlc || return $?
2525         add_net "tcp" "${INTERFACES[0]}" || return $?
2526         echo "Set < 0; Should be ignored"
2527         do_lnetctl net set --all --conns-per-peer -1 ||
2528                 error "should have succeeded $?"
2529         $LNETCTL net show -v 1 | grep -q "conns_per_peer: 1" ||
2530                 error "Did not stay at default"
2531 }
2532 run_test 230 "Test setting conns-per-peer"
2533
2534 ### Test that linux route is added for each ni
2535 test_250() {
2536         reinit_dlc || return $?
2537         add_net "tcp" "${INTERFACES[0]}" || return $?
2538         ip route show table ${INTERFACES[0]} | grep -q "${INTERFACES[0]}"
2539 }
2540 run_test 250 "test that linux routes are added"
2541
2542 test_300() {
2543         # LU-13274
2544         local header
2545         local out=$TMP/$tfile
2546         local prefix=/usr/include/linux/lnet
2547
2548         # We use a hard coded prefix so that this test will not fail
2549         # when run in tree.
2550         CC=${CC:-cc}
2551         if ! which $CC > /dev/null 2>&1; then
2552                 skip_env "$CC is not installed"
2553         fi
2554
2555         cleanup_lnet || exit 1
2556         load_lnet
2557
2558         local cc_args="-Wall -Werror -std=c99 -c -x c /dev/null -o $out"
2559         if ! [[ -d $prefix ]]; then
2560                 # Assume we're running in tree and fixup the include path.
2561                 prefix=$LUSTRE/../lnet/include/uapi/linux/lnet
2562                 cc_args+=" -I $LUSTRE/../lnet/include/uapi"
2563         fi
2564
2565         for header in $prefix/*.h; do
2566                 if ! [[ -f "$header" ]]; then
2567                         continue
2568                 fi
2569
2570                 echo "$CC $cc_args -include $header"
2571                 $CC $cc_args -include $header ||
2572                         error "cannot compile '$header'"
2573         done
2574         rm -f $out
2575 }
2576 run_test 300 "packaged LNet UAPI headers can be compiled"
2577
2578 complete $SECONDS
2579
2580 cleanup_testsuite
2581 exit_status