Commit | Line | Data |
---|---|---|
d7e09d03 PT |
1 | /* |
2 | * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. | |
3 | * | |
1dc563a6 | 4 | * Copyright (c) 2011, 2015, Intel Corporation. |
d7e09d03 PT |
5 | * |
6 | * This file is part of Portals | |
7 | * http://sourceforge.net/projects/sandiaportals/ | |
8 | * | |
9 | * Portals is free software; you can redistribute it and/or | |
10 | * modify it under the terms of version 2 of the GNU General Public | |
11 | * License as published by the Free Software Foundation. | |
12 | * | |
13 | * Portals is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
d7e09d03 PT |
18 | */ |
19 | ||
20 | #define DEBUG_SUBSYSTEM S_LNET | |
21ca52bb | 21 | #include <linux/completion.h> |
9fdaf8c0 | 22 | #include "../../include/linux/lnet/lib-lnet.h" |
d7e09d03 | 23 | |
d7e09d03 PT |
24 | #define LNET_NRB_TINY_MIN 512 /* min value for each CPT */ |
25 | #define LNET_NRB_TINY (LNET_NRB_TINY_MIN * 4) | |
26 | #define LNET_NRB_SMALL_MIN 4096 /* min value for each CPT */ | |
27 | #define LNET_NRB_SMALL (LNET_NRB_SMALL_MIN * 4) | |
86ef6250 | 28 | #define LNET_NRB_SMALL_PAGES 1 |
d7e09d03 PT |
29 | #define LNET_NRB_LARGE_MIN 256 /* min value for each CPT */ |
30 | #define LNET_NRB_LARGE (LNET_NRB_LARGE_MIN * 4) | |
09cbfeaf KS |
31 | #define LNET_NRB_LARGE_PAGES ((LNET_MTU + PAGE_SIZE - 1) >> \ |
32 | PAGE_SHIFT) | |
d7e09d03 PT |
33 | |
34 | static char *forwarding = ""; | |
8cc7b4b9 PT |
35 | module_param(forwarding, charp, 0444); |
36 | MODULE_PARM_DESC(forwarding, "Explicitly enable/disable forwarding between networks"); | |
d7e09d03 PT |
37 | |
38 | static int tiny_router_buffers; | |
8cc7b4b9 PT |
39 | module_param(tiny_router_buffers, int, 0444); |
40 | MODULE_PARM_DESC(tiny_router_buffers, "# of 0 payload messages to buffer in the router"); | |
d7e09d03 | 41 | static int small_router_buffers; |
8cc7b4b9 PT |
42 | module_param(small_router_buffers, int, 0444); |
43 | MODULE_PARM_DESC(small_router_buffers, "# of small (1 page) messages to buffer in the router"); | |
d7e09d03 | 44 | static int large_router_buffers; |
8cc7b4b9 PT |
45 | module_param(large_router_buffers, int, 0444); |
46 | MODULE_PARM_DESC(large_router_buffers, "# of large messages to buffer in the router"); | |
f96d1d7e | 47 | static int peer_buffer_credits; |
8cc7b4b9 PT |
48 | module_param(peer_buffer_credits, int, 0444); |
49 | MODULE_PARM_DESC(peer_buffer_credits, "# router buffer credits per peer"); | |
d7e09d03 PT |
50 | |
51 | static int auto_down = 1; | |
8cc7b4b9 PT |
52 | module_param(auto_down, int, 0444); |
53 | MODULE_PARM_DESC(auto_down, "Automatically mark peers down on comms error"); | |
d7e09d03 PT |
54 | |
55 | int | |
56 | lnet_peer_buffer_credits(lnet_ni_t *ni) | |
57 | { | |
58 | /* NI option overrides LNet default */ | |
59 | if (ni->ni_peerrtrcredits > 0) | |
60 | return ni->ni_peerrtrcredits; | |
61 | if (peer_buffer_credits > 0) | |
62 | return peer_buffer_credits; | |
63 | ||
4420cfd3 JS |
64 | /* |
65 | * As an approximation, allow this peer the same number of router | |
66 | * buffers as it is allowed outstanding sends | |
67 | */ | |
d7e09d03 PT |
68 | return ni->ni_peertxcredits; |
69 | } | |
70 | ||
71 | /* forward ref's */ | |
72 | static int lnet_router_checker(void *); | |
d7e09d03 | 73 | |
f96d1d7e | 74 | static int check_routers_before_use; |
8cc7b4b9 PT |
75 | module_param(check_routers_before_use, int, 0444); |
76 | MODULE_PARM_DESC(check_routers_before_use, "Assume routers are down and ping them before use"); | |
d7e09d03 | 77 | |
af3fa7c7 | 78 | int avoid_asym_router_failure = 1; |
8cc7b4b9 PT |
79 | module_param(avoid_asym_router_failure, int, 0644); |
80 | MODULE_PARM_DESC(avoid_asym_router_failure, "Avoid asymmetrical router failures (0 to disable)"); | |
d7e09d03 PT |
81 | |
82 | static int dead_router_check_interval = 60; | |
8cc7b4b9 PT |
83 | module_param(dead_router_check_interval, int, 0644); |
84 | MODULE_PARM_DESC(dead_router_check_interval, "Seconds between dead router health checks (<= 0 to disable)"); | |
d7e09d03 PT |
85 | |
86 | static int live_router_check_interval = 60; | |
8cc7b4b9 PT |
87 | module_param(live_router_check_interval, int, 0644); |
88 | MODULE_PARM_DESC(live_router_check_interval, "Seconds between live router health checks (<= 0 to disable)"); | |
d7e09d03 PT |
89 | |
90 | static int router_ping_timeout = 50; | |
8cc7b4b9 PT |
91 | module_param(router_ping_timeout, int, 0644); |
92 | MODULE_PARM_DESC(router_ping_timeout, "Seconds to wait for the reply to a router health query"); | |
d7e09d03 PT |
93 | |
94 | int | |
95 | lnet_peers_start_down(void) | |
96 | { | |
97 | return check_routers_before_use; | |
98 | } | |
99 | ||
100 | void | |
e6157b1b RG |
101 | lnet_notify_locked(lnet_peer_t *lp, int notifylnd, int alive, |
102 | unsigned long when) | |
d7e09d03 | 103 | { |
699503bc | 104 | if (time_before(when, lp->lp_timestamp)) { /* out of date information */ |
d7e09d03 PT |
105 | CDEBUG(D_NET, "Out of date\n"); |
106 | return; | |
107 | } | |
108 | ||
109 | lp->lp_timestamp = when; /* update timestamp */ | |
110 | lp->lp_ping_deadline = 0; /* disable ping timeout */ | |
111 | ||
5fd88337 | 112 | if (lp->lp_alive_count && /* got old news */ |
d7e09d03 PT |
113 | (!lp->lp_alive) == (!alive)) { /* new date for old news */ |
114 | CDEBUG(D_NET, "Old news\n"); | |
115 | return; | |
116 | } | |
117 | ||
118 | /* Flag that notification is outstanding */ | |
119 | ||
120 | lp->lp_alive_count++; | |
121 | lp->lp_alive = !(!alive); /* 1 bit! */ | |
122 | lp->lp_notify = 1; | |
123 | lp->lp_notifylnd |= notifylnd; | |
124 | if (lp->lp_alive) | |
125 | lp->lp_ping_feats = LNET_PING_FEAT_INVAL; /* reset */ | |
126 | ||
127 | CDEBUG(D_NET, "set %s %d\n", libcfs_nid2str(lp->lp_nid), alive); | |
128 | } | |
129 | ||
24008203 | 130 | static void |
d7e09d03 PT |
131 | lnet_ni_notify_locked(lnet_ni_t *ni, lnet_peer_t *lp) |
132 | { | |
7e7ab095 MS |
133 | int alive; |
134 | int notifylnd; | |
d7e09d03 | 135 | |
4420cfd3 JS |
136 | /* |
137 | * Notify only in 1 thread at any time to ensure ordered notification. | |
d7e09d03 | 138 | * NB individual events can be missed; the only guarantee is that you |
4420cfd3 JS |
139 | * always get the most recent news |
140 | */ | |
06ace26e | 141 | if (lp->lp_notifying || !ni) |
d7e09d03 PT |
142 | return; |
143 | ||
144 | lp->lp_notifying = 1; | |
145 | ||
146 | while (lp->lp_notify) { | |
7e7ab095 | 147 | alive = lp->lp_alive; |
d7e09d03 PT |
148 | notifylnd = lp->lp_notifylnd; |
149 | ||
150 | lp->lp_notifylnd = 0; | |
151 | lp->lp_notify = 0; | |
152 | ||
06ace26e | 153 | if (notifylnd && ni->ni_lnd->lnd_notify) { |
d7e09d03 PT |
154 | lnet_net_unlock(lp->lp_cpt); |
155 | ||
4420cfd3 JS |
156 | /* |
157 | * A new notification could happen now; I'll handle it | |
158 | * when control returns to me | |
159 | */ | |
0eee6778 | 160 | ni->ni_lnd->lnd_notify(ni, lp->lp_nid, alive); |
d7e09d03 PT |
161 | |
162 | lnet_net_lock(lp->lp_cpt); | |
163 | } | |
164 | } | |
165 | ||
166 | lp->lp_notifying = 0; | |
167 | } | |
168 | ||
d7e09d03 PT |
169 | static void |
170 | lnet_rtr_addref_locked(lnet_peer_t *lp) | |
171 | { | |
172 | LASSERT(lp->lp_refcount > 0); | |
173 | LASSERT(lp->lp_rtr_refcount >= 0); | |
174 | ||
175 | /* lnet_net_lock must be exclusively locked */ | |
176 | lp->lp_rtr_refcount++; | |
177 | if (lp->lp_rtr_refcount == 1) { | |
178 | struct list_head *pos; | |
179 | ||
180 | /* a simple insertion sort */ | |
181 | list_for_each_prev(pos, &the_lnet.ln_routers) { | |
182 | lnet_peer_t *rtr = list_entry(pos, lnet_peer_t, | |
c314c319 | 183 | lp_rtr_list); |
d7e09d03 PT |
184 | |
185 | if (rtr->lp_nid < lp->lp_nid) | |
186 | break; | |
187 | } | |
188 | ||
189 | list_add(&lp->lp_rtr_list, pos); | |
190 | /* addref for the_lnet.ln_routers */ | |
191 | lnet_peer_addref_locked(lp); | |
192 | the_lnet.ln_routers_version++; | |
193 | } | |
194 | } | |
195 | ||
196 | static void | |
197 | lnet_rtr_decref_locked(lnet_peer_t *lp) | |
198 | { | |
199 | LASSERT(lp->lp_refcount > 0); | |
200 | LASSERT(lp->lp_rtr_refcount > 0); | |
201 | ||
202 | /* lnet_net_lock must be exclusively locked */ | |
203 | lp->lp_rtr_refcount--; | |
5fd88337 | 204 | if (!lp->lp_rtr_refcount) { |
d7e09d03 PT |
205 | LASSERT(list_empty(&lp->lp_routes)); |
206 | ||
06ace26e | 207 | if (lp->lp_rcd) { |
d7e09d03 | 208 | list_add(&lp->lp_rcd->rcd_list, |
c314c319 | 209 | &the_lnet.ln_rcd_deathrow); |
d7e09d03 PT |
210 | lp->lp_rcd = NULL; |
211 | } | |
212 | ||
213 | list_del(&lp->lp_rtr_list); | |
214 | /* decref for the_lnet.ln_routers */ | |
215 | lnet_peer_decref_locked(lp); | |
216 | the_lnet.ln_routers_version++; | |
217 | } | |
218 | } | |
219 | ||
220 | lnet_remotenet_t * | |
939af333 | 221 | lnet_find_net_locked(__u32 net) |
d7e09d03 | 222 | { |
7e7ab095 MS |
223 | lnet_remotenet_t *rnet; |
224 | struct list_head *tmp; | |
225 | struct list_head *rn_list; | |
d7e09d03 PT |
226 | |
227 | LASSERT(!the_lnet.ln_shutdown); | |
228 | ||
229 | rn_list = lnet_net2rnethash(net); | |
230 | list_for_each(tmp, rn_list) { | |
231 | rnet = list_entry(tmp, lnet_remotenet_t, lrn_list); | |
232 | ||
233 | if (rnet->lrn_net == net) | |
234 | return rnet; | |
235 | } | |
236 | return NULL; | |
237 | } | |
238 | ||
239 | static void lnet_shuffle_seed(void) | |
240 | { | |
f96d1d7e | 241 | static int seeded; |
80feb1ef | 242 | __u32 lnd_type, seed[2]; |
1f4fc343 | 243 | struct timespec64 ts; |
d7e09d03 PT |
244 | lnet_ni_t *ni; |
245 | struct list_head *tmp; | |
246 | ||
247 | if (seeded) | |
248 | return; | |
249 | ||
250 | cfs_get_random_bytes(seed, sizeof(seed)); | |
251 | ||
4420cfd3 JS |
252 | /* |
253 | * Nodes with small feet have little entropy | |
254 | * the NID for this node gives the most entropy in the low bits | |
255 | */ | |
d7e09d03 PT |
256 | list_for_each(tmp, &the_lnet.ln_nis) { |
257 | ni = list_entry(tmp, lnet_ni_t, ni_list); | |
258 | lnd_type = LNET_NETTYP(LNET_NIDNET(ni->ni_nid)); | |
259 | ||
260 | if (lnd_type != LOLND) | |
261 | seed[0] ^= (LNET_NIDADDR(ni->ni_nid) | lnd_type); | |
262 | } | |
263 | ||
1f4fc343 AB |
264 | ktime_get_ts64(&ts); |
265 | cfs_srand(ts.tv_sec ^ seed[0], ts.tv_nsec ^ seed[1]); | |
d7e09d03 | 266 | seeded = 1; |
d7e09d03 PT |
267 | } |
268 | ||
269 | /* NB expects LNET_LOCK held */ | |
24008203 | 270 | static void |
939af333 | 271 | lnet_add_route_to_rnet(lnet_remotenet_t *rnet, lnet_route_t *route) |
d7e09d03 | 272 | { |
7e7ab095 MS |
273 | unsigned int len = 0; |
274 | unsigned int offset = 0; | |
275 | struct list_head *e; | |
d7e09d03 PT |
276 | |
277 | lnet_shuffle_seed(); | |
278 | ||
939af333 | 279 | list_for_each(e, &rnet->lrn_routes) { |
d7e09d03 PT |
280 | len++; |
281 | } | |
282 | ||
283 | /* len+1 positions to add a new entry, also prevents division by 0 */ | |
284 | offset = cfs_rand() % (len + 1); | |
939af333 | 285 | list_for_each(e, &rnet->lrn_routes) { |
5fd88337 | 286 | if (!offset) |
d7e09d03 PT |
287 | break; |
288 | offset--; | |
289 | } | |
290 | list_add(&route->lr_list, e); | |
291 | list_add(&route->lr_gwlist, &route->lr_gateway->lp_routes); | |
292 | ||
293 | the_lnet.ln_remote_nets_version++; | |
294 | lnet_rtr_addref_locked(route->lr_gateway); | |
295 | } | |
296 | ||
297 | int | |
b9bbb61c | 298 | lnet_add_route(__u32 net, __u32 hops, lnet_nid_t gateway, |
e75fb87f | 299 | unsigned int priority) |
d7e09d03 | 300 | { |
7e7ab095 MS |
301 | struct list_head *e; |
302 | lnet_remotenet_t *rnet; | |
303 | lnet_remotenet_t *rnet2; | |
304 | lnet_route_t *route; | |
305 | lnet_ni_t *ni; | |
306 | int add_route; | |
307 | int rc; | |
d7e09d03 | 308 | |
b9bbb61c | 309 | CDEBUG(D_NET, "Add route: net %s hops %d priority %u gw %s\n", |
e75fb87f | 310 | libcfs_net2str(net), hops, priority, libcfs_nid2str(gateway)); |
d7e09d03 PT |
311 | |
312 | if (gateway == LNET_NID_ANY || | |
313 | LNET_NETTYP(LNET_NIDNET(gateway)) == LOLND || | |
314 | net == LNET_NIDNET(LNET_NID_ANY) || | |
315 | LNET_NETTYP(net) == LOLND || | |
316 | LNET_NIDNET(gateway) == net || | |
b9bbb61c | 317 | (hops != LNET_UNDEFINED_HOPS && (hops < 1 || hops > 255))) |
fbe7c6c7 | 318 | return -EINVAL; |
d7e09d03 PT |
319 | |
320 | if (lnet_islocalnet(net)) /* it's a local network */ | |
be8240ac | 321 | return -EEXIST; |
d7e09d03 PT |
322 | |
323 | /* Assume net, route, all new */ | |
324 | LIBCFS_ALLOC(route, sizeof(*route)); | |
325 | LIBCFS_ALLOC(rnet, sizeof(*rnet)); | |
06ace26e | 326 | if (!route || !rnet) { |
d7e09d03 PT |
327 | CERROR("Out of memory creating route %s %d %s\n", |
328 | libcfs_net2str(net), hops, libcfs_nid2str(gateway)); | |
06ace26e | 329 | if (route) |
d7e09d03 | 330 | LIBCFS_FREE(route, sizeof(*route)); |
06ace26e | 331 | if (rnet) |
d7e09d03 PT |
332 | LIBCFS_FREE(rnet, sizeof(*rnet)); |
333 | return -ENOMEM; | |
334 | } | |
335 | ||
336 | INIT_LIST_HEAD(&rnet->lrn_routes); | |
337 | rnet->lrn_net = net; | |
338 | route->lr_hops = hops; | |
339 | route->lr_net = net; | |
e75fb87f | 340 | route->lr_priority = priority; |
d7e09d03 PT |
341 | |
342 | lnet_net_lock(LNET_LOCK_EX); | |
343 | ||
344 | rc = lnet_nid2peer_locked(&route->lr_gateway, gateway, LNET_LOCK_EX); | |
5fd88337 | 345 | if (rc) { |
d7e09d03 PT |
346 | lnet_net_unlock(LNET_LOCK_EX); |
347 | ||
348 | LIBCFS_FREE(route, sizeof(*route)); | |
349 | LIBCFS_FREE(rnet, sizeof(*rnet)); | |
350 | ||
ec523735 | 351 | if (rc == -EHOSTUNREACH) /* gateway is not on a local net */ |
be8240ac | 352 | return rc; /* ignore the route entry */ |
ec523735 RG |
353 | CERROR("Error %d creating route %s %d %s\n", rc, |
354 | libcfs_net2str(net), hops, | |
355 | libcfs_nid2str(gateway)); | |
d7e09d03 PT |
356 | return rc; |
357 | } | |
358 | ||
939af333 | 359 | LASSERT(!the_lnet.ln_shutdown); |
d7e09d03 PT |
360 | |
361 | rnet2 = lnet_find_net_locked(net); | |
06ace26e | 362 | if (!rnet2) { |
d7e09d03 PT |
363 | /* new network */ |
364 | list_add_tail(&rnet->lrn_list, lnet_net2rnethash(net)); | |
365 | rnet2 = rnet; | |
366 | } | |
367 | ||
368 | /* Search for a duplicate route (it's a NOOP if it is) */ | |
369 | add_route = 1; | |
939af333 | 370 | list_for_each(e, &rnet2->lrn_routes) { |
d7e09d03 PT |
371 | lnet_route_t *route2 = list_entry(e, lnet_route_t, lr_list); |
372 | ||
373 | if (route2->lr_gateway == route->lr_gateway) { | |
374 | add_route = 0; | |
375 | break; | |
376 | } | |
377 | ||
378 | /* our lookups must be true */ | |
939af333 | 379 | LASSERT(route2->lr_gateway->lp_nid != gateway); |
d7e09d03 PT |
380 | } |
381 | ||
382 | if (add_route) { | |
383 | lnet_peer_addref_locked(route->lr_gateway); /* +1 for notify */ | |
384 | lnet_add_route_to_rnet(rnet2, route); | |
385 | ||
386 | ni = route->lr_gateway->lp_ni; | |
387 | lnet_net_unlock(LNET_LOCK_EX); | |
388 | ||
389 | /* XXX Assume alive */ | |
06ace26e | 390 | if (ni->ni_lnd->lnd_notify) |
0eee6778 | 391 | ni->ni_lnd->lnd_notify(ni, gateway, 1); |
d7e09d03 PT |
392 | |
393 | lnet_net_lock(LNET_LOCK_EX); | |
394 | } | |
395 | ||
396 | /* -1 for notify or !add_route */ | |
397 | lnet_peer_decref_locked(route->lr_gateway); | |
398 | lnet_net_unlock(LNET_LOCK_EX); | |
be8240ac | 399 | rc = 0; |
d7e09d03 | 400 | |
be8240ac AS |
401 | if (!add_route) { |
402 | rc = -EEXIST; | |
d7e09d03 | 403 | LIBCFS_FREE(route, sizeof(*route)); |
be8240ac | 404 | } |
d7e09d03 PT |
405 | |
406 | if (rnet != rnet2) | |
407 | LIBCFS_FREE(rnet, sizeof(*rnet)); | |
408 | ||
7f8b70e0 AS |
409 | /* indicate to startup the router checker if configured */ |
410 | wake_up(&the_lnet.ln_rc_waitq); | |
411 | ||
be8240ac | 412 | return rc; |
d7e09d03 PT |
413 | } |
414 | ||
415 | int | |
416 | lnet_check_routes(void) | |
417 | { | |
7e7ab095 MS |
418 | lnet_remotenet_t *rnet; |
419 | lnet_route_t *route; | |
420 | lnet_route_t *route2; | |
421 | struct list_head *e1; | |
422 | struct list_head *e2; | |
423 | int cpt; | |
424 | struct list_head *rn_list; | |
425 | int i; | |
d7e09d03 PT |
426 | |
427 | cpt = lnet_net_lock_current(); | |
428 | ||
429 | for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) { | |
430 | rn_list = &the_lnet.ln_remote_nets_hash[i]; | |
431 | list_for_each(e1, rn_list) { | |
432 | rnet = list_entry(e1, lnet_remotenet_t, lrn_list); | |
433 | ||
434 | route2 = NULL; | |
435 | list_for_each(e2, &rnet->lrn_routes) { | |
7e7ab095 MS |
436 | lnet_nid_t nid1; |
437 | lnet_nid_t nid2; | |
438 | int net; | |
d7e09d03 | 439 | |
c314c319 | 440 | route = list_entry(e2, lnet_route_t, lr_list); |
d7e09d03 | 441 | |
06ace26e | 442 | if (!route2) { |
d7e09d03 PT |
443 | route2 = route; |
444 | continue; | |
445 | } | |
446 | ||
447 | if (route->lr_gateway->lp_ni == | |
448 | route2->lr_gateway->lp_ni) | |
449 | continue; | |
450 | ||
451 | nid1 = route->lr_gateway->lp_nid; | |
452 | nid2 = route2->lr_gateway->lp_nid; | |
453 | net = rnet->lrn_net; | |
454 | ||
455 | lnet_net_unlock(cpt); | |
456 | ||
2d00bd17 | 457 | CERROR("Routes to %s via %s and %s not supported\n", |
d7e09d03 PT |
458 | libcfs_net2str(net), |
459 | libcfs_nid2str(nid1), | |
460 | libcfs_nid2str(nid2)); | |
461 | return -EINVAL; | |
462 | } | |
463 | } | |
464 | } | |
465 | ||
466 | lnet_net_unlock(cpt); | |
467 | return 0; | |
468 | } | |
469 | ||
470 | int | |
471 | lnet_del_route(__u32 net, lnet_nid_t gw_nid) | |
472 | { | |
7e7ab095 MS |
473 | struct lnet_peer *gateway; |
474 | lnet_remotenet_t *rnet; | |
475 | lnet_route_t *route; | |
476 | struct list_head *e1; | |
477 | struct list_head *e2; | |
478 | int rc = -ENOENT; | |
479 | struct list_head *rn_list; | |
480 | int idx = 0; | |
d7e09d03 PT |
481 | |
482 | CDEBUG(D_NET, "Del route: net %s : gw %s\n", | |
483 | libcfs_net2str(net), libcfs_nid2str(gw_nid)); | |
484 | ||
4420cfd3 JS |
485 | /* |
486 | * NB Caller may specify either all routes via the given gateway | |
487 | * or a specific route entry actual NIDs) | |
488 | */ | |
d7e09d03 PT |
489 | lnet_net_lock(LNET_LOCK_EX); |
490 | if (net == LNET_NIDNET(LNET_NID_ANY)) | |
491 | rn_list = &the_lnet.ln_remote_nets_hash[0]; | |
492 | else | |
493 | rn_list = lnet_net2rnethash(net); | |
494 | ||
495 | again: | |
496 | list_for_each(e1, rn_list) { | |
497 | rnet = list_entry(e1, lnet_remotenet_t, lrn_list); | |
498 | ||
499 | if (!(net == LNET_NIDNET(LNET_NID_ANY) || | |
c314c319 | 500 | net == rnet->lrn_net)) |
d7e09d03 PT |
501 | continue; |
502 | ||
503 | list_for_each(e2, &rnet->lrn_routes) { | |
504 | route = list_entry(e2, lnet_route_t, lr_list); | |
505 | ||
506 | gateway = route->lr_gateway; | |
507 | if (!(gw_nid == LNET_NID_ANY || | |
508 | gw_nid == gateway->lp_nid)) | |
509 | continue; | |
510 | ||
511 | list_del(&route->lr_list); | |
512 | list_del(&route->lr_gwlist); | |
513 | the_lnet.ln_remote_nets_version++; | |
514 | ||
515 | if (list_empty(&rnet->lrn_routes)) | |
516 | list_del(&rnet->lrn_list); | |
517 | else | |
518 | rnet = NULL; | |
519 | ||
520 | lnet_rtr_decref_locked(gateway); | |
521 | lnet_peer_decref_locked(gateway); | |
522 | ||
523 | lnet_net_unlock(LNET_LOCK_EX); | |
524 | ||
525 | LIBCFS_FREE(route, sizeof(*route)); | |
526 | ||
06ace26e | 527 | if (rnet) |
d7e09d03 PT |
528 | LIBCFS_FREE(rnet, sizeof(*rnet)); |
529 | ||
530 | rc = 0; | |
531 | lnet_net_lock(LNET_LOCK_EX); | |
532 | goto again; | |
533 | } | |
534 | } | |
535 | ||
536 | if (net == LNET_NIDNET(LNET_NID_ANY) && | |
537 | ++idx < LNET_REMOTE_NETS_HASH_SIZE) { | |
538 | rn_list = &the_lnet.ln_remote_nets_hash[idx]; | |
539 | goto again; | |
540 | } | |
541 | lnet_net_unlock(LNET_LOCK_EX); | |
542 | ||
543 | return rc; | |
544 | } | |
545 | ||
546 | void | |
939af333 | 547 | lnet_destroy_routes(void) |
d7e09d03 PT |
548 | { |
549 | lnet_del_route(LNET_NIDNET(LNET_NID_ANY), LNET_NID_ANY); | |
550 | } | |
551 | ||
edeb5d8c AS |
552 | int lnet_get_rtr_pool_cfg(int idx, struct lnet_ioctl_pool_cfg *pool_cfg) |
553 | { | |
554 | int i, rc = -ENOENT, j; | |
555 | ||
556 | if (!the_lnet.ln_rtrpools) | |
557 | return rc; | |
558 | ||
559 | for (i = 0; i < LNET_NRBPOOLS; i++) { | |
560 | lnet_rtrbufpool_t *rbp; | |
561 | ||
562 | lnet_net_lock(LNET_LOCK_EX); | |
563 | cfs_percpt_for_each(rbp, j, the_lnet.ln_rtrpools) { | |
564 | if (i++ != idx) | |
565 | continue; | |
566 | ||
567 | pool_cfg->pl_pools[i].pl_npages = rbp[i].rbp_npages; | |
568 | pool_cfg->pl_pools[i].pl_nbuffers = rbp[i].rbp_nbuffers; | |
569 | pool_cfg->pl_pools[i].pl_credits = rbp[i].rbp_credits; | |
570 | pool_cfg->pl_pools[i].pl_mincredits = rbp[i].rbp_mincredits; | |
571 | rc = 0; | |
572 | break; | |
573 | } | |
574 | lnet_net_unlock(LNET_LOCK_EX); | |
575 | } | |
576 | ||
577 | lnet_net_lock(LNET_LOCK_EX); | |
578 | pool_cfg->pl_routing = the_lnet.ln_routing; | |
579 | lnet_net_unlock(LNET_LOCK_EX); | |
580 | ||
581 | return rc; | |
582 | } | |
583 | ||
d7e09d03 PT |
584 | int |
585 | lnet_get_route(int idx, __u32 *net, __u32 *hops, | |
e75fb87f | 586 | lnet_nid_t *gateway, __u32 *alive, __u32 *priority) |
d7e09d03 | 587 | { |
7e7ab095 MS |
588 | struct list_head *e1; |
589 | struct list_head *e2; | |
590 | lnet_remotenet_t *rnet; | |
591 | lnet_route_t *route; | |
592 | int cpt; | |
593 | int i; | |
594 | struct list_head *rn_list; | |
d7e09d03 PT |
595 | |
596 | cpt = lnet_net_lock_current(); | |
597 | ||
598 | for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) { | |
599 | rn_list = &the_lnet.ln_remote_nets_hash[i]; | |
600 | list_for_each(e1, rn_list) { | |
601 | rnet = list_entry(e1, lnet_remotenet_t, lrn_list); | |
602 | ||
603 | list_for_each(e2, &rnet->lrn_routes) { | |
c314c319 | 604 | route = list_entry(e2, lnet_route_t, lr_list); |
d7e09d03 | 605 | |
5fd88337 | 606 | if (!idx--) { |
7e7ab095 MS |
607 | *net = rnet->lrn_net; |
608 | *hops = route->lr_hops; | |
e75fb87f DO |
609 | *priority = route->lr_priority; |
610 | *gateway = route->lr_gateway->lp_nid; | |
e9f25919 | 611 | *alive = lnet_is_route_alive(route); |
d7e09d03 PT |
612 | lnet_net_unlock(cpt); |
613 | return 0; | |
614 | } | |
615 | } | |
616 | } | |
617 | } | |
618 | ||
619 | lnet_net_unlock(cpt); | |
620 | return -ENOENT; | |
621 | } | |
622 | ||
623 | void | |
624 | lnet_swap_pinginfo(lnet_ping_info_t *info) | |
625 | { | |
7e7ab095 | 626 | int i; |
d7e09d03 PT |
627 | lnet_ni_status_t *stat; |
628 | ||
629 | __swab32s(&info->pi_magic); | |
630 | __swab32s(&info->pi_features); | |
631 | __swab32s(&info->pi_pid); | |
632 | __swab32s(&info->pi_nnis); | |
633 | for (i = 0; i < info->pi_nnis && i < LNET_MAX_RTR_NIS; i++) { | |
634 | stat = &info->pi_ni[i]; | |
635 | __swab64s(&stat->ns_nid); | |
636 | __swab32s(&stat->ns_status); | |
637 | } | |
d7e09d03 PT |
638 | } |
639 | ||
640 | /** | |
641 | * parse router-checker pinginfo, record number of down NIs for remote | |
642 | * networks on that router. | |
643 | */ | |
644 | static void | |
645 | lnet_parse_rc_info(lnet_rc_data_t *rcd) | |
646 | { | |
7e7ab095 MS |
647 | lnet_ping_info_t *info = rcd->rcd_pinginfo; |
648 | struct lnet_peer *gw = rcd->rcd_gateway; | |
86ef6250 | 649 | lnet_route_t *rte; |
d7e09d03 PT |
650 | |
651 | if (!gw->lp_alive) | |
652 | return; | |
653 | ||
654 | if (info->pi_magic == __swab32(LNET_PROTO_PING_MAGIC)) | |
655 | lnet_swap_pinginfo(info); | |
656 | ||
657 | /* NB always racing with network! */ | |
658 | if (info->pi_magic != LNET_PROTO_PING_MAGIC) { | |
659 | CDEBUG(D_NET, "%s: Unexpected magic %08x\n", | |
660 | libcfs_nid2str(gw->lp_nid), info->pi_magic); | |
661 | gw->lp_ping_feats = LNET_PING_FEAT_INVAL; | |
662 | return; | |
663 | } | |
664 | ||
665 | gw->lp_ping_feats = info->pi_features; | |
5fd88337 | 666 | if (!(gw->lp_ping_feats & LNET_PING_FEAT_MASK)) { |
d7e09d03 PT |
667 | CDEBUG(D_NET, "%s: Unexpected features 0x%x\n", |
668 | libcfs_nid2str(gw->lp_nid), gw->lp_ping_feats); | |
669 | return; /* nothing I can understand */ | |
670 | } | |
671 | ||
5fd88337 | 672 | if (!(gw->lp_ping_feats & LNET_PING_FEAT_NI_STATUS)) |
d7e09d03 PT |
673 | return; /* can't carry NI status info */ |
674 | ||
86ef6250 | 675 | list_for_each_entry(rte, &gw->lp_routes, lr_gwlist) { |
7e7ab095 MS |
676 | int down = 0; |
677 | int up = 0; | |
678 | int i; | |
d7e09d03 | 679 | |
86ef6250 AS |
680 | if (gw->lp_ping_feats & LNET_PING_FEAT_RTE_DISABLED) { |
681 | rte->lr_downis = 1; | |
682 | continue; | |
683 | } | |
684 | ||
d7e09d03 PT |
685 | for (i = 0; i < info->pi_nnis && i < LNET_MAX_RTR_NIS; i++) { |
686 | lnet_ni_status_t *stat = &info->pi_ni[i]; | |
7e7ab095 | 687 | lnet_nid_t nid = stat->ns_nid; |
d7e09d03 PT |
688 | |
689 | if (nid == LNET_NID_ANY) { | |
690 | CDEBUG(D_NET, "%s: unexpected LNET_NID_ANY\n", | |
691 | libcfs_nid2str(gw->lp_nid)); | |
692 | gw->lp_ping_feats = LNET_PING_FEAT_INVAL; | |
693 | return; | |
694 | } | |
695 | ||
696 | if (LNET_NETTYP(LNET_NIDNET(nid)) == LOLND) | |
697 | continue; | |
698 | ||
699 | if (stat->ns_status == LNET_NI_STATUS_DOWN) { | |
764d2e9a | 700 | down++; |
d7e09d03 PT |
701 | continue; |
702 | } | |
703 | ||
704 | if (stat->ns_status == LNET_NI_STATUS_UP) { | |
86ef6250 | 705 | if (LNET_NIDNET(nid) == rte->lr_net) { |
d7e09d03 PT |
706 | up = 1; |
707 | break; | |
708 | } | |
d7e09d03 PT |
709 | continue; |
710 | } | |
711 | ||
712 | CDEBUG(D_NET, "%s: Unexpected status 0x%x\n", | |
713 | libcfs_nid2str(gw->lp_nid), stat->ns_status); | |
714 | gw->lp_ping_feats = LNET_PING_FEAT_INVAL; | |
715 | return; | |
716 | } | |
717 | ||
718 | if (up) { /* ignore downed NIs if NI for dest network is up */ | |
86ef6250 | 719 | rte->lr_downis = 0; |
d7e09d03 PT |
720 | continue; |
721 | } | |
e816f235 LZ |
722 | /** |
723 | * if @down is zero and this route is single-hop, it means | |
724 | * we can't find NI for target network | |
725 | */ | |
726 | if (!down && rte->lr_hops == 1) | |
727 | down = 1; | |
728 | ||
86ef6250 | 729 | rte->lr_downis = down; |
d7e09d03 PT |
730 | } |
731 | } | |
732 | ||
733 | static void | |
734 | lnet_router_checker_event(lnet_event_t *event) | |
735 | { | |
7e7ab095 MS |
736 | lnet_rc_data_t *rcd = event->md.user_ptr; |
737 | struct lnet_peer *lp; | |
d7e09d03 | 738 | |
06ace26e | 739 | LASSERT(rcd); |
d7e09d03 PT |
740 | |
741 | if (event->unlinked) { | |
742 | LNetInvalidateHandle(&rcd->rcd_mdh); | |
743 | return; | |
744 | } | |
745 | ||
746 | LASSERT(event->type == LNET_EVENT_SEND || | |
747 | event->type == LNET_EVENT_REPLY); | |
748 | ||
749 | lp = rcd->rcd_gateway; | |
06ace26e | 750 | LASSERT(lp); |
d7e09d03 | 751 | |
4420cfd3 JS |
752 | /* |
753 | * NB: it's called with holding lnet_res_lock, we have a few | |
754 | * places need to hold both locks at the same time, please take | |
755 | * care of lock ordering | |
756 | */ | |
d7e09d03 PT |
757 | lnet_net_lock(lp->lp_cpt); |
758 | if (!lnet_isrouter(lp) || lp->lp_rcd != rcd) { | |
759 | /* ignore if no longer a router or rcd is replaced */ | |
760 | goto out; | |
761 | } | |
762 | ||
763 | if (event->type == LNET_EVENT_SEND) { | |
764 | lp->lp_ping_notsent = 0; | |
5fd88337 | 765 | if (!event->status) |
d7e09d03 PT |
766 | goto out; |
767 | } | |
768 | ||
769 | /* LNET_EVENT_REPLY */ | |
4420cfd3 JS |
770 | /* |
771 | * A successful REPLY means the router is up. If _any_ comms | |
d7e09d03 PT |
772 | * to the router fail I assume it's down (this will happen if |
773 | * we ping alive routers to try to detect router death before | |
4420cfd3 JS |
774 | * apps get burned). |
775 | */ | |
5fd88337 | 776 | lnet_notify_locked(lp, 1, !event->status, cfs_time_current()); |
4420cfd3 JS |
777 | |
778 | /* | |
779 | * The router checker will wake up very shortly and do the | |
d7e09d03 PT |
780 | * actual notification. |
781 | * XXX If 'lp' stops being a router before then, it will still | |
4420cfd3 JS |
782 | * have the notification pending!!! |
783 | */ | |
5fd88337 | 784 | if (avoid_asym_router_failure && !event->status) |
d7e09d03 PT |
785 | lnet_parse_rc_info(rcd); |
786 | ||
787 | out: | |
788 | lnet_net_unlock(lp->lp_cpt); | |
789 | } | |
790 | ||
2595fa36 | 791 | static void |
d7e09d03 PT |
792 | lnet_wait_known_routerstate(void) |
793 | { | |
7e7ab095 MS |
794 | lnet_peer_t *rtr; |
795 | struct list_head *entry; | |
796 | int all_known; | |
d7e09d03 | 797 | |
939af333 | 798 | LASSERT(the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING); |
d7e09d03 PT |
799 | |
800 | for (;;) { | |
7e7ab095 | 801 | int cpt = lnet_net_lock_current(); |
d7e09d03 PT |
802 | |
803 | all_known = 1; | |
939af333 | 804 | list_for_each(entry, &the_lnet.ln_routers) { |
d7e09d03 PT |
805 | rtr = list_entry(entry, lnet_peer_t, lp_rtr_list); |
806 | ||
5fd88337 | 807 | if (!rtr->lp_alive_count) { |
d7e09d03 PT |
808 | all_known = 0; |
809 | break; | |
810 | } | |
811 | } | |
812 | ||
813 | lnet_net_unlock(cpt); | |
814 | ||
815 | if (all_known) | |
816 | return; | |
817 | ||
d3caf4d5 PT |
818 | set_current_state(TASK_UNINTERRUPTIBLE); |
819 | schedule_timeout(cfs_time_seconds(1)); | |
d7e09d03 PT |
820 | } |
821 | } | |
822 | ||
af3fa7c7 LZ |
823 | void |
824 | lnet_router_ni_update_locked(lnet_peer_t *gw, __u32 net) | |
825 | { | |
826 | lnet_route_t *rte; | |
827 | ||
5fd88337 | 828 | if ((gw->lp_ping_feats & LNET_PING_FEAT_NI_STATUS)) { |
af3fa7c7 LZ |
829 | list_for_each_entry(rte, &gw->lp_routes, lr_gwlist) { |
830 | if (rte->lr_net == net) { | |
831 | rte->lr_downis = 0; | |
832 | break; | |
833 | } | |
834 | } | |
835 | } | |
836 | } | |
837 | ||
2595fa36 | 838 | static void |
d7e09d03 PT |
839 | lnet_update_ni_status_locked(void) |
840 | { | |
7e7ab095 | 841 | lnet_ni_t *ni; |
ec0067d1 | 842 | time64_t now; |
7e7ab095 | 843 | int timeout; |
d7e09d03 PT |
844 | |
845 | LASSERT(the_lnet.ln_routing); | |
846 | ||
847 | timeout = router_ping_timeout + | |
0c575417 | 848 | max(live_router_check_interval, dead_router_check_interval); |
d7e09d03 | 849 | |
ec0067d1 | 850 | now = ktime_get_real_seconds(); |
d7e09d03 PT |
851 | list_for_each_entry(ni, &the_lnet.ln_nis, ni_list) { |
852 | if (ni->ni_lnd->lnd_type == LOLND) | |
853 | continue; | |
854 | ||
855 | if (now < ni->ni_last_alive + timeout) | |
856 | continue; | |
857 | ||
858 | lnet_ni_lock(ni); | |
859 | /* re-check with lock */ | |
860 | if (now < ni->ni_last_alive + timeout) { | |
861 | lnet_ni_unlock(ni); | |
862 | continue; | |
863 | } | |
864 | ||
06ace26e | 865 | LASSERT(ni->ni_status); |
d7e09d03 PT |
866 | |
867 | if (ni->ni_status->ns_status != LNET_NI_STATUS_DOWN) { | |
868 | CDEBUG(D_NET, "NI(%s:%d) status changed to down\n", | |
869 | libcfs_nid2str(ni->ni_nid), timeout); | |
4420cfd3 JS |
870 | /* |
871 | * NB: so far, this is the only place to set | |
872 | * NI status to "down" | |
873 | */ | |
d7e09d03 PT |
874 | ni->ni_status->ns_status = LNET_NI_STATUS_DOWN; |
875 | } | |
876 | lnet_ni_unlock(ni); | |
877 | } | |
878 | } | |
879 | ||
2595fa36 | 880 | static void |
d7e09d03 PT |
881 | lnet_destroy_rc_data(lnet_rc_data_t *rcd) |
882 | { | |
883 | LASSERT(list_empty(&rcd->rcd_list)); | |
884 | /* detached from network */ | |
885 | LASSERT(LNetHandleIsInvalid(rcd->rcd_mdh)); | |
886 | ||
06ace26e | 887 | if (rcd->rcd_gateway) { |
d7e09d03 PT |
888 | int cpt = rcd->rcd_gateway->lp_cpt; |
889 | ||
890 | lnet_net_lock(cpt); | |
891 | lnet_peer_decref_locked(rcd->rcd_gateway); | |
892 | lnet_net_unlock(cpt); | |
893 | } | |
894 | ||
06ace26e | 895 | if (rcd->rcd_pinginfo) |
d7e09d03 PT |
896 | LIBCFS_FREE(rcd->rcd_pinginfo, LNET_PINGINFO_SIZE); |
897 | ||
898 | LIBCFS_FREE(rcd, sizeof(*rcd)); | |
899 | } | |
900 | ||
2595fa36 | 901 | static lnet_rc_data_t * |
d7e09d03 PT |
902 | lnet_create_rc_data_locked(lnet_peer_t *gateway) |
903 | { | |
7e7ab095 MS |
904 | lnet_rc_data_t *rcd = NULL; |
905 | lnet_ping_info_t *pi; | |
906 | int rc; | |
907 | int i; | |
d7e09d03 PT |
908 | |
909 | lnet_net_unlock(gateway->lp_cpt); | |
910 | ||
911 | LIBCFS_ALLOC(rcd, sizeof(*rcd)); | |
06ace26e | 912 | if (!rcd) |
d7e09d03 PT |
913 | goto out; |
914 | ||
915 | LNetInvalidateHandle(&rcd->rcd_mdh); | |
916 | INIT_LIST_HEAD(&rcd->rcd_list); | |
917 | ||
918 | LIBCFS_ALLOC(pi, LNET_PINGINFO_SIZE); | |
06ace26e | 919 | if (!pi) |
d7e09d03 PT |
920 | goto out; |
921 | ||
d7e09d03 PT |
922 | for (i = 0; i < LNET_MAX_RTR_NIS; i++) { |
923 | pi->pi_ni[i].ns_nid = LNET_NID_ANY; | |
924 | pi->pi_ni[i].ns_status = LNET_NI_STATUS_INVALID; | |
925 | } | |
926 | rcd->rcd_pinginfo = pi; | |
927 | ||
939af333 | 928 | LASSERT(!LNetHandleIsInvalid(the_lnet.ln_rc_eqh)); |
d7e09d03 PT |
929 | rc = LNetMDBind((lnet_md_t){.start = pi, |
930 | .user_ptr = rcd, | |
931 | .length = LNET_PINGINFO_SIZE, | |
932 | .threshold = LNET_MD_THRESH_INF, | |
933 | .options = LNET_MD_TRUNCATE, | |
934 | .eq_handle = the_lnet.ln_rc_eqh}, | |
935 | LNET_UNLINK, | |
936 | &rcd->rcd_mdh); | |
937 | if (rc < 0) { | |
938 | CERROR("Can't bind MD: %d\n", rc); | |
939 | goto out; | |
940 | } | |
5fd88337 | 941 | LASSERT(!rc); |
d7e09d03 PT |
942 | |
943 | lnet_net_lock(gateway->lp_cpt); | |
944 | /* router table changed or someone has created rcd for this gateway */ | |
06ace26e | 945 | if (!lnet_isrouter(gateway) || gateway->lp_rcd) { |
d7e09d03 PT |
946 | lnet_net_unlock(gateway->lp_cpt); |
947 | goto out; | |
948 | } | |
949 | ||
950 | lnet_peer_addref_locked(gateway); | |
951 | rcd->rcd_gateway = gateway; | |
952 | gateway->lp_rcd = rcd; | |
953 | gateway->lp_ping_notsent = 0; | |
954 | ||
955 | return rcd; | |
956 | ||
957 | out: | |
06ace26e | 958 | if (rcd) { |
d7e09d03 PT |
959 | if (!LNetHandleIsInvalid(rcd->rcd_mdh)) { |
960 | rc = LNetMDUnlink(rcd->rcd_mdh); | |
5fd88337 | 961 | LASSERT(!rc); |
d7e09d03 PT |
962 | } |
963 | lnet_destroy_rc_data(rcd); | |
964 | } | |
965 | ||
966 | lnet_net_lock(gateway->lp_cpt); | |
967 | return gateway->lp_rcd; | |
968 | } | |
969 | ||
970 | static int | |
939af333 | 971 | lnet_router_check_interval(lnet_peer_t *rtr) |
d7e09d03 PT |
972 | { |
973 | int secs; | |
974 | ||
975 | secs = rtr->lp_alive ? live_router_check_interval : | |
976 | dead_router_check_interval; | |
977 | if (secs < 0) | |
978 | secs = 0; | |
979 | ||
980 | return secs; | |
981 | } | |
982 | ||
983 | static void | |
939af333 | 984 | lnet_ping_router_locked(lnet_peer_t *rtr) |
d7e09d03 PT |
985 | { |
986 | lnet_rc_data_t *rcd = NULL; | |
7e7ab095 MS |
987 | unsigned long now = cfs_time_current(); |
988 | int secs; | |
d7e09d03 PT |
989 | |
990 | lnet_peer_addref_locked(rtr); | |
991 | ||
5fd88337 | 992 | if (rtr->lp_ping_deadline && /* ping timed out? */ |
d7e09d03 PT |
993 | cfs_time_after(now, rtr->lp_ping_deadline)) |
994 | lnet_notify_locked(rtr, 1, 0, now); | |
995 | ||
996 | /* Run any outstanding notifications */ | |
997 | lnet_ni_notify_locked(rtr->lp_ni, rtr); | |
998 | ||
999 | if (!lnet_isrouter(rtr) || | |
1000 | the_lnet.ln_rc_state != LNET_RC_STATE_RUNNING) { | |
1001 | /* router table changed or router checker is shutting down */ | |
1002 | lnet_peer_decref_locked(rtr); | |
1003 | return; | |
1004 | } | |
1005 | ||
06ace26e | 1006 | rcd = rtr->lp_rcd ? |
d7e09d03 PT |
1007 | rtr->lp_rcd : lnet_create_rc_data_locked(rtr); |
1008 | ||
06ace26e | 1009 | if (!rcd) |
d7e09d03 PT |
1010 | return; |
1011 | ||
1012 | secs = lnet_router_check_interval(rtr); | |
1013 | ||
1014 | CDEBUG(D_NET, | |
2d00bd17 | 1015 | "rtr %s %d: deadline %lu ping_notsent %d alive %d alive_count %d lp_ping_timestamp %lu\n", |
d7e09d03 PT |
1016 | libcfs_nid2str(rtr->lp_nid), secs, |
1017 | rtr->lp_ping_deadline, rtr->lp_ping_notsent, | |
1018 | rtr->lp_alive, rtr->lp_alive_count, rtr->lp_ping_timestamp); | |
1019 | ||
5fd88337 | 1020 | if (secs && !rtr->lp_ping_notsent && |
d7e09d03 PT |
1021 | cfs_time_after(now, cfs_time_add(rtr->lp_ping_timestamp, |
1022 | cfs_time_seconds(secs)))) { | |
7e7ab095 | 1023 | int rc; |
d7e09d03 | 1024 | lnet_process_id_t id; |
7e7ab095 | 1025 | lnet_handle_md_t mdh; |
d7e09d03 PT |
1026 | |
1027 | id.nid = rtr->lp_nid; | |
fe7cb65d | 1028 | id.pid = LNET_PID_LUSTRE; |
d7e09d03 PT |
1029 | CDEBUG(D_NET, "Check: %s\n", libcfs_id2str(id)); |
1030 | ||
1031 | rtr->lp_ping_notsent = 1; | |
1032 | rtr->lp_ping_timestamp = now; | |
1033 | ||
1034 | mdh = rcd->rcd_mdh; | |
1035 | ||
5fd88337 | 1036 | if (!rtr->lp_ping_deadline) { |
d7e09d03 PT |
1037 | rtr->lp_ping_deadline = |
1038 | cfs_time_shift(router_ping_timeout); | |
1039 | } | |
1040 | ||
1041 | lnet_net_unlock(rtr->lp_cpt); | |
1042 | ||
1043 | rc = LNetGet(LNET_NID_ANY, mdh, id, LNET_RESERVED_PORTAL, | |
1044 | LNET_PROTO_PING_MATCHBITS, 0); | |
1045 | ||
1046 | lnet_net_lock(rtr->lp_cpt); | |
5fd88337 | 1047 | if (rc) |
d7e09d03 PT |
1048 | rtr->lp_ping_notsent = 0; /* no event pending */ |
1049 | } | |
1050 | ||
1051 | lnet_peer_decref_locked(rtr); | |
d7e09d03 PT |
1052 | } |
1053 | ||
1054 | int | |
1055 | lnet_router_checker_start(void) | |
1056 | { | |
060c2820 | 1057 | struct task_struct *task; |
7e7ab095 | 1058 | int rc; |
94bfb3cf | 1059 | int eqsz = 0; |
d7e09d03 | 1060 | |
939af333 | 1061 | LASSERT(the_lnet.ln_rc_state == LNET_RC_STATE_SHUTDOWN); |
d7e09d03 PT |
1062 | |
1063 | if (check_routers_before_use && | |
1064 | dead_router_check_interval <= 0) { | |
2d00bd17 | 1065 | LCONSOLE_ERROR_MSG(0x10a, "'dead_router_check_interval' must be set if 'check_routers_before_use' is set\n"); |
d7e09d03 PT |
1066 | return -EINVAL; |
1067 | } | |
1068 | ||
21ca52bb | 1069 | init_completion(&the_lnet.ln_rc_signal); |
94bfb3cf JH |
1070 | |
1071 | rc = LNetEQAlloc(0, lnet_router_checker_event, &the_lnet.ln_rc_eqh); | |
5fd88337 | 1072 | if (rc) { |
d7e09d03 PT |
1073 | CERROR("Can't allocate EQ(%d): %d\n", eqsz, rc); |
1074 | return -ENOMEM; | |
1075 | } | |
1076 | ||
1077 | the_lnet.ln_rc_state = LNET_RC_STATE_RUNNING; | |
060c2820 JH |
1078 | task = kthread_run(lnet_router_checker, NULL, "router_checker"); |
1079 | if (IS_ERR(task)) { | |
1080 | rc = PTR_ERR(task); | |
d7e09d03 PT |
1081 | CERROR("Can't start router checker thread: %d\n", rc); |
1082 | /* block until event callback signals exit */ | |
21ca52bb | 1083 | wait_for_completion(&the_lnet.ln_rc_signal); |
d7e09d03 | 1084 | rc = LNetEQFree(the_lnet.ln_rc_eqh); |
5fd88337 | 1085 | LASSERT(!rc); |
d7e09d03 PT |
1086 | the_lnet.ln_rc_state = LNET_RC_STATE_SHUTDOWN; |
1087 | return -ENOMEM; | |
1088 | } | |
1089 | ||
1090 | if (check_routers_before_use) { | |
4420cfd3 JS |
1091 | /* |
1092 | * Note that a helpful side-effect of pinging all known routers | |
d7e09d03 | 1093 | * at startup is that it makes them drop stale connections they |
4420cfd3 JS |
1094 | * may have to a previous instance of me. |
1095 | */ | |
d7e09d03 PT |
1096 | lnet_wait_known_routerstate(); |
1097 | } | |
1098 | ||
1099 | return 0; | |
1100 | } | |
1101 | ||
1102 | void | |
939af333 | 1103 | lnet_router_checker_stop(void) |
d7e09d03 PT |
1104 | { |
1105 | int rc; | |
1106 | ||
1107 | if (the_lnet.ln_rc_state == LNET_RC_STATE_SHUTDOWN) | |
1108 | return; | |
1109 | ||
939af333 | 1110 | LASSERT(the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING); |
d7e09d03 | 1111 | the_lnet.ln_rc_state = LNET_RC_STATE_STOPPING; |
7f8b70e0 AS |
1112 | /* wakeup the RC thread if it's sleeping */ |
1113 | wake_up(&the_lnet.ln_rc_waitq); | |
d7e09d03 PT |
1114 | |
1115 | /* block until event callback signals exit */ | |
21ca52bb | 1116 | wait_for_completion(&the_lnet.ln_rc_signal); |
d7e09d03 PT |
1117 | LASSERT(the_lnet.ln_rc_state == LNET_RC_STATE_SHUTDOWN); |
1118 | ||
1119 | rc = LNetEQFree(the_lnet.ln_rc_eqh); | |
5fd88337 | 1120 | LASSERT(!rc); |
d7e09d03 PT |
1121 | } |
1122 | ||
1123 | static void | |
1124 | lnet_prune_rc_data(int wait_unlink) | |
1125 | { | |
7e7ab095 MS |
1126 | lnet_rc_data_t *rcd; |
1127 | lnet_rc_data_t *tmp; | |
1128 | lnet_peer_t *lp; | |
1129 | struct list_head head; | |
1130 | int i = 2; | |
d7e09d03 PT |
1131 | |
1132 | if (likely(the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING && | |
1133 | list_empty(&the_lnet.ln_rcd_deathrow) && | |
1134 | list_empty(&the_lnet.ln_rcd_zombie))) | |
1135 | return; | |
1136 | ||
1137 | INIT_LIST_HEAD(&head); | |
1138 | ||
1139 | lnet_net_lock(LNET_LOCK_EX); | |
1140 | ||
1141 | if (the_lnet.ln_rc_state != LNET_RC_STATE_RUNNING) { | |
1142 | /* router checker is stopping, prune all */ | |
1143 | list_for_each_entry(lp, &the_lnet.ln_routers, | |
c314c319 | 1144 | lp_rtr_list) { |
06ace26e | 1145 | if (!lp->lp_rcd) |
d7e09d03 PT |
1146 | continue; |
1147 | ||
1148 | LASSERT(list_empty(&lp->lp_rcd->rcd_list)); | |
1149 | list_add(&lp->lp_rcd->rcd_list, | |
c314c319 | 1150 | &the_lnet.ln_rcd_deathrow); |
d7e09d03 PT |
1151 | lp->lp_rcd = NULL; |
1152 | } | |
1153 | } | |
1154 | ||
1155 | /* unlink all RCDs on deathrow list */ | |
1156 | list_splice_init(&the_lnet.ln_rcd_deathrow, &head); | |
1157 | ||
1158 | if (!list_empty(&head)) { | |
1159 | lnet_net_unlock(LNET_LOCK_EX); | |
1160 | ||
1161 | list_for_each_entry(rcd, &head, rcd_list) | |
1162 | LNetMDUnlink(rcd->rcd_mdh); | |
1163 | ||
1164 | lnet_net_lock(LNET_LOCK_EX); | |
1165 | } | |
1166 | ||
1167 | list_splice_init(&head, &the_lnet.ln_rcd_zombie); | |
1168 | ||
1169 | /* release all zombie RCDs */ | |
1170 | while (!list_empty(&the_lnet.ln_rcd_zombie)) { | |
1171 | list_for_each_entry_safe(rcd, tmp, &the_lnet.ln_rcd_zombie, | |
c314c319 | 1172 | rcd_list) { |
d7e09d03 PT |
1173 | if (LNetHandleIsInvalid(rcd->rcd_mdh)) |
1174 | list_move(&rcd->rcd_list, &head); | |
1175 | } | |
1176 | ||
1177 | wait_unlink = wait_unlink && | |
1178 | !list_empty(&the_lnet.ln_rcd_zombie); | |
1179 | ||
1180 | lnet_net_unlock(LNET_LOCK_EX); | |
1181 | ||
1182 | while (!list_empty(&head)) { | |
1183 | rcd = list_entry(head.next, | |
c314c319 | 1184 | lnet_rc_data_t, rcd_list); |
d7e09d03 PT |
1185 | list_del_init(&rcd->rcd_list); |
1186 | lnet_destroy_rc_data(rcd); | |
1187 | } | |
1188 | ||
1189 | if (!wait_unlink) | |
1190 | return; | |
1191 | ||
1192 | i++; | |
1193 | CDEBUG(((i & (-i)) == i) ? D_WARNING : D_NET, | |
1194 | "Waiting for rc buffers to unlink\n"); | |
d3caf4d5 PT |
1195 | set_current_state(TASK_UNINTERRUPTIBLE); |
1196 | schedule_timeout(cfs_time_seconds(1) / 4); | |
d7e09d03 PT |
1197 | |
1198 | lnet_net_lock(LNET_LOCK_EX); | |
1199 | } | |
1200 | ||
1201 | lnet_net_unlock(LNET_LOCK_EX); | |
1202 | } | |
1203 | ||
7f8b70e0 AS |
1204 | /* |
1205 | * This function is called to check if the RC should block indefinitely. | |
1206 | * It's called from lnet_router_checker() as well as being passed to | |
1207 | * wait_event_interruptible() to avoid the lost wake_up problem. | |
1208 | * | |
1209 | * When it's called from wait_event_interruptible() it is necessary to | |
1210 | * also not sleep if the rc state is not running to avoid a deadlock | |
1211 | * when the system is shutting down | |
1212 | */ | |
1213 | static inline bool | |
1214 | lnet_router_checker_active(void) | |
1215 | { | |
1216 | if (the_lnet.ln_rc_state != LNET_RC_STATE_RUNNING) | |
1217 | return true; | |
1218 | ||
1219 | /* | |
1220 | * Router Checker thread needs to run when routing is enabled in | |
1221 | * order to call lnet_update_ni_status_locked() | |
1222 | */ | |
1223 | if (the_lnet.ln_routing) | |
1224 | return true; | |
1225 | ||
1226 | return !list_empty(&the_lnet.ln_routers) && | |
1227 | (live_router_check_interval > 0 || | |
1228 | dead_router_check_interval > 0); | |
1229 | } | |
1230 | ||
d7e09d03 PT |
1231 | static int |
1232 | lnet_router_checker(void *arg) | |
1233 | { | |
7e7ab095 MS |
1234 | lnet_peer_t *rtr; |
1235 | struct list_head *entry; | |
d7e09d03 PT |
1236 | |
1237 | cfs_block_allsigs(); | |
1238 | ||
d7e09d03 | 1239 | while (the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING) { |
7e7ab095 MS |
1240 | __u64 version; |
1241 | int cpt; | |
1242 | int cpt2; | |
d7e09d03 PT |
1243 | |
1244 | cpt = lnet_net_lock_current(); | |
1245 | rescan: | |
1246 | version = the_lnet.ln_routers_version; | |
1247 | ||
1248 | list_for_each(entry, &the_lnet.ln_routers) { | |
1249 | rtr = list_entry(entry, lnet_peer_t, lp_rtr_list); | |
1250 | ||
1251 | cpt2 = lnet_cpt_of_nid_locked(rtr->lp_nid); | |
1252 | if (cpt != cpt2) { | |
1253 | lnet_net_unlock(cpt); | |
1254 | cpt = cpt2; | |
1255 | lnet_net_lock(cpt); | |
1256 | /* the routers list has changed */ | |
1257 | if (version != the_lnet.ln_routers_version) | |
1258 | goto rescan; | |
1259 | } | |
1260 | ||
1261 | lnet_ping_router_locked(rtr); | |
1262 | ||
1263 | /* NB dropped lock */ | |
1264 | if (version != the_lnet.ln_routers_version) { | |
1265 | /* the routers list has changed */ | |
1266 | goto rescan; | |
1267 | } | |
1268 | } | |
1269 | ||
1270 | if (the_lnet.ln_routing) | |
1271 | lnet_update_ni_status_locked(); | |
1272 | ||
1273 | lnet_net_unlock(cpt); | |
1274 | ||
1275 | lnet_prune_rc_data(0); /* don't wait for UNLINK */ | |
1276 | ||
4420cfd3 JS |
1277 | /* |
1278 | * Call schedule_timeout() here always adds 1 to load average | |
d7e09d03 | 1279 | * because kernel counts # active tasks as nr_running |
4420cfd3 JS |
1280 | * + nr_uninterruptible. |
1281 | */ | |
7f8b70e0 AS |
1282 | /* |
1283 | * if there are any routes then wakeup every second. If | |
1284 | * there are no routes then sleep indefinitely until woken | |
1285 | * up by a user adding a route | |
1286 | */ | |
1287 | if (!lnet_router_checker_active()) | |
1288 | wait_event_interruptible(the_lnet.ln_rc_waitq, | |
1289 | lnet_router_checker_active()); | |
1290 | else | |
1291 | wait_event_interruptible_timeout(the_lnet.ln_rc_waitq, | |
1292 | false, | |
1293 | cfs_time_seconds(1)); | |
d7e09d03 PT |
1294 | } |
1295 | ||
d7e09d03 PT |
1296 | lnet_prune_rc_data(1); /* wait for UNLINK */ |
1297 | ||
1298 | the_lnet.ln_rc_state = LNET_RC_STATE_SHUTDOWN; | |
21ca52bb | 1299 | complete(&the_lnet.ln_rc_signal); |
d7e09d03 PT |
1300 | /* The unlink event callback will signal final completion */ |
1301 | return 0; | |
1302 | } | |
1303 | ||
86ef6250 | 1304 | void |
d7e09d03 PT |
1305 | lnet_destroy_rtrbuf(lnet_rtrbuf_t *rb, int npages) |
1306 | { | |
1307 | int sz = offsetof(lnet_rtrbuf_t, rb_kiov[npages]); | |
1308 | ||
1309 | while (--npages >= 0) | |
65ffc679 | 1310 | __free_page(rb->rb_kiov[npages].bv_page); |
d7e09d03 PT |
1311 | |
1312 | LIBCFS_FREE(rb, sz); | |
1313 | } | |
1314 | ||
2595fa36 | 1315 | static lnet_rtrbuf_t * |
d7e09d03 PT |
1316 | lnet_new_rtrbuf(lnet_rtrbufpool_t *rbp, int cpt) |
1317 | { | |
7e7ab095 MS |
1318 | int npages = rbp->rbp_npages; |
1319 | int sz = offsetof(lnet_rtrbuf_t, rb_kiov[npages]); | |
1320 | struct page *page; | |
d7e09d03 | 1321 | lnet_rtrbuf_t *rb; |
7e7ab095 | 1322 | int i; |
d7e09d03 PT |
1323 | |
1324 | LIBCFS_CPT_ALLOC(rb, lnet_cpt_table(), cpt, sz); | |
06ace26e | 1325 | if (!rb) |
d7e09d03 PT |
1326 | return NULL; |
1327 | ||
1328 | rb->rb_pool = rbp; | |
1329 | ||
1330 | for (i = 0; i < npages; i++) { | |
49c02a75 PT |
1331 | page = alloc_pages_node( |
1332 | cfs_cpt_spread_node(lnet_cpt_table(), cpt), | |
40113370 | 1333 | GFP_KERNEL | __GFP_ZERO, 0); |
06ace26e | 1334 | if (!page) { |
d7e09d03 | 1335 | while (--i >= 0) |
65ffc679 | 1336 | __free_page(rb->rb_kiov[i].bv_page); |
d7e09d03 PT |
1337 | |
1338 | LIBCFS_FREE(rb, sz); | |
1339 | return NULL; | |
1340 | } | |
1341 | ||
65ffc679 AV |
1342 | rb->rb_kiov[i].bv_len = PAGE_SIZE; |
1343 | rb->rb_kiov[i].bv_offset = 0; | |
1344 | rb->rb_kiov[i].bv_page = page; | |
d7e09d03 PT |
1345 | } |
1346 | ||
1347 | return rb; | |
1348 | } | |
1349 | ||
2595fa36 | 1350 | static void |
86ef6250 | 1351 | lnet_rtrpool_free_bufs(lnet_rtrbufpool_t *rbp, int cpt) |
d7e09d03 | 1352 | { |
7e7ab095 | 1353 | int npages = rbp->rbp_npages; |
86ef6250 | 1354 | struct list_head tmp; |
7e7ab095 | 1355 | lnet_rtrbuf_t *rb; |
37cce1bc | 1356 | lnet_rtrbuf_t *temp; |
d7e09d03 | 1357 | |
5fd88337 | 1358 | if (!rbp->rbp_nbuffers) /* not initialized or already freed */ |
d7e09d03 PT |
1359 | return; |
1360 | ||
86ef6250 | 1361 | INIT_LIST_HEAD(&tmp); |
d7e09d03 | 1362 | |
86ef6250 AS |
1363 | lnet_net_lock(cpt); |
1364 | lnet_drop_routed_msgs_locked(&rbp->rbp_msgs, cpt); | |
1365 | list_splice_init(&rbp->rbp_bufs, &tmp); | |
95fc2938 | 1366 | rbp->rbp_req_nbuffers = 0; |
86ef6250 AS |
1367 | rbp->rbp_nbuffers = 0; |
1368 | rbp->rbp_credits = 0; | |
1369 | rbp->rbp_mincredits = 0; | |
1370 | lnet_net_unlock(cpt); | |
d7e09d03 | 1371 | |
86ef6250 | 1372 | /* Free buffers on the free list. */ |
37cce1bc | 1373 | list_for_each_entry_safe(rb, temp, &tmp, rb_list) { |
d7e09d03 PT |
1374 | list_del(&rb->rb_list); |
1375 | lnet_destroy_rtrbuf(rb, npages); | |
d7e09d03 | 1376 | } |
d7e09d03 PT |
1377 | } |
1378 | ||
2595fa36 | 1379 | static int |
86ef6250 | 1380 | lnet_rtrpool_adjust_bufs(lnet_rtrbufpool_t *rbp, int nbufs, int cpt) |
d7e09d03 | 1381 | { |
86ef6250 | 1382 | struct list_head rb_list; |
d7e09d03 | 1383 | lnet_rtrbuf_t *rb; |
86ef6250 AS |
1384 | int num_rb; |
1385 | int num_buffers = 0; | |
95fc2938 | 1386 | int old_req_nbufs; |
86ef6250 | 1387 | int npages = rbp->rbp_npages; |
d7e09d03 | 1388 | |
95fc2938 | 1389 | lnet_net_lock(cpt); |
86ef6250 AS |
1390 | /* |
1391 | * If we are called for less buffers than already in the pool, we | |
95fc2938 | 1392 | * just lower the req_nbuffers number and excess buffers will be |
86ef6250 AS |
1393 | * thrown away as they are returned to the free list. Credits |
1394 | * then get adjusted as well. | |
95fc2938 AS |
1395 | * If we already have enough buffers allocated to serve the |
1396 | * increase requested, then we can treat that the same way as we | |
1397 | * do the decrease. | |
86ef6250 | 1398 | */ |
95fc2938 AS |
1399 | num_rb = nbufs - rbp->rbp_nbuffers; |
1400 | if (nbufs <= rbp->rbp_req_nbuffers || num_rb <= 0) { | |
1401 | rbp->rbp_req_nbuffers = nbufs; | |
86ef6250 | 1402 | lnet_net_unlock(cpt); |
d7e09d03 PT |
1403 | return 0; |
1404 | } | |
95fc2938 AS |
1405 | /* |
1406 | * store the older value of rbp_req_nbuffers and then set it to | |
1407 | * the new request to prevent lnet_return_rx_credits_locked() from | |
1408 | * freeing buffers that we need to keep around | |
1409 | */ | |
1410 | old_req_nbufs = rbp->rbp_req_nbuffers; | |
1411 | rbp->rbp_req_nbuffers = nbufs; | |
1412 | lnet_net_unlock(cpt); | |
d7e09d03 | 1413 | |
86ef6250 | 1414 | INIT_LIST_HEAD(&rb_list); |
d7e09d03 | 1415 | |
86ef6250 AS |
1416 | /* |
1417 | * allocate the buffers on a local list first. If all buffers are | |
1418 | * allocated successfully then join this list to the rbp buffer | |
1419 | * list. If not then free all allocated buffers. | |
1420 | */ | |
95fc2938 | 1421 | while (num_rb-- > 0) { |
86ef6250 | 1422 | rb = lnet_new_rtrbuf(rbp, cpt); |
06ace26e | 1423 | if (!rb) { |
86ef6250 AS |
1424 | CERROR("Failed to allocate %d route bufs of %d pages\n", |
1425 | nbufs, npages); | |
95fc2938 AS |
1426 | |
1427 | lnet_net_lock(cpt); | |
1428 | rbp->rbp_req_nbuffers = old_req_nbufs; | |
1429 | lnet_net_unlock(cpt); | |
1430 | ||
86ef6250 | 1431 | goto failed; |
d7e09d03 PT |
1432 | } |
1433 | ||
86ef6250 AS |
1434 | list_add(&rb->rb_list, &rb_list); |
1435 | num_buffers++; | |
d7e09d03 PT |
1436 | } |
1437 | ||
86ef6250 AS |
1438 | lnet_net_lock(cpt); |
1439 | ||
1440 | list_splice_tail(&rb_list, &rbp->rbp_bufs); | |
1441 | rbp->rbp_nbuffers += num_buffers; | |
1442 | rbp->rbp_credits += num_buffers; | |
1443 | rbp->rbp_mincredits = rbp->rbp_credits; | |
1444 | /* | |
1445 | * We need to schedule blocked msg using the newly | |
1446 | * added buffers. | |
1447 | */ | |
1448 | while (!list_empty(&rbp->rbp_bufs) && | |
1449 | !list_empty(&rbp->rbp_msgs)) | |
1450 | lnet_schedule_blocked_locked(rbp); | |
1451 | ||
1452 | lnet_net_unlock(cpt); | |
1453 | ||
d7e09d03 | 1454 | return 0; |
86ef6250 AS |
1455 | |
1456 | failed: | |
1457 | while (!list_empty(&rb_list)) { | |
1458 | rb = list_entry(rb_list.next, lnet_rtrbuf_t, rb_list); | |
1459 | list_del(&rb->rb_list); | |
1460 | lnet_destroy_rtrbuf(rb, npages); | |
1461 | } | |
1462 | ||
1463 | return -ENOMEM; | |
d7e09d03 PT |
1464 | } |
1465 | ||
2595fa36 | 1466 | static void |
d7e09d03 PT |
1467 | lnet_rtrpool_init(lnet_rtrbufpool_t *rbp, int npages) |
1468 | { | |
1469 | INIT_LIST_HEAD(&rbp->rbp_msgs); | |
1470 | INIT_LIST_HEAD(&rbp->rbp_bufs); | |
1471 | ||
1472 | rbp->rbp_npages = npages; | |
1473 | rbp->rbp_credits = 0; | |
1474 | rbp->rbp_mincredits = 0; | |
1475 | } | |
1476 | ||
1477 | void | |
86ef6250 | 1478 | lnet_rtrpools_free(int keep_pools) |
d7e09d03 PT |
1479 | { |
1480 | lnet_rtrbufpool_t *rtrp; | |
7e7ab095 | 1481 | int i; |
d7e09d03 | 1482 | |
06ace26e | 1483 | if (!the_lnet.ln_rtrpools) /* uninitialized or freed */ |
d7e09d03 PT |
1484 | return; |
1485 | ||
1486 | cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) { | |
86ef6250 AS |
1487 | lnet_rtrpool_free_bufs(&rtrp[LNET_TINY_BUF_IDX], i); |
1488 | lnet_rtrpool_free_bufs(&rtrp[LNET_SMALL_BUF_IDX], i); | |
1489 | lnet_rtrpool_free_bufs(&rtrp[LNET_LARGE_BUF_IDX], i); | |
d7e09d03 PT |
1490 | } |
1491 | ||
86ef6250 AS |
1492 | if (!keep_pools) { |
1493 | cfs_percpt_free(the_lnet.ln_rtrpools); | |
1494 | the_lnet.ln_rtrpools = NULL; | |
1495 | } | |
d7e09d03 PT |
1496 | } |
1497 | ||
1498 | static int | |
86ef6250 | 1499 | lnet_nrb_tiny_calculate(void) |
d7e09d03 | 1500 | { |
7e7ab095 | 1501 | int nrbs = LNET_NRB_TINY; |
d7e09d03 PT |
1502 | |
1503 | if (tiny_router_buffers < 0) { | |
1504 | LCONSOLE_ERROR_MSG(0x10c, | |
2d00bd17 JP |
1505 | "tiny_router_buffers=%d invalid when routing enabled\n", |
1506 | tiny_router_buffers); | |
58cb2ad3 | 1507 | return -EINVAL; |
d7e09d03 PT |
1508 | } |
1509 | ||
1510 | if (tiny_router_buffers > 0) | |
1511 | nrbs = tiny_router_buffers; | |
1512 | ||
1513 | nrbs /= LNET_CPT_NUMBER; | |
1514 | return max(nrbs, LNET_NRB_TINY_MIN); | |
1515 | } | |
1516 | ||
1517 | static int | |
86ef6250 | 1518 | lnet_nrb_small_calculate(void) |
d7e09d03 | 1519 | { |
7e7ab095 | 1520 | int nrbs = LNET_NRB_SMALL; |
d7e09d03 PT |
1521 | |
1522 | if (small_router_buffers < 0) { | |
1523 | LCONSOLE_ERROR_MSG(0x10c, | |
2d00bd17 JP |
1524 | "small_router_buffers=%d invalid when routing enabled\n", |
1525 | small_router_buffers); | |
58cb2ad3 | 1526 | return -EINVAL; |
d7e09d03 PT |
1527 | } |
1528 | ||
1529 | if (small_router_buffers > 0) | |
1530 | nrbs = small_router_buffers; | |
1531 | ||
1532 | nrbs /= LNET_CPT_NUMBER; | |
1533 | return max(nrbs, LNET_NRB_SMALL_MIN); | |
1534 | } | |
1535 | ||
1536 | static int | |
86ef6250 | 1537 | lnet_nrb_large_calculate(void) |
d7e09d03 | 1538 | { |
7e7ab095 | 1539 | int nrbs = LNET_NRB_LARGE; |
d7e09d03 PT |
1540 | |
1541 | if (large_router_buffers < 0) { | |
1542 | LCONSOLE_ERROR_MSG(0x10c, | |
2d00bd17 JP |
1543 | "large_router_buffers=%d invalid when routing enabled\n", |
1544 | large_router_buffers); | |
58cb2ad3 | 1545 | return -EINVAL; |
d7e09d03 PT |
1546 | } |
1547 | ||
1548 | if (large_router_buffers > 0) | |
1549 | nrbs = large_router_buffers; | |
1550 | ||
1551 | nrbs /= LNET_CPT_NUMBER; | |
1552 | return max(nrbs, LNET_NRB_LARGE_MIN); | |
1553 | } | |
1554 | ||
1555 | int | |
1556 | lnet_rtrpools_alloc(int im_a_router) | |
1557 | { | |
1558 | lnet_rtrbufpool_t *rtrp; | |
7e7ab095 MS |
1559 | int nrb_tiny; |
1560 | int nrb_small; | |
1561 | int nrb_large; | |
1562 | int rc; | |
1563 | int i; | |
d7e09d03 PT |
1564 | |
1565 | if (!strcmp(forwarding, "")) { | |
1566 | /* not set either way */ | |
1567 | if (!im_a_router) | |
1568 | return 0; | |
1569 | } else if (!strcmp(forwarding, "disabled")) { | |
1570 | /* explicitly disabled */ | |
1571 | return 0; | |
1572 | } else if (!strcmp(forwarding, "enabled")) { | |
1573 | /* explicitly enabled */ | |
1574 | } else { | |
2d00bd17 | 1575 | LCONSOLE_ERROR_MSG(0x10b, "'forwarding' not set to either 'enabled' or 'disabled'\n"); |
d7e09d03 PT |
1576 | return -EINVAL; |
1577 | } | |
1578 | ||
86ef6250 | 1579 | nrb_tiny = lnet_nrb_tiny_calculate(); |
d7e09d03 PT |
1580 | if (nrb_tiny < 0) |
1581 | return -EINVAL; | |
1582 | ||
86ef6250 | 1583 | nrb_small = lnet_nrb_small_calculate(); |
d7e09d03 PT |
1584 | if (nrb_small < 0) |
1585 | return -EINVAL; | |
1586 | ||
86ef6250 | 1587 | nrb_large = lnet_nrb_large_calculate(); |
d7e09d03 PT |
1588 | if (nrb_large < 0) |
1589 | return -EINVAL; | |
1590 | ||
1591 | the_lnet.ln_rtrpools = cfs_percpt_alloc(lnet_cpt_table(), | |
1592 | LNET_NRBPOOLS * | |
1593 | sizeof(lnet_rtrbufpool_t)); | |
06ace26e | 1594 | if (!the_lnet.ln_rtrpools) { |
d7e09d03 PT |
1595 | LCONSOLE_ERROR_MSG(0x10c, |
1596 | "Failed to initialize router buffe pool\n"); | |
1597 | return -ENOMEM; | |
1598 | } | |
1599 | ||
1600 | cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) { | |
86ef6250 AS |
1601 | lnet_rtrpool_init(&rtrp[LNET_TINY_BUF_IDX], 0); |
1602 | rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_TINY_BUF_IDX], | |
1603 | nrb_tiny, i); | |
5fd88337 | 1604 | if (rc) |
d7e09d03 PT |
1605 | goto failed; |
1606 | ||
86ef6250 AS |
1607 | lnet_rtrpool_init(&rtrp[LNET_SMALL_BUF_IDX], |
1608 | LNET_NRB_SMALL_PAGES); | |
1609 | rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_SMALL_BUF_IDX], | |
1610 | nrb_small, i); | |
5fd88337 | 1611 | if (rc) |
d7e09d03 PT |
1612 | goto failed; |
1613 | ||
86ef6250 AS |
1614 | lnet_rtrpool_init(&rtrp[LNET_LARGE_BUF_IDX], |
1615 | LNET_NRB_LARGE_PAGES); | |
1616 | rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_LARGE_BUF_IDX], | |
1617 | nrb_large, i); | |
5fd88337 | 1618 | if (rc) |
d7e09d03 PT |
1619 | goto failed; |
1620 | } | |
1621 | ||
1622 | lnet_net_lock(LNET_LOCK_EX); | |
1623 | the_lnet.ln_routing = 1; | |
1624 | lnet_net_unlock(LNET_LOCK_EX); | |
1625 | ||
1626 | return 0; | |
1627 | ||
1628 | failed: | |
86ef6250 | 1629 | lnet_rtrpools_free(0); |
d7e09d03 PT |
1630 | return rc; |
1631 | } | |
1632 | ||
edeb5d8c AS |
1633 | static int |
1634 | lnet_rtrpools_adjust_helper(int tiny, int small, int large) | |
86ef6250 AS |
1635 | { |
1636 | int nrb = 0; | |
1637 | int rc = 0; | |
1638 | int i; | |
1639 | lnet_rtrbufpool_t *rtrp; | |
1640 | ||
86ef6250 AS |
1641 | /* |
1642 | * If the provided values for each buffer pool are different than the | |
1643 | * configured values, we need to take action. | |
1644 | */ | |
edeb5d8c | 1645 | if (tiny >= 0) { |
86ef6250 AS |
1646 | tiny_router_buffers = tiny; |
1647 | nrb = lnet_nrb_tiny_calculate(); | |
1648 | cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) { | |
1649 | rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_TINY_BUF_IDX], | |
1650 | nrb, i); | |
1651 | if (rc) | |
1652 | return rc; | |
1653 | } | |
1654 | } | |
edeb5d8c | 1655 | if (small >= 0) { |
86ef6250 AS |
1656 | small_router_buffers = small; |
1657 | nrb = lnet_nrb_small_calculate(); | |
1658 | cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) { | |
1659 | rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_SMALL_BUF_IDX], | |
1660 | nrb, i); | |
1661 | if (rc) | |
1662 | return rc; | |
1663 | } | |
1664 | } | |
edeb5d8c | 1665 | if (large >= 0) { |
86ef6250 AS |
1666 | large_router_buffers = large; |
1667 | nrb = lnet_nrb_large_calculate(); | |
1668 | cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) { | |
1669 | rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_LARGE_BUF_IDX], | |
1670 | nrb, i); | |
1671 | if (rc) | |
1672 | return rc; | |
1673 | } | |
1674 | } | |
1675 | ||
1676 | return 0; | |
1677 | } | |
1678 | ||
edeb5d8c AS |
1679 | int |
1680 | lnet_rtrpools_adjust(int tiny, int small, int large) | |
1681 | { | |
1682 | /* | |
1683 | * this function doesn't revert the changes if adding new buffers | |
1684 | * failed. It's up to the user space caller to revert the | |
1685 | * changes. | |
1686 | */ | |
1687 | if (!the_lnet.ln_routing) | |
1688 | return 0; | |
1689 | ||
1690 | return lnet_rtrpools_adjust_helper(tiny, small, large); | |
1691 | } | |
1692 | ||
86ef6250 AS |
1693 | int |
1694 | lnet_rtrpools_enable(void) | |
1695 | { | |
1696 | int rc; | |
1697 | ||
1698 | if (the_lnet.ln_routing) | |
1699 | return 0; | |
1700 | ||
1701 | if (!the_lnet.ln_rtrpools) | |
1702 | /* | |
1703 | * If routing is turned off, and we have never | |
1704 | * initialized the pools before, just call the | |
1705 | * standard buffer pool allocation routine as | |
1706 | * if we are just configuring this for the first | |
1707 | * time. | |
1708 | */ | |
1709 | return lnet_rtrpools_alloc(1); | |
1710 | ||
edeb5d8c | 1711 | rc = lnet_rtrpools_adjust_helper(0, 0, 0); |
86ef6250 AS |
1712 | if (rc) |
1713 | return rc; | |
1714 | ||
1715 | lnet_net_lock(LNET_LOCK_EX); | |
1716 | the_lnet.ln_routing = 1; | |
1717 | ||
1718 | the_lnet.ln_ping_info->pi_features &= ~LNET_PING_FEAT_RTE_DISABLED; | |
1719 | lnet_net_unlock(LNET_LOCK_EX); | |
1720 | ||
1721 | return 0; | |
1722 | } | |
1723 | ||
1724 | void | |
1725 | lnet_rtrpools_disable(void) | |
1726 | { | |
1727 | if (!the_lnet.ln_routing) | |
1728 | return; | |
1729 | ||
1730 | lnet_net_lock(LNET_LOCK_EX); | |
1731 | the_lnet.ln_routing = 0; | |
1732 | the_lnet.ln_ping_info->pi_features |= LNET_PING_FEAT_RTE_DISABLED; | |
1733 | ||
1734 | tiny_router_buffers = 0; | |
1735 | small_router_buffers = 0; | |
1736 | large_router_buffers = 0; | |
1737 | lnet_net_unlock(LNET_LOCK_EX); | |
1738 | lnet_rtrpools_free(1); | |
1739 | } | |
1740 | ||
d7e09d03 | 1741 | int |
a649ad1d | 1742 | lnet_notify(lnet_ni_t *ni, lnet_nid_t nid, int alive, unsigned long when) |
d7e09d03 | 1743 | { |
7e7ab095 MS |
1744 | struct lnet_peer *lp = NULL; |
1745 | unsigned long now = cfs_time_current(); | |
1746 | int cpt = lnet_cpt_of_nid(nid); | |
d7e09d03 | 1747 | |
59cfb96f | 1748 | LASSERT(!in_interrupt()); |
d7e09d03 | 1749 | |
939af333 | 1750 | CDEBUG(D_NET, "%s notifying %s: %s\n", |
06ace26e | 1751 | !ni ? "userspace" : libcfs_nid2str(ni->ni_nid), |
c314c319 JS |
1752 | libcfs_nid2str(nid), |
1753 | alive ? "up" : "down"); | |
d7e09d03 | 1754 | |
06ace26e | 1755 | if (ni && |
d7e09d03 | 1756 | LNET_NIDNET(ni->ni_nid) != LNET_NIDNET(nid)) { |
939af333 | 1757 | CWARN("Ignoring notification of %s %s by %s (different net)\n", |
c314c319 JS |
1758 | libcfs_nid2str(nid), alive ? "birth" : "death", |
1759 | libcfs_nid2str(ni->ni_nid)); | |
d7e09d03 PT |
1760 | return -EINVAL; |
1761 | } | |
1762 | ||
1763 | /* can't do predictions... */ | |
1764 | if (cfs_time_after(when, now)) { | |
2d00bd17 | 1765 | CWARN("Ignoring prediction from %s of %s %s %ld seconds in the future\n", |
06ace26e | 1766 | !ni ? "userspace" : libcfs_nid2str(ni->ni_nid), |
2d00bd17 JP |
1767 | libcfs_nid2str(nid), alive ? "up" : "down", |
1768 | cfs_duration_sec(cfs_time_sub(when, now))); | |
d7e09d03 PT |
1769 | return -EINVAL; |
1770 | } | |
1771 | ||
06ace26e | 1772 | if (ni && !alive && /* LND telling me she's down */ |
d7e09d03 PT |
1773 | !auto_down) { /* auto-down disabled */ |
1774 | CDEBUG(D_NET, "Auto-down disabled\n"); | |
1775 | return 0; | |
1776 | } | |
1777 | ||
1778 | lnet_net_lock(cpt); | |
1779 | ||
1780 | if (the_lnet.ln_shutdown) { | |
1781 | lnet_net_unlock(cpt); | |
1782 | return -ESHUTDOWN; | |
1783 | } | |
1784 | ||
1785 | lp = lnet_find_peer_locked(the_lnet.ln_peer_tables[cpt], nid); | |
06ace26e | 1786 | if (!lp) { |
d7e09d03 PT |
1787 | /* nid not found */ |
1788 | lnet_net_unlock(cpt); | |
1789 | CDEBUG(D_NET, "%s not found\n", libcfs_nid2str(nid)); | |
1790 | return 0; | |
1791 | } | |
1792 | ||
4420cfd3 JS |
1793 | /* |
1794 | * We can't fully trust LND on reporting exact peer last_alive | |
d7e09d03 PT |
1795 | * if he notifies us about dead peer. For example ksocklnd can |
1796 | * call us with when == _time_when_the_node_was_booted_ if | |
4420cfd3 JS |
1797 | * no connections were successfully established |
1798 | */ | |
06ace26e | 1799 | if (ni && !alive && when < lp->lp_last_alive) |
d7e09d03 PT |
1800 | when = lp->lp_last_alive; |
1801 | ||
06ace26e | 1802 | lnet_notify_locked(lp, !ni, alive, when); |
d7e09d03 | 1803 | |
72159bb6 DE |
1804 | if (ni) |
1805 | lnet_ni_notify_locked(ni, lp); | |
d7e09d03 PT |
1806 | |
1807 | lnet_peer_decref_locked(lp); | |
1808 | ||
1809 | lnet_net_unlock(cpt); | |
1810 | return 0; | |
1811 | } | |
1812 | EXPORT_SYMBOL(lnet_notify); |