2 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
4 * Copyright (c) 2011, 2015, Intel Corporation.
6 * This file is part of Portals
7 * http://sourceforge.net/projects/sandiaportals/
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.
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.
20 #define DEBUG_SUBSYSTEM S_LNET
21 #include "../../include/linux/lnet/lib-lnet.h"
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)
27 #define LNET_NRB_SMALL_PAGES 1
28 #define LNET_NRB_LARGE_MIN 256 /* min value for each CPT */
29 #define LNET_NRB_LARGE (LNET_NRB_LARGE_MIN * 4)
30 #define LNET_NRB_LARGE_PAGES ((LNET_MTU + PAGE_CACHE_SIZE - 1) >> \
33 static char *forwarding
= "";
34 module_param(forwarding
, charp
, 0444);
35 MODULE_PARM_DESC(forwarding
, "Explicitly enable/disable forwarding between networks");
37 static int tiny_router_buffers
;
38 module_param(tiny_router_buffers
, int, 0444);
39 MODULE_PARM_DESC(tiny_router_buffers
, "# of 0 payload messages to buffer in the router");
40 static int small_router_buffers
;
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");
43 static int large_router_buffers
;
44 module_param(large_router_buffers
, int, 0444);
45 MODULE_PARM_DESC(large_router_buffers
, "# of large messages to buffer in the router");
46 static int peer_buffer_credits
;
47 module_param(peer_buffer_credits
, int, 0444);
48 MODULE_PARM_DESC(peer_buffer_credits
, "# router buffer credits per peer");
50 static int auto_down
= 1;
51 module_param(auto_down
, int, 0444);
52 MODULE_PARM_DESC(auto_down
, "Automatically mark peers down on comms error");
55 lnet_peer_buffer_credits(lnet_ni_t
*ni
)
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
;
64 * As an approximation, allow this peer the same number of router
65 * buffers as it is allowed outstanding sends
67 return ni
->ni_peertxcredits
;
71 static int lnet_router_checker(void *);
73 static int check_routers_before_use
;
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");
77 int avoid_asym_router_failure
= 1;
78 module_param(avoid_asym_router_failure
, int, 0644);
79 MODULE_PARM_DESC(avoid_asym_router_failure
, "Avoid asymmetrical router failures (0 to disable)");
81 static int dead_router_check_interval
= 60;
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)");
85 static int live_router_check_interval
= 60;
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)");
89 static int router_ping_timeout
= 50;
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");
94 lnet_peers_start_down(void)
96 return check_routers_before_use
;
100 lnet_notify_locked(lnet_peer_t
*lp
, int notifylnd
, int alive
,
103 if (time_before(when
, lp
->lp_timestamp
)) { /* out of date information */
104 CDEBUG(D_NET
, "Out of date\n");
108 lp
->lp_timestamp
= when
; /* update timestamp */
109 lp
->lp_ping_deadline
= 0; /* disable ping timeout */
111 if (lp
->lp_alive_count
&& /* got old news */
112 (!lp
->lp_alive
) == (!alive
)) { /* new date for old news */
113 CDEBUG(D_NET
, "Old news\n");
117 /* Flag that notification is outstanding */
119 lp
->lp_alive_count
++;
120 lp
->lp_alive
= !(!alive
); /* 1 bit! */
122 lp
->lp_notifylnd
|= notifylnd
;
124 lp
->lp_ping_feats
= LNET_PING_FEAT_INVAL
; /* reset */
126 CDEBUG(D_NET
, "set %s %d\n", libcfs_nid2str(lp
->lp_nid
), alive
);
130 lnet_ni_notify_locked(lnet_ni_t
*ni
, lnet_peer_t
*lp
)
136 * Notify only in 1 thread at any time to ensure ordered notification.
137 * NB individual events can be missed; the only guarantee is that you
138 * always get the most recent news
140 if (lp
->lp_notifying
|| !ni
)
143 lp
->lp_notifying
= 1;
145 while (lp
->lp_notify
) {
146 alive
= lp
->lp_alive
;
147 notifylnd
= lp
->lp_notifylnd
;
149 lp
->lp_notifylnd
= 0;
152 if (notifylnd
&& ni
->ni_lnd
->lnd_notify
) {
153 lnet_net_unlock(lp
->lp_cpt
);
156 * A new notification could happen now; I'll handle it
157 * when control returns to me
159 ni
->ni_lnd
->lnd_notify(ni
, lp
->lp_nid
, alive
);
161 lnet_net_lock(lp
->lp_cpt
);
165 lp
->lp_notifying
= 0;
169 lnet_rtr_addref_locked(lnet_peer_t
*lp
)
171 LASSERT(lp
->lp_refcount
> 0);
172 LASSERT(lp
->lp_rtr_refcount
>= 0);
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
;
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
,
184 if (rtr
->lp_nid
< lp
->lp_nid
)
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
++;
196 lnet_rtr_decref_locked(lnet_peer_t
*lp
)
198 LASSERT(lp
->lp_refcount
> 0);
199 LASSERT(lp
->lp_rtr_refcount
> 0);
201 /* lnet_net_lock must be exclusively locked */
202 lp
->lp_rtr_refcount
--;
203 if (!lp
->lp_rtr_refcount
) {
204 LASSERT(list_empty(&lp
->lp_routes
));
207 list_add(&lp
->lp_rcd
->rcd_list
,
208 &the_lnet
.ln_rcd_deathrow
);
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
++;
220 lnet_find_net_locked(__u32 net
)
222 lnet_remotenet_t
*rnet
;
223 struct list_head
*tmp
;
224 struct list_head
*rn_list
;
226 LASSERT(!the_lnet
.ln_shutdown
);
228 rn_list
= lnet_net2rnethash(net
);
229 list_for_each(tmp
, rn_list
) {
230 rnet
= list_entry(tmp
, lnet_remotenet_t
, lrn_list
);
232 if (rnet
->lrn_net
== net
)
238 static void lnet_shuffle_seed(void)
241 __u32 lnd_type
, seed
[2];
242 struct timespec64 ts
;
244 struct list_head
*tmp
;
249 cfs_get_random_bytes(seed
, sizeof(seed
));
252 * Nodes with small feet have little entropy
253 * the NID for this node gives the most entropy in the low bits
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
));
259 if (lnd_type
!= LOLND
)
260 seed
[0] ^= (LNET_NIDADDR(ni
->ni_nid
) | lnd_type
);
264 cfs_srand(ts
.tv_sec
^ seed
[0], ts
.tv_nsec
^ seed
[1]);
268 /* NB expects LNET_LOCK held */
270 lnet_add_route_to_rnet(lnet_remotenet_t
*rnet
, lnet_route_t
*route
)
272 unsigned int len
= 0;
273 unsigned int offset
= 0;
278 list_for_each(e
, &rnet
->lrn_routes
) {
282 /* len+1 positions to add a new entry, also prevents division by 0 */
283 offset
= cfs_rand() % (len
+ 1);
284 list_for_each(e
, &rnet
->lrn_routes
) {
289 list_add(&route
->lr_list
, e
);
290 list_add(&route
->lr_gwlist
, &route
->lr_gateway
->lp_routes
);
292 the_lnet
.ln_remote_nets_version
++;
293 lnet_rtr_addref_locked(route
->lr_gateway
);
297 lnet_add_route(__u32 net
, unsigned int hops
, lnet_nid_t gateway
,
298 unsigned int priority
)
301 lnet_remotenet_t
*rnet
;
302 lnet_remotenet_t
*rnet2
;
308 CDEBUG(D_NET
, "Add route: net %s hops %u priority %u gw %s\n",
309 libcfs_net2str(net
), hops
, priority
, libcfs_nid2str(gateway
));
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
||
316 hops
< 1 || hops
> 255)
319 if (lnet_islocalnet(net
)) /* it's a local network */
322 /* Assume net, route, all new */
323 LIBCFS_ALLOC(route
, sizeof(*route
));
324 LIBCFS_ALLOC(rnet
, sizeof(*rnet
));
325 if (!route
|| !rnet
) {
326 CERROR("Out of memory creating route %s %d %s\n",
327 libcfs_net2str(net
), hops
, libcfs_nid2str(gateway
));
329 LIBCFS_FREE(route
, sizeof(*route
));
331 LIBCFS_FREE(rnet
, sizeof(*rnet
));
335 INIT_LIST_HEAD(&rnet
->lrn_routes
);
337 route
->lr_hops
= hops
;
339 route
->lr_priority
= priority
;
341 lnet_net_lock(LNET_LOCK_EX
);
343 rc
= lnet_nid2peer_locked(&route
->lr_gateway
, gateway
, LNET_LOCK_EX
);
345 lnet_net_unlock(LNET_LOCK_EX
);
347 LIBCFS_FREE(route
, sizeof(*route
));
348 LIBCFS_FREE(rnet
, sizeof(*rnet
));
350 if (rc
== -EHOSTUNREACH
) /* gateway is not on a local net */
351 return rc
; /* ignore the route entry */
352 CERROR("Error %d creating route %s %d %s\n", rc
,
353 libcfs_net2str(net
), hops
,
354 libcfs_nid2str(gateway
));
358 LASSERT(!the_lnet
.ln_shutdown
);
360 rnet2
= lnet_find_net_locked(net
);
363 list_add_tail(&rnet
->lrn_list
, lnet_net2rnethash(net
));
367 /* Search for a duplicate route (it's a NOOP if it is) */
369 list_for_each(e
, &rnet2
->lrn_routes
) {
370 lnet_route_t
*route2
= list_entry(e
, lnet_route_t
, lr_list
);
372 if (route2
->lr_gateway
== route
->lr_gateway
) {
377 /* our lookups must be true */
378 LASSERT(route2
->lr_gateway
->lp_nid
!= gateway
);
382 lnet_peer_addref_locked(route
->lr_gateway
); /* +1 for notify */
383 lnet_add_route_to_rnet(rnet2
, route
);
385 ni
= route
->lr_gateway
->lp_ni
;
386 lnet_net_unlock(LNET_LOCK_EX
);
388 /* XXX Assume alive */
389 if (ni
->ni_lnd
->lnd_notify
)
390 ni
->ni_lnd
->lnd_notify(ni
, gateway
, 1);
392 lnet_net_lock(LNET_LOCK_EX
);
395 /* -1 for notify or !add_route */
396 lnet_peer_decref_locked(route
->lr_gateway
);
397 lnet_net_unlock(LNET_LOCK_EX
);
402 LIBCFS_FREE(route
, sizeof(*route
));
406 LIBCFS_FREE(rnet
, sizeof(*rnet
));
412 lnet_check_routes(void)
414 lnet_remotenet_t
*rnet
;
416 lnet_route_t
*route2
;
417 struct list_head
*e1
;
418 struct list_head
*e2
;
420 struct list_head
*rn_list
;
423 cpt
= lnet_net_lock_current();
425 for (i
= 0; i
< LNET_REMOTE_NETS_HASH_SIZE
; i
++) {
426 rn_list
= &the_lnet
.ln_remote_nets_hash
[i
];
427 list_for_each(e1
, rn_list
) {
428 rnet
= list_entry(e1
, lnet_remotenet_t
, lrn_list
);
431 list_for_each(e2
, &rnet
->lrn_routes
) {
436 route
= list_entry(e2
, lnet_route_t
, lr_list
);
443 if (route
->lr_gateway
->lp_ni
==
444 route2
->lr_gateway
->lp_ni
)
447 nid1
= route
->lr_gateway
->lp_nid
;
448 nid2
= route2
->lr_gateway
->lp_nid
;
451 lnet_net_unlock(cpt
);
453 CERROR("Routes to %s via %s and %s not supported\n",
455 libcfs_nid2str(nid1
),
456 libcfs_nid2str(nid2
));
462 lnet_net_unlock(cpt
);
467 lnet_del_route(__u32 net
, lnet_nid_t gw_nid
)
469 struct lnet_peer
*gateway
;
470 lnet_remotenet_t
*rnet
;
472 struct list_head
*e1
;
473 struct list_head
*e2
;
475 struct list_head
*rn_list
;
478 CDEBUG(D_NET
, "Del route: net %s : gw %s\n",
479 libcfs_net2str(net
), libcfs_nid2str(gw_nid
));
482 * NB Caller may specify either all routes via the given gateway
483 * or a specific route entry actual NIDs)
485 lnet_net_lock(LNET_LOCK_EX
);
486 if (net
== LNET_NIDNET(LNET_NID_ANY
))
487 rn_list
= &the_lnet
.ln_remote_nets_hash
[0];
489 rn_list
= lnet_net2rnethash(net
);
492 list_for_each(e1
, rn_list
) {
493 rnet
= list_entry(e1
, lnet_remotenet_t
, lrn_list
);
495 if (!(net
== LNET_NIDNET(LNET_NID_ANY
) ||
496 net
== rnet
->lrn_net
))
499 list_for_each(e2
, &rnet
->lrn_routes
) {
500 route
= list_entry(e2
, lnet_route_t
, lr_list
);
502 gateway
= route
->lr_gateway
;
503 if (!(gw_nid
== LNET_NID_ANY
||
504 gw_nid
== gateway
->lp_nid
))
507 list_del(&route
->lr_list
);
508 list_del(&route
->lr_gwlist
);
509 the_lnet
.ln_remote_nets_version
++;
511 if (list_empty(&rnet
->lrn_routes
))
512 list_del(&rnet
->lrn_list
);
516 lnet_rtr_decref_locked(gateway
);
517 lnet_peer_decref_locked(gateway
);
519 lnet_net_unlock(LNET_LOCK_EX
);
521 LIBCFS_FREE(route
, sizeof(*route
));
524 LIBCFS_FREE(rnet
, sizeof(*rnet
));
527 lnet_net_lock(LNET_LOCK_EX
);
532 if (net
== LNET_NIDNET(LNET_NID_ANY
) &&
533 ++idx
< LNET_REMOTE_NETS_HASH_SIZE
) {
534 rn_list
= &the_lnet
.ln_remote_nets_hash
[idx
];
537 lnet_net_unlock(LNET_LOCK_EX
);
543 lnet_destroy_routes(void)
545 lnet_del_route(LNET_NIDNET(LNET_NID_ANY
), LNET_NID_ANY
);
548 int lnet_get_rtr_pool_cfg(int idx
, struct lnet_ioctl_pool_cfg
*pool_cfg
)
550 int i
, rc
= -ENOENT
, j
;
552 if (!the_lnet
.ln_rtrpools
)
555 for (i
= 0; i
< LNET_NRBPOOLS
; i
++) {
556 lnet_rtrbufpool_t
*rbp
;
558 lnet_net_lock(LNET_LOCK_EX
);
559 cfs_percpt_for_each(rbp
, j
, the_lnet
.ln_rtrpools
) {
563 pool_cfg
->pl_pools
[i
].pl_npages
= rbp
[i
].rbp_npages
;
564 pool_cfg
->pl_pools
[i
].pl_nbuffers
= rbp
[i
].rbp_nbuffers
;
565 pool_cfg
->pl_pools
[i
].pl_credits
= rbp
[i
].rbp_credits
;
566 pool_cfg
->pl_pools
[i
].pl_mincredits
= rbp
[i
].rbp_mincredits
;
570 lnet_net_unlock(LNET_LOCK_EX
);
573 lnet_net_lock(LNET_LOCK_EX
);
574 pool_cfg
->pl_routing
= the_lnet
.ln_routing
;
575 lnet_net_unlock(LNET_LOCK_EX
);
581 lnet_get_route(int idx
, __u32
*net
, __u32
*hops
,
582 lnet_nid_t
*gateway
, __u32
*alive
, __u32
*priority
)
584 struct list_head
*e1
;
585 struct list_head
*e2
;
586 lnet_remotenet_t
*rnet
;
590 struct list_head
*rn_list
;
592 cpt
= lnet_net_lock_current();
594 for (i
= 0; i
< LNET_REMOTE_NETS_HASH_SIZE
; i
++) {
595 rn_list
= &the_lnet
.ln_remote_nets_hash
[i
];
596 list_for_each(e1
, rn_list
) {
597 rnet
= list_entry(e1
, lnet_remotenet_t
, lrn_list
);
599 list_for_each(e2
, &rnet
->lrn_routes
) {
600 route
= list_entry(e2
, lnet_route_t
, lr_list
);
603 *net
= rnet
->lrn_net
;
604 *hops
= route
->lr_hops
;
605 *priority
= route
->lr_priority
;
606 *gateway
= route
->lr_gateway
->lp_nid
;
607 *alive
= route
->lr_gateway
->lp_alive
&&
609 lnet_net_unlock(cpt
);
616 lnet_net_unlock(cpt
);
621 lnet_swap_pinginfo(lnet_ping_info_t
*info
)
624 lnet_ni_status_t
*stat
;
626 __swab32s(&info
->pi_magic
);
627 __swab32s(&info
->pi_features
);
628 __swab32s(&info
->pi_pid
);
629 __swab32s(&info
->pi_nnis
);
630 for (i
= 0; i
< info
->pi_nnis
&& i
< LNET_MAX_RTR_NIS
; i
++) {
631 stat
= &info
->pi_ni
[i
];
632 __swab64s(&stat
->ns_nid
);
633 __swab32s(&stat
->ns_status
);
638 * parse router-checker pinginfo, record number of down NIs for remote
639 * networks on that router.
642 lnet_parse_rc_info(lnet_rc_data_t
*rcd
)
644 lnet_ping_info_t
*info
= rcd
->rcd_pinginfo
;
645 struct lnet_peer
*gw
= rcd
->rcd_gateway
;
651 if (info
->pi_magic
== __swab32(LNET_PROTO_PING_MAGIC
))
652 lnet_swap_pinginfo(info
);
654 /* NB always racing with network! */
655 if (info
->pi_magic
!= LNET_PROTO_PING_MAGIC
) {
656 CDEBUG(D_NET
, "%s: Unexpected magic %08x\n",
657 libcfs_nid2str(gw
->lp_nid
), info
->pi_magic
);
658 gw
->lp_ping_feats
= LNET_PING_FEAT_INVAL
;
662 gw
->lp_ping_feats
= info
->pi_features
;
663 if (!(gw
->lp_ping_feats
& LNET_PING_FEAT_MASK
)) {
664 CDEBUG(D_NET
, "%s: Unexpected features 0x%x\n",
665 libcfs_nid2str(gw
->lp_nid
), gw
->lp_ping_feats
);
666 return; /* nothing I can understand */
669 if (!(gw
->lp_ping_feats
& LNET_PING_FEAT_NI_STATUS
))
670 return; /* can't carry NI status info */
672 list_for_each_entry(rte
, &gw
->lp_routes
, lr_gwlist
) {
677 if (gw
->lp_ping_feats
& LNET_PING_FEAT_RTE_DISABLED
) {
682 for (i
= 0; i
< info
->pi_nnis
&& i
< LNET_MAX_RTR_NIS
; i
++) {
683 lnet_ni_status_t
*stat
= &info
->pi_ni
[i
];
684 lnet_nid_t nid
= stat
->ns_nid
;
686 if (nid
== LNET_NID_ANY
) {
687 CDEBUG(D_NET
, "%s: unexpected LNET_NID_ANY\n",
688 libcfs_nid2str(gw
->lp_nid
));
689 gw
->lp_ping_feats
= LNET_PING_FEAT_INVAL
;
693 if (LNET_NETTYP(LNET_NIDNET(nid
)) == LOLND
)
696 if (stat
->ns_status
== LNET_NI_STATUS_DOWN
) {
701 if (stat
->ns_status
== LNET_NI_STATUS_UP
) {
702 if (LNET_NIDNET(nid
) == rte
->lr_net
) {
709 CDEBUG(D_NET
, "%s: Unexpected status 0x%x\n",
710 libcfs_nid2str(gw
->lp_nid
), stat
->ns_status
);
711 gw
->lp_ping_feats
= LNET_PING_FEAT_INVAL
;
715 if (up
) { /* ignore downed NIs if NI for dest network is up */
719 rte
->lr_downis
= down
;
724 lnet_router_checker_event(lnet_event_t
*event
)
726 lnet_rc_data_t
*rcd
= event
->md
.user_ptr
;
727 struct lnet_peer
*lp
;
731 if (event
->unlinked
) {
732 LNetInvalidateHandle(&rcd
->rcd_mdh
);
736 LASSERT(event
->type
== LNET_EVENT_SEND
||
737 event
->type
== LNET_EVENT_REPLY
);
739 lp
= rcd
->rcd_gateway
;
743 * NB: it's called with holding lnet_res_lock, we have a few
744 * places need to hold both locks at the same time, please take
745 * care of lock ordering
747 lnet_net_lock(lp
->lp_cpt
);
748 if (!lnet_isrouter(lp
) || lp
->lp_rcd
!= rcd
) {
749 /* ignore if no longer a router or rcd is replaced */
753 if (event
->type
== LNET_EVENT_SEND
) {
754 lp
->lp_ping_notsent
= 0;
759 /* LNET_EVENT_REPLY */
761 * A successful REPLY means the router is up. If _any_ comms
762 * to the router fail I assume it's down (this will happen if
763 * we ping alive routers to try to detect router death before
766 lnet_notify_locked(lp
, 1, !event
->status
, cfs_time_current());
769 * The router checker will wake up very shortly and do the
770 * actual notification.
771 * XXX If 'lp' stops being a router before then, it will still
772 * have the notification pending!!!
774 if (avoid_asym_router_failure
&& !event
->status
)
775 lnet_parse_rc_info(rcd
);
778 lnet_net_unlock(lp
->lp_cpt
);
782 lnet_wait_known_routerstate(void)
785 struct list_head
*entry
;
788 LASSERT(the_lnet
.ln_rc_state
== LNET_RC_STATE_RUNNING
);
791 int cpt
= lnet_net_lock_current();
794 list_for_each(entry
, &the_lnet
.ln_routers
) {
795 rtr
= list_entry(entry
, lnet_peer_t
, lp_rtr_list
);
797 if (!rtr
->lp_alive_count
) {
803 lnet_net_unlock(cpt
);
808 set_current_state(TASK_UNINTERRUPTIBLE
);
809 schedule_timeout(cfs_time_seconds(1));
814 lnet_router_ni_update_locked(lnet_peer_t
*gw
, __u32 net
)
818 if ((gw
->lp_ping_feats
& LNET_PING_FEAT_NI_STATUS
)) {
819 list_for_each_entry(rte
, &gw
->lp_routes
, lr_gwlist
) {
820 if (rte
->lr_net
== net
) {
829 lnet_update_ni_status_locked(void)
835 LASSERT(the_lnet
.ln_routing
);
837 timeout
= router_ping_timeout
+
838 max(live_router_check_interval
, dead_router_check_interval
);
840 now
= ktime_get_real_seconds();
841 list_for_each_entry(ni
, &the_lnet
.ln_nis
, ni_list
) {
842 if (ni
->ni_lnd
->lnd_type
== LOLND
)
845 if (now
< ni
->ni_last_alive
+ timeout
)
849 /* re-check with lock */
850 if (now
< ni
->ni_last_alive
+ timeout
) {
855 LASSERT(ni
->ni_status
);
857 if (ni
->ni_status
->ns_status
!= LNET_NI_STATUS_DOWN
) {
858 CDEBUG(D_NET
, "NI(%s:%d) status changed to down\n",
859 libcfs_nid2str(ni
->ni_nid
), timeout
);
861 * NB: so far, this is the only place to set
862 * NI status to "down"
864 ni
->ni_status
->ns_status
= LNET_NI_STATUS_DOWN
;
871 lnet_destroy_rc_data(lnet_rc_data_t
*rcd
)
873 LASSERT(list_empty(&rcd
->rcd_list
));
874 /* detached from network */
875 LASSERT(LNetHandleIsInvalid(rcd
->rcd_mdh
));
877 if (rcd
->rcd_gateway
) {
878 int cpt
= rcd
->rcd_gateway
->lp_cpt
;
881 lnet_peer_decref_locked(rcd
->rcd_gateway
);
882 lnet_net_unlock(cpt
);
885 if (rcd
->rcd_pinginfo
)
886 LIBCFS_FREE(rcd
->rcd_pinginfo
, LNET_PINGINFO_SIZE
);
888 LIBCFS_FREE(rcd
, sizeof(*rcd
));
891 static lnet_rc_data_t
*
892 lnet_create_rc_data_locked(lnet_peer_t
*gateway
)
894 lnet_rc_data_t
*rcd
= NULL
;
895 lnet_ping_info_t
*pi
;
899 lnet_net_unlock(gateway
->lp_cpt
);
901 LIBCFS_ALLOC(rcd
, sizeof(*rcd
));
905 LNetInvalidateHandle(&rcd
->rcd_mdh
);
906 INIT_LIST_HEAD(&rcd
->rcd_list
);
908 LIBCFS_ALLOC(pi
, LNET_PINGINFO_SIZE
);
912 for (i
= 0; i
< LNET_MAX_RTR_NIS
; i
++) {
913 pi
->pi_ni
[i
].ns_nid
= LNET_NID_ANY
;
914 pi
->pi_ni
[i
].ns_status
= LNET_NI_STATUS_INVALID
;
916 rcd
->rcd_pinginfo
= pi
;
918 LASSERT(!LNetHandleIsInvalid(the_lnet
.ln_rc_eqh
));
919 rc
= LNetMDBind((lnet_md_t
){.start
= pi
,
921 .length
= LNET_PINGINFO_SIZE
,
922 .threshold
= LNET_MD_THRESH_INF
,
923 .options
= LNET_MD_TRUNCATE
,
924 .eq_handle
= the_lnet
.ln_rc_eqh
},
928 CERROR("Can't bind MD: %d\n", rc
);
933 lnet_net_lock(gateway
->lp_cpt
);
934 /* router table changed or someone has created rcd for this gateway */
935 if (!lnet_isrouter(gateway
) || gateway
->lp_rcd
) {
936 lnet_net_unlock(gateway
->lp_cpt
);
940 lnet_peer_addref_locked(gateway
);
941 rcd
->rcd_gateway
= gateway
;
942 gateway
->lp_rcd
= rcd
;
943 gateway
->lp_ping_notsent
= 0;
949 if (!LNetHandleIsInvalid(rcd
->rcd_mdh
)) {
950 rc
= LNetMDUnlink(rcd
->rcd_mdh
);
953 lnet_destroy_rc_data(rcd
);
956 lnet_net_lock(gateway
->lp_cpt
);
957 return gateway
->lp_rcd
;
961 lnet_router_check_interval(lnet_peer_t
*rtr
)
965 secs
= rtr
->lp_alive
? live_router_check_interval
:
966 dead_router_check_interval
;
974 lnet_ping_router_locked(lnet_peer_t
*rtr
)
976 lnet_rc_data_t
*rcd
= NULL
;
977 unsigned long now
= cfs_time_current();
980 lnet_peer_addref_locked(rtr
);
982 if (rtr
->lp_ping_deadline
&& /* ping timed out? */
983 cfs_time_after(now
, rtr
->lp_ping_deadline
))
984 lnet_notify_locked(rtr
, 1, 0, now
);
986 /* Run any outstanding notifications */
987 lnet_ni_notify_locked(rtr
->lp_ni
, rtr
);
989 if (!lnet_isrouter(rtr
) ||
990 the_lnet
.ln_rc_state
!= LNET_RC_STATE_RUNNING
) {
991 /* router table changed or router checker is shutting down */
992 lnet_peer_decref_locked(rtr
);
997 rtr
->lp_rcd
: lnet_create_rc_data_locked(rtr
);
1002 secs
= lnet_router_check_interval(rtr
);
1005 "rtr %s %d: deadline %lu ping_notsent %d alive %d alive_count %d lp_ping_timestamp %lu\n",
1006 libcfs_nid2str(rtr
->lp_nid
), secs
,
1007 rtr
->lp_ping_deadline
, rtr
->lp_ping_notsent
,
1008 rtr
->lp_alive
, rtr
->lp_alive_count
, rtr
->lp_ping_timestamp
);
1010 if (secs
&& !rtr
->lp_ping_notsent
&&
1011 cfs_time_after(now
, cfs_time_add(rtr
->lp_ping_timestamp
,
1012 cfs_time_seconds(secs
)))) {
1014 lnet_process_id_t id
;
1015 lnet_handle_md_t mdh
;
1017 id
.nid
= rtr
->lp_nid
;
1018 id
.pid
= LNET_PID_LUSTRE
;
1019 CDEBUG(D_NET
, "Check: %s\n", libcfs_id2str(id
));
1021 rtr
->lp_ping_notsent
= 1;
1022 rtr
->lp_ping_timestamp
= now
;
1026 if (!rtr
->lp_ping_deadline
) {
1027 rtr
->lp_ping_deadline
=
1028 cfs_time_shift(router_ping_timeout
);
1031 lnet_net_unlock(rtr
->lp_cpt
);
1033 rc
= LNetGet(LNET_NID_ANY
, mdh
, id
, LNET_RESERVED_PORTAL
,
1034 LNET_PROTO_PING_MATCHBITS
, 0);
1036 lnet_net_lock(rtr
->lp_cpt
);
1038 rtr
->lp_ping_notsent
= 0; /* no event pending */
1041 lnet_peer_decref_locked(rtr
);
1045 lnet_router_checker_start(void)
1047 struct task_struct
*task
;
1051 LASSERT(the_lnet
.ln_rc_state
== LNET_RC_STATE_SHUTDOWN
);
1053 if (check_routers_before_use
&&
1054 dead_router_check_interval
<= 0) {
1055 LCONSOLE_ERROR_MSG(0x10a, "'dead_router_check_interval' must be set if 'check_routers_before_use' is set\n");
1059 if (!the_lnet
.ln_routing
&&
1060 live_router_check_interval
<= 0 &&
1061 dead_router_check_interval
<= 0)
1064 sema_init(&the_lnet
.ln_rc_signal
, 0);
1066 * EQ size doesn't matter; the callback is guaranteed to get every
1070 rc
= LNetEQAlloc(eqsz
, lnet_router_checker_event
,
1071 &the_lnet
.ln_rc_eqh
);
1073 CERROR("Can't allocate EQ(%d): %d\n", eqsz
, rc
);
1077 the_lnet
.ln_rc_state
= LNET_RC_STATE_RUNNING
;
1078 task
= kthread_run(lnet_router_checker
, NULL
, "router_checker");
1081 CERROR("Can't start router checker thread: %d\n", rc
);
1082 /* block until event callback signals exit */
1083 down(&the_lnet
.ln_rc_signal
);
1084 rc
= LNetEQFree(the_lnet
.ln_rc_eqh
);
1086 the_lnet
.ln_rc_state
= LNET_RC_STATE_SHUTDOWN
;
1090 if (check_routers_before_use
) {
1092 * Note that a helpful side-effect of pinging all known routers
1093 * at startup is that it makes them drop stale connections they
1094 * may have to a previous instance of me.
1096 lnet_wait_known_routerstate();
1103 lnet_router_checker_stop(void)
1107 if (the_lnet
.ln_rc_state
== LNET_RC_STATE_SHUTDOWN
)
1110 LASSERT(the_lnet
.ln_rc_state
== LNET_RC_STATE_RUNNING
);
1111 the_lnet
.ln_rc_state
= LNET_RC_STATE_STOPPING
;
1113 /* block until event callback signals exit */
1114 down(&the_lnet
.ln_rc_signal
);
1115 LASSERT(the_lnet
.ln_rc_state
== LNET_RC_STATE_SHUTDOWN
);
1117 rc
= LNetEQFree(the_lnet
.ln_rc_eqh
);
1122 lnet_prune_rc_data(int wait_unlink
)
1124 lnet_rc_data_t
*rcd
;
1125 lnet_rc_data_t
*tmp
;
1127 struct list_head head
;
1130 if (likely(the_lnet
.ln_rc_state
== LNET_RC_STATE_RUNNING
&&
1131 list_empty(&the_lnet
.ln_rcd_deathrow
) &&
1132 list_empty(&the_lnet
.ln_rcd_zombie
)))
1135 INIT_LIST_HEAD(&head
);
1137 lnet_net_lock(LNET_LOCK_EX
);
1139 if (the_lnet
.ln_rc_state
!= LNET_RC_STATE_RUNNING
) {
1140 /* router checker is stopping, prune all */
1141 list_for_each_entry(lp
, &the_lnet
.ln_routers
,
1146 LASSERT(list_empty(&lp
->lp_rcd
->rcd_list
));
1147 list_add(&lp
->lp_rcd
->rcd_list
,
1148 &the_lnet
.ln_rcd_deathrow
);
1153 /* unlink all RCDs on deathrow list */
1154 list_splice_init(&the_lnet
.ln_rcd_deathrow
, &head
);
1156 if (!list_empty(&head
)) {
1157 lnet_net_unlock(LNET_LOCK_EX
);
1159 list_for_each_entry(rcd
, &head
, rcd_list
)
1160 LNetMDUnlink(rcd
->rcd_mdh
);
1162 lnet_net_lock(LNET_LOCK_EX
);
1165 list_splice_init(&head
, &the_lnet
.ln_rcd_zombie
);
1167 /* release all zombie RCDs */
1168 while (!list_empty(&the_lnet
.ln_rcd_zombie
)) {
1169 list_for_each_entry_safe(rcd
, tmp
, &the_lnet
.ln_rcd_zombie
,
1171 if (LNetHandleIsInvalid(rcd
->rcd_mdh
))
1172 list_move(&rcd
->rcd_list
, &head
);
1175 wait_unlink
= wait_unlink
&&
1176 !list_empty(&the_lnet
.ln_rcd_zombie
);
1178 lnet_net_unlock(LNET_LOCK_EX
);
1180 while (!list_empty(&head
)) {
1181 rcd
= list_entry(head
.next
,
1182 lnet_rc_data_t
, rcd_list
);
1183 list_del_init(&rcd
->rcd_list
);
1184 lnet_destroy_rc_data(rcd
);
1191 CDEBUG(((i
& (-i
)) == i
) ? D_WARNING
: D_NET
,
1192 "Waiting for rc buffers to unlink\n");
1193 set_current_state(TASK_UNINTERRUPTIBLE
);
1194 schedule_timeout(cfs_time_seconds(1) / 4);
1196 lnet_net_lock(LNET_LOCK_EX
);
1199 lnet_net_unlock(LNET_LOCK_EX
);
1203 lnet_router_checker(void *arg
)
1206 struct list_head
*entry
;
1208 cfs_block_allsigs();
1210 LASSERT(the_lnet
.ln_rc_state
== LNET_RC_STATE_RUNNING
);
1212 while (the_lnet
.ln_rc_state
== LNET_RC_STATE_RUNNING
) {
1217 cpt
= lnet_net_lock_current();
1219 version
= the_lnet
.ln_routers_version
;
1221 list_for_each(entry
, &the_lnet
.ln_routers
) {
1222 rtr
= list_entry(entry
, lnet_peer_t
, lp_rtr_list
);
1224 cpt2
= lnet_cpt_of_nid_locked(rtr
->lp_nid
);
1226 lnet_net_unlock(cpt
);
1229 /* the routers list has changed */
1230 if (version
!= the_lnet
.ln_routers_version
)
1234 lnet_ping_router_locked(rtr
);
1236 /* NB dropped lock */
1237 if (version
!= the_lnet
.ln_routers_version
) {
1238 /* the routers list has changed */
1243 if (the_lnet
.ln_routing
)
1244 lnet_update_ni_status_locked();
1246 lnet_net_unlock(cpt
);
1248 lnet_prune_rc_data(0); /* don't wait for UNLINK */
1251 * Call schedule_timeout() here always adds 1 to load average
1252 * because kernel counts # active tasks as nr_running
1253 * + nr_uninterruptible.
1255 set_current_state(TASK_INTERRUPTIBLE
);
1256 schedule_timeout(cfs_time_seconds(1));
1259 LASSERT(the_lnet
.ln_rc_state
== LNET_RC_STATE_STOPPING
);
1261 lnet_prune_rc_data(1); /* wait for UNLINK */
1263 the_lnet
.ln_rc_state
= LNET_RC_STATE_SHUTDOWN
;
1264 up(&the_lnet
.ln_rc_signal
);
1265 /* The unlink event callback will signal final completion */
1270 lnet_destroy_rtrbuf(lnet_rtrbuf_t
*rb
, int npages
)
1272 int sz
= offsetof(lnet_rtrbuf_t
, rb_kiov
[npages
]);
1274 while (--npages
>= 0)
1275 __free_page(rb
->rb_kiov
[npages
].kiov_page
);
1277 LIBCFS_FREE(rb
, sz
);
1280 static lnet_rtrbuf_t
*
1281 lnet_new_rtrbuf(lnet_rtrbufpool_t
*rbp
, int cpt
)
1283 int npages
= rbp
->rbp_npages
;
1284 int sz
= offsetof(lnet_rtrbuf_t
, rb_kiov
[npages
]);
1289 LIBCFS_CPT_ALLOC(rb
, lnet_cpt_table(), cpt
, sz
);
1295 for (i
= 0; i
< npages
; i
++) {
1296 page
= alloc_pages_node(
1297 cfs_cpt_spread_node(lnet_cpt_table(), cpt
),
1298 GFP_KERNEL
| __GFP_ZERO
, 0);
1301 __free_page(rb
->rb_kiov
[i
].kiov_page
);
1303 LIBCFS_FREE(rb
, sz
);
1307 rb
->rb_kiov
[i
].kiov_len
= PAGE_CACHE_SIZE
;
1308 rb
->rb_kiov
[i
].kiov_offset
= 0;
1309 rb
->rb_kiov
[i
].kiov_page
= page
;
1316 lnet_rtrpool_free_bufs(lnet_rtrbufpool_t
*rbp
, int cpt
)
1318 int npages
= rbp
->rbp_npages
;
1319 struct list_head tmp
;
1322 if (!rbp
->rbp_nbuffers
) /* not initialized or already freed */
1325 INIT_LIST_HEAD(&tmp
);
1328 lnet_drop_routed_msgs_locked(&rbp
->rbp_msgs
, cpt
);
1329 list_splice_init(&rbp
->rbp_bufs
, &tmp
);
1330 rbp
->rbp_nbuffers
= 0;
1331 rbp
->rbp_credits
= 0;
1332 rbp
->rbp_mincredits
= 0;
1333 lnet_net_unlock(cpt
);
1335 /* Free buffers on the free list. */
1336 while (!list_empty(&tmp
)) {
1337 rb
= list_entry(tmp
.next
, lnet_rtrbuf_t
, rb_list
);
1338 list_del(&rb
->rb_list
);
1339 lnet_destroy_rtrbuf(rb
, npages
);
1344 lnet_rtrpool_adjust_bufs(lnet_rtrbufpool_t
*rbp
, int nbufs
, int cpt
)
1346 struct list_head rb_list
;
1349 int num_buffers
= 0;
1350 int npages
= rbp
->rbp_npages
;
1353 * If we are called for less buffers than already in the pool, we
1354 * just lower the nbuffers number and excess buffers will be
1355 * thrown away as they are returned to the free list. Credits
1356 * then get adjusted as well.
1358 if (nbufs
<= rbp
->rbp_nbuffers
) {
1360 rbp
->rbp_nbuffers
= nbufs
;
1361 lnet_net_unlock(cpt
);
1365 INIT_LIST_HEAD(&rb_list
);
1368 * allocate the buffers on a local list first. If all buffers are
1369 * allocated successfully then join this list to the rbp buffer
1370 * list. If not then free all allocated buffers.
1372 num_rb
= rbp
->rbp_nbuffers
;
1374 while (num_rb
< nbufs
) {
1375 rb
= lnet_new_rtrbuf(rbp
, cpt
);
1377 CERROR("Failed to allocate %d route bufs of %d pages\n",
1382 list_add(&rb
->rb_list
, &rb_list
);
1389 list_splice_tail(&rb_list
, &rbp
->rbp_bufs
);
1390 rbp
->rbp_nbuffers
+= num_buffers
;
1391 rbp
->rbp_credits
+= num_buffers
;
1392 rbp
->rbp_mincredits
= rbp
->rbp_credits
;
1394 * We need to schedule blocked msg using the newly
1397 while (!list_empty(&rbp
->rbp_bufs
) &&
1398 !list_empty(&rbp
->rbp_msgs
))
1399 lnet_schedule_blocked_locked(rbp
);
1401 lnet_net_unlock(cpt
);
1406 while (!list_empty(&rb_list
)) {
1407 rb
= list_entry(rb_list
.next
, lnet_rtrbuf_t
, rb_list
);
1408 list_del(&rb
->rb_list
);
1409 lnet_destroy_rtrbuf(rb
, npages
);
1416 lnet_rtrpool_init(lnet_rtrbufpool_t
*rbp
, int npages
)
1418 INIT_LIST_HEAD(&rbp
->rbp_msgs
);
1419 INIT_LIST_HEAD(&rbp
->rbp_bufs
);
1421 rbp
->rbp_npages
= npages
;
1422 rbp
->rbp_credits
= 0;
1423 rbp
->rbp_mincredits
= 0;
1427 lnet_rtrpools_free(int keep_pools
)
1429 lnet_rtrbufpool_t
*rtrp
;
1432 if (!the_lnet
.ln_rtrpools
) /* uninitialized or freed */
1435 cfs_percpt_for_each(rtrp
, i
, the_lnet
.ln_rtrpools
) {
1436 lnet_rtrpool_free_bufs(&rtrp
[LNET_TINY_BUF_IDX
], i
);
1437 lnet_rtrpool_free_bufs(&rtrp
[LNET_SMALL_BUF_IDX
], i
);
1438 lnet_rtrpool_free_bufs(&rtrp
[LNET_LARGE_BUF_IDX
], i
);
1442 cfs_percpt_free(the_lnet
.ln_rtrpools
);
1443 the_lnet
.ln_rtrpools
= NULL
;
1448 lnet_nrb_tiny_calculate(void)
1450 int nrbs
= LNET_NRB_TINY
;
1452 if (tiny_router_buffers
< 0) {
1453 LCONSOLE_ERROR_MSG(0x10c,
1454 "tiny_router_buffers=%d invalid when routing enabled\n",
1455 tiny_router_buffers
);
1459 if (tiny_router_buffers
> 0)
1460 nrbs
= tiny_router_buffers
;
1462 nrbs
/= LNET_CPT_NUMBER
;
1463 return max(nrbs
, LNET_NRB_TINY_MIN
);
1467 lnet_nrb_small_calculate(void)
1469 int nrbs
= LNET_NRB_SMALL
;
1471 if (small_router_buffers
< 0) {
1472 LCONSOLE_ERROR_MSG(0x10c,
1473 "small_router_buffers=%d invalid when routing enabled\n",
1474 small_router_buffers
);
1478 if (small_router_buffers
> 0)
1479 nrbs
= small_router_buffers
;
1481 nrbs
/= LNET_CPT_NUMBER
;
1482 return max(nrbs
, LNET_NRB_SMALL_MIN
);
1486 lnet_nrb_large_calculate(void)
1488 int nrbs
= LNET_NRB_LARGE
;
1490 if (large_router_buffers
< 0) {
1491 LCONSOLE_ERROR_MSG(0x10c,
1492 "large_router_buffers=%d invalid when routing enabled\n",
1493 large_router_buffers
);
1497 if (large_router_buffers
> 0)
1498 nrbs
= large_router_buffers
;
1500 nrbs
/= LNET_CPT_NUMBER
;
1501 return max(nrbs
, LNET_NRB_LARGE_MIN
);
1505 lnet_rtrpools_alloc(int im_a_router
)
1507 lnet_rtrbufpool_t
*rtrp
;
1514 if (!strcmp(forwarding
, "")) {
1515 /* not set either way */
1518 } else if (!strcmp(forwarding
, "disabled")) {
1519 /* explicitly disabled */
1521 } else if (!strcmp(forwarding
, "enabled")) {
1522 /* explicitly enabled */
1524 LCONSOLE_ERROR_MSG(0x10b, "'forwarding' not set to either 'enabled' or 'disabled'\n");
1528 nrb_tiny
= lnet_nrb_tiny_calculate();
1532 nrb_small
= lnet_nrb_small_calculate();
1536 nrb_large
= lnet_nrb_large_calculate();
1540 the_lnet
.ln_rtrpools
= cfs_percpt_alloc(lnet_cpt_table(),
1542 sizeof(lnet_rtrbufpool_t
));
1543 if (!the_lnet
.ln_rtrpools
) {
1544 LCONSOLE_ERROR_MSG(0x10c,
1545 "Failed to initialize router buffe pool\n");
1549 cfs_percpt_for_each(rtrp
, i
, the_lnet
.ln_rtrpools
) {
1550 lnet_rtrpool_init(&rtrp
[LNET_TINY_BUF_IDX
], 0);
1551 rc
= lnet_rtrpool_adjust_bufs(&rtrp
[LNET_TINY_BUF_IDX
],
1556 lnet_rtrpool_init(&rtrp
[LNET_SMALL_BUF_IDX
],
1557 LNET_NRB_SMALL_PAGES
);
1558 rc
= lnet_rtrpool_adjust_bufs(&rtrp
[LNET_SMALL_BUF_IDX
],
1563 lnet_rtrpool_init(&rtrp
[LNET_LARGE_BUF_IDX
],
1564 LNET_NRB_LARGE_PAGES
);
1565 rc
= lnet_rtrpool_adjust_bufs(&rtrp
[LNET_LARGE_BUF_IDX
],
1571 lnet_net_lock(LNET_LOCK_EX
);
1572 the_lnet
.ln_routing
= 1;
1573 lnet_net_unlock(LNET_LOCK_EX
);
1578 lnet_rtrpools_free(0);
1583 lnet_rtrpools_adjust_helper(int tiny
, int small
, int large
)
1588 lnet_rtrbufpool_t
*rtrp
;
1591 * If the provided values for each buffer pool are different than the
1592 * configured values, we need to take action.
1595 tiny_router_buffers
= tiny
;
1596 nrb
= lnet_nrb_tiny_calculate();
1597 cfs_percpt_for_each(rtrp
, i
, the_lnet
.ln_rtrpools
) {
1598 rc
= lnet_rtrpool_adjust_bufs(&rtrp
[LNET_TINY_BUF_IDX
],
1605 small_router_buffers
= small
;
1606 nrb
= lnet_nrb_small_calculate();
1607 cfs_percpt_for_each(rtrp
, i
, the_lnet
.ln_rtrpools
) {
1608 rc
= lnet_rtrpool_adjust_bufs(&rtrp
[LNET_SMALL_BUF_IDX
],
1615 large_router_buffers
= large
;
1616 nrb
= lnet_nrb_large_calculate();
1617 cfs_percpt_for_each(rtrp
, i
, the_lnet
.ln_rtrpools
) {
1618 rc
= lnet_rtrpool_adjust_bufs(&rtrp
[LNET_LARGE_BUF_IDX
],
1629 lnet_rtrpools_adjust(int tiny
, int small
, int large
)
1632 * this function doesn't revert the changes if adding new buffers
1633 * failed. It's up to the user space caller to revert the
1636 if (!the_lnet
.ln_routing
)
1639 return lnet_rtrpools_adjust_helper(tiny
, small
, large
);
1643 lnet_rtrpools_enable(void)
1647 if (the_lnet
.ln_routing
)
1650 if (!the_lnet
.ln_rtrpools
)
1652 * If routing is turned off, and we have never
1653 * initialized the pools before, just call the
1654 * standard buffer pool allocation routine as
1655 * if we are just configuring this for the first
1658 return lnet_rtrpools_alloc(1);
1660 rc
= lnet_rtrpools_adjust_helper(0, 0, 0);
1664 lnet_net_lock(LNET_LOCK_EX
);
1665 the_lnet
.ln_routing
= 1;
1667 the_lnet
.ln_ping_info
->pi_features
&= ~LNET_PING_FEAT_RTE_DISABLED
;
1668 lnet_net_unlock(LNET_LOCK_EX
);
1674 lnet_rtrpools_disable(void)
1676 if (!the_lnet
.ln_routing
)
1679 lnet_net_lock(LNET_LOCK_EX
);
1680 the_lnet
.ln_routing
= 0;
1681 the_lnet
.ln_ping_info
->pi_features
|= LNET_PING_FEAT_RTE_DISABLED
;
1683 tiny_router_buffers
= 0;
1684 small_router_buffers
= 0;
1685 large_router_buffers
= 0;
1686 lnet_net_unlock(LNET_LOCK_EX
);
1687 lnet_rtrpools_free(1);
1691 lnet_notify(lnet_ni_t
*ni
, lnet_nid_t nid
, int alive
, unsigned long when
)
1693 struct lnet_peer
*lp
= NULL
;
1694 unsigned long now
= cfs_time_current();
1695 int cpt
= lnet_cpt_of_nid(nid
);
1697 LASSERT(!in_interrupt());
1699 CDEBUG(D_NET
, "%s notifying %s: %s\n",
1700 !ni
? "userspace" : libcfs_nid2str(ni
->ni_nid
),
1701 libcfs_nid2str(nid
),
1702 alive
? "up" : "down");
1705 LNET_NIDNET(ni
->ni_nid
) != LNET_NIDNET(nid
)) {
1706 CWARN("Ignoring notification of %s %s by %s (different net)\n",
1707 libcfs_nid2str(nid
), alive
? "birth" : "death",
1708 libcfs_nid2str(ni
->ni_nid
));
1712 /* can't do predictions... */
1713 if (cfs_time_after(when
, now
)) {
1714 CWARN("Ignoring prediction from %s of %s %s %ld seconds in the future\n",
1715 !ni
? "userspace" : libcfs_nid2str(ni
->ni_nid
),
1716 libcfs_nid2str(nid
), alive
? "up" : "down",
1717 cfs_duration_sec(cfs_time_sub(when
, now
)));
1721 if (ni
&& !alive
&& /* LND telling me she's down */
1722 !auto_down
) { /* auto-down disabled */
1723 CDEBUG(D_NET
, "Auto-down disabled\n");
1729 if (the_lnet
.ln_shutdown
) {
1730 lnet_net_unlock(cpt
);
1734 lp
= lnet_find_peer_locked(the_lnet
.ln_peer_tables
[cpt
], nid
);
1737 lnet_net_unlock(cpt
);
1738 CDEBUG(D_NET
, "%s not found\n", libcfs_nid2str(nid
));
1743 * We can't fully trust LND on reporting exact peer last_alive
1744 * if he notifies us about dead peer. For example ksocklnd can
1745 * call us with when == _time_when_the_node_was_booted_ if
1746 * no connections were successfully established
1748 if (ni
&& !alive
&& when
< lp
->lp_last_alive
)
1749 when
= lp
->lp_last_alive
;
1751 lnet_notify_locked(lp
, !ni
, alive
, when
);
1753 lnet_ni_notify_locked(ni
, lp
);
1755 lnet_peer_decref_locked(lp
);
1757 lnet_net_unlock(cpt
);
1760 EXPORT_SYMBOL(lnet_notify
);