Whamcloud - gitweb
LU-14128 lov: correctly set OST obj size
[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 # bug number for skipped test:
11 ALWAYS_EXCEPT="$SANITY_LNET_EXCEPT "
12 [ "$SLOW" = "no" ] && EXCEPT_SLOW=""
13 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
14
15 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
16
17 . $LUSTRE/tests/test-framework.sh
18 CLEANUP=${CLEANUP:-:}
19 SETUP=${SETUP:-:}
20 init_test_env $@
21 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
22 init_logging
23
24 build_test_filter
25
26 [[ -z $LNETCTL ]] && skip "Need lnetctl"
27
28 load_lnet() {
29         load_module ../libcfs/libcfs/libcfs
30         # Prevent local MODOPTS_LIBCFS being passed as part of environment
31         # variable to remote nodes
32         unset MODOPTS_LIBCFS
33
34         set_default_debug
35         load_module ../lnet/lnet/lnet "$@"
36
37         LNDPATH=${LNDPATH:-"../lnet/klnds"}
38         if [ -z "$LNETLND" ]; then
39                 case $NETTYPE in
40                 o2ib*)  LNETLND="o2iblnd/ko2iblnd" ;;
41                 tcp*)   LNETLND="socklnd/ksocklnd" ;;
42                 *)      local lnd="${NETTYPE%%[0-9]}lnd"
43                         [ -f "$LNDPATH/$lnd/k$lnd.ko" ] &&
44                                 LNETLND="$lnd/k$lnd" ||
45                                 LNETLND="socklnd/ksocklnd"
46                 esac
47         fi
48         load_module ../lnet/klnds/$LNETLND
49 }
50
51 cleanup_lnet() {
52         echo "Cleaning up LNet"
53         lsmod | grep -q lnet &&
54                 $LNETCTL lnet unconfigure 2>/dev/null
55         unload_modules
56 }
57
58 TESTNS='test_ns'
59 RUN_NS="ip netns exec $TESTNS"
60 FAKE_IF="test1pg"
61 FAKE_IP="10.1.2.3"
62
63 setup_netns() {
64         cleanup_netns
65
66         ip netns add $TESTNS
67         ip link add 'test1pl' type veth peer name $FAKE_IF netns $TESTNS
68         ip link set 'test1pl' up
69         $RUN_NS ip addr add "${FAKE_IP}/31" dev $FAKE_IF
70         $RUN_NS ip link set $FAKE_IF up
71 }
72
73 cleanup_netns() {
74         (ip netns list | grep -q $TESTNS) && ip netns del $TESTNS
75         ip link show test1pl >& /dev/null && ip link del test1pl || return 0
76 }
77
78 cleanupall -f
79
80 setup_netns
81 load_lnet
82
83 test_1() {
84         $LNETCTL lnet configure
85 }
86 run_test 1 "configure lnet with lnetctl"
87
88
89 ### load lnet in default namespace, configure in target namespace
90
91 test_2() {
92         cleanup_lnet || exit 1
93         load_lnet "networks=\"\""
94         $RUN_NS $LNETCTL lnet configure --all || exit 1
95         $LNETCTL net show --net tcp | grep -q "nid: ${FAKE_IP}@tcp$"
96 }
97 run_test 2 "load lnet w/o module option, configure in a non-default namespace"
98
99 test_3() {
100         cleanup_lnet || exit 1
101         load_lnet "networks=tcp($FAKE_IF)"
102         $RUN_NS $LNETCTL lnet configure --all || exit 1
103         $LNETCTL net show --net tcp | grep -q "nid: ${FAKE_IP}@tcp$"
104 }
105 run_test 3 "load lnet using networks module options in a non-default namespace"
106
107 test_4() {
108         cleanup_lnet || exit 1
109         load_lnet "networks=\"\" ip2nets=\"tcp0($FAKE_IF) ${FAKE_IP}\""
110         $RUN_NS $LNETCTL lnet configure --all || exit 1
111         $LNETCTL net show | grep -q "nid: ${FAKE_IP}@tcp$"
112 }
113 run_test 4 "load lnet using ip2nets in a non-default namespace"
114
115
116 ### Add the interfaces in the target namespace
117
118 test_5() {
119         cleanup_lnet || exit 1
120         load_lnet
121         $LNETCTL lnet configure || exit 1
122         $RUN_NS $LNETCTL net add --net tcp0 --if $FAKE_IF
123 }
124 run_test 5 "add a network using an interface in the non-default namespace"
125
126 test_212() {
127         local rnodes=$(remote_nodes_list)
128         [[ -z $rnodes ]] && skip "Need at least 1 remote node"
129
130         cleanup_lnet || error "Failed to cleanup before test execution"
131
132         # Loading modules should configure LNet with the appropriate
133         # test-framework configuration
134         load_modules || error "Failed to load modules"
135
136         local my_nid=$($LCTL list_nids | head -n 1)
137         [[ -z $my_nid ]] &&
138                 error "Failed to get primary NID for local host $HOSTNAME"
139
140         local rnode=$(awk '{print $1}' <<<$rnodes)
141         local rnodenids=$(do_node $rnode $LCTL list_nids | xargs echo)
142         local rloaded=false
143
144         if [[ -z $rnodenids ]]; then
145                 do_rpc_nodes $rnode load_modules_local
146                 rloaded=true
147                 rnodenids=$(do_node $rnode $LCTL list_nids | xargs echo)
148         fi
149
150         local rnodepnid=$(awk '{print $1}' <<< $rnodenids)
151
152         [[ -z $rnodepnid ]] &&
153                 error "Failed to get primary NID for remote host $rnode"
154
155         log "Initial discovery"
156         $LNETCTL discover --force $rnodepnid ||
157                 error "Failed to discover $rnodepnid"
158
159         do_node $rnode "$LNETCTL discover --force $my_nid" ||
160                 error "$rnode failed to discover $my_nid"
161
162         log "Fail local discover ping to set LNET_PEER_REDISCOVER flag"
163         $LCTL net_drop_add -s "*@$NETTYPE" -d "*@$NETTYPE" -r 1 -e local_error
164         $LNETCTL discover --force $rnodepnid &&
165                 error "Discovery should have failed"
166         $LCTL net_drop_del -a
167
168         local nid
169         for nid in $rnodenids; do
170                 # We need GET (PING) delay just long enough so we can trigger
171                 # discovery on the remote peer
172                 $LCTL net_delay_add -s "*@$NETTYPE" -d $nid -r 1 -m GET -l 3
173                 $LCTL net_drop_add -s "*@$NETTYPE" -d $nid -r 1 -m GET -e local_error
174                 # We need PUT (PUSH) delay just long enough so we can process
175                 # the PING failure
176                 $LCTL net_delay_add -s "*@$NETTYPE" -d $nid -r 1 -m PUT -l 6
177         done
178
179         log "Force $HOSTNAME to discover $rnodepnid (in background)"
180         # We want to get a PING sent that we know will eventually fail.
181         # The delay rules we added will ensure the ping is not sent until
182         # the PUSH is also in flight (see below), and the drop rule ensures that
183         # when the PING is eventually sent it will error out
184         $LNETCTL discover --force $rnodepnid &
185         local pid1=$!
186
187         # We want a discovery PUSH from rnode to put rnode back on our
188         # discovery queue. This should cause us to try and send a PUSH to rnode
189         # while the PING is still outstanding.
190         log "Force $rnode to discover $my_nid"
191         do_node $rnode $LNETCTL discover --force $my_nid
192
193         # At this point we'll have both PING_SENT and PUSH_SENT set for the
194         # rnode peer. Wait for the PING to error out which should terminate the
195         # discovery process that we backgrounded.
196         log "Wait for $pid1"
197         wait $pid1
198         log "Finished wait on $pid1"
199
200         # The PING send failure clears the PING_SENT flag and puts the peer back
201         # on the discovery queue. When discovery thread processes the peer it
202         # will mistakenly clear the PUSH_SENT flag (and set PUSH_FAILED).
203         # Discovery will then complete for this peer even though we have an
204         # outstanding PUSH.
205         # When PUSH is actually unlinked it will be forced back onto the
206         # discovery queue, but we no longer have a ref on the peer. When
207         # discovery completes again, we'll trip the ASSERT in
208         # lnet_destroy_peer_locked()
209
210         # Delete the delay rules to send the PUSH
211         $LCTL net_delay_del -a
212         # Delete the drop rules
213         $LCTL net_drop_del -a
214
215         unload_modules ||
216                 error "Failed to unload modules"
217         if $rloaded; then
218                 do_rpc_nodes $rnode unload_modules_local ||
219                         error "Failed to unload modules on $rnode"
220         fi
221
222         return 0
223 }
224 run_test 212 "Check discovery refcount loss bug (LU-14627)"
225
226
227 cleanup_netns
228 cleanup_lnet
229 exit_status