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