Whamcloud - gitweb
d71635355a70982699f9fb971164728255c7f236
[fs/lustre-release.git] / lustre / tests / sanity-lnet.sh
1 #!/bin/bash
2 #
3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
5 #
6
7 set -e
8
9 ONLY=${ONLY:-"$*"}
10
11 # bug number for skipped test:
12 ALWAYS_EXCEPT="$SANITY_LNET_EXCEPT "
13 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
14
15 # skip test ARM testing until they are fixed
16 if [[ $(uname -m) = aarch64 ]]; then
17         # bug number for skipped test: LU-13704 LU-13701 LU-13701 LU-13701
18         ALWAYS_EXCEPT+="               204      205      206      207 "
19 fi
20
21 [ "$SLOW" = "no" ] && EXCEPT_SLOW=""
22
23 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
24
25 . $LUSTRE/tests/test-framework.sh
26 CLEANUP=${CLEANUP:-:}
27 SETUP=${SETUP:-:}
28 init_test_env $@
29 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
30 init_logging
31
32 build_test_filter
33
34 export LNETCTL=${LNETCTL:-"$LUSTRE/../lnet/utils/lnetctl"}
35 [ ! -f "$LNETCTL" ] &&
36         export LNETCTL=$(which lnetctl 2> /dev/null)
37 [[ -z $LNETCTL ]] && skip "Need lnetctl"
38
39 restore_mounts=false
40
41 if is_mounted $MOUNT || is_mounted $MOUNT2; then
42         cleanupall || error "Failed cleanup prior to test execution"
43         restore_mounts=true
44 fi
45
46 cleanup_lnet() {
47         echo "Cleaning up LNet"
48         $LNETCTL lnet unconfigure 2>/dev/null
49         unload_modules
50 }
51
52 restore_modules=false
53 if module_loaded lnet ; then
54         cleanup_lnet || error "Failed to unload modules before test execution"
55         restore_modules=true
56 fi
57
58 cleanup_testsuite() {
59         trap "" EXIT
60         rm -f $TMP/sanity-dlc*
61         cleanup_netns
62         cleanup_lnet
63         if $restore_mounts; then
64                 setupall || error "Failed to setup Lustre after test execution"
65         elif $restore_modules; then
66                 load_modules ||
67                         error "Couldn't load modules after test execution"
68         fi
69         return 0
70 }
71
72 load_lnet() {
73         load_module ../libcfs/libcfs/libcfs
74         # Prevent local MODOPTS_LIBCFS being passed as part of environment
75         # variable to remote nodes
76         unset MODOPTS_LIBCFS
77
78         set_default_debug "neterror net nettrace malloc"
79         load_module ../lnet/lnet/lnet "$@"
80
81         LNDPATH=${LNDPATH:-"../lnet/klnds"}
82         if [ -z "$LNETLND" ]; then
83                 case $NETTYPE in
84                 o2ib*)  LNETLND="o2iblnd/ko2iblnd" ;;
85                 tcp*)   LNETLND="socklnd/ksocklnd" ;;
86                 *)      local lnd="${NETTYPE%%[0-9]}lnd"
87                         [ -f "$LNDPATH/$lnd/k$lnd.ko" ] &&
88                                 LNETLND="$lnd/k$lnd" ||
89                                 LNETLND="socklnd/ksocklnd"
90                 esac
91         fi
92         load_module ../lnet/klnds/$LNETLND
93 }
94
95 do_lnetctl() {
96         echo "$LNETCTL $@"
97         $LNETCTL "$@"
98 }
99
100 TESTNS='test_ns'
101 FAKE_IF="test1pg"
102 FAKE_IP="10.1.2.3"
103 do_ns() {
104         echo "ip netns exec $TESTNS $@"
105         ip netns exec $TESTNS "$@"
106 }
107
108 setup_netns() {
109         cleanup_netns
110
111         ip netns add $TESTNS
112         ip link add 'test1pl' type veth peer name $FAKE_IF netns $TESTNS
113         ip link set 'test1pl' up
114         do_ns ip addr add "${FAKE_IP}/31" dev $FAKE_IF
115         do_ns ip link set $FAKE_IF up
116 }
117
118 cleanup_netns() {
119         (ip netns list | grep -q $TESTNS) && ip netns del $TESTNS
120         ip link show test1pl >& /dev/null && ip link del test1pl || return 0
121 }
122
123 configure_dlc() {
124         echo "Loading LNet and configuring DLC"
125         load_lnet
126         do_lnetctl lnet configure
127 }
128
129 GLOBAL_YAML_FILE=$TMP/sanity-lnet-global.yaml
130 define_global_yaml() {
131         $LNETCTL export --backup >${GLOBAL_YAML_FILE} ||
132                 error "Failed to export global yaml $?"
133 }
134
135 reinit_dlc() {
136         if lsmod | grep -q lnet; then
137                 do_lnetctl lnet unconfigure ||
138                         error "lnetctl lnet unconfigure failed $?"
139                 do_lnetctl lnet configure ||
140                         error "lnetctl lnet configure failed $?"
141         else
142                 configure_dlc || error "configure_dlc failed $?"
143         fi
144         define_global_yaml
145 }
146
147 append_global_yaml() {
148         [[ ! -e ${GLOBAL_YAML_FILE} ]] &&
149                 error "Missing global yaml at ${GLOBAL_YAML_FILE}"
150
151         cat ${GLOBAL_YAML_FILE} >> $TMP/sanity-lnet-$testnum-expected.yaml
152 }
153
154 create_base_yaml_file() {
155         append_global_yaml
156 }
157
158 compare_yaml_files() {
159         local expected="$TMP/sanity-lnet-$testnum-expected.yaml"
160         local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
161         local rc=0
162         ! [[ -e $expected ]] && echo "$expected not found" && return 1
163         ! [[ -e $actual ]] && echo "$actual not found" && return 1
164         diff -upN ${actual} ${expected} || rc=$?
165         echo "Expected:"
166         cat $expected
167         echo "Actual:"
168         cat $actual
169         return $rc
170 }
171
172 validate_nid() {
173         local nid="$1"
174         local net="${nid//*@/}"
175         local addr="${nid//@*/}"
176
177         local num_re='[0-9]\+'
178         local ip_re="[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
179
180         if [[ $net =~ gni[0-9]* ]]; then
181                 [[ $addr =~ ${num_re} ]] && return 0
182         else
183                 [[ $addr =~ ${ip_re} ]] && return 0
184         fi
185 }
186
187 validate_nids() {
188         local yfile=$TMP/sanity-lnet-$testnum-actual.yaml
189         local primary_nids=$(awk '/- primary nid:/{print $NF}' $yfile | xargs echo)
190         local secondary_nids=$(awk '/- nid:/{print $NF}' $yfile | xargs echo)
191         local gateway_nids=$(awk '/gateway:/{print $NF}' $yfile | xargs echo)
192
193         local nid
194         for nid in $primary_nids $secondary_nids; do
195                 validate_nid "$nid" || error "Bad NID \"${nid}\""
196         done
197         return 0
198 }
199
200 validate_peer_nids() {
201         local num_peers="$1"
202         local nids_per_peer="$2"
203
204         local expect_p="$num_peers"
205         # The primary nid also shows up in the list of secondary nids
206         local expect_s="$(($num_peers + $(($nids_per_peer*$num_peers))))"
207
208         local actual_p=$(grep -c -- '- primary nid:' $TMP/sanity-lnet-$testnum-actual.yaml)
209         local actual_s=$(grep -c -- '- nid:' $TMP/sanity-lnet-$testnum-actual.yaml)
210         if [[ $expect_p -ne $actual_p ]]; then
211                 compare_yaml_files
212                 error "Expected $expect_p but found $actual_p primary nids"
213         elif [[ $expect_s -ne $actual_s ]]; then
214                 compare_yaml_files
215                 error "Expected $expect_s but found $actual_s secondary nids"
216         fi
217         validate_nids
218 }
219
220 validate_gateway_nids() {
221         local expect_gw=$(grep -c -- 'gateway:' $TMP/sanity-lnet-$testnum-expected.yaml)
222         local actual_gw=$(grep -c -- 'gateway:' $TMP/sanity-lnet-$testnum-actual.yaml)
223         if [[ $expect_gw -ne $actual_gw ]]; then
224                 compare_yaml_files
225                 error "Expected $expect_gw gateways but found $actual_gw gateways"
226         fi
227         validate_nids
228 }
229
230 cleanupall -f
231 setup_netns || error "setup_netns failed with $?"
232
233 stack_trap 'cleanup_testsuite' EXIT
234
235 test_0() {
236         load_module ../lnet/lnet/lnet || error "Failed to load module rc = $?"
237         do_lnetctl lnet configure || error "lnet configure failed rc = $?"
238         define_global_yaml
239         reinit_dlc || return $?
240         do_lnetctl import <  ${GLOBAL_YAML_FILE} || error "Import failed $?"
241         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
242         create_base_yaml_file
243         compare_yaml_files || error "Configuration changed after import"
244 }
245 run_test 0 "Export empty config, import the config, compare"
246
247 compare_peer_add() {
248         local prim_nid="${1:+--prim_nid $1}"
249         local nid="${2:+--nid $2}"
250
251         local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
252
253         do_lnetctl peer add ${prim_nid} ${nid} || error "peer add failed $?"
254         $LNETCTL export --backup > $actual || error "export failed $?"
255         compare_yaml_files
256         return $?
257 }
258
259 test_1() {
260         reinit_dlc || return $?
261         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
262 peer:
263     - primary nid: 1.1.1.1@tcp
264       Multi-Rail: True
265       peer ni:
266         - nid: 1.1.1.1@tcp
267 EOF
268         append_global_yaml
269         compare_peer_add "1.1.1.1@tcp"
270 }
271 run_test 1 "Add peer with single nid (tcp)"
272
273 test_2() {
274         reinit_dlc || return $?
275         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
276 peer:
277     - primary nid: 2.2.2.2@o2ib
278       Multi-Rail: True
279       peer ni:
280         - nid: 2.2.2.2@o2ib
281 EOF
282         append_global_yaml
283         compare_peer_add "2.2.2.2@o2ib"
284 }
285 run_test 2 "Add peer with single nid (o2ib)"
286
287 test_3() {
288         reinit_dlc || return $?
289         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
290 peer:
291     - primary nid: 3.3.3.3@tcp
292       Multi-Rail: True
293       peer ni:
294         - nid: 3.3.3.3@tcp
295         - nid: 3.3.3.3@o2ib
296 EOF
297         append_global_yaml
298         compare_peer_add "3.3.3.3@tcp" "3.3.3.3@o2ib"
299 }
300 run_test 3 "Add peer with tcp primary o2ib secondary"
301
302 test_4() {
303         reinit_dlc || return $?
304         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
305 peer:
306     - primary nid: 4.4.4.4@tcp
307       Multi-Rail: True
308       peer ni:
309         - nid: 4.4.4.4@tcp
310         - nid: 4.4.4.1@tcp
311         - nid: 4.4.4.2@tcp
312         - nid: 4.4.4.3@tcp
313 EOF
314         append_global_yaml
315         echo "Add peer with nidrange (tcp)"
316         compare_peer_add "4.4.4.4@tcp" "4.4.4.[1-3]@tcp"
317
318         echo "Add peer with nidrange that overlaps primary nid (tcp)"
319         compare_peer_add "4.4.4.4@tcp" "4.4.4.[1-4]@tcp"
320 }
321 run_test 4 "Add peer with nidrange (tcp)"
322
323 test_5() {
324         reinit_dlc || return $?
325         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
326 peer:
327     - primary nid: 5.5.5.5@o2ib
328       Multi-Rail: True
329       peer ni:
330         - nid: 5.5.5.5@o2ib
331         - nid: 5.5.5.1@o2ib
332         - nid: 5.5.5.2@o2ib
333         - nid: 5.5.5.3@o2ib
334         - nid: 5.5.5.4@o2ib
335 EOF
336         append_global_yaml
337         echo "Add peer with nidrange (o2ib)"
338         compare_peer_add "5.5.5.5@o2ib" "5.5.5.[1-4]@o2ib"
339
340         echo "Add peer with nidranage that overlaps primary nid (o2ib)"
341         compare_peer_add "5.5.5.5@o2ib" "5.5.5.[1-4]@o2ib"
342 }
343 run_test 5 "Add peer with nidrange (o2ib)"
344
345 test_6() {
346         reinit_dlc || return $?
347         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
348 peer:
349     - primary nid: 6.6.6.6@tcp
350       Multi-Rail: True
351       peer ni:
352         - nid: 6.6.6.6@tcp
353         - nid: 6.6.6.0@tcp
354         - nid: 6.6.6.2@tcp
355         - nid: 6.6.6.4@tcp
356         - nid: 6.6.7.0@tcp
357         - nid: 6.6.7.2@tcp
358         - nid: 6.6.7.4@tcp
359         - nid: 6.6.1.0@o2ib
360         - nid: 6.6.1.3@o2ib
361         - nid: 6.6.1.6@o2ib
362         - nid: 6.6.3.0@o2ib
363         - nid: 6.6.3.3@o2ib
364         - nid: 6.6.3.6@o2ib
365         - nid: 6@gni
366         - nid: 10@gni
367 EOF
368         append_global_yaml
369         compare_peer_add "6.6.6.6@tcp" \
370                 "6.6.[6-7].[0-4/2]@tcp,6.6.[1-4/2].[0-6/3]@o2ib,[6-12/4]@gni"
371 }
372 run_test 6 "Add peer with multiple nidranges"
373
374 compare_peer_del() {
375         local prim_nid="${1:+--prim_nid $1}"
376         local nid="${2:+--nid $2}"
377
378         local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
379
380         do_lnetctl peer del ${prim_nid} ${nid} || error "peer del failed $?"
381         $LNETCTL export --backup > $actual || error "export failed $?"
382         compare_yaml_files
383         return $?
384 }
385
386 test_7() {
387         reinit_dlc || return $?
388         create_base_yaml_file
389
390         echo "Delete peer with single nid (tcp)"
391         do_lnetctl peer add --prim_nid 7.7.7.7@tcp || error "Peer add failed $?"
392         compare_peer_del "7.7.7.7@tcp"
393
394         echo "Delete peer with single nid (o2ib)"
395         do_lnetctl peer add --prim_nid 7.7.7.7@o2ib || error "Peer add failed $?"
396         compare_peer_del "7.7.7.7@o2ib"
397
398         echo "Delete peer that has multiple nids (tcp)"
399         do_lnetctl peer add --prim_nid 7.7.7.7@tcp --nid 7.7.7.[8-12]@tcp ||
400                 error "Peer add failed $?"
401         compare_peer_del "7.7.7.7@tcp"
402
403         echo "Delete peer that has multiple nids (o2ib)"
404         do_lnetctl peer add --prim_nid 7.7.7.7@o2ib --nid 7.7.7.[8-12]@o2ib ||
405                 error "Peer add failed $?"
406         compare_peer_del "7.7.7.7@o2ib"
407
408         echo "Delete peer that has both tcp and o2ib nids"
409         do_lnetctl peer add --prim_nid 7.7.7.7@tcp \
410                 --nid 7.7.7.[9-12]@tcp,7.7.7.[13-15]@o2ib ||
411                 error "Peer add failed $?"
412         compare_peer_del "7.7.7.7@tcp"
413
414         echo "Delete peer with single nid (gni)"
415         do_lnetctl peer add --prim_nid 7@gni || error "Peer add failed $?"
416         compare_peer_del "7@gni"
417
418         echo "Delete peer that has multiple nids (gni)"
419         do_lnetctl peer add --prim_nid 7@gni --nid [8-12]@gni ||
420                 error "Peer add failed $?"
421         compare_peer_del "7@gni"
422
423         echo "Delete peer that has tcp, o2ib and gni nids"
424         do_lnetctl peer add --prim_nid 7@gni \
425                 --nid [8-12]@gni,7.7.7.[9-12]@tcp,7.7.7.[13-15]@o2ib ||
426                 error "Peer add failed $?"
427         compare_peer_del "7@gni"
428 }
429 run_test 7 "Various peer delete tests"
430
431 test_8() {
432         reinit_dlc || return $?
433
434         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
435 peer:
436     - primary nid: 8.8.8.8@tcp
437       Multi-Rail: True
438       peer ni:
439         - nid: 8.8.8.8@tcp
440         - nid: 8.8.8.10@tcp
441         - nid: 8.8.8.11@tcp
442         - nid: 8.8.8.12@tcp
443         - nid: 8.8.8.14@tcp
444         - nid: 8.8.8.15@tcp
445 EOF
446         append_global_yaml
447
448         do_lnetctl peer add --prim_nid 8.8.8.8@tcp --nid 8.8.8.[10-15]@tcp ||
449                 error "Peer add failed $?"
450         compare_peer_del "8.8.8.8@tcp" "8.8.8.13@tcp"
451 }
452 run_test 8 "Delete single secondary nid from peer (tcp)"
453
454 test_9() {
455         reinit_dlc || return $?
456
457         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
458 peer:
459     - primary nid: 9.9.9.9@tcp
460       Multi-Rail: True
461       peer ni:
462         - nid: 9.9.9.9@tcp
463 EOF
464         append_global_yaml
465
466         do_lnetctl peer add --prim_nid 9.9.9.9@tcp \
467                 --nid 9.9.9.[11-16]@tcp || error "Peer add failed $?"
468         compare_peer_del "9.9.9.9@tcp" "9.9.9.[11-16]@tcp"
469 }
470 run_test 9 "Delete all secondary nids from peer (tcp)"
471
472 test_10() {
473         reinit_dlc || return $?
474
475         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
476 peer:
477     - primary nid: 10.10.10.10@tcp
478       Multi-Rail: True
479       peer ni:
480         - nid: 10.10.10.10@tcp
481         - nid: 10.10.10.12@tcp
482         - nid: 10.10.10.13@tcp
483         - nid: 10.10.10.15@tcp
484         - nid: 10.10.10.16@tcp
485 EOF
486         append_global_yaml
487         do_lnetctl peer add --prim_nid 10.10.10.10@tcp \
488                 --nid 10.10.10.[12-16]@tcp || error "Peer add failed $?"
489         compare_peer_del "10.10.10.10@tcp" "10.10.10.14@tcp"
490 }
491 run_test 10 "Delete single secondary nid from peer (o2ib)"
492
493 test_11() {
494         reinit_dlc || return $?
495
496         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
497 peer:
498     - primary nid: 11.11.11.11@tcp
499       Multi-Rail: True
500       peer ni:
501         - nid: 11.11.11.11@tcp
502 EOF
503         append_global_yaml
504         do_lnetctl peer add --prim_nid 11.11.11.11@tcp \
505                 --nid 11.11.11.[13-17]@tcp || error "Peer add failed $?"
506         compare_peer_del "11.11.11.11@tcp" "11.11.11.[13-17]@tcp"
507 }
508 run_test 11 "Delete all secondary nids from peer (o2ib)"
509
510 test_12() {
511         reinit_dlc || return $?
512
513         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
514 peer:
515     - primary nid: 12.12.12.12@o2ib
516       Multi-Rail: True
517       peer ni:
518         - nid: 12.12.12.12@o2ib
519         - nid: 13.13.13.13@o2ib
520         - nid: 14.13.13.13@o2ib
521         - nid: 14.15.13.13@o2ib
522         - nid: 15.17.1.5@tcp
523         - nid: 15.17.1.10@tcp
524         - nid: 15.17.1.20@tcp
525 EOF
526         append_global_yaml
527         do_lnetctl peer add --prim_nid 12.12.12.12@o2ib \
528                 --nid [13-14/1].[13-15/2].13.13@o2ib,[15-16/3].[17-19/4].[1].[5-20/5]@tcp ||
529                 error "Peer add failed $?"
530         compare_peer_del "12.12.12.12@o2ib" "13.15.13.13@o2ib,15.17.1.15@tcp"
531 }
532 run_test 12 "Delete a secondary nid from peer (tcp and o2ib)"
533
534 test_13() {
535         reinit_dlc || return $?
536
537         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
538 peer:
539     - primary nid: 13.13.13.13@o2ib
540       Multi-Rail: True
541       peer ni:
542         - nid: 13.13.13.13@o2ib
543 EOF
544         append_global_yaml
545         do_lnetctl peer add --prim_nid 13.13.13.13@o2ib \
546                 --nid [14-15].[1-2/1].[1].[100-254/10]@tcp,14.14.[254].14@o2ib ||
547                 error "Peer add failed $?"
548         compare_peer_del "13.13.13.13@o2ib" \
549                 "[14-15].[1-2/1].[1].[100-254/10]@tcp,14.14.[254].14@o2ib"
550 }
551 run_test 13 "Delete all secondary nids from peer (tcp and o2ib)"
552
553 create_nid() {
554         local num="$1"
555         local net="$2"
556
557         if [[ $net =~ gni* ]]; then
558                 echo "${num}@${net}"
559         else
560                 echo "${num}.${num}.${num}.${num}@${net}"
561         fi
562 }
563
564 create_mr_peer_yaml() {
565         local num_peers="$1"
566         local secondary_nids="$2"
567         local net="$3"
568
569         echo "Generating peer yaml for $num_peers peers with $secondary_nids secondary nids"
570         echo "peer:" >> $TMP/sanity-lnet-$testnum-expected.yaml
571         local i
572         local total_nids=$((num_peers + $((num_peers * secondary_nids))))
573         local created=0
574         local nidnum=1
575         while [[ $created -lt $num_peers ]]; do
576                 local primary=$(create_nid ${nidnum} ${net})
577         cat <<EOF >> $TMP/sanity-lnet-$testnum-expected.yaml
578     - primary nid: $primary
579       Multi-Rail: True
580       peer ni:
581         - nid: $primary
582 EOF
583                 local j
584                 local start=$((nidnum + 1))
585                 local end=$((nidnum + $secondary_nids))
586                 for j in $(seq ${start} ${end}); do
587                         local nid=$(create_nid $j ${net})
588                         echo "        - nid: $nid" >> $TMP/sanity-lnet-$testnum-expected.yaml
589                 done
590                 nidnum=$((end + 1))
591                 ((created++))
592         done
593 }
594
595 test_14() {
596         reinit_dlc || return $?
597
598         echo "Create single peer, single nid, using import"
599         create_mr_peer_yaml 1 0 tcp
600         do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
601                 error "Import failed $?"
602         append_global_yaml
603         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
604         compare_yaml_files
605
606         echo "Delete single peer using import --del"
607         do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
608                 error "Import failed $?"
609         rm -f $TMP/sanity-lnet-$testnum-expected.yaml
610         create_base_yaml_file
611         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
612         compare_yaml_files
613 }
614 run_test 14 "import peer create/delete with single nid"
615
616 test_15() {
617         reinit_dlc || return $?
618
619         echo "Create multiple peers, single nid per peer, using import"
620         create_mr_peer_yaml 5 0 o2ib
621         # The ordering of nids for this use-case is non-deterministic, so we
622         # we can't just diff the expected/actual output.
623         do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
624                 error "Import failed $?"
625         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
626         validate_peer_nids 5 0
627
628         echo "Delete multiple peers, single nid per peer, using import --del"
629         do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
630                 error "Import failed $?"
631         rm -f $TMP/sanity-lnet-$testnum-expected.yaml
632         create_base_yaml_file
633         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
634         compare_yaml_files
635 }
636 run_test 15 "import multi peer create/delete with single nid per peer"
637
638 test_16() {
639         reinit_dlc || return $?
640
641         echo "Create single peer, multiple nids, using import"
642         create_mr_peer_yaml 1 5 tcp
643         do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
644                 error "Import failed $?"
645         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
646         validate_peer_nids 1 5
647
648         echo "Delete single peer, multiple nids, using import --del"
649         do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
650                 error "Import failed $?"
651         rm -f $TMP/sanity-lnet-$testnum-expected.yaml
652         create_base_yaml_file
653         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
654         compare_yaml_files
655 }
656 run_test 16 "import peer create/delete with multiple nids"
657
658 test_17() {
659         reinit_dlc || return $?
660
661         echo "Create multiple peers, multiple nids per peer, using import"
662         create_mr_peer_yaml 5 7 o2ib
663         do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
664                 error "Import failed $?"
665         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
666         validate_peer_nids 5 7
667
668         echo "Delete multiple peers, multiple nids per peer, using import --del"
669         do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
670                 error "Import failed $?"
671         rm -f $TMP/sanity-lnet-$testnum-expected.yaml
672         create_base_yaml_file
673         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
674         compare_yaml_files
675 }
676 run_test 17 "import multi peer create/delete with multiple nids"
677
678 test_18a() {
679         reinit_dlc || return $?
680
681         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
682 peer:
683     - primary nid: 1.1.1.1@tcp
684       Multi-Rail: True
685       peer ni:
686         - nid: 1.1.1.1@tcp
687         - nid: 2.2.2.2@tcp
688         - nid: 4.4.4.4@tcp
689         - nid: 3.3.3.3@o2ib
690         - nid: 5@gni
691 EOF
692         echo "Import peer with 5 nids"
693         cat $TMP/sanity-lnet-$testnum-expected.yaml
694         do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
695                 error "Import failed $?"
696         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
697 peer:
698     - primary nid: 1.1.1.1@tcp
699       Multi-Rail: True
700       peer ni:
701         - nid: 2.2.2.2@tcp
702         - nid: 3.3.3.3@o2ib
703         - nid: 5@gni
704 EOF
705         echo "Delete three of the nids"
706         cat $TMP/sanity-lnet-$testnum-expected.yaml
707         do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml
708         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
709 peer:
710     - primary nid: 1.1.1.1@tcp
711       Multi-Rail: True
712       peer ni:
713         - nid: 1.1.1.1@tcp
714         - nid: 4.4.4.4@tcp
715 EOF
716         echo "Check peer has expected nids remaining"
717         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
718         append_global_yaml
719         compare_yaml_files
720 }
721 run_test 18a "Delete a subset of nids from a single peer using import --del"
722
723 test_18b() {
724         reinit_dlc || return $?
725
726         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
727 peer:
728     - primary nid: 1.1.1.1@tcp
729       Multi-Rail: True
730       peer ni:
731         - nid: 1.1.1.1@tcp
732         - nid: 2.2.2.2@tcp
733         - nid: 4.4.4.4@tcp
734         - nid: 3.3.3.3@o2ib
735         - nid: 5@gni
736     - primary nid: 6.6.6.6@o2ib
737       Multi-Rail: True
738       peer ni:
739         - nid: 6.6.6.6@o2ib
740         - nid: 7.7.7.7@tcp
741         - nid: 8.8.8.8@tcp
742         - nid: 9.9.9.9@tcp
743         - nid: 10@gni
744 EOF
745         echo "Import two peers with 5 nids each"
746         cat $TMP/sanity-lnet-$testnum-expected.yaml
747         do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
748                 error "Import failed $?"
749         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
750 peer:
751     - primary nid: 1.1.1.1@tcp
752       Multi-Rail: True
753       peer ni:
754         - nid: 2.2.2.2@tcp
755         - nid: 3.3.3.3@o2ib
756         - nid: 5@gni
757     - primary nid: 6.6.6.6@o2ib
758       Multi-Rail: True
759       peer ni:
760         - nid: 7.7.7.7@tcp
761         - nid: 8.8.8.8@tcp
762         - nid: 10@gni
763 EOF
764         echo "Delete three of the nids from each peer"
765         cat $TMP/sanity-lnet-$testnum-expected.yaml
766         do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml
767         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
768 peer:
769     - primary nid: 6.6.6.6@o2ib
770       Multi-Rail: True
771       peer ni:
772         - nid: 6.6.6.6@o2ib
773         - nid: 7.7.7.7@tcp
774     - primary nid: 1.1.1.1@tcp
775       Multi-Rail: True
776       peer ni:
777         - nid: 1.1.1.1@tcp
778         - nid: 4.4.4.4@tcp
779 EOF
780         append_global_yaml
781         echo "Check peers have expected nids remaining"
782         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
783         compare_yaml_files
784         validate_peer_nids 2 1
785 }
786 run_test 18b "Delete multiple nids from multiple peers using import --del"
787
788 test_19() {
789         reinit_dlc || return $?
790         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
791 peer:
792     - primary nid: 19@gni
793       Multi-Rail: True
794       peer ni:
795         - nid: 19@gni
796 EOF
797         append_global_yaml
798         compare_peer_add "19@gni"
799 }
800 run_test 19 "Add peer with single nid (gni)"
801
802 test_20() {
803         reinit_dlc || return $?
804         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
805 peer:
806     - primary nid: 20@gni
807       Multi-Rail: True
808       peer ni:
809         - nid: 20@gni
810         - nid: 20.20.20.20@tcp
811         - nid: 20.20.20.20@o2ib
812 EOF
813         append_global_yaml
814         compare_peer_add "20@gni" "20.20.20.20@tcp,20.20.20.20@o2ib"
815 }
816 run_test 20 "Add peer with gni primary and tcp, o2ib secondary"
817
818 test_21() {
819         reinit_dlc || return $?
820         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
821 peer:
822     - primary nid: 21@gni
823       Multi-Rail: True
824       peer ni:
825         - nid: 21@gni
826         - nid: 22@gni
827         - nid: 23@gni
828         - nid: 24@gni
829         - nid: 25@gni
830 EOF
831         append_global_yaml
832         echo"Add peer with nidrange (gni)"
833         compare_peer_add "21@gni" "[22-25]@gni" || error
834         echo "Add peer with nidrange that overlaps primary nid (gni)"
835         compare_peer_add "21@gni" "[21-25]@gni"
836 }
837 run_test 21 "Add peer with nidrange (gni)"
838
839 test_22() {
840         reinit_dlc || return $?
841         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
842 peer:
843     - primary nid: 22@gni
844       Multi-Rail: True
845       peer ni:
846         - nid: 22@gni
847         - nid: 24@gni
848         - nid: 25@gni
849         - nid: 27@gni
850         - nid: 28@gni
851         - nid: 29@gni
852 EOF
853         append_global_yaml
854         do_lnetctl peer add --prim_nid 22@gni --nid [24-29]@gni ||
855                 error "Peer add failed $?"
856         compare_peer_del "22@gni" "26@gni"
857 }
858 run_test 22 "Delete single secondary nid from peer (gni)"
859
860 test_23() {
861         reinit_dlc || return $?
862         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
863 peer:
864     - primary nid: 23@gni
865       Multi-Rail: True
866       peer ni:
867         - nid: 23@gni
868 EOF
869         append_global_yaml
870
871         do_lnetctl peer add --prim_nid 23@gni --nid [25-29]@gni ||
872                 error "Peer add failed $?"
873         compare_peer_del "23@gni" "[25-29]@gni"
874 }
875 run_test 23 "Delete all secondary nids from peer (gni)"
876
877 test_24() {
878         reinit_dlc || return $?
879         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
880 peer:
881     - primary nid: 24@gni
882       Multi-Rail: True
883       peer ni:
884         - nid: 24@gni
885         - nid: 11@gni
886         - nid: 13.13.13.13@o2ib
887         - nid: 14.13.13.13@o2ib
888         - nid: 14.15.13.13@o2ib
889         - nid: 15.17.1.5@tcp
890         - nid: 15.17.1.10@tcp
891         - nid: 15.17.1.20@tcp
892 EOF
893         append_global_yaml
894         do_lnetctl peer add --prim_nid 24@gni \
895                 --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 ||
896                 error "Peer add failed $?"
897         compare_peer_del "24@gni" "5@gni,13.15.13.13@o2ib,15.17.1.15@tcp"
898 }
899 run_test 24 "Delete a secondary nid from peer (tcp, o2ib and gni)"
900
901 test_25() {
902         reinit_dlc || return $?
903         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
904 peer:
905     - primary nid: 25@gni
906       Multi-Rail: True
907       peer ni:
908         - nid: 25@gni
909 EOF
910         append_global_yaml
911         do_lnetctl peer add --prim_nid 25@gni \
912                 --nid [26-27].[4-10/3].26.26@tcp,26.26.26.26@o2ib,[30-35]@gni ||
913                 error "Peer add failed $?"
914         compare_peer_del "25@gni" \
915                 "[26-27].[4-10/3].26.26@tcp,26.26.26.26@o2ib,[30-35]@gni"
916 }
917 run_test 25 "Delete all secondary nids from peer (tcp, gni and o2ib)"
918
919 test_99a() {
920         reinit_dlc || return $?
921
922         echo "Invalid prim_nid - peer add"
923         do_lnetctl peer add --prim_nid foobar &&
924                 error "Command should have failed"
925
926         echo "Invalid prim_nid - peer del"
927         do_lnetctl peer del --prim_nid foobar &&
928                 error "Command should have failed"
929
930         echo "Delete non-existing peer"
931         do_lnetctl peer del --prim_nid 1.1.1.1@o2ib &&
932                 error "Command should have failed"
933
934         echo "Don't provide mandatory arguments peer del"
935         do_lnetctl peer del --nid 1.1.1.1@tcp &&
936                 error "Command should have failed"
937
938         echo "Don't provide mandatory arguments peer add"
939         do_lnetctl peer add &&
940                 error "Command should have failed"
941
942         echo "Invalid secondary nids"
943         do_lnetctl peer add --prim_nid 1.1.1.1@tcp --nid foobar &&
944                 error "Command should have failed"
945
946         echo "Exceed max nids per peer"
947         do_lnetctl peer add --prim_nid 1.1.1.1@tcp --nid 1.1.1.[2-255]@tcp &&
948                 error "Command should have failed"
949
950         echo "Invalid net type"
951         do_lnetctl peer add --prim_nid 1@foo &&
952                 error "Command should have failed"
953
954         echo "Invalid nid format"
955         local invalid_nids="1@tcp 1@o2ib 1.1.1.1@gni"
956
957         local nid
958         for nid in ${invalid_nids}; do
959                 echo "Check invalid primary nid - '$nid'"
960                 do_lnetctl peer add --prim_nid $nid &&
961                         error "Command should have failed"
962         done
963
964         local invalid_strs="[2-1]@gni [a-f/x]@gni 256.256.256.256@tcp"
965         invalid_strs+=" 1.1.1.1.[2-5/f]@tcp 1.]2[.3.4@o2ib"
966         invalid_strs+="1.[2-4,[5-6],7-8].1.1@tcp foobar"
967
968         local nidstr
969         for nidstr in ${invalid_strs}; do
970                 echo "Check invalid nidstring - '$nidstr'"
971                 do_lnetctl peer add --nid $nidstr &&
972                         error "Command should have failed"
973         done
974
975         echo "Add non-local gateway"
976         do_lnetctl route add --net tcp --gateway 1@gni &&
977                 error "Command should have failed"
978
979         return 0
980 }
981 run_test 99a "Check various invalid inputs to lnetctl peer"
982
983 test_99b() {
984         reinit_dlc || return $?
985
986         create_base_yaml_file
987
988         cat <<EOF > $TMP/sanity-lnet-$testnum-invalid.yaml
989 peer:
990     - primary nid: 99.99.99.99@tcp
991       Multi-Rail: Foobar
992       peer ni:
993         - nid: 99.99.99.99@tcp
994 EOF
995         do_lnetctl import < $TMP/sanity-lnet-$testnum-invalid.yaml &&
996                 error "import should have failed"
997         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
998         compare_yaml_files
999 }
1000 run_test 99b "Invalid value for Multi-Rail in yaml import"
1001
1002 have_interface() {
1003         local if="$1"
1004         local ip=$(ip addr show dev $if | awk '/ inet /{print $2}')
1005         [[ -n $ip ]]
1006 }
1007
1008 add_net() {
1009         local net="$1"
1010         local if="$2"
1011
1012         if ! lsmod | grep -q ksocklnd ; then
1013                 load_module ../lnet/klnds/socklnd/ksocklnd ||
1014                         error "Can't load ksocklnd.ko"
1015         fi
1016
1017         do_lnetctl net add --net ${net} --if ${if} ||
1018                 error "Failed to add net ${net} on if ${if}"
1019 }
1020
1021 compare_route_add() {
1022         local rnet="$1"
1023         local gw="$2"
1024
1025         local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
1026
1027         do_lnetctl route add --net ${rnet} --gateway ${gw} ||
1028                 error "route add failed $?"
1029         # CPT configuration is pruned from the exported yaml, since the default
1030         # can vary across test systems (unlike default values for things like
1031         # peer_credits, peer_timeout, etc.)
1032         $LNETCTL export --backup | grep -v CPT > $actual ||
1033                 error "export failed $?"
1034         validate_gateway_nids
1035         return $?
1036 }
1037
1038 test_100() {
1039         have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1040         reinit_dlc || return $?
1041         add_net "tcp" "eth0"
1042         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
1043 net:
1044     - net type: tcp
1045       local NI(s):
1046         - interfaces:
1047               0: eth0
1048           tunables:
1049               peer_timeout: 180
1050               peer_credits: 8
1051               peer_buffer_credits: 0
1052               credits: 256
1053 route:
1054     - net: tcp7
1055       gateway: 7.7.7.7@tcp
1056       hop: -1
1057       priority: 0
1058       health_sensitivity: 1
1059 peer:
1060     - primary nid: 7.7.7.7@tcp
1061       Multi-Rail: False
1062       peer ni:
1063         - nid: 7.7.7.7@tcp
1064 EOF
1065         append_global_yaml
1066         compare_route_add "tcp7" "7.7.7.7@tcp" || return $?
1067         compare_yaml_files
1068 }
1069 run_test 100 "Add route with single gw (tcp)"
1070
1071 test_101() {
1072         have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1073         reinit_dlc || return $?
1074         add_net "tcp" "eth0"
1075         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
1076 net:
1077     - net type: tcp
1078       local NI(s):
1079         - interfaces:
1080               0: eth0
1081           tunables:
1082               peer_timeout: 180
1083               peer_credits: 8
1084               peer_buffer_credits: 0
1085               credits: 256
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         have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1136         reinit_dlc || return $?
1137         add_net "tcp" "eth0"
1138         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-expected.yaml
1139         do_lnetctl route add --net tcp102 --gateway 102.102.102.102@tcp ||
1140                 error "route add failed $?"
1141         compare_route_del "tcp102" "102.102.102.102@tcp"
1142 }
1143 run_test 102 "Delete route with single gw (tcp)"
1144
1145 test_103() {
1146         have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1147         reinit_dlc || return $?
1148         add_net "tcp" "eth0"
1149         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-expected.yaml
1150         do_lnetctl route add --net tcp103 \
1151                 --gateway 103.103.103.[103-120/4]@tcp ||
1152                 error "route add failed $?"
1153         compare_route_del "tcp103" "103.103.103.[103-120/4]@tcp"
1154 }
1155 run_test 103 "Delete route with multiple gw (tcp)"
1156
1157 ### load lnet in default namespace, configure in target namespace
1158
1159 test_200() {
1160         cleanup_lnet || exit 1
1161         load_lnet "networks=\"\""
1162         do_ns $LNETCTL lnet configure --all || exit 1
1163         $LNETCTL net show --net tcp | grep -q "nid: ${FAKE_IP}@tcp$"
1164 }
1165 run_test 200 "load lnet w/o module option, configure in a non-default namespace"
1166
1167 test_201() {
1168         cleanup_lnet || exit 1
1169         load_lnet "networks=tcp($FAKE_IF)"
1170         do_ns $LNETCTL lnet configure --all || exit 1
1171         $LNETCTL net show --net tcp | grep -q "nid: ${FAKE_IP}@tcp$"
1172 }
1173 run_test 201 "load lnet using networks module options in a non-default namespace"
1174
1175 test_202() {
1176         cleanup_lnet || exit 1
1177         load_lnet "networks=\"\" ip2nets=\"tcp0($FAKE_IF) ${FAKE_IP}\""
1178         do_ns $LNETCTL lnet configure --all || exit 1
1179         $LNETCTL net show | grep -q "nid: ${FAKE_IP}@tcp$"
1180 }
1181 run_test 202 "load lnet using ip2nets in a non-default namespace"
1182
1183
1184 ### Add the interfaces in the target namespace
1185
1186 test_203() {
1187         cleanup_lnet || exit 1
1188         load_lnet
1189         do_lnetctl lnet configure || exit 1
1190         do_ns $LNETCTL net add --net tcp0 --if $FAKE_IF
1191 }
1192 run_test 203 "add a network using an interface in the non-default namespace"
1193
1194 LNET_PARAMS_FILE="$TMP/$TESTSUITE.parameters"
1195 function save_lnet_params() {
1196         $LNETCTL global show | egrep -v '^global:$' |
1197                                sed 's/://' > $LNET_PARAMS_FILE
1198 }
1199
1200 function restore_lnet_params() {
1201         local param value
1202         while read param value; do
1203                 [[ $param == max_intf ]] && continue
1204                 [[ $param == lnd_timeout ]] && continue
1205                 $LNETCTL set ${param} ${value} ||
1206                         error "Failed to restore ${param} to ${value}"
1207         done < $LNET_PARAMS_FILE
1208 }
1209
1210 function lnet_health_pre() {
1211         save_lnet_params
1212
1213         # Lower transaction timeout to speed up test execution
1214         $LNETCTL set transaction_timeout 10 ||
1215                 error "Failed to set transaction_timeout $?"
1216
1217         # Increase recovery interval so we have time to capture health values
1218         $LNETCTL set recovery_interval 20 ||
1219                 error "Failed to set recovery_interval $?"
1220
1221         RETRY_PARAM=$($LNETCTL global show | awk '/retry_count/{print $NF}')
1222         RSND_PRE=$($LNETCTL stats show | awk '/resend_count/{print $NF}')
1223         LO_HVAL_PRE=$($LNETCTL net show -v 2 | awk '/health value/{print $NF}' |
1224                       xargs echo | sed 's/ /+/g' | bc -l)
1225
1226         local my_nid=$($LCTL list_nids | head -n 1)
1227
1228         RMT_HVAL_PRE=$($LNETCTL peer show --nid $my_nid -v 2 2>/dev/null |
1229                        awk '/health value/{print $NF}' | xargs echo |
1230                        sed 's/ /+/g' | bc -l)
1231
1232         # Might not have any peers so initialize to zero.
1233         RMT_HVAL_PRE=${RMT_HVAL_PRE:-0}
1234
1235         return 0
1236 }
1237
1238 function lnet_health_post() {
1239         RSND_POST=$($LNETCTL stats show | awk '/resend_count/{print $NF}')
1240         LO_HVAL_POST=$($LNETCTL net show -v 2 |
1241                        awk '/health value/{print $NF}' |
1242                        xargs echo | sed 's/ /+/g' | bc -l)
1243
1244         local my_nid=$($LCTL list_nids | head -n 1)
1245
1246         RMT_HVAL_POST=$($LNETCTL peer show --nid $my_nid -v 2 2>/dev/null |
1247                         awk '/health value/{print $NF}' | xargs echo |
1248                         sed 's/ /+/g' | bc -l)
1249
1250         # Might not have any peers so initialize to zero.
1251         RMT_HVAL_POST=${RMT_HVAL_POST:-0}
1252
1253         ${VERBOSE} &&
1254         echo "Pre resends: $RSND_PRE" &&
1255         echo "Post resends: $RSND_POST" &&
1256         echo "Resends delta: $((RSND_POST - RSND_PRE))" &&
1257         echo "Pre local health: $LO_HVAL_PRE" &&
1258         echo "Post local health: $LO_HVAL_POST" &&
1259         echo "Pre remote health: $RMT_HVAL_PRE" &&
1260         echo "Post remote health: $RMT_HVAL_POST"
1261
1262         restore_lnet_params
1263
1264         return 0
1265 }
1266
1267 function check_no_resends() {
1268         echo "Check that no resends took place"
1269         [[ $RSND_POST -ne $RSND_PRE ]] &&
1270                 error "Found resends: $RSND_POST != $RSND_PRE"
1271
1272         return 0
1273 }
1274
1275 function check_resends() {
1276         local delta=$((RSND_POST - RSND_PRE))
1277
1278         echo "Check that $RETRY_PARAM resends took place"
1279         [[ $delta -ne $RETRY_PARAM ]] &&
1280                 error "Expected $RETRY_PARAM resends found $delta"
1281
1282         return 0
1283 }
1284
1285 function check_no_local_health() {
1286         echo "Check that local NI health is unchanged"
1287         [[ $LO_HVAL_POST -ne $LO_HVAL_PRE ]] &&
1288                 error "Local health changed: $LO_HVAL_POST != $LO_HVAL_PRE"
1289
1290         return 0
1291 }
1292
1293 function check_local_health() {
1294         echo "Check that local NI health has been changed"
1295         [[ $LO_HVAL_POST -eq $LO_HVAL_PRE ]] &&
1296                 error "Local health unchanged: $LO_HVAL_POST == $LO_HVAL_PRE"
1297
1298         return 0
1299 }
1300
1301 function check_no_remote_health() {
1302         echo "Check that remote NI health is unchanged"
1303         [[ $RMT_HVAL_POST -ne $RMT_HVAL_PRE ]] &&
1304                 error "Remote health changed: $RMT_HVAL_POST != $RMT_HVAL_PRE"
1305
1306         return 0
1307 }
1308
1309 function check_remote_health() {
1310         echo "Check that remote NI health has been changed"
1311         [[ $RMT_HVAL_POST -eq $RMT_HVAL_PRE ]] &&
1312                 error "Remote health unchanged: $RMT_HVAL_POST == $RMT_HVAL_PRE"
1313
1314         return 0
1315 }
1316
1317 # See lnet/lnet/lib-msg.c:lnet_health_check()
1318 LNET_LOCAL_RESEND_STATUSES="local_interrupt local_dropped local_aborted"
1319 LNET_LOCAL_RESEND_STATUSES+=" local_no_route local_timeout"
1320 LNET_LOCAL_NO_RESEND_STATUSES="local_error"
1321 test_204() {
1322         have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1323         reinit_dlc || return $?
1324         add_net "tcp" "eth0" || return $?
1325
1326         lnet_health_pre || return $?
1327
1328         local hstatus
1329         for hstatus in ${LNET_LOCAL_RESEND_STATUSES} \
1330                        ${LNET_LOCAL_NO_RESEND_STATUSES}; do
1331                 echo "Simulate $hstatus"
1332                 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1333                 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1334                         error "Should have failed"
1335                 $LCTL net_drop_del *
1336         done
1337
1338         lnet_health_post
1339
1340         check_no_resends || return $?
1341         check_no_local_health || return $?
1342
1343         return 0
1344 }
1345 run_test 204 "Check no health or resends for single-rail local failures"
1346
1347 test_205() {
1348         have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1349
1350         local hstatus
1351         for hstatus in ${LNET_LOCAL_RESEND_STATUSES}; do
1352                 reinit_dlc || return $?
1353                 add_net "tcp" "eth0" || return $?
1354                 add_net "tcp1" "eth0" || return $?
1355
1356                 echo "Simulate $hstatus"
1357                 lnet_health_pre
1358
1359                 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1360                 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e ${hstatus}
1361                 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1362                         error "Should have failed"
1363                 $LCTL net_drop_del *
1364
1365                 lnet_health_post
1366
1367                 check_resends || return $?
1368                 check_local_health || return $?
1369         done
1370
1371         for hstatus in ${LNET_LOCAL_NO_RESEND_STATUSES}; do
1372                 reinit_dlc || return $?
1373                 add_net "tcp" "eth0" || return $?
1374                 add_net "tcp1" "eth0" || return $?
1375
1376                 echo "Simulate $hstatus"
1377                 lnet_health_pre || return $?
1378
1379                 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1380                 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e ${hstatus}
1381                 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1382                         error "Should have failed"
1383                 $LCTL net_drop_del *
1384
1385                 lnet_health_post
1386
1387                 check_no_resends || return $?
1388                 check_local_health || return $?
1389         done
1390
1391         return 0
1392 }
1393 run_test 205 "Check health and resends for multi-rail local failures"
1394
1395 # See lnet/lnet/lib-msg.c:lnet_health_check()
1396 LNET_REMOTE_RESEND_STATUSES="remote_dropped"
1397 LNET_REMOTE_NO_RESEND_STATUSES="remote_error remote_timeout network_timeout"
1398 test_206() {
1399         have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1400         reinit_dlc || return $?
1401         add_net "tcp" "eth0" || return $?
1402
1403         do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1404                 error "failed to discover myself"
1405
1406         lnet_health_pre || return $?
1407
1408         local hstatus
1409         for hstatus in ${LNET_REMOTE_RESEND_STATUSES} \
1410                        ${LNET_REMOTE_NO_RESEND_STATUSES}; do
1411                 echo "Simulate $hstatus"
1412                 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1413                 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1414                         error "Should have failed"
1415                 $LCTL net_drop_del *
1416         done
1417
1418         lnet_health_post
1419
1420         check_no_resends || return $?
1421         check_no_local_health || return $?
1422         check_no_remote_health || return $?
1423
1424         return 0
1425 }
1426 run_test 206 "Check no health or resends for single-rail remote failures"
1427
1428 test_207() {
1429         have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1430
1431         local hstatus
1432         for hstatus in ${LNET_REMOTE_RESEND_STATUSES}; do
1433                 reinit_dlc || return $?
1434                 add_net "tcp" "eth0" || return $?
1435                 add_net "tcp1" "eth0" || return $?
1436
1437                 do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1438                         error "failed to discover myself"
1439
1440                 echo "Simulate $hstatus"
1441                 lnet_health_pre || return $?
1442                 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1443                 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e ${hstatus}
1444                 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1445                         error "Should have failed"
1446                 $LCTL net_drop_del *
1447
1448                 lnet_health_post
1449
1450                 check_resends || return $?
1451                 check_no_local_health || return $?
1452                 check_remote_health || return $?
1453         done
1454         for hstatus in ${LNET_REMOTE_NO_RESEND_STATUSES}; do
1455                 reinit_dlc || return $?
1456                 add_net "tcp" "eth0" || return $?
1457                 add_net "tcp1" "eth0" || return $?
1458
1459                 do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1460                         error "failed to discover myself"
1461
1462                 echo "Simulate $hstatus"
1463                 lnet_health_pre || return $?
1464                 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1465                 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e ${hstatus}
1466                 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1467                         error "Should have failed"
1468                 $LCTL net_drop_del *
1469
1470                 lnet_health_post
1471
1472                 check_no_resends || return $?
1473                 check_no_local_health || return $?
1474                 check_remote_health || return $?
1475         done
1476
1477         return 0
1478 }
1479 run_test 207 "Check health and resends for multi-rail remote errors"
1480
1481 test_300() {
1482         # LU-13274
1483         local header
1484         local out=$TMP/$tfile
1485         local prefix=/usr/include/linux/lnet
1486
1487         # We use a hard coded prefix so that this test will not fail
1488         # when run in tree.
1489         CC=${CC:-cc}
1490         if ! which $CC > /dev/null 2>&1; then
1491                 skip_env "$CC is not installed"
1492         fi
1493
1494         cleanup_lnet || exit 1
1495         load_lnet
1496
1497         if ! [[ -d $prefix ]]; then
1498                 # Assume we're running in tree and fixup the include path.
1499                 prefix=$LUSTRE/../lnet/include/uapi/linux/lnet
1500         fi
1501
1502         for header in $prefix/*.h; do
1503                 if ! [[ -f "$header" ]]; then
1504                         continue
1505                 fi
1506
1507                 $CC -Wall -Werror -std=c99 -include $header -c -x c /dev/null -o $out ||
1508                         error "cannot compile '$header'"
1509         done
1510         rm -f $out
1511 }
1512 run_test 300 "packaged LNet UAPI headers can be compiled"
1513
1514 complete $SECONDS
1515
1516 cleanup_testsuite
1517 exit_status