2 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
4 * Copyright (c) 2011, 2017, Intel Corporation.
6 * This file is part of Lustre, https://wiki.whamcloud.com/
8 * Portals is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Portals is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Portals; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #define DEBUG_SUBSYSTEM S_LNET
25 #include <linux/random.h>
26 #include <lnet/lib-lnet.h>
28 #define LNET_NRB_TINY_MIN 512 /* min value for each CPT */
29 #define LNET_NRB_TINY (LNET_NRB_TINY_MIN * 4)
30 #define LNET_NRB_SMALL_MIN 4096 /* min value for each CPT */
31 #define LNET_NRB_SMALL (LNET_NRB_SMALL_MIN * 4)
32 #define LNET_NRB_SMALL_PAGES 1
33 #define LNET_NRB_LARGE_MIN 256 /* min value for each CPT */
34 #define LNET_NRB_LARGE (LNET_NRB_LARGE_MIN * 4)
35 #define LNET_NRB_LARGE_PAGES ((LNET_MTU + PAGE_SIZE - 1) >> \
38 static char *forwarding = "";
39 module_param(forwarding, charp, 0444);
40 MODULE_PARM_DESC(forwarding, "Explicitly enable/disable forwarding between networks");
42 static int tiny_router_buffers;
43 module_param(tiny_router_buffers, int, 0444);
44 MODULE_PARM_DESC(tiny_router_buffers, "# of 0 payload messages to buffer in the router");
45 static int small_router_buffers;
46 module_param(small_router_buffers, int, 0444);
47 MODULE_PARM_DESC(small_router_buffers, "# of small (1 page) messages to buffer in the router");
48 static int large_router_buffers;
49 module_param(large_router_buffers, int, 0444);
50 MODULE_PARM_DESC(large_router_buffers, "# of large messages to buffer in the router");
51 static int peer_buffer_credits;
52 module_param(peer_buffer_credits, int, 0444);
53 MODULE_PARM_DESC(peer_buffer_credits, "# router buffer credits per peer");
55 static int auto_down = 1;
56 module_param(auto_down, int, 0444);
57 MODULE_PARM_DESC(auto_down, "Automatically mark peers down on comms error");
60 lnet_peer_buffer_credits(struct lnet_net *net)
62 /* NI option overrides LNet default */
63 if (net->net_tunables.lct_peer_rtr_credits > 0)
64 return net->net_tunables.lct_peer_rtr_credits;
65 if (peer_buffer_credits > 0)
66 return peer_buffer_credits;
68 /* As an approximation, allow this peer the same number of router
69 * buffers as it is allowed outstanding sends */
70 return net->net_tunables.lct_peer_tx_credits;
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 int dead_router_check_interval = INT_MIN;
82 module_param(dead_router_check_interval, int, 0444);
83 MODULE_PARM_DESC(dead_router_check_interval, "(DEPRECATED - Use alive_router_check_interval)");
85 int live_router_check_interval = INT_MIN;
86 module_param(live_router_check_interval, int, 0444);
87 MODULE_PARM_DESC(live_router_check_interval, "(DEPRECATED - Use alive_router_check_interval)");
89 int alive_router_check_interval = 60;
90 module_param(alive_router_check_interval, int, 0644);
91 MODULE_PARM_DESC(alive_router_check_interval, "Seconds between live router health checks (<= 0 to disable)");
93 static int router_ping_timeout = 50;
94 module_param(router_ping_timeout, int, 0644);
95 MODULE_PARM_DESC(router_ping_timeout, "Seconds to wait for the reply to a router health query");
98 * A value between 0 and 100. 0 meaning that even if router's interfaces
99 * have the worse health still consider the gateway usable.
100 * 100 means that at least one interface on the route's remote net is 100%
101 * healthy to consider the route alive.
102 * The default is set to 100 to ensure we maintain the original behavior.
104 unsigned int router_sensitivity_percentage = 100;
105 static int rtr_sensitivity_set(const char *val, cfs_kernel_param_arg_t *kp);
106 static struct kernel_param_ops param_ops_rtr_sensitivity = {
107 .set = rtr_sensitivity_set,
108 .get = param_get_int,
110 #define param_check_rtr_sensitivity(name, p) \
111 __param_check(name, p, int)
112 #ifdef HAVE_KERNEL_PARAM_OPS
113 module_param(router_sensitivity_percentage, rtr_sensitivity, S_IRUGO|S_IWUSR);
115 module_param_call(router_sensitivity_percentage, rtr_sensitivity_set, param_get_int,
116 &router_sensitivity_percentage, S_IRUGO|S_IWUSR);
118 MODULE_PARM_DESC(router_sensitivity_percentage,
119 "How healthy a gateway should be to be used in percent");
122 rtr_sensitivity_set(const char *val, cfs_kernel_param_arg_t *kp)
125 unsigned *sen = (unsigned *)kp->arg;
128 rc = kstrtoul(val, 0, &value);
130 CERROR("Invalid module parameter value for 'router_sensitivity_percentage'\n");
134 if (value < 0 || value > 100) {
135 CERROR("Invalid value: %lu for 'router_sensitivity_percentage'\n", value);
140 * The purpose of locking the api_mutex here is to ensure that
141 * the correct value ends up stored properly.
143 mutex_lock(&the_lnet.ln_api_mutex);
147 mutex_unlock(&the_lnet.ln_api_mutex);
153 lnet_rtr_transfer_to_peer(struct lnet_peer *src, struct lnet_peer *target)
155 struct lnet_route *route;
157 lnet_net_lock(LNET_LOCK_EX);
158 target->lp_rtr_refcount += src->lp_rtr_refcount;
159 /* move the list of queued messages to the new peer */
160 list_splice_init(&src->lp_rtrq, &target->lp_rtrq);
161 /* move all the routes that reference the peer */
162 list_splice_init(&src->lp_routes, &target->lp_routes);
163 /* update all the routes to point to the new peer */
164 list_for_each_entry(route, &target->lp_routes, lr_gwlist)
165 route->lr_gateway = target;
166 /* remove the old peer from the ln_routers list */
167 list_del_init(&src->lp_rtr_list);
168 /* add the new peer to the ln_routers list */
169 if (list_empty(&target->lp_rtr_list)) {
170 lnet_peer_addref_locked(target);
171 list_add_tail(&target->lp_rtr_list, &the_lnet.ln_routers);
173 /* reset the ref count on the old peer and decrement its ref count */
174 src->lp_rtr_refcount = 0;
175 lnet_peer_decref_locked(src);
176 /* update the router version */
177 the_lnet.ln_routers_version++;
178 lnet_net_unlock(LNET_LOCK_EX);
182 lnet_peers_start_down(void)
184 return check_routers_before_use;
188 * The peer_net of a gateway is alive if at least one of the peer_ni's on
189 * that peer_net is alive.
192 lnet_is_gateway_net_alive(struct lnet_peer_net *lpn)
194 struct lnet_peer_ni *lpni;
196 list_for_each_entry(lpni, &lpn->lpn_peer_nis, lpni_peer_nis) {
197 if (lnet_is_peer_ni_alive(lpni))
205 * a gateway is alive only if all its nets are alive
206 * called with cpt lock held
208 bool lnet_is_gateway_alive(struct lnet_peer *gw)
210 struct lnet_peer_net *lpn;
215 list_for_each_entry(lpn, &gw->lp_peer_nets, lpn_peer_nets) {
216 if (!lnet_is_gateway_net_alive(lpn))
224 * lnet_is_route_alive() needs to be called with cpt lock held
225 * A route is alive if the gateway can route between the local network and
226 * the remote network of the route.
227 * This means at least one NI is alive on each of the local and remote
228 * networks of the gateway.
230 bool lnet_is_route_alive(struct lnet_route *route)
232 struct lnet_peer *gw = route->lr_gateway;
233 struct lnet_peer_net *llpn;
234 struct lnet_peer_net *rlpn;
236 /* If the gateway is down then all routes are considered down */
241 * if discovery is disabled then rely on the cached aliveness
242 * information. This is handicapped information which we log when
243 * we receive the discovery ping response. The most uptodate
244 * aliveness information can only be obtained when discovery is
247 if (lnet_is_discovery_disabled(gw))
248 return route->lr_alive;
251 * check the gateway's interfaces on the local network
253 llpn = lnet_peer_get_net_locked(gw, route->lr_lnet);
257 if (!lnet_is_gateway_net_alive(llpn))
261 * For single hop routes avoid_asym_router_failure dictates
262 * that the remote net must exist on the gateway. For multi-hop
263 * routes the next-hop will not have the remote net.
265 if (avoid_asym_router_failure && route->lr_single_hop) {
266 rlpn = lnet_peer_get_net_locked(gw, route->lr_net);
269 if (!lnet_is_gateway_net_alive(rlpn))
273 spin_lock(&gw->lp_lock);
274 if (!(gw->lp_state & LNET_PEER_ROUTER_ENABLED)) {
275 spin_unlock(&gw->lp_lock);
276 if (gw->lp_rtr_refcount > 0)
277 CERROR("peer %s is being used as a gateway but routing feature is not turned on\n",
278 libcfs_nid2str(gw->lp_primary_nid));
281 spin_unlock(&gw->lp_lock);
287 lnet_consolidate_routes_locked(struct lnet_peer *orig_lp,
288 struct lnet_peer *new_lp)
290 struct lnet_peer_ni *lpni;
291 struct lnet_route *route;
294 * Although a route is correlated with a peer, but when it's added
295 * a specific NID is used. That NID refers to a peer_ni within
296 * a peer. There could be other peer_nis on the same net, which
297 * can be used to send to that gateway. However when we are
298 * consolidating gateways because of discovery, the nid used to
299 * add the route might've moved between gateway peers. In this
300 * case we want to move the route to the new gateway as well. The
301 * intent here is not to confuse the user who added the route.
303 list_for_each_entry(route, &orig_lp->lp_routes, lr_gwlist) {
304 lpni = lnet_peer_get_ni_locked(orig_lp, route->lr_nid);
306 lnet_net_lock(LNET_LOCK_EX);
307 list_move(&route->lr_gwlist, &new_lp->lp_routes);
308 lnet_net_unlock(LNET_LOCK_EX);
314 lnet_check_route_inconsistency(struct lnet_route *route)
316 if (!route->lr_single_hop && (int)route->lr_hops <= 1) {
317 CWARN("route %s->%s is detected to be multi-hop but hop count is set to %d\n",
318 libcfs_net2str(route->lr_net),
319 libcfs_nid2str(route->lr_gateway->lp_primary_nid),
320 (int) route->lr_hops);
325 lnet_set_route_hop_type(struct lnet_peer *gw, struct lnet_route *route)
327 struct lnet_peer_net *lpn;
328 bool single_hop = false;
330 list_for_each_entry(lpn, &gw->lp_peer_nets, lpn_peer_nets) {
331 if (route->lr_net == lpn->lpn_net_id) {
336 route->lr_single_hop = single_hop;
337 lnet_check_route_inconsistency(route);
341 lnet_set_route_aliveness(struct lnet_route *route, bool alive)
343 /* Log when there's a state change */
344 if (route->lr_alive != alive) {
345 CERROR("route to %s through %s has gone from %s to %s\n",
346 libcfs_net2str(route->lr_net),
347 libcfs_nid2str(route->lr_gateway->lp_primary_nid),
348 (route->lr_alive) ? "up" : "down",
349 alive ? "up" : "down");
350 route->lr_alive = alive;
355 lnet_router_discovery_ping_reply(struct lnet_peer *lp)
357 struct lnet_ping_buffer *pbuf = lp->lp_data;
358 struct lnet_peer_net *llpn;
359 struct lnet_route *route;
360 bool single_hop = false;
367 spin_lock(&lp->lp_lock);
368 lp_state = lp->lp_state;
370 /* only handle replies if discovery is disabled. */
371 if (!lnet_is_discovery_disabled_locked(lp)) {
372 spin_unlock(&lp->lp_lock);
376 spin_unlock(&lp->lp_lock);
378 if (lp_state & LNET_PEER_PING_FAILED ||
379 pbuf->pb_info.pi_features & LNET_PING_FEAT_RTE_DISABLED) {
380 CDEBUG(D_NET, "Set routes down for gw %s because %s %d\n",
381 libcfs_nid2str(lp->lp_primary_nid),
382 lp_state & LNET_PEER_PING_FAILED ? "ping failed" :
383 "route feature is disabled", lp->lp_ping_error);
384 /* If the ping failed or the peer has routing disabled then
385 * mark the routes served by this peer down
387 list_for_each_entry(route, &lp->lp_routes, lr_gwlist)
388 lnet_set_route_aliveness(route, false);
392 CDEBUG(D_NET, "Discovery is disabled. Processing reply for gw: %s:%d\n",
393 libcfs_nid2str(lp->lp_primary_nid), pbuf->pb_info.pi_nnis);
396 * examine the ping response to determine if the routes on that
397 * gateway should be declared alive.
398 * The route is alive if:
399 * 1. local network to reach the route is alive and
400 * 2. route is single hop, avoid_async_router_failure is set and
401 * there exists at least one NI on the route's remote net
403 list_for_each_entry(route, &lp->lp_routes, lr_gwlist) {
404 llpn = lnet_peer_get_net_locked(lp, route->lr_lnet);
406 lnet_set_route_aliveness(route, false);
410 if (!lnet_is_gateway_net_alive(llpn)) {
411 lnet_set_route_aliveness(route, false);
415 single_hop = net_up = false;
416 for (i = 1; i < pbuf->pb_info.pi_nnis; i++) {
417 net = LNET_NIDNET(pbuf->pb_info.pi_ni[i].ns_nid);
419 if (route->lr_net == net) {
421 if (pbuf->pb_info.pi_ni[i].ns_status ==
429 route->lr_single_hop = single_hop;
430 if (avoid_asym_router_failure && single_hop)
431 lnet_set_route_aliveness(route, net_up);
433 lnet_set_route_aliveness(route, true);
436 * warn that the route is configured as single-hop but it
437 * really is multi-hop as far as we can tell.
439 lnet_check_route_inconsistency(route);
444 lnet_router_discovery_complete(struct lnet_peer *lp)
446 struct lnet_peer_ni *lpni = NULL;
447 struct lnet_route *route;
449 spin_lock(&lp->lp_lock);
450 lp->lp_state &= ~LNET_PEER_RTR_DISCOVERY;
451 lp->lp_state |= LNET_PEER_RTR_DISCOVERED;
452 lp->lp_alive = lp->lp_dc_error == 0;
453 spin_unlock(&lp->lp_lock);
455 /* ping replies are being handled when discovery is disabled */
456 if (lnet_is_discovery_disabled_locked(lp))
459 if (!lp->lp_dc_error) {
461 * mark single-hop routes. If the remote net is not configured on
462 * the gateway we assume this is intentional and we mark the
463 * gateway as multi-hop
465 list_for_each_entry(route, &lp->lp_routes, lr_gwlist)
466 lnet_set_route_hop_type(lp, route);
472 * We do not send messages directly to the remote interfaces
473 * of an LNet router. As such, we rely on the PING response
474 * to determine the up/down status of these interfaces. If
475 * a PING response is not receieved, or some other problem with
476 * discovery occurs that prevents us from getting this status,
477 * we assume all interfaces are down until we're able to
478 * determine otherwise.
480 CDEBUG(D_NET, "%s: Router discovery failed %d\n",
481 libcfs_nid2str(lp->lp_primary_nid), lp->lp_dc_error);
482 while ((lpni = lnet_get_next_peer_ni_locked(lp, NULL, lpni)) != NULL)
483 lpni->lpni_ns_status = LNET_NI_STATUS_DOWN;
485 list_for_each_entry(route, &lp->lp_routes, lr_gwlist)
486 lnet_set_route_aliveness(route, false);
490 lnet_rtr_addref_locked(struct lnet_peer *lp)
492 LASSERT(lp->lp_rtr_refcount >= 0);
494 /* lnet_net_lock must be exclusively locked */
495 lp->lp_rtr_refcount++;
496 if (lp->lp_rtr_refcount == 1) {
497 list_add_tail(&lp->lp_rtr_list, &the_lnet.ln_routers);
498 /* addref for the_lnet.ln_routers */
499 lnet_peer_addref_locked(lp);
500 the_lnet.ln_routers_version++;
505 lnet_rtr_decref_locked(struct lnet_peer *lp)
507 LASSERT(atomic_read(&lp->lp_refcount) > 0);
508 LASSERT(lp->lp_rtr_refcount > 0);
510 /* lnet_net_lock must be exclusively locked */
511 lp->lp_rtr_refcount--;
512 if (lp->lp_rtr_refcount == 0) {
513 LASSERT(list_empty(&lp->lp_routes));
515 list_del(&lp->lp_rtr_list);
516 /* decref for the_lnet.ln_routers */
517 lnet_peer_decref_locked(lp);
518 the_lnet.ln_routers_version++;
522 struct lnet_remotenet *
523 lnet_find_rnet_locked(__u32 net)
525 struct lnet_remotenet *rnet;
526 struct list_head *tmp;
527 struct list_head *rn_list;
529 LASSERT(the_lnet.ln_state == LNET_STATE_RUNNING);
531 rn_list = lnet_net2rnethash(net);
532 list_for_each(tmp, rn_list) {
533 rnet = list_entry(tmp, struct lnet_remotenet, lrn_list);
535 if (rnet->lrn_net == net)
541 static void lnet_shuffle_seed(void)
544 struct lnet_ni *ni = NULL;
549 /* Nodes with small feet have little entropy
550 * the NID for this node gives the most entropy in the low bits */
551 while ((ni = lnet_get_next_ni_locked(NULL, ni)))
552 add_device_randomness(&ni->ni_nid, sizeof(ni->ni_nid));
557 /* NB expects LNET_LOCK held */
559 lnet_add_route_to_rnet(struct lnet_remotenet *rnet, struct lnet_route *route)
561 struct lnet_peer_net *lpn;
562 unsigned int offset = 0;
563 unsigned int len = 0;
568 list_for_each(e, &rnet->lrn_routes)
572 * Randomly adding routes to the list is done to ensure that when
573 * different nodes are using the same list of routers, they end up
574 * preferring different routers.
576 offset = prandom_u32_max(len + 1);
577 list_for_each(e, &rnet->lrn_routes) {
582 list_add(&route->lr_list, e);
584 * force a router check on the gateway to make sure the route is
587 list_for_each_entry(lpn, &route->lr_gateway->lp_peer_nets,
589 lpn->lpn_rtrcheck_timestamp = 0;
592 the_lnet.ln_remote_nets_version++;
594 /* add the route on the gateway list */
595 list_add(&route->lr_gwlist, &route->lr_gateway->lp_routes);
597 /* take a router reference count on the gateway */
598 lnet_rtr_addref_locked(route->lr_gateway);
602 lnet_add_route(__u32 net, __u32 hops, lnet_nid_t gateway,
603 __u32 priority, __u32 sensitivity)
605 struct list_head *route_entry;
606 struct lnet_remotenet *rnet;
607 struct lnet_remotenet *rnet2;
608 struct lnet_route *route;
609 struct lnet_peer_ni *lpni;
610 struct lnet_peer *gw;
614 CDEBUG(D_NET, "Add route: remote net %s hops %d priority %u gw %s\n",
615 libcfs_net2str(net), hops, priority, libcfs_nid2str(gateway));
617 if (gateway == LNET_NID_ANY ||
618 LNET_NETTYP(LNET_NIDNET(gateway)) == LOLND ||
619 net == LNET_NIDNET(LNET_NID_ANY) ||
620 LNET_NETTYP(net) == LOLND ||
621 LNET_NIDNET(gateway) == net ||
622 (hops != LNET_UNDEFINED_HOPS && (hops < 1 || hops > 255)))
625 /* it's a local network */
626 if (lnet_islocalnet(net))
629 if (!lnet_islocalnet(LNET_NIDNET(gateway))) {
630 CERROR("Cannot add route with gateway %s. There is no local interface configured on LNet %s\n",
631 libcfs_nid2str(gateway),
632 libcfs_net2str(LNET_NIDNET(gateway)));
633 return -EHOSTUNREACH;
636 /* Assume net, route, all new */
637 LIBCFS_ALLOC(route, sizeof(*route));
638 LIBCFS_ALLOC(rnet, sizeof(*rnet));
639 if (route == NULL || rnet == NULL) {
640 CERROR("Out of memory creating route %s %d %s\n",
641 libcfs_net2str(net), hops, libcfs_nid2str(gateway));
643 LIBCFS_FREE(route, sizeof(*route));
645 LIBCFS_FREE(rnet, sizeof(*rnet));
649 INIT_LIST_HEAD(&rnet->lrn_routes);
651 /* store the local and remote net that the route represents */
652 route->lr_lnet = LNET_NIDNET(gateway);
654 route->lr_nid = gateway;
655 route->lr_priority = priority;
656 route->lr_hops = hops;
658 lnet_net_lock(LNET_LOCK_EX);
661 * lnet_nid2peerni_ex() grabs a ref on the lpni. We will need to
662 * lose that once we're done
664 lpni = lnet_nid2peerni_ex(gateway, LNET_LOCK_EX);
666 lnet_net_unlock(LNET_LOCK_EX);
668 LIBCFS_FREE(route, sizeof(*route));
669 LIBCFS_FREE(rnet, sizeof(*rnet));
672 CERROR("Error %d creating route %s %d %s\n", rc,
673 libcfs_net2str(net), hops,
674 libcfs_nid2str(gateway));
678 LASSERT(lpni->lpni_peer_net && lpni->lpni_peer_net->lpn_peer);
679 gw = lpni->lpni_peer_net->lpn_peer;
681 route->lr_gateway = gw;
683 rnet2 = lnet_find_rnet_locked(net);
686 list_add_tail(&rnet->lrn_list, lnet_net2rnethash(net));
690 /* Search for a duplicate route (it's a NOOP if it is) */
692 list_for_each(route_entry, &rnet2->lrn_routes) {
693 struct lnet_route *route2;
695 route2 = list_entry(route_entry, struct lnet_route, lr_list);
696 if (route2->lr_gateway == route->lr_gateway) {
701 /* our lookups must be true */
702 LASSERT(route2->lr_gateway->lp_primary_nid != gateway);
706 * It is possible to add multiple routes through the same peer,
707 * but it'll be using a different NID of that peer. When the
708 * gateway is discovered, discovery will consolidate the different
709 * peers into one peer. In this case the discovery code will have
710 * to move the routes from the peer that's being deleted to the
711 * consolidated peer lp_routes list
714 gw->lp_health_sensitivity = sensitivity;
715 lnet_add_route_to_rnet(rnet2, route);
716 if (lnet_peer_discovery_disabled)
717 CWARN("Consider turning discovery on to enable full "
718 "Multi-Rail routing functionality\n");
722 * get rid of the reference on the lpni.
724 lnet_peer_ni_decref_locked(lpni);
725 lnet_net_unlock(LNET_LOCK_EX);
731 LIBCFS_FREE(route, sizeof(*route));
735 LIBCFS_FREE(rnet, sizeof(*rnet));
737 /* kick start the monitor thread to handle the added route */
738 complete(&the_lnet.ln_mt_wait_complete);
744 lnet_del_route_from_rnet(lnet_nid_t gw_nid, struct list_head *route_list,
745 struct list_head *zombies)
747 struct lnet_peer *gateway;
748 struct lnet_route *route;
749 struct lnet_route *tmp;
751 list_for_each_entry_safe(route, tmp, route_list, lr_list) {
752 gateway = route->lr_gateway;
753 if (gw_nid != LNET_NID_ANY &&
754 gw_nid != gateway->lp_primary_nid)
758 * move to zombie to delete outside the lock
759 * Note that this function is called with the
760 * ln_api_mutex held as well as the exclusive net
761 * lock. Adding to the remote net list happens
762 * under the same conditions. Same goes for the
763 * gateway router list
765 list_move(&route->lr_list, zombies);
766 the_lnet.ln_remote_nets_version++;
768 list_del(&route->lr_gwlist);
769 lnet_rtr_decref_locked(gateway);
774 lnet_del_route(__u32 net, lnet_nid_t gw_nid)
776 LIST_HEAD(rnet_zombies);
777 struct lnet_remotenet *rnet;
778 struct lnet_remotenet *tmp;
779 struct list_head *rn_list;
780 struct lnet_peer_ni *lpni;
781 struct lnet_route *route;
783 struct lnet_peer *lp = NULL;
786 CDEBUG(D_NET, "Del route: net %s : gw %s\n",
787 libcfs_net2str(net), libcfs_nid2str(gw_nid));
789 /* NB Caller may specify either all routes via the given gateway
790 * or a specific route entry actual NIDs) */
792 lnet_net_lock(LNET_LOCK_EX);
794 lpni = lnet_find_peer_ni_locked(gw_nid);
796 lp = lpni->lpni_peer_net->lpn_peer;
798 gw_nid = lp->lp_primary_nid;
799 lnet_peer_ni_decref_locked(lpni);
802 if (net != LNET_NIDNET(LNET_NID_ANY)) {
803 rnet = lnet_find_rnet_locked(net);
805 lnet_net_unlock(LNET_LOCK_EX);
808 lnet_del_route_from_rnet(gw_nid, &rnet->lrn_routes,
810 if (list_empty(&rnet->lrn_routes))
811 list_move(&rnet->lrn_list, &rnet_zombies);
815 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) {
816 rn_list = &the_lnet.ln_remote_nets_hash[i];
818 list_for_each_entry_safe(rnet, tmp, rn_list, lrn_list) {
819 lnet_del_route_from_rnet(gw_nid, &rnet->lrn_routes,
821 if (list_empty(&rnet->lrn_routes))
822 list_move(&rnet->lrn_list, &rnet_zombies);
828 * check if there are any routes remaining on the gateway
829 * If there are no more routes make sure to set the peer's
830 * lp_disc_net_id to 0 (invalid), in case we add more routes in
831 * the future on that gateway, then we start our discovery process
835 if (list_empty(&lp->lp_routes))
836 lp->lp_disc_net_id = 0;
839 lnet_net_unlock(LNET_LOCK_EX);
841 while (!list_empty(&zombies)) {
842 route = list_first_entry(&zombies, struct lnet_route, lr_list);
843 list_del(&route->lr_list);
844 LIBCFS_FREE(route, sizeof(*route));
847 while (!list_empty(&rnet_zombies)) {
848 rnet = list_first_entry(&rnet_zombies, struct lnet_remotenet,
850 list_del(&rnet->lrn_list);
851 LIBCFS_FREE(rnet, sizeof(*rnet));
858 lnet_destroy_routes (void)
860 lnet_del_route(LNET_NIDNET(LNET_NID_ANY), LNET_NID_ANY);
863 int lnet_get_rtr_pool_cfg(int cpt, struct lnet_ioctl_pool_cfg *pool_cfg)
865 struct lnet_rtrbufpool *rbp;
866 int i, rc = -ENOENT, j;
868 if (the_lnet.ln_rtrpools == NULL)
872 cfs_percpt_for_each(rbp, i, the_lnet.ln_rtrpools) {
877 for (j = 0; j < LNET_NRBPOOLS; j++) {
878 pool_cfg->pl_pools[j].pl_npages = rbp[j].rbp_npages;
879 pool_cfg->pl_pools[j].pl_nbuffers = rbp[j].rbp_nbuffers;
880 pool_cfg->pl_pools[j].pl_credits = rbp[j].rbp_credits;
881 pool_cfg->pl_pools[j].pl_mincredits = rbp[j].rbp_mincredits;
888 lnet_net_lock(LNET_LOCK_EX);
889 pool_cfg->pl_routing = the_lnet.ln_routing;
890 lnet_net_unlock(LNET_LOCK_EX);
896 lnet_get_route(int idx, __u32 *net, __u32 *hops,
897 lnet_nid_t *gateway, __u32 *flags, __u32 *priority, __u32 *sensitivity)
899 struct lnet_remotenet *rnet;
900 struct list_head *rn_list;
901 struct lnet_route *route;
902 struct list_head *e1;
903 struct list_head *e2;
907 cpt = lnet_net_lock_current();
909 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) {
910 rn_list = &the_lnet.ln_remote_nets_hash[i];
911 list_for_each(e1, rn_list) {
912 rnet = list_entry(e1, struct lnet_remotenet, lrn_list);
914 list_for_each(e2, &rnet->lrn_routes) {
915 route = list_entry(e2, struct lnet_route,
919 *net = rnet->lrn_net;
920 *gateway = route->lr_nid;
921 *hops = route->lr_hops;
922 *priority = route->lr_priority;
923 *sensitivity = route->lr_gateway->
924 lp_health_sensitivity;
925 if (lnet_is_route_alive(route))
926 *flags |= LNET_RT_ALIVE;
928 *flags &= ~LNET_RT_ALIVE;
929 if (route->lr_single_hop)
930 *flags &= ~LNET_RT_MULTI_HOP;
932 *flags |= LNET_RT_MULTI_HOP;
933 lnet_net_unlock(cpt);
940 lnet_net_unlock(cpt);
945 lnet_wait_known_routerstate(void)
947 struct lnet_peer *rtr;
948 struct list_head *entry;
951 LASSERT(the_lnet.ln_mt_state == LNET_MT_STATE_RUNNING);
954 int cpt = lnet_net_lock_current();
957 list_for_each(entry, &the_lnet.ln_routers) {
958 rtr = list_entry(entry, struct lnet_peer,
961 spin_lock(&rtr->lp_lock);
963 if ((rtr->lp_state & LNET_PEER_RTR_DISCOVERED) == 0) {
965 spin_unlock(&rtr->lp_lock);
968 spin_unlock(&rtr->lp_lock);
971 lnet_net_unlock(cpt);
976 schedule_timeout_uninterruptible(cfs_time_seconds(1));
981 lnet_net_set_status_locked(struct lnet_net *net, __u32 status)
986 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
989 ni->ni_status->ns_status != status) {
990 ni->ni_status->ns_status = status;
1000 lnet_update_ni_status_locked(void)
1002 struct lnet_net *net;
1007 LASSERT(the_lnet.ln_routing);
1009 timeout = router_ping_timeout + alive_router_check_interval;
1011 now = ktime_get_real_seconds();
1012 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1013 if (net->net_lnd->lnd_type == LOLND)
1016 if (now < net->net_last_alive + timeout)
1019 spin_lock(&net->net_lock);
1020 /* re-check with lock */
1021 if (now < net->net_last_alive + timeout) {
1022 spin_unlock(&net->net_lock);
1025 spin_unlock(&net->net_lock);
1028 * if the net didn't receive any traffic for past the
1029 * timeout on any of its constituent NIs, then mark all
1032 push = lnet_net_set_status_locked(net, LNET_NI_STATUS_DOWN);
1038 void lnet_wait_router_start(void)
1040 if (check_routers_before_use) {
1041 /* Note that a helpful side-effect of pinging all known routers
1042 * at startup is that it makes them drop stale connections they
1043 * may have to a previous instance of me. */
1044 lnet_wait_known_routerstate();
1049 * This function is called from the monitor thread to check if there are
1050 * any active routers that need to be checked.
1053 lnet_router_checker_active(void)
1055 /* Router Checker thread needs to run when routing is enabled in
1056 * order to call lnet_update_ni_status_locked() */
1057 if (the_lnet.ln_routing)
1060 return !list_empty(&the_lnet.ln_routers) &&
1061 alive_router_check_interval > 0;
1065 lnet_check_routers(void)
1067 struct lnet_peer_net *first_lpn = NULL;
1068 struct lnet_peer_net *lpn;
1069 struct lnet_peer_ni *lpni;
1070 struct list_head *entry;
1071 struct lnet_peer *rtr;
1080 cpt = lnet_net_lock_current();
1082 version = the_lnet.ln_routers_version;
1084 list_for_each(entry, &the_lnet.ln_routers) {
1085 rtr = list_entry(entry, struct lnet_peer,
1088 now = ktime_get_real_seconds();
1091 * only discover the router if we've passed
1092 * alive_router_check_interval seconds. Some of the router
1093 * interfaces could be down and in that case they would be
1094 * undergoing recovery separately from this discovery.
1096 /* find next peer net which is also local */
1097 net_id = rtr->lp_disc_net_id;
1099 lpn = lnet_get_next_peer_net_locked(rtr, net_id);
1101 CERROR("gateway %s has no networks\n",
1102 libcfs_nid2str(rtr->lp_primary_nid));
1105 if (first_lpn == lpn)
1109 found_lpn = lnet_islocalnet_locked(lpn->lpn_net_id);
1110 net_id = lpn->lpn_net_id;
1111 } while (!found_lpn);
1113 if (!found_lpn || !lpn) {
1114 CERROR("no local network found for gateway %s\n",
1115 libcfs_nid2str(rtr->lp_primary_nid));
1119 if (now - lpn->lpn_rtrcheck_timestamp <
1120 alive_router_check_interval / lnet_current_net_count)
1124 * If we're currently discovering the peer then don't
1125 * issue another discovery
1127 spin_lock(&rtr->lp_lock);
1128 if (rtr->lp_state & LNET_PEER_RTR_DISCOVERY) {
1129 spin_unlock(&rtr->lp_lock);
1132 /* make sure we actively discover the router */
1133 rtr->lp_state &= ~LNET_PEER_NIDS_UPTODATE;
1134 rtr->lp_state |= LNET_PEER_RTR_DISCOVERY;
1135 spin_unlock(&rtr->lp_lock);
1137 /* find the peer_ni associated with the primary NID */
1138 lpni = lnet_peer_get_ni_locked(rtr, rtr->lp_primary_nid);
1140 CDEBUG(D_NET, "Expected to find an lpni for %s, but non found\n",
1141 libcfs_nid2str(rtr->lp_primary_nid));
1144 lnet_peer_ni_addref_locked(lpni);
1146 /* specify the net to use */
1147 rtr->lp_disc_net_id = lpn->lpn_net_id;
1149 /* discover the router */
1150 CDEBUG(D_NET, "discover %s, cpt = %d\n",
1151 libcfs_nid2str(lpni->lpni_nid), cpt);
1152 rc = lnet_discover_peer_locked(lpni, cpt, false);
1154 /* decrement ref count acquired by find_peer_ni_locked() */
1155 lnet_peer_ni_decref_locked(lpni);
1158 lpn->lpn_rtrcheck_timestamp = now;
1160 CERROR("Failed to discover router %s\n",
1161 libcfs_nid2str(rtr->lp_primary_nid));
1163 /* NB dropped lock */
1164 if (version != the_lnet.ln_routers_version) {
1165 /* the routers list has changed */
1170 if (the_lnet.ln_routing)
1171 push = lnet_update_ni_status_locked();
1173 lnet_net_unlock(cpt);
1175 /* if the status of the ni changed update the peers */
1177 lnet_push_update_to_peers(1);
1181 lnet_destroy_rtrbuf(struct lnet_rtrbuf *rb, int npages)
1183 int sz = offsetof(struct lnet_rtrbuf, rb_kiov[npages]);
1185 while (--npages >= 0)
1186 __free_page(rb->rb_kiov[npages].kiov_page);
1188 LIBCFS_FREE(rb, sz);
1191 static struct lnet_rtrbuf *
1192 lnet_new_rtrbuf(struct lnet_rtrbufpool *rbp, int cpt)
1194 int npages = rbp->rbp_npages;
1195 int sz = offsetof(struct lnet_rtrbuf, rb_kiov[npages]);
1197 struct lnet_rtrbuf *rb;
1200 LIBCFS_CPT_ALLOC(rb, lnet_cpt_table(), cpt, sz);
1206 for (i = 0; i < npages; i++) {
1207 page = cfs_page_cpt_alloc(lnet_cpt_table(), cpt,
1208 GFP_KERNEL | __GFP_ZERO);
1211 __free_page(rb->rb_kiov[i].kiov_page);
1213 LIBCFS_FREE(rb, sz);
1217 rb->rb_kiov[i].kiov_len = PAGE_SIZE;
1218 rb->rb_kiov[i].kiov_offset = 0;
1219 rb->rb_kiov[i].kiov_page = page;
1226 lnet_rtrpool_free_bufs(struct lnet_rtrbufpool *rbp, int cpt)
1228 int npages = rbp->rbp_npages;
1229 struct lnet_rtrbuf *rb;
1232 if (rbp->rbp_nbuffers == 0) /* not initialized or already freed */
1236 list_splice_init(&rbp->rbp_msgs, &tmp);
1237 lnet_drop_routed_msgs_locked(&tmp, cpt);
1238 list_splice_init(&rbp->rbp_bufs, &tmp);
1239 rbp->rbp_req_nbuffers = 0;
1240 rbp->rbp_nbuffers = rbp->rbp_credits = 0;
1241 rbp->rbp_mincredits = 0;
1242 lnet_net_unlock(cpt);
1244 /* Free buffers on the free list. */
1245 while (!list_empty(&tmp)) {
1246 rb = list_entry(tmp.next, struct lnet_rtrbuf, rb_list);
1247 list_del(&rb->rb_list);
1248 lnet_destroy_rtrbuf(rb, npages);
1253 lnet_rtrpool_adjust_bufs(struct lnet_rtrbufpool *rbp, int nbufs, int cpt)
1256 struct lnet_rtrbuf *rb;
1258 int num_buffers = 0;
1260 int npages = rbp->rbp_npages;
1263 /* If we are called for less buffers than already in the pool, we
1264 * just lower the req_nbuffers number and excess buffers will be
1265 * thrown away as they are returned to the free list. Credits
1266 * then get adjusted as well.
1267 * If we already have enough buffers allocated to serve the
1268 * increase requested, then we can treat that the same way as we
1269 * do the decrease. */
1270 num_rb = nbufs - rbp->rbp_nbuffers;
1271 if (nbufs <= rbp->rbp_req_nbuffers || num_rb <= 0) {
1272 rbp->rbp_req_nbuffers = nbufs;
1273 lnet_net_unlock(cpt);
1276 /* store the older value of rbp_req_nbuffers and then set it to
1277 * the new request to prevent lnet_return_rx_credits_locked() from
1278 * freeing buffers that we need to keep around */
1279 old_req_nbufs = rbp->rbp_req_nbuffers;
1280 rbp->rbp_req_nbuffers = nbufs;
1281 lnet_net_unlock(cpt);
1283 /* allocate the buffers on a local list first. If all buffers are
1284 * allocated successfully then join this list to the rbp buffer
1285 * list. If not then free all allocated buffers. */
1286 while (num_rb-- > 0) {
1287 rb = lnet_new_rtrbuf(rbp, cpt);
1289 CERROR("Failed to allocate %d route bufs of %d pages\n",
1293 rbp->rbp_req_nbuffers = old_req_nbufs;
1294 lnet_net_unlock(cpt);
1299 list_add(&rb->rb_list, &rb_list);
1305 list_splice_tail(&rb_list, &rbp->rbp_bufs);
1306 rbp->rbp_nbuffers += num_buffers;
1307 rbp->rbp_credits += num_buffers;
1308 rbp->rbp_mincredits = rbp->rbp_credits;
1309 /* We need to schedule blocked msg using the newly
1311 while (!list_empty(&rbp->rbp_bufs) &&
1312 !list_empty(&rbp->rbp_msgs))
1313 lnet_schedule_blocked_locked(rbp);
1315 lnet_net_unlock(cpt);
1320 while (!list_empty(&rb_list)) {
1321 rb = list_entry(rb_list.next, struct lnet_rtrbuf, rb_list);
1322 list_del(&rb->rb_list);
1323 lnet_destroy_rtrbuf(rb, npages);
1330 lnet_rtrpool_init(struct lnet_rtrbufpool *rbp, int npages)
1332 INIT_LIST_HEAD(&rbp->rbp_msgs);
1333 INIT_LIST_HEAD(&rbp->rbp_bufs);
1335 rbp->rbp_npages = npages;
1336 rbp->rbp_credits = 0;
1337 rbp->rbp_mincredits = 0;
1341 lnet_rtrpools_free(int keep_pools)
1343 struct lnet_rtrbufpool *rtrp;
1346 if (the_lnet.ln_rtrpools == NULL) /* uninitialized or freed */
1349 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1350 lnet_rtrpool_free_bufs(&rtrp[LNET_TINY_BUF_IDX], i);
1351 lnet_rtrpool_free_bufs(&rtrp[LNET_SMALL_BUF_IDX], i);
1352 lnet_rtrpool_free_bufs(&rtrp[LNET_LARGE_BUF_IDX], i);
1356 cfs_percpt_free(the_lnet.ln_rtrpools);
1357 the_lnet.ln_rtrpools = NULL;
1362 lnet_nrb_tiny_calculate(void)
1364 int nrbs = LNET_NRB_TINY;
1366 if (tiny_router_buffers < 0) {
1367 LCONSOLE_ERROR_MSG(0x10c,
1368 "tiny_router_buffers=%d invalid when "
1369 "routing enabled\n", tiny_router_buffers);
1373 if (tiny_router_buffers > 0)
1374 nrbs = tiny_router_buffers;
1376 nrbs /= LNET_CPT_NUMBER;
1377 return max(nrbs, LNET_NRB_TINY_MIN);
1381 lnet_nrb_small_calculate(void)
1383 int nrbs = LNET_NRB_SMALL;
1385 if (small_router_buffers < 0) {
1386 LCONSOLE_ERROR_MSG(0x10c,
1387 "small_router_buffers=%d invalid when "
1388 "routing enabled\n", small_router_buffers);
1392 if (small_router_buffers > 0)
1393 nrbs = small_router_buffers;
1395 nrbs /= LNET_CPT_NUMBER;
1396 return max(nrbs, LNET_NRB_SMALL_MIN);
1400 lnet_nrb_large_calculate(void)
1402 int nrbs = LNET_NRB_LARGE;
1404 if (large_router_buffers < 0) {
1405 LCONSOLE_ERROR_MSG(0x10c,
1406 "large_router_buffers=%d invalid when "
1407 "routing enabled\n", large_router_buffers);
1411 if (large_router_buffers > 0)
1412 nrbs = large_router_buffers;
1414 nrbs /= LNET_CPT_NUMBER;
1415 return max(nrbs, LNET_NRB_LARGE_MIN);
1419 lnet_rtrpools_alloc(int im_a_router)
1421 struct lnet_rtrbufpool *rtrp;
1428 if (!strcmp(forwarding, "")) {
1429 /* not set either way */
1432 } else if (!strcmp(forwarding, "disabled")) {
1433 /* explicitly disabled */
1435 } else if (!strcmp(forwarding, "enabled")) {
1436 /* explicitly enabled */
1438 LCONSOLE_ERROR_MSG(0x10b, "'forwarding' not set to either "
1439 "'enabled' or 'disabled'\n");
1443 nrb_tiny = lnet_nrb_tiny_calculate();
1447 nrb_small = lnet_nrb_small_calculate();
1451 nrb_large = lnet_nrb_large_calculate();
1455 the_lnet.ln_rtrpools = cfs_percpt_alloc(lnet_cpt_table(),
1457 sizeof(struct lnet_rtrbufpool));
1458 if (the_lnet.ln_rtrpools == NULL) {
1459 LCONSOLE_ERROR_MSG(0x10c,
1460 "Failed to initialize router buffe pool\n");
1464 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1465 lnet_rtrpool_init(&rtrp[LNET_TINY_BUF_IDX], 0);
1466 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_TINY_BUF_IDX],
1471 lnet_rtrpool_init(&rtrp[LNET_SMALL_BUF_IDX],
1472 LNET_NRB_SMALL_PAGES);
1473 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_SMALL_BUF_IDX],
1478 lnet_rtrpool_init(&rtrp[LNET_LARGE_BUF_IDX],
1479 LNET_NRB_LARGE_PAGES);
1480 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_LARGE_BUF_IDX],
1486 lnet_net_lock(LNET_LOCK_EX);
1487 the_lnet.ln_routing = 1;
1488 lnet_net_unlock(LNET_LOCK_EX);
1489 complete(&the_lnet.ln_mt_wait_complete);
1493 lnet_rtrpools_free(0);
1498 lnet_rtrpools_adjust_helper(int tiny, int small, int large)
1503 struct lnet_rtrbufpool *rtrp;
1505 /* If the provided values for each buffer pool are different than the
1506 * configured values, we need to take action. */
1508 tiny_router_buffers = tiny;
1509 nrb = lnet_nrb_tiny_calculate();
1510 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1511 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_TINY_BUF_IDX],
1518 small_router_buffers = small;
1519 nrb = lnet_nrb_small_calculate();
1520 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1521 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_SMALL_BUF_IDX],
1528 large_router_buffers = large;
1529 nrb = lnet_nrb_large_calculate();
1530 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1531 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_LARGE_BUF_IDX],
1542 lnet_rtrpools_adjust(int tiny, int small, int large)
1544 /* this function doesn't revert the changes if adding new buffers
1545 * failed. It's up to the user space caller to revert the
1548 if (!the_lnet.ln_routing)
1551 return lnet_rtrpools_adjust_helper(tiny, small, large);
1555 lnet_rtrpools_enable(void)
1559 if (the_lnet.ln_routing)
1562 if (the_lnet.ln_rtrpools == NULL)
1563 /* If routing is turned off, and we have never
1564 * initialized the pools before, just call the
1565 * standard buffer pool allocation routine as
1566 * if we are just configuring this for the first
1568 rc = lnet_rtrpools_alloc(1);
1570 rc = lnet_rtrpools_adjust_helper(0, 0, 0);
1574 lnet_net_lock(LNET_LOCK_EX);
1575 the_lnet.ln_routing = 1;
1577 the_lnet.ln_ping_target->pb_info.pi_features &=
1578 ~LNET_PING_FEAT_RTE_DISABLED;
1579 lnet_net_unlock(LNET_LOCK_EX);
1581 if (lnet_peer_discovery_disabled)
1582 CWARN("Consider turning discovery on to enable full "
1583 "Multi-Rail routing functionality\n");
1589 lnet_rtrpools_disable(void)
1591 if (!the_lnet.ln_routing)
1594 lnet_net_lock(LNET_LOCK_EX);
1595 the_lnet.ln_routing = 0;
1596 the_lnet.ln_ping_target->pb_info.pi_features |=
1597 LNET_PING_FEAT_RTE_DISABLED;
1599 tiny_router_buffers = 0;
1600 small_router_buffers = 0;
1601 large_router_buffers = 0;
1602 lnet_net_unlock(LNET_LOCK_EX);
1603 lnet_rtrpools_free(1);
1607 lnet_notify_peer_down(struct lnet_ni *ni, lnet_nid_t nid)
1609 if (ni->ni_net->net_lnd->lnd_notify_peer_down != NULL)
1610 (ni->ni_net->net_lnd->lnd_notify_peer_down)(nid);
1614 * ni: local NI used to communicate with the peer
1616 * alive: true if peer is alive, false otherwise
1617 * reset: reset health value. This is requested by the LND.
1618 * when: notificaiton time.
1621 lnet_notify(struct lnet_ni *ni, lnet_nid_t nid, bool alive, bool reset,
1624 struct lnet_peer_ni *lpni = NULL;
1625 struct lnet_route *route;
1626 struct lnet_peer *lp;
1627 time64_t now = ktime_get_seconds();
1630 LASSERT (!in_interrupt ());
1632 CDEBUG (D_NET, "%s notifying %s: %s\n",
1633 (ni == NULL) ? "userspace" : libcfs_nid2str(ni->ni_nid),
1634 libcfs_nid2str(nid),
1635 alive ? "up" : "down");
1638 LNET_NIDNET(ni->ni_nid) != LNET_NIDNET(nid)) {
1639 CWARN("Ignoring notification of %s %s by %s (different net)\n",
1640 libcfs_nid2str(nid), alive ? "birth" : "death",
1641 libcfs_nid2str(ni->ni_nid));
1645 /* can't do predictions... */
1647 CWARN("Ignoring prediction from %s of %s %s "
1648 "%lld seconds in the future\n",
1649 (ni == NULL) ? "userspace" : libcfs_nid2str(ni->ni_nid),
1650 libcfs_nid2str(nid), alive ? "up" : "down", when - now);
1654 if (ni != NULL && !alive && /* LND telling me she's down */
1655 !auto_down) { /* auto-down disabled */
1656 CDEBUG(D_NET, "Auto-down disabled\n");
1660 /* must lock 0 since this is used for synchronization */
1663 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
1668 lpni = lnet_find_peer_ni_locked(nid);
1672 CDEBUG(D_NET, "%s not found\n", libcfs_nid2str(nid));
1678 lnet_set_lpni_healthv_locked(lpni,
1679 LNET_MAX_HEALTH_VALUE);
1681 lnet_inc_lpni_healthv_locked(lpni);
1683 lnet_handle_remote_failure_locked(lpni);
1686 /* recalculate aliveness */
1687 alive = lnet_is_peer_ni_alive(lpni);
1690 if (ni != NULL && !alive)
1691 lnet_notify_peer_down(ni, lpni->lpni_nid);
1693 cpt = lpni->lpni_cpt;
1695 lnet_peer_ni_decref_locked(lpni);
1696 if (lpni && lpni->lpni_peer_net && lpni->lpni_peer_net->lpn_peer) {
1697 lp = lpni->lpni_peer_net->lpn_peer;
1698 lp->lp_alive = alive;
1699 list_for_each_entry(route, &lp->lp_routes, lr_gwlist)
1700 lnet_set_route_aliveness(route, alive);
1702 lnet_net_unlock(cpt);
1706 EXPORT_SYMBOL(lnet_notify);