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");
121 static void lnet_add_route_to_rnet(struct lnet_remotenet *rnet,
122 struct lnet_route *route);
123 static void lnet_del_route_from_rnet(lnet_nid_t gw_nid,
124 struct list_head *route_list,
125 struct list_head *zombies);
128 rtr_sensitivity_set(const char *val, cfs_kernel_param_arg_t *kp)
131 unsigned *sen = (unsigned *)kp->arg;
134 rc = kstrtoul(val, 0, &value);
136 CERROR("Invalid module parameter value for 'router_sensitivity_percentage'\n");
140 if (value < 0 || value > 100) {
141 CERROR("Invalid value: %lu for 'router_sensitivity_percentage'\n", value);
146 * The purpose of locking the api_mutex here is to ensure that
147 * the correct value ends up stored properly.
149 mutex_lock(&the_lnet.ln_api_mutex);
153 mutex_unlock(&the_lnet.ln_api_mutex);
159 lnet_move_route(struct lnet_route *route, struct lnet_peer *lp)
161 struct lnet_remotenet *rnet;
162 struct list_head zombies;
164 INIT_LIST_HEAD(&zombies);
166 rnet = lnet_find_rnet_locked(route->lr_net);
169 lnet_del_route_from_rnet(route->lr_nid, &rnet->lrn_routes,
173 route = list_first_entry(&zombies, struct lnet_route,
175 route->lr_gateway = lp;
176 lnet_add_route_to_rnet(rnet, route);
178 while (!list_empty(&zombies)) {
179 route = list_first_entry(&zombies, struct lnet_route,
181 list_del(&route->lr_list);
182 LIBCFS_FREE(route, sizeof(*route));
189 lnet_rtr_transfer_to_peer(struct lnet_peer *src, struct lnet_peer *target)
191 struct lnet_route *route;
192 struct lnet_route *tmp, *tmp2;
194 lnet_net_lock(LNET_LOCK_EX);
195 CDEBUG(D_NET, "transfering routes from %s -> %s\n",
196 libcfs_nid2str(src->lp_primary_nid),
197 libcfs_nid2str(target->lp_primary_nid));
198 list_for_each_entry(route, &src->lp_routes, lr_gwlist) {
199 CDEBUG(D_NET, "%s: %s->%s\n", libcfs_nid2str(src->lp_primary_nid),
200 libcfs_net2str(route->lr_net),
201 libcfs_nid2str(route->lr_nid));
203 list_splice_init(&src->lp_rtrq, &target->lp_rtrq);
204 list_for_each_entry_safe(route, tmp, &src->lp_routes, lr_gwlist) {
205 struct lnet_route *r2;
206 bool present = false;
207 list_for_each_entry_safe(r2, tmp2, &target->lp_routes, lr_gwlist) {
208 if (route->lr_net == r2->lr_net) {
209 if (route->lr_priority >= r2->lr_priority)
211 else if (route->lr_hops >= r2->lr_hops)
214 lnet_move_route(r2, NULL);
218 lnet_move_route(route, NULL);
220 lnet_move_route(route, target);
223 if (list_empty(&target->lp_rtr_list)) {
224 lnet_peer_addref_locked(target);
225 list_add_tail(&target->lp_rtr_list, &the_lnet.ln_routers);
228 the_lnet.ln_routers_version++;
229 lnet_net_unlock(LNET_LOCK_EX);
233 lnet_peers_start_down(void)
235 return check_routers_before_use;
239 * The peer_net of a gateway is alive if at least one of the peer_ni's on
240 * that peer_net is alive.
243 lnet_is_gateway_net_alive(struct lnet_peer_net *lpn)
245 struct lnet_peer_ni *lpni;
247 list_for_each_entry(lpni, &lpn->lpn_peer_nis, lpni_peer_nis) {
248 if (lnet_is_peer_ni_alive(lpni))
256 * a gateway is alive only if all its nets are alive
257 * called with cpt lock held
259 bool lnet_is_gateway_alive(struct lnet_peer *gw)
261 struct lnet_peer_net *lpn;
266 list_for_each_entry(lpn, &gw->lp_peer_nets, lpn_peer_nets) {
267 if (!lnet_is_gateway_net_alive(lpn))
275 * lnet_is_route_alive() needs to be called with cpt lock held
276 * A route is alive if the gateway can route between the local network and
277 * the remote network of the route.
278 * This means at least one NI is alive on each of the local and remote
279 * networks of the gateway.
281 bool lnet_is_route_alive(struct lnet_route *route)
283 struct lnet_peer *gw = route->lr_gateway;
284 struct lnet_peer_net *llpn;
285 struct lnet_peer_net *rlpn;
287 /* If the gateway is down then all routes are considered down */
292 * if discovery is disabled then rely on the cached aliveness
293 * information. This is handicapped information which we log when
294 * we receive the discovery ping response. The most uptodate
295 * aliveness information can only be obtained when discovery is
298 if (lnet_is_discovery_disabled(gw))
299 return route->lr_alive;
302 * check the gateway's interfaces on the local network
304 llpn = lnet_peer_get_net_locked(gw, route->lr_lnet);
308 if (!lnet_is_gateway_net_alive(llpn))
312 * For single hop routes avoid_asym_router_failure dictates
313 * that the remote net must exist on the gateway. For multi-hop
314 * routes the next-hop will not have the remote net.
316 if (avoid_asym_router_failure && route->lr_single_hop) {
317 rlpn = lnet_peer_get_net_locked(gw, route->lr_net);
320 if (!lnet_is_gateway_net_alive(rlpn))
324 spin_lock(&gw->lp_lock);
325 if (!(gw->lp_state & LNET_PEER_ROUTER_ENABLED)) {
326 spin_unlock(&gw->lp_lock);
327 if (gw->lp_rtr_refcount > 0)
328 CERROR("peer %s is being used as a gateway but routing feature is not turned on\n",
329 libcfs_nid2str(gw->lp_primary_nid));
332 spin_unlock(&gw->lp_lock);
338 lnet_consolidate_routes_locked(struct lnet_peer *orig_lp,
339 struct lnet_peer *new_lp)
341 struct lnet_peer_ni *lpni;
342 struct lnet_route *route;
345 * Although a route is correlated with a peer, but when it's added
346 * a specific NID is used. That NID refers to a peer_ni within
347 * a peer. There could be other peer_nis on the same net, which
348 * can be used to send to that gateway. However when we are
349 * consolidating gateways because of discovery, the nid used to
350 * add the route might've moved between gateway peers. In this
351 * case we want to move the route to the new gateway as well. The
352 * intent here is not to confuse the user who added the route.
354 list_for_each_entry(route, &orig_lp->lp_routes, lr_gwlist) {
355 lpni = lnet_peer_get_ni_locked(orig_lp, route->lr_nid);
357 lnet_net_lock(LNET_LOCK_EX);
358 list_move(&route->lr_gwlist, &new_lp->lp_routes);
359 lnet_net_unlock(LNET_LOCK_EX);
365 lnet_check_route_inconsistency(struct lnet_route *route)
367 if (!route->lr_single_hop && (int)route->lr_hops <= 1) {
368 CWARN("route %s->%s is detected to be multi-hop but hop count is set to %d\n",
369 libcfs_net2str(route->lr_net),
370 libcfs_nid2str(route->lr_gateway->lp_primary_nid),
371 (int) route->lr_hops);
376 lnet_set_route_hop_type(struct lnet_peer *gw, struct lnet_route *route)
378 struct lnet_peer_net *lpn;
379 bool single_hop = false;
381 list_for_each_entry(lpn, &gw->lp_peer_nets, lpn_peer_nets) {
382 if (route->lr_net == lpn->lpn_net_id) {
387 route->lr_single_hop = single_hop;
388 lnet_check_route_inconsistency(route);
392 lnet_set_route_aliveness(struct lnet_route *route, bool alive)
394 /* Log when there's a state change */
395 if (route->lr_alive != alive) {
396 CERROR("route to %s through %s has gone from %s to %s\n",
397 libcfs_net2str(route->lr_net),
398 libcfs_nid2str(route->lr_gateway->lp_primary_nid),
399 (route->lr_alive) ? "up" : "down",
400 alive ? "up" : "down");
401 route->lr_alive = alive;
406 lnet_router_discovery_ping_reply(struct lnet_peer *lp)
408 struct lnet_ping_buffer *pbuf = lp->lp_data;
409 struct lnet_peer_net *llpn;
410 struct lnet_route *route;
411 bool single_hop = false;
418 spin_lock(&lp->lp_lock);
419 lp_state = lp->lp_state;
421 /* only handle replies if discovery is disabled. */
422 if (!lnet_is_discovery_disabled_locked(lp)) {
423 spin_unlock(&lp->lp_lock);
427 spin_unlock(&lp->lp_lock);
429 if (lp_state & LNET_PEER_PING_FAILED ||
430 pbuf->pb_info.pi_features & LNET_PING_FEAT_RTE_DISABLED) {
431 CDEBUG(D_NET, "Set routes down for gw %s because %s %d\n",
432 libcfs_nid2str(lp->lp_primary_nid),
433 lp_state & LNET_PEER_PING_FAILED ? "ping failed" :
434 "route feature is disabled", lp->lp_ping_error);
435 /* If the ping failed or the peer has routing disabled then
436 * mark the routes served by this peer down
438 list_for_each_entry(route, &lp->lp_routes, lr_gwlist)
439 lnet_set_route_aliveness(route, false);
443 CDEBUG(D_NET, "Discovery is disabled. Processing reply for gw: %s:%d\n",
444 libcfs_nid2str(lp->lp_primary_nid), pbuf->pb_info.pi_nnis);
447 * examine the ping response to determine if the routes on that
448 * gateway should be declared alive.
449 * The route is alive if:
450 * 1. local network to reach the route is alive and
451 * 2. route is single hop, avoid_async_router_failure is set and
452 * there exists at least one NI on the route's remote net
454 list_for_each_entry(route, &lp->lp_routes, lr_gwlist) {
455 llpn = lnet_peer_get_net_locked(lp, route->lr_lnet);
457 lnet_set_route_aliveness(route, false);
461 if (!lnet_is_gateway_net_alive(llpn)) {
462 lnet_set_route_aliveness(route, false);
466 single_hop = net_up = false;
467 for (i = 1; i < pbuf->pb_info.pi_nnis; i++) {
468 net = LNET_NIDNET(pbuf->pb_info.pi_ni[i].ns_nid);
470 if (route->lr_net == net) {
472 if (pbuf->pb_info.pi_ni[i].ns_status ==
480 route->lr_single_hop = single_hop;
481 if (avoid_asym_router_failure && single_hop)
482 lnet_set_route_aliveness(route, net_up);
484 lnet_set_route_aliveness(route, true);
487 * warn that the route is configured as single-hop but it
488 * really is multi-hop as far as we can tell.
490 lnet_check_route_inconsistency(route);
495 lnet_router_discovery_complete(struct lnet_peer *lp)
497 struct lnet_peer_ni *lpni = NULL;
498 struct lnet_route *route;
500 spin_lock(&lp->lp_lock);
501 lp->lp_state &= ~LNET_PEER_RTR_DISCOVERY;
502 lp->lp_state |= LNET_PEER_RTR_DISCOVERED;
503 lp->lp_alive = lp->lp_dc_error == 0;
504 spin_unlock(&lp->lp_lock);
506 /* ping replies are being handled when discovery is disabled */
507 if (lnet_is_discovery_disabled_locked(lp))
510 if (!lp->lp_dc_error) {
512 * mark single-hop routes. If the remote net is not configured on
513 * the gateway we assume this is intentional and we mark the
514 * gateway as multi-hop
516 list_for_each_entry(route, &lp->lp_routes, lr_gwlist)
517 lnet_set_route_hop_type(lp, route);
523 * We do not send messages directly to the remote interfaces
524 * of an LNet router. As such, we rely on the PING response
525 * to determine the up/down status of these interfaces. If
526 * a PING response is not receieved, or some other problem with
527 * discovery occurs that prevents us from getting this status,
528 * we assume all interfaces are down until we're able to
529 * determine otherwise.
531 CDEBUG(D_NET, "%s: Router discovery failed %d\n",
532 libcfs_nid2str(lp->lp_primary_nid), lp->lp_dc_error);
533 while ((lpni = lnet_get_next_peer_ni_locked(lp, NULL, lpni)) != NULL)
534 lpni->lpni_ns_status = LNET_NI_STATUS_DOWN;
536 list_for_each_entry(route, &lp->lp_routes, lr_gwlist)
537 lnet_set_route_aliveness(route, false);
541 lnet_rtr_addref_locked(struct lnet_peer *lp)
543 LASSERT(lp->lp_rtr_refcount >= 0);
545 /* lnet_net_lock must be exclusively locked */
546 lp->lp_rtr_refcount++;
547 if (lp->lp_rtr_refcount == 1) {
548 list_add_tail(&lp->lp_rtr_list, &the_lnet.ln_routers);
549 /* addref for the_lnet.ln_routers */
550 lnet_peer_addref_locked(lp);
551 the_lnet.ln_routers_version++;
556 lnet_rtr_decref_locked(struct lnet_peer *lp)
558 LASSERT(atomic_read(&lp->lp_refcount) > 0);
559 LASSERT(lp->lp_rtr_refcount > 0);
561 /* lnet_net_lock must be exclusively locked */
562 lp->lp_rtr_refcount--;
563 if (lp->lp_rtr_refcount == 0) {
564 LASSERT(list_empty(&lp->lp_routes));
566 list_del(&lp->lp_rtr_list);
567 /* decref for the_lnet.ln_routers */
568 lnet_peer_decref_locked(lp);
569 the_lnet.ln_routers_version++;
573 struct lnet_remotenet *
574 lnet_find_rnet_locked(__u32 net)
576 struct lnet_remotenet *rnet;
577 struct list_head *tmp;
578 struct list_head *rn_list;
580 LASSERT(the_lnet.ln_state == LNET_STATE_RUNNING);
582 rn_list = lnet_net2rnethash(net);
583 list_for_each(tmp, rn_list) {
584 rnet = list_entry(tmp, struct lnet_remotenet, lrn_list);
586 if (rnet->lrn_net == net)
592 static void lnet_shuffle_seed(void)
595 struct lnet_ni *ni = NULL;
600 /* Nodes with small feet have little entropy
601 * the NID for this node gives the most entropy in the low bits */
602 while ((ni = lnet_get_next_ni_locked(NULL, ni)))
603 add_device_randomness(&ni->ni_nid, sizeof(ni->ni_nid));
608 /* NB expects LNET_LOCK held */
610 lnet_add_route_to_rnet(struct lnet_remotenet *rnet, struct lnet_route *route)
612 struct lnet_peer_net *lpn;
613 unsigned int offset = 0;
614 unsigned int len = 0;
619 list_for_each(e, &rnet->lrn_routes)
623 * Randomly adding routes to the list is done to ensure that when
624 * different nodes are using the same list of routers, they end up
625 * preferring different routers.
627 offset = prandom_u32_max(len + 1);
628 list_for_each(e, &rnet->lrn_routes) {
633 list_add(&route->lr_list, e);
635 * force a router check on the gateway to make sure the route is
638 list_for_each_entry(lpn, &route->lr_gateway->lp_peer_nets,
640 lpn->lpn_rtrcheck_timestamp = 0;
643 the_lnet.ln_remote_nets_version++;
645 /* add the route on the gateway list */
646 list_add(&route->lr_gwlist, &route->lr_gateway->lp_routes);
648 /* take a router reference count on the gateway */
649 lnet_rtr_addref_locked(route->lr_gateway);
653 lnet_add_route(__u32 net, __u32 hops, lnet_nid_t gateway,
654 __u32 priority, __u32 sensitivity)
656 struct list_head *route_entry;
657 struct lnet_remotenet *rnet;
658 struct lnet_remotenet *rnet2;
659 struct lnet_route *route;
660 struct lnet_peer_ni *lpni;
661 struct lnet_peer *gw;
665 CDEBUG(D_NET, "Add route: remote net %s hops %d priority %u gw %s\n",
666 libcfs_net2str(net), hops, priority, libcfs_nid2str(gateway));
668 if (gateway == LNET_NID_ANY ||
669 LNET_NETTYP(LNET_NIDNET(gateway)) == LOLND ||
670 net == LNET_NIDNET(LNET_NID_ANY) ||
671 LNET_NETTYP(net) == LOLND ||
672 LNET_NIDNET(gateway) == net ||
673 (hops != LNET_UNDEFINED_HOPS && (hops < 1 || hops > 255)))
676 /* it's a local network */
677 if (lnet_islocalnet(net))
680 if (!lnet_islocalnet(LNET_NIDNET(gateway))) {
681 CERROR("Cannot add route with gateway %s. There is no local interface configured on LNet %s\n",
682 libcfs_nid2str(gateway),
683 libcfs_net2str(LNET_NIDNET(gateway)));
684 return -EHOSTUNREACH;
687 /* Assume net, route, all new */
688 LIBCFS_ALLOC(route, sizeof(*route));
689 LIBCFS_ALLOC(rnet, sizeof(*rnet));
690 if (route == NULL || rnet == NULL) {
691 CERROR("Out of memory creating route %s %d %s\n",
692 libcfs_net2str(net), hops, libcfs_nid2str(gateway));
694 LIBCFS_FREE(route, sizeof(*route));
696 LIBCFS_FREE(rnet, sizeof(*rnet));
700 INIT_LIST_HEAD(&rnet->lrn_routes);
702 /* store the local and remote net that the route represents */
703 route->lr_lnet = LNET_NIDNET(gateway);
705 route->lr_nid = gateway;
706 route->lr_priority = priority;
707 route->lr_hops = hops;
709 lnet_net_lock(LNET_LOCK_EX);
712 * lnet_nid2peerni_ex() grabs a ref on the lpni. We will need to
713 * lose that once we're done
715 lpni = lnet_nid2peerni_ex(gateway, LNET_LOCK_EX);
717 lnet_net_unlock(LNET_LOCK_EX);
719 LIBCFS_FREE(route, sizeof(*route));
720 LIBCFS_FREE(rnet, sizeof(*rnet));
723 CERROR("Error %d creating route %s %d %s\n", rc,
724 libcfs_net2str(net), hops,
725 libcfs_nid2str(gateway));
729 LASSERT(lpni->lpni_peer_net && lpni->lpni_peer_net->lpn_peer);
730 gw = lpni->lpni_peer_net->lpn_peer;
732 route->lr_gateway = gw;
734 rnet2 = lnet_find_rnet_locked(net);
737 list_add_tail(&rnet->lrn_list, lnet_net2rnethash(net));
741 /* Search for a duplicate route (it's a NOOP if it is) */
743 list_for_each(route_entry, &rnet2->lrn_routes) {
744 struct lnet_route *route2;
746 route2 = list_entry(route_entry, struct lnet_route, lr_list);
747 if (route2->lr_gateway == route->lr_gateway) {
752 /* our lookups must be true */
753 LASSERT(route2->lr_gateway->lp_primary_nid != gateway);
757 * It is possible to add multiple routes through the same peer,
758 * but it'll be using a different NID of that peer. When the
759 * gateway is discovered, discovery will consolidate the different
760 * peers into one peer. In this case the discovery code will have
761 * to move the routes from the peer that's being deleted to the
762 * consolidated peer lp_routes list
765 gw->lp_health_sensitivity = sensitivity;
766 lnet_add_route_to_rnet(rnet2, route);
767 if (lnet_peer_discovery_disabled)
768 CWARN("Consider turning discovery on to enable full "
769 "Multi-Rail routing functionality\n");
773 * get rid of the reference on the lpni.
775 lnet_peer_ni_decref_locked(lpni);
776 lnet_net_unlock(LNET_LOCK_EX);
782 LIBCFS_FREE(route, sizeof(*route));
786 LIBCFS_FREE(rnet, sizeof(*rnet));
788 /* kick start the monitor thread to handle the added route */
789 complete(&the_lnet.ln_mt_wait_complete);
795 lnet_del_route_from_rnet(lnet_nid_t gw_nid, struct list_head *route_list,
796 struct list_head *zombies)
798 struct lnet_peer *gateway;
799 struct lnet_route *route;
800 struct lnet_route *tmp;
802 list_for_each_entry_safe(route, tmp, route_list, lr_list) {
803 gateway = route->lr_gateway;
804 if (gw_nid != LNET_NID_ANY &&
805 gw_nid != gateway->lp_primary_nid)
809 * move to zombie to delete outside the lock
810 * Note that this function is called with the
811 * ln_api_mutex held as well as the exclusive net
812 * lock. Adding to the remote net list happens
813 * under the same conditions. Same goes for the
814 * gateway router list
816 list_move(&route->lr_list, zombies);
817 the_lnet.ln_remote_nets_version++;
819 list_del(&route->lr_gwlist);
820 lnet_rtr_decref_locked(gateway);
825 lnet_del_route(__u32 net, lnet_nid_t gw_nid)
827 LIST_HEAD(rnet_zombies);
828 struct lnet_remotenet *rnet;
829 struct lnet_remotenet *tmp;
830 struct list_head *rn_list;
831 struct lnet_peer_ni *lpni;
832 struct lnet_route *route;
834 struct lnet_peer *lp = NULL;
837 CDEBUG(D_NET, "Del route: net %s : gw %s\n",
838 libcfs_net2str(net), libcfs_nid2str(gw_nid));
840 /* NB Caller may specify either all routes via the given gateway
841 * or a specific route entry actual NIDs) */
843 lnet_net_lock(LNET_LOCK_EX);
845 lpni = lnet_find_peer_ni_locked(gw_nid);
847 lp = lpni->lpni_peer_net->lpn_peer;
849 gw_nid = lp->lp_primary_nid;
850 lnet_peer_ni_decref_locked(lpni);
853 if (net != LNET_NIDNET(LNET_NID_ANY)) {
854 rnet = lnet_find_rnet_locked(net);
856 lnet_net_unlock(LNET_LOCK_EX);
859 lnet_del_route_from_rnet(gw_nid, &rnet->lrn_routes,
861 if (list_empty(&rnet->lrn_routes))
862 list_move(&rnet->lrn_list, &rnet_zombies);
866 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) {
867 rn_list = &the_lnet.ln_remote_nets_hash[i];
869 list_for_each_entry_safe(rnet, tmp, rn_list, lrn_list) {
870 lnet_del_route_from_rnet(gw_nid, &rnet->lrn_routes,
872 if (list_empty(&rnet->lrn_routes))
873 list_move(&rnet->lrn_list, &rnet_zombies);
879 * check if there are any routes remaining on the gateway
880 * If there are no more routes make sure to set the peer's
881 * lp_disc_net_id to 0 (invalid), in case we add more routes in
882 * the future on that gateway, then we start our discovery process
886 if (list_empty(&lp->lp_routes))
887 lp->lp_disc_net_id = 0;
890 lnet_net_unlock(LNET_LOCK_EX);
892 while (!list_empty(&zombies)) {
893 route = list_first_entry(&zombies, struct lnet_route, lr_list);
894 list_del(&route->lr_list);
895 LIBCFS_FREE(route, sizeof(*route));
898 while (!list_empty(&rnet_zombies)) {
899 rnet = list_first_entry(&rnet_zombies, struct lnet_remotenet,
901 list_del(&rnet->lrn_list);
902 LIBCFS_FREE(rnet, sizeof(*rnet));
909 lnet_destroy_routes (void)
911 lnet_del_route(LNET_NIDNET(LNET_NID_ANY), LNET_NID_ANY);
914 int lnet_get_rtr_pool_cfg(int cpt, struct lnet_ioctl_pool_cfg *pool_cfg)
916 struct lnet_rtrbufpool *rbp;
917 int i, rc = -ENOENT, j;
919 if (the_lnet.ln_rtrpools == NULL)
923 cfs_percpt_for_each(rbp, i, the_lnet.ln_rtrpools) {
928 for (j = 0; j < LNET_NRBPOOLS; j++) {
929 pool_cfg->pl_pools[j].pl_npages = rbp[j].rbp_npages;
930 pool_cfg->pl_pools[j].pl_nbuffers = rbp[j].rbp_nbuffers;
931 pool_cfg->pl_pools[j].pl_credits = rbp[j].rbp_credits;
932 pool_cfg->pl_pools[j].pl_mincredits = rbp[j].rbp_mincredits;
939 lnet_net_lock(LNET_LOCK_EX);
940 pool_cfg->pl_routing = the_lnet.ln_routing;
941 lnet_net_unlock(LNET_LOCK_EX);
947 lnet_get_route(int idx, __u32 *net, __u32 *hops,
948 lnet_nid_t *gateway, __u32 *flags, __u32 *priority, __u32 *sensitivity)
950 struct lnet_remotenet *rnet;
951 struct list_head *rn_list;
952 struct lnet_route *route;
953 struct list_head *e1;
954 struct list_head *e2;
958 cpt = lnet_net_lock_current();
960 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) {
961 rn_list = &the_lnet.ln_remote_nets_hash[i];
962 list_for_each(e1, rn_list) {
963 rnet = list_entry(e1, struct lnet_remotenet, lrn_list);
965 list_for_each(e2, &rnet->lrn_routes) {
966 route = list_entry(e2, struct lnet_route,
970 *net = rnet->lrn_net;
971 *gateway = route->lr_nid;
972 *hops = route->lr_hops;
973 *priority = route->lr_priority;
974 *sensitivity = route->lr_gateway->
975 lp_health_sensitivity;
976 if (lnet_is_route_alive(route))
977 *flags |= LNET_RT_ALIVE;
979 *flags &= ~LNET_RT_ALIVE;
980 if (route->lr_single_hop)
981 *flags &= ~LNET_RT_MULTI_HOP;
983 *flags |= LNET_RT_MULTI_HOP;
984 lnet_net_unlock(cpt);
991 lnet_net_unlock(cpt);
996 lnet_wait_known_routerstate(void)
998 struct lnet_peer *rtr;
999 struct list_head *entry;
1002 LASSERT(the_lnet.ln_mt_state == LNET_MT_STATE_RUNNING);
1005 int cpt = lnet_net_lock_current();
1008 list_for_each(entry, &the_lnet.ln_routers) {
1009 rtr = list_entry(entry, struct lnet_peer,
1012 spin_lock(&rtr->lp_lock);
1014 if ((rtr->lp_state & LNET_PEER_RTR_DISCOVERED) == 0) {
1016 spin_unlock(&rtr->lp_lock);
1019 spin_unlock(&rtr->lp_lock);
1022 lnet_net_unlock(cpt);
1027 schedule_timeout_uninterruptible(cfs_time_seconds(1));
1032 lnet_net_set_status_locked(struct lnet_net *net, __u32 status)
1035 bool update = false;
1037 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
1039 if (ni->ni_status &&
1040 ni->ni_status->ns_status != status) {
1041 ni->ni_status->ns_status = status;
1051 lnet_update_ni_status_locked(void)
1053 struct lnet_net *net;
1058 LASSERT(the_lnet.ln_routing);
1060 timeout = router_ping_timeout + alive_router_check_interval;
1062 now = ktime_get_real_seconds();
1063 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1064 if (net->net_lnd->lnd_type == LOLND)
1067 if (now < net->net_last_alive + timeout)
1070 spin_lock(&net->net_lock);
1071 /* re-check with lock */
1072 if (now < net->net_last_alive + timeout) {
1073 spin_unlock(&net->net_lock);
1076 spin_unlock(&net->net_lock);
1079 * if the net didn't receive any traffic for past the
1080 * timeout on any of its constituent NIs, then mark all
1083 push = lnet_net_set_status_locked(net, LNET_NI_STATUS_DOWN);
1089 void lnet_wait_router_start(void)
1091 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. */
1095 lnet_wait_known_routerstate();
1100 * This function is called from the monitor thread to check if there are
1101 * any active routers that need to be checked.
1104 lnet_router_checker_active(void)
1106 /* Router Checker thread needs to run when routing is enabled in
1107 * order to call lnet_update_ni_status_locked() */
1108 if (the_lnet.ln_routing)
1111 return !list_empty(&the_lnet.ln_routers) &&
1112 alive_router_check_interval > 0;
1116 lnet_check_routers(void)
1118 struct lnet_peer_net *first_lpn = NULL;
1119 struct lnet_peer_net *lpn;
1120 struct lnet_peer_ni *lpni;
1121 struct list_head *entry;
1122 struct lnet_peer *rtr;
1131 cpt = lnet_net_lock_current();
1133 version = the_lnet.ln_routers_version;
1135 list_for_each(entry, &the_lnet.ln_routers) {
1136 rtr = list_entry(entry, struct lnet_peer,
1139 now = ktime_get_real_seconds();
1142 * only discover the router if we've passed
1143 * alive_router_check_interval seconds. Some of the router
1144 * interfaces could be down and in that case they would be
1145 * undergoing recovery separately from this discovery.
1147 /* find next peer net which is also local */
1148 net_id = rtr->lp_disc_net_id;
1150 lpn = lnet_get_next_peer_net_locked(rtr, net_id);
1152 CERROR("gateway %s has no networks\n",
1153 libcfs_nid2str(rtr->lp_primary_nid));
1156 if (first_lpn == lpn)
1160 found_lpn = lnet_islocalnet_locked(lpn->lpn_net_id);
1161 net_id = lpn->lpn_net_id;
1162 } while (!found_lpn);
1164 if (!found_lpn || !lpn) {
1165 CERROR("no local network found for gateway %s\n",
1166 libcfs_nid2str(rtr->lp_primary_nid));
1170 if (now - lpn->lpn_rtrcheck_timestamp <
1171 alive_router_check_interval / lnet_current_net_count)
1175 * If we're currently discovering the peer then don't
1176 * issue another discovery
1178 spin_lock(&rtr->lp_lock);
1179 if (rtr->lp_state & LNET_PEER_RTR_DISCOVERY) {
1180 spin_unlock(&rtr->lp_lock);
1183 /* make sure we actively discover the router */
1184 rtr->lp_state &= ~LNET_PEER_NIDS_UPTODATE;
1185 rtr->lp_state |= LNET_PEER_RTR_DISCOVERY;
1186 spin_unlock(&rtr->lp_lock);
1188 /* find the peer_ni associated with the primary NID */
1189 lpni = lnet_peer_get_ni_locked(rtr, rtr->lp_primary_nid);
1191 CDEBUG(D_NET, "Expected to find an lpni for %s, but non found\n",
1192 libcfs_nid2str(rtr->lp_primary_nid));
1195 lnet_peer_ni_addref_locked(lpni);
1197 /* specify the net to use */
1198 rtr->lp_disc_net_id = lpn->lpn_net_id;
1200 /* discover the router */
1201 CDEBUG(D_NET, "discover %s, cpt = %d\n",
1202 libcfs_nid2str(lpni->lpni_nid), cpt);
1203 rc = lnet_discover_peer_locked(lpni, cpt, false);
1205 /* decrement ref count acquired by find_peer_ni_locked() */
1206 lnet_peer_ni_decref_locked(lpni);
1209 lpn->lpn_rtrcheck_timestamp = now;
1211 CERROR("Failed to discover router %s\n",
1212 libcfs_nid2str(rtr->lp_primary_nid));
1214 /* NB dropped lock */
1215 if (version != the_lnet.ln_routers_version) {
1216 /* the routers list has changed */
1221 if (the_lnet.ln_routing)
1222 push = lnet_update_ni_status_locked();
1224 lnet_net_unlock(cpt);
1226 /* if the status of the ni changed update the peers */
1228 lnet_push_update_to_peers(1);
1232 lnet_destroy_rtrbuf(struct lnet_rtrbuf *rb, int npages)
1234 int sz = offsetof(struct lnet_rtrbuf, rb_kiov[npages]);
1236 while (--npages >= 0)
1237 __free_page(rb->rb_kiov[npages].bv_page);
1239 LIBCFS_FREE(rb, sz);
1242 static struct lnet_rtrbuf *
1243 lnet_new_rtrbuf(struct lnet_rtrbufpool *rbp, int cpt)
1245 int npages = rbp->rbp_npages;
1246 int sz = offsetof(struct lnet_rtrbuf, rb_kiov[npages]);
1248 struct lnet_rtrbuf *rb;
1251 LIBCFS_CPT_ALLOC(rb, lnet_cpt_table(), cpt, sz);
1257 for (i = 0; i < npages; i++) {
1258 page = cfs_page_cpt_alloc(lnet_cpt_table(), cpt,
1259 GFP_KERNEL | __GFP_ZERO);
1262 __free_page(rb->rb_kiov[i].bv_page);
1264 LIBCFS_FREE(rb, sz);
1268 rb->rb_kiov[i].bv_len = PAGE_SIZE;
1269 rb->rb_kiov[i].bv_offset = 0;
1270 rb->rb_kiov[i].bv_page = page;
1277 lnet_rtrpool_free_bufs(struct lnet_rtrbufpool *rbp, int cpt)
1279 int npages = rbp->rbp_npages;
1280 struct lnet_rtrbuf *rb;
1283 if (rbp->rbp_nbuffers == 0) /* not initialized or already freed */
1287 list_splice_init(&rbp->rbp_msgs, &tmp);
1288 lnet_drop_routed_msgs_locked(&tmp, cpt);
1289 list_splice_init(&rbp->rbp_bufs, &tmp);
1290 rbp->rbp_req_nbuffers = 0;
1291 rbp->rbp_nbuffers = rbp->rbp_credits = 0;
1292 rbp->rbp_mincredits = 0;
1293 lnet_net_unlock(cpt);
1295 /* Free buffers on the free list. */
1296 while (!list_empty(&tmp)) {
1297 rb = list_entry(tmp.next, struct lnet_rtrbuf, rb_list);
1298 list_del(&rb->rb_list);
1299 lnet_destroy_rtrbuf(rb, npages);
1304 lnet_rtrpool_adjust_bufs(struct lnet_rtrbufpool *rbp, int nbufs, int cpt)
1307 struct lnet_rtrbuf *rb;
1309 int num_buffers = 0;
1311 int npages = rbp->rbp_npages;
1314 /* If we are called for less buffers than already in the pool, we
1315 * just lower the req_nbuffers number and excess buffers will be
1316 * thrown away as they are returned to the free list. Credits
1317 * then get adjusted as well.
1318 * If we already have enough buffers allocated to serve the
1319 * increase requested, then we can treat that the same way as we
1320 * do the decrease. */
1321 num_rb = nbufs - rbp->rbp_nbuffers;
1322 if (nbufs <= rbp->rbp_req_nbuffers || num_rb <= 0) {
1323 rbp->rbp_req_nbuffers = nbufs;
1324 lnet_net_unlock(cpt);
1327 /* store the older value of rbp_req_nbuffers and then set it to
1328 * the new request to prevent lnet_return_rx_credits_locked() from
1329 * freeing buffers that we need to keep around */
1330 old_req_nbufs = rbp->rbp_req_nbuffers;
1331 rbp->rbp_req_nbuffers = nbufs;
1332 lnet_net_unlock(cpt);
1334 /* allocate the buffers on a local list first. If all buffers are
1335 * allocated successfully then join this list to the rbp buffer
1336 * list. If not then free all allocated buffers. */
1337 while (num_rb-- > 0) {
1338 rb = lnet_new_rtrbuf(rbp, cpt);
1340 CERROR("Failed to allocate %d route bufs of %d pages\n",
1344 rbp->rbp_req_nbuffers = old_req_nbufs;
1345 lnet_net_unlock(cpt);
1350 list_add(&rb->rb_list, &rb_list);
1356 list_splice_tail(&rb_list, &rbp->rbp_bufs);
1357 rbp->rbp_nbuffers += num_buffers;
1358 rbp->rbp_credits += num_buffers;
1359 rbp->rbp_mincredits = rbp->rbp_credits;
1360 /* We need to schedule blocked msg using the newly
1362 while (!list_empty(&rbp->rbp_bufs) &&
1363 !list_empty(&rbp->rbp_msgs))
1364 lnet_schedule_blocked_locked(rbp);
1366 lnet_net_unlock(cpt);
1371 while (!list_empty(&rb_list)) {
1372 rb = list_entry(rb_list.next, struct lnet_rtrbuf, rb_list);
1373 list_del(&rb->rb_list);
1374 lnet_destroy_rtrbuf(rb, npages);
1381 lnet_rtrpool_init(struct lnet_rtrbufpool *rbp, int npages)
1383 INIT_LIST_HEAD(&rbp->rbp_msgs);
1384 INIT_LIST_HEAD(&rbp->rbp_bufs);
1386 rbp->rbp_npages = npages;
1387 rbp->rbp_credits = 0;
1388 rbp->rbp_mincredits = 0;
1392 lnet_rtrpools_free(int keep_pools)
1394 struct lnet_rtrbufpool *rtrp;
1397 if (the_lnet.ln_rtrpools == NULL) /* uninitialized or freed */
1400 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1401 lnet_rtrpool_free_bufs(&rtrp[LNET_TINY_BUF_IDX], i);
1402 lnet_rtrpool_free_bufs(&rtrp[LNET_SMALL_BUF_IDX], i);
1403 lnet_rtrpool_free_bufs(&rtrp[LNET_LARGE_BUF_IDX], i);
1407 cfs_percpt_free(the_lnet.ln_rtrpools);
1408 the_lnet.ln_rtrpools = NULL;
1413 lnet_nrb_tiny_calculate(void)
1415 int nrbs = LNET_NRB_TINY;
1417 if (tiny_router_buffers < 0) {
1418 LCONSOLE_ERROR_MSG(0x10c,
1419 "tiny_router_buffers=%d invalid when "
1420 "routing enabled\n", tiny_router_buffers);
1424 if (tiny_router_buffers > 0)
1425 nrbs = tiny_router_buffers;
1427 nrbs /= LNET_CPT_NUMBER;
1428 return max(nrbs, LNET_NRB_TINY_MIN);
1432 lnet_nrb_small_calculate(void)
1434 int nrbs = LNET_NRB_SMALL;
1436 if (small_router_buffers < 0) {
1437 LCONSOLE_ERROR_MSG(0x10c,
1438 "small_router_buffers=%d invalid when "
1439 "routing enabled\n", small_router_buffers);
1443 if (small_router_buffers > 0)
1444 nrbs = small_router_buffers;
1446 nrbs /= LNET_CPT_NUMBER;
1447 return max(nrbs, LNET_NRB_SMALL_MIN);
1451 lnet_nrb_large_calculate(void)
1453 int nrbs = LNET_NRB_LARGE;
1455 if (large_router_buffers < 0) {
1456 LCONSOLE_ERROR_MSG(0x10c,
1457 "large_router_buffers=%d invalid when "
1458 "routing enabled\n", large_router_buffers);
1462 if (large_router_buffers > 0)
1463 nrbs = large_router_buffers;
1465 nrbs /= LNET_CPT_NUMBER;
1466 return max(nrbs, LNET_NRB_LARGE_MIN);
1470 lnet_rtrpools_alloc(int im_a_router)
1472 struct lnet_rtrbufpool *rtrp;
1479 if (!strcmp(forwarding, "")) {
1480 /* not set either way */
1483 } else if (!strcmp(forwarding, "disabled")) {
1484 /* explicitly disabled */
1486 } else if (!strcmp(forwarding, "enabled")) {
1487 /* explicitly enabled */
1489 LCONSOLE_ERROR_MSG(0x10b, "'forwarding' not set to either "
1490 "'enabled' or 'disabled'\n");
1494 nrb_tiny = lnet_nrb_tiny_calculate();
1498 nrb_small = lnet_nrb_small_calculate();
1502 nrb_large = lnet_nrb_large_calculate();
1506 the_lnet.ln_rtrpools = cfs_percpt_alloc(lnet_cpt_table(),
1508 sizeof(struct lnet_rtrbufpool));
1509 if (the_lnet.ln_rtrpools == NULL) {
1510 LCONSOLE_ERROR_MSG(0x10c,
1511 "Failed to initialize router buffe pool\n");
1515 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1516 lnet_rtrpool_init(&rtrp[LNET_TINY_BUF_IDX], 0);
1517 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_TINY_BUF_IDX],
1522 lnet_rtrpool_init(&rtrp[LNET_SMALL_BUF_IDX],
1523 LNET_NRB_SMALL_PAGES);
1524 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_SMALL_BUF_IDX],
1529 lnet_rtrpool_init(&rtrp[LNET_LARGE_BUF_IDX],
1530 LNET_NRB_LARGE_PAGES);
1531 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_LARGE_BUF_IDX],
1537 lnet_net_lock(LNET_LOCK_EX);
1538 the_lnet.ln_routing = 1;
1539 lnet_net_unlock(LNET_LOCK_EX);
1540 complete(&the_lnet.ln_mt_wait_complete);
1544 lnet_rtrpools_free(0);
1549 lnet_rtrpools_adjust_helper(int tiny, int small, int large)
1554 struct lnet_rtrbufpool *rtrp;
1556 /* If the provided values for each buffer pool are different than the
1557 * configured values, we need to take action. */
1559 tiny_router_buffers = tiny;
1560 nrb = lnet_nrb_tiny_calculate();
1561 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1562 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_TINY_BUF_IDX],
1569 small_router_buffers = small;
1570 nrb = lnet_nrb_small_calculate();
1571 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1572 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_SMALL_BUF_IDX],
1579 large_router_buffers = large;
1580 nrb = lnet_nrb_large_calculate();
1581 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1582 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_LARGE_BUF_IDX],
1593 lnet_rtrpools_adjust(int tiny, int small, int large)
1595 /* this function doesn't revert the changes if adding new buffers
1596 * failed. It's up to the user space caller to revert the
1599 if (!the_lnet.ln_routing)
1602 return lnet_rtrpools_adjust_helper(tiny, small, large);
1606 lnet_rtrpools_enable(void)
1610 if (the_lnet.ln_routing)
1613 if (the_lnet.ln_rtrpools == NULL)
1614 /* If routing is turned off, and we have never
1615 * initialized the pools before, just call the
1616 * standard buffer pool allocation routine as
1617 * if we are just configuring this for the first
1619 rc = lnet_rtrpools_alloc(1);
1621 rc = lnet_rtrpools_adjust_helper(0, 0, 0);
1625 lnet_net_lock(LNET_LOCK_EX);
1626 the_lnet.ln_routing = 1;
1628 the_lnet.ln_ping_target->pb_info.pi_features &=
1629 ~LNET_PING_FEAT_RTE_DISABLED;
1630 lnet_net_unlock(LNET_LOCK_EX);
1632 if (lnet_peer_discovery_disabled)
1633 CWARN("Consider turning discovery on to enable full "
1634 "Multi-Rail routing functionality\n");
1640 lnet_rtrpools_disable(void)
1642 if (!the_lnet.ln_routing)
1645 lnet_net_lock(LNET_LOCK_EX);
1646 the_lnet.ln_routing = 0;
1647 the_lnet.ln_ping_target->pb_info.pi_features |=
1648 LNET_PING_FEAT_RTE_DISABLED;
1650 tiny_router_buffers = 0;
1651 small_router_buffers = 0;
1652 large_router_buffers = 0;
1653 lnet_net_unlock(LNET_LOCK_EX);
1654 lnet_rtrpools_free(1);
1658 lnet_notify_peer_down(struct lnet_ni *ni, lnet_nid_t nid)
1660 if (ni->ni_net->net_lnd->lnd_notify_peer_down != NULL)
1661 (ni->ni_net->net_lnd->lnd_notify_peer_down)(nid);
1665 * ni: local NI used to communicate with the peer
1667 * alive: true if peer is alive, false otherwise
1668 * reset: reset health value. This is requested by the LND.
1669 * when: notificaiton time.
1672 lnet_notify(struct lnet_ni *ni, lnet_nid_t nid, bool alive, bool reset,
1675 struct lnet_peer_ni *lpni = NULL;
1676 struct lnet_route *route;
1677 struct lnet_peer *lp;
1678 time64_t now = ktime_get_seconds();
1681 LASSERT (!in_interrupt ());
1683 CDEBUG (D_NET, "%s notifying %s: %s\n",
1684 (ni == NULL) ? "userspace" : libcfs_nid2str(ni->ni_nid),
1685 libcfs_nid2str(nid),
1686 alive ? "up" : "down");
1689 LNET_NIDNET(ni->ni_nid) != LNET_NIDNET(nid)) {
1690 CWARN("Ignoring notification of %s %s by %s (different net)\n",
1691 libcfs_nid2str(nid), alive ? "birth" : "death",
1692 libcfs_nid2str(ni->ni_nid));
1696 /* can't do predictions... */
1698 CWARN("Ignoring prediction from %s of %s %s "
1699 "%lld seconds in the future\n",
1700 (ni == NULL) ? "userspace" : libcfs_nid2str(ni->ni_nid),
1701 libcfs_nid2str(nid), alive ? "up" : "down", when - now);
1705 if (ni != NULL && !alive && /* LND telling me she's down */
1706 !auto_down) { /* auto-down disabled */
1707 CDEBUG(D_NET, "Auto-down disabled\n");
1711 /* must lock 0 since this is used for synchronization */
1714 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
1719 lpni = lnet_find_peer_ni_locked(nid);
1723 CDEBUG(D_NET, "%s not found\n", libcfs_nid2str(nid));
1729 lnet_set_lpni_healthv_locked(lpni,
1730 LNET_MAX_HEALTH_VALUE);
1732 lnet_inc_lpni_healthv_locked(lpni);
1734 lnet_handle_remote_failure_locked(lpni);
1737 /* recalculate aliveness */
1738 alive = lnet_is_peer_ni_alive(lpni);
1741 if (ni != NULL && !alive)
1742 lnet_notify_peer_down(ni, lpni->lpni_nid);
1744 cpt = lpni->lpni_cpt;
1746 lnet_peer_ni_decref_locked(lpni);
1747 if (lpni && lpni->lpni_peer_net && lpni->lpni_peer_net->lpn_peer) {
1748 lp = lpni->lpni_peer_net->lpn_peer;
1749 lp->lp_alive = alive;
1750 list_for_each_entry(route, &lp->lp_routes, lr_gwlist)
1751 lnet_set_route_aliveness(route, alive);
1753 lnet_net_unlock(cpt);
1757 EXPORT_SYMBOL(lnet_notify);