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, struct list_head *route_list,
124 struct list_head *zombies);
127 rtr_sensitivity_set(const char *val, cfs_kernel_param_arg_t *kp)
130 unsigned *sen = (unsigned *)kp->arg;
133 rc = kstrtoul(val, 0, &value);
135 CERROR("Invalid module parameter value for 'router_sensitivity_percentage'\n");
139 if (value < 0 || value > 100) {
140 CERROR("Invalid value: %lu for 'router_sensitivity_percentage'\n", value);
145 * The purpose of locking the api_mutex here is to ensure that
146 * the correct value ends up stored properly.
148 mutex_lock(&the_lnet.ln_api_mutex);
152 mutex_unlock(&the_lnet.ln_api_mutex);
158 lnet_move_route(struct lnet_route *route, struct lnet_peer *lp,
159 struct list_head *rt_list)
161 struct lnet_remotenet *rnet;
162 struct list_head zombies;
165 INIT_LIST_HEAD(&zombies);
172 rnet = lnet_find_rnet_locked(route->lr_net);
175 CDEBUG(D_NET, "deleting route %s->%s\n",
176 libcfs_net2str(route->lr_net),
177 libcfs_nidstr(&route->lr_nid));
180 * use the gateway's lp_primary_nid to delete the route as the
181 * lr_nid can be a constituent NID of the peer
183 lnet_del_route_from_rnet(
184 lnet_nid_to_nid4(&route->lr_gateway->lp_primary_nid),
185 &rnet->lrn_routes, l);
188 route = list_first_entry(l, struct lnet_route,
190 route->lr_gateway = lp;
191 lnet_add_route_to_rnet(rnet, route);
193 while (!list_empty(l) && !rt_list) {
194 route = list_first_entry(l, struct lnet_route,
196 list_del(&route->lr_list);
197 LIBCFS_FREE(route, sizeof(*route));
203 lnet_rtr_transfer_to_peer(struct lnet_peer *src, struct lnet_peer *target)
205 struct lnet_route *route;
206 struct lnet_route *tmp, *tmp2;
208 lnet_net_lock(LNET_LOCK_EX);
209 CDEBUG(D_NET, "transfering routes from %s -> %s\n",
210 libcfs_nidstr(&src->lp_primary_nid),
211 libcfs_nidstr(&target->lp_primary_nid));
212 list_for_each_entry(route, &src->lp_routes, lr_gwlist) {
213 CDEBUG(D_NET, "%s: %s->%s\n",
214 libcfs_nidstr(&src->lp_primary_nid),
215 libcfs_net2str(route->lr_net),
216 libcfs_nidstr(&route->lr_nid));
218 list_splice_init(&src->lp_rtrq, &target->lp_rtrq);
219 list_for_each_entry_safe(route, tmp, &src->lp_routes, lr_gwlist) {
220 struct lnet_route *r2;
221 bool present = false;
222 list_for_each_entry_safe(r2, tmp2, &target->lp_routes, lr_gwlist) {
223 if (route->lr_net == r2->lr_net) {
224 if (route->lr_priority >= r2->lr_priority)
226 else if (route->lr_hops >= r2->lr_hops)
229 lnet_move_route(r2, NULL, NULL);
233 lnet_move_route(route, NULL, NULL);
235 lnet_move_route(route, target, NULL);
238 if (list_empty(&target->lp_rtr_list)) {
239 lnet_peer_addref_locked(target);
240 list_add_tail(&target->lp_rtr_list, &the_lnet.ln_routers);
243 the_lnet.ln_routers_version++;
244 lnet_net_unlock(LNET_LOCK_EX);
248 lnet_peers_start_down(void)
250 return check_routers_before_use;
254 * The peer_net of a gateway is alive if at least one of the peer_ni's on
255 * that peer_net is alive.
258 lnet_is_gateway_net_alive(struct lnet_peer_net *lpn)
260 struct lnet_peer_ni *lpni;
262 list_for_each_entry(lpni, &lpn->lpn_peer_nis, lpni_peer_nis) {
263 if (lnet_is_peer_ni_alive(lpni))
271 * a gateway is alive only if all its nets are alive
272 * called with cpt lock held
274 bool lnet_is_gateway_alive(struct lnet_peer *gw)
276 struct lnet_peer_net *lpn;
281 list_for_each_entry(lpn, &gw->lp_peer_nets, lpn_peer_nets) {
282 if (!lnet_is_gateway_net_alive(lpn))
290 * lnet_is_route_alive() needs to be called with cpt lock held
291 * A route is alive if the gateway can route between the local network and
292 * the remote network of the route.
293 * This means at least one NI is alive on each of the local and remote
294 * networks of the gateway.
296 bool lnet_is_route_alive(struct lnet_route *route)
298 struct lnet_peer *gw = route->lr_gateway;
299 struct lnet_peer_net *llpn;
300 struct lnet_peer_net *rlpn;
302 /* If the gateway is down then all routes are considered down */
307 * if discovery is disabled then rely on the cached aliveness
308 * information. This is handicapped information which we log when
309 * we receive the discovery ping response. The most uptodate
310 * aliveness information can only be obtained when discovery is
313 if (lnet_is_discovery_disabled(gw))
314 return atomic_read(&route->lr_alive) == 1;
317 * check the gateway's interfaces on the local network
319 llpn = lnet_peer_get_net_locked(gw, route->lr_lnet);
323 if (!lnet_is_gateway_net_alive(llpn))
327 * For single hop routes avoid_asym_router_failure dictates
328 * that the remote net must exist on the gateway. For multi-hop
329 * routes the next-hop will not have the remote net.
331 if (avoid_asym_router_failure &&
332 (route->lr_hops == 1 || route->lr_single_hop)) {
333 rlpn = lnet_peer_get_net_locked(gw, route->lr_net);
336 if (!lnet_is_gateway_net_alive(rlpn))
340 spin_lock(&gw->lp_lock);
341 if (!(gw->lp_state & LNET_PEER_ROUTER_ENABLED)) {
342 spin_unlock(&gw->lp_lock);
343 if (gw->lp_rtr_refcount > 0)
344 CERROR("peer %s is being used as a gateway but routing feature is not turned on\n",
345 libcfs_nidstr(&gw->lp_primary_nid));
348 spin_unlock(&gw->lp_lock);
354 lnet_consolidate_routes_locked(struct lnet_peer *orig_lp,
355 struct lnet_peer *new_lp)
357 struct lnet_peer_ni *lpni;
358 struct lnet_route *route;
361 * Although a route is correlated with a peer, but when it's added
362 * a specific NID is used. That NID refers to a peer_ni within
363 * a peer. There could be other peer_nis on the same net, which
364 * can be used to send to that gateway. However when we are
365 * consolidating gateways because of discovery, the nid used to
366 * add the route might've moved between gateway peers. In this
367 * case we want to move the route to the new gateway as well. The
368 * intent here is not to confuse the user who added the route.
370 list_for_each_entry(route, &orig_lp->lp_routes, lr_gwlist) {
371 lpni = lnet_peer_ni_get_locked(orig_lp, &route->lr_nid);
373 lnet_net_lock(LNET_LOCK_EX);
374 list_move(&route->lr_gwlist, &new_lp->lp_routes);
375 lnet_net_unlock(LNET_LOCK_EX);
381 lnet_check_route_inconsistency(struct lnet_route *route)
383 if (!route->lr_single_hop &&
384 (route->lr_hops == 1 || route->lr_hops == LNET_UNDEFINED_HOPS)) {
385 CWARN("route %s->%s is detected to be multi-hop but hop count is set to %d\n",
386 libcfs_net2str(route->lr_net),
387 libcfs_nidstr(&route->lr_gateway->lp_primary_nid),
388 (int) route->lr_hops);
393 lnet_set_route_hop_type(struct lnet_peer *gw, struct lnet_route *route)
395 struct lnet_peer_net *lpn;
396 bool single_hop = false;
398 list_for_each_entry(lpn, &gw->lp_peer_nets, lpn_peer_nets) {
399 if (route->lr_net == lpn->lpn_net_id) {
404 route->lr_single_hop = single_hop;
405 lnet_check_route_inconsistency(route);
408 /* Must hold net_lock/EX */
410 lnet_router_discovery_ping_reply(struct lnet_peer *lp)
412 struct lnet_ping_buffer *pbuf = lp->lp_data;
413 struct lnet_peer_net *llpn;
414 struct lnet_route *route;
415 bool single_hop = false;
422 spin_lock(&lp->lp_lock);
423 lp_state = lp->lp_state;
425 /* only handle replies if discovery is disabled. */
426 if (!lnet_is_discovery_disabled_locked(lp)) {
427 spin_unlock(&lp->lp_lock);
431 spin_unlock(&lp->lp_lock);
433 if (lp_state & LNET_PEER_PING_FAILED ||
434 pbuf->pb_info.pi_features & LNET_PING_FEAT_RTE_DISABLED) {
435 CDEBUG(D_NET, "Set routes down for gw %s because %s %d\n",
436 libcfs_nidstr(&lp->lp_primary_nid),
437 lp_state & LNET_PEER_PING_FAILED ? "ping failed" :
438 "route feature is disabled", lp->lp_ping_error);
439 /* If the ping failed or the peer has routing disabled then
440 * mark the routes served by this peer down
442 list_for_each_entry(route, &lp->lp_routes, lr_gwlist)
443 lnet_set_route_aliveness(route, false);
447 CDEBUG(D_NET, "Discovery is disabled. Processing reply for gw: %s:%d\n",
448 libcfs_nidstr(&lp->lp_primary_nid), pbuf->pb_info.pi_nnis);
451 * examine the ping response to determine if the routes on that
452 * gateway should be declared alive.
453 * The route is alive if:
454 * 1. local network to reach the route is alive and
455 * 2. route is single hop, avoid_async_router_failure is set and
456 * there exists at least one NI on the route's remote net
458 list_for_each_entry(route, &lp->lp_routes, lr_gwlist) {
459 llpn = lnet_peer_get_net_locked(lp, route->lr_lnet);
461 lnet_set_route_aliveness(route, false);
465 if (!lnet_is_gateway_net_alive(llpn)) {
466 lnet_set_route_aliveness(route, false);
470 single_hop = net_up = false;
471 for (i = 1; i < pbuf->pb_info.pi_nnis; i++) {
472 net = LNET_NIDNET(pbuf->pb_info.pi_ni[i].ns_nid);
474 if (route->lr_net == net) {
476 if (pbuf->pb_info.pi_ni[i].ns_status ==
484 route->lr_single_hop = single_hop;
485 if (avoid_asym_router_failure &&
486 (route->lr_hops == 1 || route->lr_single_hop))
487 lnet_set_route_aliveness(route, net_up);
489 lnet_set_route_aliveness(route, true);
492 * warn that the route is configured as single-hop but it
493 * really is multi-hop as far as we can tell.
495 lnet_check_route_inconsistency(route);
500 lnet_router_discovery_complete(struct lnet_peer *lp)
502 struct lnet_peer_ni *lpni = NULL;
503 struct lnet_route *route;
505 spin_lock(&lp->lp_lock);
506 lp->lp_state &= ~LNET_PEER_RTR_DISCOVERY;
507 lp->lp_state |= LNET_PEER_RTR_DISCOVERED;
508 lp->lp_alive = lp->lp_dc_error == 0;
509 spin_unlock(&lp->lp_lock);
511 if (!lp->lp_dc_error) {
512 /* ping replies are being handled when discovery is disabled */
513 if (lnet_is_discovery_disabled_locked(lp))
517 * mark single-hop routes. If the remote net is not configured on
518 * the gateway we assume this is intentional and we mark the
519 * gateway as multi-hop
521 list_for_each_entry(route, &lp->lp_routes, lr_gwlist) {
522 lnet_set_route_aliveness(route, true);
523 lnet_set_route_hop_type(lp, route);
530 * We do not send messages directly to the remote interfaces
531 * of an LNet router. As such, we rely on the PING response
532 * to determine the up/down status of these interfaces. If
533 * a PING response is not receieved, or some other problem with
534 * discovery occurs that prevents us from getting this status,
535 * we assume all interfaces are down until we're able to
536 * determine otherwise.
538 CDEBUG(D_NET, "%s: Router discovery failed %d\n",
539 libcfs_nidstr(&lp->lp_primary_nid), lp->lp_dc_error);
540 while ((lpni = lnet_get_next_peer_ni_locked(lp, NULL, lpni)) != NULL)
541 lpni->lpni_ns_status = LNET_NI_STATUS_DOWN;
543 list_for_each_entry(route, &lp->lp_routes, lr_gwlist)
544 lnet_set_route_aliveness(route, false);
548 lnet_rtr_addref_locked(struct lnet_peer *lp)
550 LASSERT(lp->lp_rtr_refcount >= 0);
552 /* lnet_net_lock must be exclusively locked */
553 lp->lp_rtr_refcount++;
554 if (lp->lp_rtr_refcount == 1) {
555 list_add_tail(&lp->lp_rtr_list, &the_lnet.ln_routers);
556 /* addref for the_lnet.ln_routers */
557 lnet_peer_addref_locked(lp);
558 the_lnet.ln_routers_version++;
563 lnet_rtr_decref_locked(struct lnet_peer *lp)
565 LASSERT(atomic_read(&lp->lp_refcount) > 0);
566 LASSERT(lp->lp_rtr_refcount > 0);
568 /* lnet_net_lock must be exclusively locked */
569 lp->lp_rtr_refcount--;
570 if (lp->lp_rtr_refcount == 0) {
571 LASSERT(list_empty(&lp->lp_routes));
573 list_del(&lp->lp_rtr_list);
574 /* decref for the_lnet.ln_routers */
575 lnet_peer_decref_locked(lp);
576 the_lnet.ln_routers_version++;
580 struct lnet_remotenet *
581 lnet_find_rnet_locked(__u32 net)
583 struct lnet_remotenet *rnet;
584 struct list_head *tmp;
585 struct list_head *rn_list;
587 LASSERT(the_lnet.ln_state == LNET_STATE_RUNNING);
589 rn_list = lnet_net2rnethash(net);
590 list_for_each(tmp, rn_list) {
591 rnet = list_entry(tmp, struct lnet_remotenet, lrn_list);
593 if (rnet->lrn_net == net)
599 static void lnet_shuffle_seed(void)
602 struct lnet_ni *ni = NULL;
607 /* Nodes with small feet have little entropy
608 * the NID for this node gives the most entropy in the low bits */
609 while ((ni = lnet_get_next_ni_locked(NULL, ni)))
610 add_device_randomness(&ni->ni_nid, sizeof(ni->ni_nid));
615 /* NB expects LNET_LOCK held */
617 lnet_add_route_to_rnet(struct lnet_remotenet *rnet, struct lnet_route *route)
619 struct lnet_peer_net *lpn;
620 unsigned int offset = 0;
621 unsigned int len = 0;
627 list_for_each(e, &rnet->lrn_routes)
631 * Randomly adding routes to the list is done to ensure that when
632 * different nodes are using the same list of routers, they end up
633 * preferring different routers.
635 offset = prandom_u32_max(len + 1);
636 list_for_each(e, &rnet->lrn_routes) {
641 list_add(&route->lr_list, e);
643 * force a router check on the gateway to make sure the route is
646 now = ktime_get_real_seconds();
647 list_for_each_entry(lpn, &route->lr_gateway->lp_peer_nets,
649 lpn->lpn_next_ping = now;
652 the_lnet.ln_remote_nets_version++;
654 /* add the route on the gateway list */
655 list_add(&route->lr_gwlist, &route->lr_gateway->lp_routes);
657 /* take a router reference count on the gateway */
658 lnet_rtr_addref_locked(route->lr_gateway);
662 lnet_add_route(__u32 net, __u32 hops, struct lnet_nid *gateway,
663 __u32 priority, __u32 sensitivity)
665 struct list_head *route_entry;
666 struct lnet_remotenet *rnet;
667 struct lnet_remotenet *rnet2;
668 struct lnet_route *route;
669 struct lnet_peer_ni *lpni;
670 struct lnet_peer *gw;
674 CDEBUG(D_NET, "Add route: remote net %s hops %d priority %u gw %s\n",
675 libcfs_net2str(net), hops, priority, libcfs_nidstr(gateway));
677 if (LNET_NID_IS_ANY(gateway) ||
678 nid_is_lo0(gateway) ||
679 net == LNET_NET_ANY ||
680 LNET_NETTYP(net) == LOLND ||
681 LNET_NID_NET(gateway) == net ||
682 (hops != LNET_UNDEFINED_HOPS && (hops < 1 || hops > 255)))
685 /* it's a local network */
686 if (lnet_islocalnet(net))
689 if (!lnet_islocalnet(LNET_NID_NET(gateway))) {
690 CERROR("Cannot add route with gateway %s. There is no local interface configured on LNet %s\n",
691 libcfs_nidstr(gateway),
692 libcfs_net2str(LNET_NID_NET(gateway)));
693 return -EHOSTUNREACH;
696 /* Assume net, route, all new */
697 LIBCFS_ALLOC(route, sizeof(*route));
698 LIBCFS_ALLOC(rnet, sizeof(*rnet));
699 if (route == NULL || rnet == NULL) {
700 CERROR("Out of memory creating route %s %d %s\n",
701 libcfs_net2str(net), hops, libcfs_nidstr(gateway));
703 LIBCFS_FREE(route, sizeof(*route));
705 LIBCFS_FREE(rnet, sizeof(*rnet));
709 INIT_LIST_HEAD(&rnet->lrn_routes);
711 /* store the local and remote net that the route represents */
712 route->lr_lnet = LNET_NID_NET(gateway);
714 route->lr_nid = *gateway;
715 route->lr_priority = priority;
716 route->lr_hops = hops;
717 if (lnet_peers_start_down())
718 atomic_set(&route->lr_alive, 0);
720 atomic_set(&route->lr_alive, 1);
722 lnet_net_lock(LNET_LOCK_EX);
725 * lnet_nid2peerni_ex() grabs a ref on the lpni. We will need to
726 * lose that once we're done
728 lpni = lnet_nid2peerni_ex(gateway, LNET_LOCK_EX);
730 lnet_net_unlock(LNET_LOCK_EX);
732 LIBCFS_FREE(route, sizeof(*route));
733 LIBCFS_FREE(rnet, sizeof(*rnet));
736 CERROR("Error %d creating route %s %d %s\n", rc,
737 libcfs_net2str(net), hops,
738 libcfs_nidstr(gateway));
742 LASSERT(lpni->lpni_peer_net && lpni->lpni_peer_net->lpn_peer);
743 gw = lpni->lpni_peer_net->lpn_peer;
745 route->lr_gateway = gw;
747 rnet2 = lnet_find_rnet_locked(net);
750 list_add_tail(&rnet->lrn_list, lnet_net2rnethash(net));
754 /* Search for a duplicate route (it's a NOOP if it is) */
756 list_for_each(route_entry, &rnet2->lrn_routes) {
757 struct lnet_route *route2;
759 route2 = list_entry(route_entry, struct lnet_route, lr_list);
760 if (route2->lr_gateway == route->lr_gateway) {
765 /* our lookups must be true */
766 LASSERT(!nid_same(&route2->lr_gateway->lp_primary_nid,
771 * It is possible to add multiple routes through the same peer,
772 * but it'll be using a different NID of that peer. When the
773 * gateway is discovered, discovery will consolidate the different
774 * peers into one peer. In this case the discovery code will have
775 * to move the routes from the peer that's being deleted to the
776 * consolidated peer lp_routes list
779 gw->lp_health_sensitivity = sensitivity;
780 lnet_add_route_to_rnet(rnet2, route);
781 if (lnet_peer_discovery_disabled)
782 CWARN("Consider turning discovery on to enable full Multi-Rail routing functionality\n");
786 * get rid of the reference on the lpni.
788 lnet_peer_ni_decref_locked(lpni);
789 lnet_net_unlock(LNET_LOCK_EX);
791 /* If avoid_asym_router_failure is enabled and hop count is not
792 * set to 1 for a route that is actually single-hop, then the
793 * feature will fail to prevent the router from being selected
794 * if it is missing a NI on the remote network due to misconfiguration.
796 if (avoid_asym_router_failure && hops == LNET_UNDEFINED_HOPS)
797 CWARN("Use hops = 1 for a single-hop route when avoid_asym_router_failure feature is enabled\n");
803 LIBCFS_FREE(route, sizeof(*route));
807 LIBCFS_FREE(rnet, sizeof(*rnet));
809 /* kick start the monitor thread to handle the added route */
810 complete(&the_lnet.ln_mt_wait_complete);
816 lnet_del_route_from_rnet(lnet_nid_t gw_nid, struct list_head *route_list,
817 struct list_head *zombies)
819 struct lnet_peer *gateway;
820 struct lnet_route *route;
821 struct lnet_route *tmp;
823 list_for_each_entry_safe(route, tmp, route_list, lr_list) {
824 gateway = route->lr_gateway;
825 if (gw_nid != LNET_NID_ANY &&
826 gw_nid != lnet_nid_to_nid4(&gateway->lp_primary_nid))
830 * move to zombie to delete outside the lock
831 * Note that this function is called with the
832 * ln_api_mutex held as well as the exclusive net
833 * lock. Adding to the remote net list happens
834 * under the same conditions. Same goes for the
835 * gateway router list
837 list_move(&route->lr_list, zombies);
838 the_lnet.ln_remote_nets_version++;
840 list_del(&route->lr_gwlist);
841 lnet_rtr_decref_locked(gateway);
846 lnet_del_route(__u32 net, lnet_nid_t gw_nid)
848 LIST_HEAD(rnet_zombies);
849 struct lnet_remotenet *rnet;
850 struct lnet_remotenet *tmp;
851 struct list_head *rn_list;
852 struct lnet_peer_ni *lpni;
853 struct lnet_route *route;
855 struct lnet_peer *lp = NULL;
858 CDEBUG(D_NET, "Del route: net %s : gw %s\n",
859 libcfs_net2str(net), libcfs_nid2str(gw_nid));
861 /* NB Caller may specify either all routes via the given gateway
862 * or a specific route entry actual NIDs) */
864 lnet_net_lock(LNET_LOCK_EX);
866 lpni = lnet_find_peer_ni_locked(gw_nid);
868 lp = lpni->lpni_peer_net->lpn_peer;
870 gw_nid = lnet_nid_to_nid4(&lp->lp_primary_nid);
871 lnet_peer_ni_decref_locked(lpni);
874 if (net != LNET_NET_ANY) {
875 rnet = lnet_find_rnet_locked(net);
877 lnet_net_unlock(LNET_LOCK_EX);
880 lnet_del_route_from_rnet(gw_nid, &rnet->lrn_routes,
882 if (list_empty(&rnet->lrn_routes))
883 list_move(&rnet->lrn_list, &rnet_zombies);
887 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) {
888 rn_list = &the_lnet.ln_remote_nets_hash[i];
890 list_for_each_entry_safe(rnet, tmp, rn_list, lrn_list) {
891 lnet_del_route_from_rnet(gw_nid, &rnet->lrn_routes,
893 if (list_empty(&rnet->lrn_routes))
894 list_move(&rnet->lrn_list, &rnet_zombies);
900 * check if there are any routes remaining on the gateway
901 * If there are no more routes make sure to set the peer's
902 * lp_disc_net_id to 0 (invalid), in case we add more routes in
903 * the future on that gateway, then we start our discovery process
907 if (list_empty(&lp->lp_routes))
908 lp->lp_disc_net_id = 0;
911 lnet_net_unlock(LNET_LOCK_EX);
913 while (!list_empty(&zombies)) {
914 route = list_first_entry(&zombies, struct lnet_route, lr_list);
915 list_del(&route->lr_list);
916 LIBCFS_FREE(route, sizeof(*route));
919 while (!list_empty(&rnet_zombies)) {
920 rnet = list_first_entry(&rnet_zombies, struct lnet_remotenet,
922 list_del(&rnet->lrn_list);
923 LIBCFS_FREE(rnet, sizeof(*rnet));
930 lnet_destroy_routes (void)
932 lnet_del_route(LNET_NET_ANY, LNET_NID_ANY);
935 int lnet_get_rtr_pool_cfg(int cpt, struct lnet_ioctl_pool_cfg *pool_cfg)
937 struct lnet_rtrbufpool *rbp;
938 int i, rc = -ENOENT, j;
940 if (the_lnet.ln_rtrpools == NULL)
944 cfs_percpt_for_each(rbp, i, the_lnet.ln_rtrpools) {
949 for (j = 0; j < LNET_NRBPOOLS; j++) {
950 pool_cfg->pl_pools[j].pl_npages = rbp[j].rbp_npages;
951 pool_cfg->pl_pools[j].pl_nbuffers = rbp[j].rbp_nbuffers;
952 pool_cfg->pl_pools[j].pl_credits = rbp[j].rbp_credits;
953 pool_cfg->pl_pools[j].pl_mincredits = rbp[j].rbp_mincredits;
960 lnet_net_lock(LNET_LOCK_EX);
961 pool_cfg->pl_routing = the_lnet.ln_routing;
962 lnet_net_unlock(LNET_LOCK_EX);
968 lnet_get_route(int idx, __u32 *net, __u32 *hops, lnet_nid_t *gateway,
969 __u32 *flags, __u32 *priority, __u32 *sensitivity)
971 struct lnet_remotenet *rnet;
972 struct list_head *rn_list;
973 struct lnet_route *route;
974 struct list_head *e1;
975 struct list_head *e2;
979 cpt = lnet_net_lock_current();
981 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) {
982 rn_list = &the_lnet.ln_remote_nets_hash[i];
983 list_for_each(e1, rn_list) {
984 rnet = list_entry(e1, struct lnet_remotenet, lrn_list);
986 list_for_each(e2, &rnet->lrn_routes) {
987 route = list_entry(e2, struct lnet_route,
991 *net = rnet->lrn_net;
992 *gateway = lnet_nid_to_nid4(&route->lr_nid);
993 *hops = route->lr_hops;
994 *priority = route->lr_priority;
995 *sensitivity = route->lr_gateway->
996 lp_health_sensitivity;
997 if (lnet_is_route_alive(route))
998 *flags |= LNET_RT_ALIVE;
1000 *flags &= ~LNET_RT_ALIVE;
1001 if (route->lr_single_hop)
1002 *flags &= ~LNET_RT_MULTI_HOP;
1004 *flags |= LNET_RT_MULTI_HOP;
1005 lnet_net_unlock(cpt);
1012 lnet_net_unlock(cpt);
1017 lnet_wait_known_routerstate(void)
1019 struct lnet_peer *rtr;
1020 struct list_head *entry;
1023 LASSERT(the_lnet.ln_mt_state == LNET_MT_STATE_RUNNING);
1026 int cpt = lnet_net_lock_current();
1029 list_for_each(entry, &the_lnet.ln_routers) {
1030 rtr = list_entry(entry, struct lnet_peer,
1033 spin_lock(&rtr->lp_lock);
1035 if ((rtr->lp_state & LNET_PEER_RTR_DISCOVERED) == 0) {
1037 spin_unlock(&rtr->lp_lock);
1040 spin_unlock(&rtr->lp_lock);
1043 lnet_net_unlock(cpt);
1048 schedule_timeout_uninterruptible(cfs_time_seconds(1));
1053 lnet_net_set_status_locked(struct lnet_net *net, __u32 status)
1056 bool update = false;
1058 list_for_each_entry(ni, &net->net_ni_list, ni_netlist)
1059 if (lnet_ni_set_status(ni, status))
1066 lnet_update_ni_status_locked(void)
1068 struct lnet_net *net;
1074 LASSERT(the_lnet.ln_routing);
1076 timeout = router_ping_timeout + alive_router_check_interval;
1078 now = ktime_get_real_seconds();
1079 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1080 if (net->net_lnd->lnd_type == LOLND)
1083 if (now < net->net_last_alive + timeout)
1084 goto check_ni_fatal;
1086 spin_lock(&net->net_lock);
1087 /* re-check with lock */
1088 if (now < net->net_last_alive + timeout) {
1089 spin_unlock(&net->net_lock);
1090 goto check_ni_fatal;
1092 spin_unlock(&net->net_lock);
1095 * if the net didn't receive any traffic for past the
1096 * timeout on any of its constituent NIs, then mark all
1099 if (lnet_net_set_status_locked(net, LNET_NI_STATUS_DOWN)) {
1105 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
1106 /* lnet_ni_set_status() will perform the same check of
1107 * ni_status while holding the ni lock. We can safely
1108 * check ni_status without that lock because it is only
1109 * written to under net_lock/EX and our caller is
1110 * holding a net lock.
1112 if (atomic_read(&ni->ni_fatal_error_on) &&
1114 ni->ni_status->ns_status != LNET_NI_STATUS_DOWN &&
1115 lnet_ni_set_status(ni, LNET_NI_STATUS_DOWN))
1123 void lnet_wait_router_start(void)
1125 if (check_routers_before_use) {
1126 /* Note that a helpful side-effect of pinging all known routers
1127 * at startup is that it makes them drop stale connections they
1128 * may have to a previous instance of me. */
1129 lnet_wait_known_routerstate();
1134 * This function is called from the monitor thread to check if there are
1135 * any active routers that need to be checked.
1137 bool lnet_router_checker_active(void)
1139 /* Router Checker thread needs to run when routing is enabled in
1140 * order to call lnet_update_ni_status_locked() */
1141 if (the_lnet.ln_routing)
1144 return !list_empty(&the_lnet.ln_routers) &&
1145 alive_router_check_interval > 0;
1149 lnet_check_routers(void)
1151 struct lnet_peer_net *first_lpn;
1152 struct lnet_peer_net *lpn;
1153 struct lnet_peer_ni *lpni;
1154 struct list_head *entry;
1155 struct lnet_peer *rtr;
1165 cpt = lnet_net_lock_current();
1167 version = the_lnet.ln_routers_version;
1169 list_for_each(entry, &the_lnet.ln_routers) {
1170 rtr = list_entry(entry, struct lnet_peer,
1173 /* If we're currently discovering the peer then don't
1174 * issue another discovery
1176 if (rtr->lp_state & LNET_PEER_RTR_DISCOVERY)
1179 now = ktime_get_real_seconds();
1181 /* find the next local peer net which needs to be ping'd */
1185 net_id = rtr->lp_disc_net_id;
1187 lpn = lnet_get_next_peer_net_locked(rtr, net_id);
1189 CERROR("gateway %s has no networks\n",
1190 libcfs_nidstr(&rtr->lp_primary_nid));
1194 /* We looped back to the first peer net */
1195 if (first_lpn == lpn)
1200 net_id = lpn->lpn_net_id;
1201 if (!lnet_islocalnet_locked(net_id))
1206 CDEBUG(D_NET, "rtr %s(%p) %s(%p) next ping %lld\n",
1207 libcfs_nidstr(&rtr->lp_primary_nid), rtr,
1208 libcfs_net2str(net_id), lpn,
1209 lpn->lpn_next_ping);
1211 needs_ping = now >= lpn->lpn_next_ping;
1213 } while (!needs_ping);
1215 if (!found_lpn || !lpn) {
1216 CERROR("no local network found for gateway %s\n",
1217 libcfs_nidstr(&rtr->lp_primary_nid));
1224 spin_lock(&rtr->lp_lock);
1225 /* make sure we fully discover the router */
1226 rtr->lp_state &= ~LNET_PEER_NIDS_UPTODATE;
1227 rtr->lp_state |= LNET_PEER_FORCE_PING | LNET_PEER_FORCE_PUSH |
1228 LNET_PEER_RTR_DISCOVERY;
1229 spin_unlock(&rtr->lp_lock);
1231 /* find the peer_ni associated with the primary NID */
1232 lpni = lnet_peer_get_ni_locked(
1233 rtr, lnet_nid_to_nid4(&rtr->lp_primary_nid));
1235 CDEBUG(D_NET, "Expected to find an lpni for %s, but non found\n",
1236 libcfs_nidstr(&rtr->lp_primary_nid));
1239 lnet_peer_ni_addref_locked(lpni);
1241 /* specify the net to use */
1242 rtr->lp_disc_net_id = lpn->lpn_net_id;
1244 /* discover the router */
1245 CDEBUG(D_NET, "discover %s, cpt = %d\n",
1246 libcfs_nidstr(&lpni->lpni_nid), cpt);
1247 rc = lnet_discover_peer_locked(lpni, cpt, false);
1249 /* drop ref taken above */
1250 lnet_peer_ni_decref_locked(lpni);
1253 lpn->lpn_next_ping = now + alive_router_check_interval;
1255 CERROR("Failed to discover router %s\n",
1256 libcfs_nidstr(&rtr->lp_primary_nid));
1258 /* NB cpt lock was dropped in lnet_discover_peer_locked() */
1259 if (version != the_lnet.ln_routers_version) {
1260 /* the routers list has changed */
1265 if (the_lnet.ln_routing)
1266 push = lnet_update_ni_status_locked();
1268 lnet_net_unlock(cpt);
1270 /* if the status of the ni changed update the peers */
1272 lnet_push_update_to_peers(1);
1276 lnet_destroy_rtrbuf(struct lnet_rtrbuf *rb, int npages)
1278 int sz = offsetof(struct lnet_rtrbuf, rb_kiov[npages]);
1280 while (--npages >= 0)
1281 __free_page(rb->rb_kiov[npages].bv_page);
1283 LIBCFS_FREE(rb, sz);
1286 static struct lnet_rtrbuf *
1287 lnet_new_rtrbuf(struct lnet_rtrbufpool *rbp, int cpt)
1289 int npages = rbp->rbp_npages;
1290 int sz = offsetof(struct lnet_rtrbuf, rb_kiov[npages]);
1292 struct lnet_rtrbuf *rb;
1295 LIBCFS_CPT_ALLOC(rb, lnet_cpt_table(), cpt, sz);
1301 for (i = 0; i < npages; i++) {
1302 page = cfs_page_cpt_alloc(lnet_cpt_table(), cpt, GFP_KERNEL |
1303 __GFP_ZERO | __GFP_NORETRY);
1306 __free_page(rb->rb_kiov[i].bv_page);
1308 LIBCFS_FREE(rb, sz);
1312 rb->rb_kiov[i].bv_len = PAGE_SIZE;
1313 rb->rb_kiov[i].bv_offset = 0;
1314 rb->rb_kiov[i].bv_page = page;
1321 lnet_rtrpool_free_bufs(struct lnet_rtrbufpool *rbp, int cpt)
1323 int npages = rbp->rbp_npages;
1324 struct lnet_rtrbuf *rb;
1327 if (rbp->rbp_nbuffers == 0) /* not initialized or already freed */
1331 list_splice_init(&rbp->rbp_msgs, &tmp);
1332 lnet_drop_routed_msgs_locked(&tmp, cpt);
1333 list_splice_init(&rbp->rbp_bufs, &tmp);
1334 rbp->rbp_req_nbuffers = 0;
1335 rbp->rbp_nbuffers = rbp->rbp_credits = 0;
1336 rbp->rbp_mincredits = 0;
1337 lnet_net_unlock(cpt);
1339 /* Free buffers on the free list. */
1340 while (!list_empty(&tmp)) {
1341 rb = list_entry(tmp.next, struct lnet_rtrbuf, rb_list);
1342 list_del(&rb->rb_list);
1343 lnet_destroy_rtrbuf(rb, npages);
1348 lnet_rtrpool_adjust_bufs(struct lnet_rtrbufpool *rbp, int nbufs, int cpt)
1351 struct lnet_rtrbuf *rb;
1353 int num_buffers = 0;
1355 int npages = rbp->rbp_npages;
1358 /* If we are called for less buffers than already in the pool, we
1359 * just lower the req_nbuffers number and excess buffers will be
1360 * thrown away as they are returned to the free list. Credits
1361 * then get adjusted as well.
1362 * If we already have enough buffers allocated to serve the
1363 * increase requested, then we can treat that the same way as we
1364 * do the decrease. */
1365 num_rb = nbufs - rbp->rbp_nbuffers;
1366 if (nbufs <= rbp->rbp_req_nbuffers || num_rb <= 0) {
1367 rbp->rbp_req_nbuffers = nbufs;
1368 lnet_net_unlock(cpt);
1371 /* store the older value of rbp_req_nbuffers and then set it to
1372 * the new request to prevent lnet_return_rx_credits_locked() from
1373 * freeing buffers that we need to keep around */
1374 old_req_nbufs = rbp->rbp_req_nbuffers;
1375 rbp->rbp_req_nbuffers = nbufs;
1376 lnet_net_unlock(cpt);
1378 /* allocate the buffers on a local list first. If all buffers are
1379 * allocated successfully then join this list to the rbp buffer
1380 * list. If not then free all allocated buffers. */
1381 while (num_rb-- > 0) {
1382 rb = lnet_new_rtrbuf(rbp, cpt);
1384 CERROR("lnet: error allocating %ux%u page router buffers on CPT %u: rc = %d\n",
1385 nbufs, npages, cpt, -ENOMEM);
1388 rbp->rbp_req_nbuffers = old_req_nbufs;
1389 lnet_net_unlock(cpt);
1394 list_add(&rb->rb_list, &rb_list);
1400 list_splice_tail(&rb_list, &rbp->rbp_bufs);
1401 rbp->rbp_nbuffers += num_buffers;
1402 rbp->rbp_credits += num_buffers;
1403 rbp->rbp_mincredits = rbp->rbp_credits;
1404 /* We need to schedule blocked msg using the newly
1406 while (!list_empty(&rbp->rbp_bufs) &&
1407 !list_empty(&rbp->rbp_msgs))
1408 lnet_schedule_blocked_locked(rbp);
1410 lnet_net_unlock(cpt);
1415 while (!list_empty(&rb_list)) {
1416 rb = list_entry(rb_list.next, struct lnet_rtrbuf, rb_list);
1417 list_del(&rb->rb_list);
1418 lnet_destroy_rtrbuf(rb, npages);
1425 lnet_rtrpool_init(struct lnet_rtrbufpool *rbp, int npages)
1427 INIT_LIST_HEAD(&rbp->rbp_msgs);
1428 INIT_LIST_HEAD(&rbp->rbp_bufs);
1430 rbp->rbp_npages = npages;
1431 rbp->rbp_credits = 0;
1432 rbp->rbp_mincredits = 0;
1436 lnet_rtrpools_free(int keep_pools)
1438 struct lnet_rtrbufpool *rtrp;
1441 if (the_lnet.ln_rtrpools == NULL) /* uninitialized or freed */
1444 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1445 lnet_rtrpool_free_bufs(&rtrp[LNET_TINY_BUF_IDX], i);
1446 lnet_rtrpool_free_bufs(&rtrp[LNET_SMALL_BUF_IDX], i);
1447 lnet_rtrpool_free_bufs(&rtrp[LNET_LARGE_BUF_IDX], i);
1451 cfs_percpt_free(the_lnet.ln_rtrpools);
1452 the_lnet.ln_rtrpools = NULL;
1457 lnet_nrb_tiny_calculate(void)
1459 int nrbs = LNET_NRB_TINY;
1461 if (tiny_router_buffers < 0) {
1462 LCONSOLE_ERROR_MSG(0x10c,
1463 "tiny_router_buffers=%d invalid when "
1464 "routing enabled\n", tiny_router_buffers);
1468 if (tiny_router_buffers > 0)
1469 nrbs = tiny_router_buffers;
1471 nrbs /= LNET_CPT_NUMBER;
1472 return max(nrbs, LNET_NRB_TINY_MIN);
1476 lnet_nrb_small_calculate(void)
1478 int nrbs = LNET_NRB_SMALL;
1480 if (small_router_buffers < 0) {
1481 LCONSOLE_ERROR_MSG(0x10c,
1482 "small_router_buffers=%d invalid when "
1483 "routing enabled\n", small_router_buffers);
1487 if (small_router_buffers > 0)
1488 nrbs = small_router_buffers;
1490 nrbs /= LNET_CPT_NUMBER;
1491 return max(nrbs, LNET_NRB_SMALL_MIN);
1495 lnet_nrb_large_calculate(void)
1497 int nrbs = LNET_NRB_LARGE;
1499 if (large_router_buffers < 0) {
1500 LCONSOLE_ERROR_MSG(0x10c,
1501 "large_router_buffers=%d invalid when "
1502 "routing enabled\n", large_router_buffers);
1506 if (large_router_buffers > 0)
1507 nrbs = large_router_buffers;
1509 nrbs /= LNET_CPT_NUMBER;
1510 return max(nrbs, LNET_NRB_LARGE_MIN);
1514 lnet_rtrpools_alloc(int im_a_router)
1516 struct lnet_rtrbufpool *rtrp;
1523 if (!strcmp(forwarding, "")) {
1524 /* not set either way */
1527 } else if (!strcmp(forwarding, "disabled")) {
1528 /* explicitly disabled */
1530 } else if (!strcmp(forwarding, "enabled")) {
1531 /* explicitly enabled */
1534 LCONSOLE_ERROR_MSG(0x10b,
1535 "lnet: forwarding='%s' not set to either 'enabled' or 'disabled': rc = %d\n",
1540 nrb_tiny = lnet_nrb_tiny_calculate();
1544 nrb_small = lnet_nrb_small_calculate();
1548 nrb_large = lnet_nrb_large_calculate();
1552 the_lnet.ln_rtrpools = cfs_percpt_alloc(lnet_cpt_table(),
1554 sizeof(struct lnet_rtrbufpool));
1555 if (the_lnet.ln_rtrpools == NULL) {
1557 LCONSOLE_ERROR_MSG(0x10c,
1558 "lnet: error allocating router buffer pool: rc = %d\n",
1563 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1564 lnet_rtrpool_init(&rtrp[LNET_TINY_BUF_IDX], 0);
1565 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_TINY_BUF_IDX],
1570 lnet_rtrpool_init(&rtrp[LNET_SMALL_BUF_IDX],
1571 LNET_NRB_SMALL_PAGES);
1572 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_SMALL_BUF_IDX],
1577 lnet_rtrpool_init(&rtrp[LNET_LARGE_BUF_IDX],
1578 LNET_NRB_LARGE_PAGES);
1579 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_LARGE_BUF_IDX],
1585 lnet_net_lock(LNET_LOCK_EX);
1586 the_lnet.ln_routing = 1;
1587 lnet_net_unlock(LNET_LOCK_EX);
1588 complete(&the_lnet.ln_mt_wait_complete);
1592 lnet_rtrpools_free(0);
1597 lnet_rtrpools_adjust_helper(int tiny, int small, int large)
1602 struct lnet_rtrbufpool *rtrp;
1604 /* If the provided values for each buffer pool are different than the
1605 * configured values, we need to take action. */
1607 tiny_router_buffers = tiny;
1608 nrb = lnet_nrb_tiny_calculate();
1609 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1610 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_TINY_BUF_IDX],
1617 small_router_buffers = small;
1618 nrb = lnet_nrb_small_calculate();
1619 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1620 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_SMALL_BUF_IDX],
1627 large_router_buffers = large;
1628 nrb = lnet_nrb_large_calculate();
1629 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1630 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_LARGE_BUF_IDX],
1641 lnet_rtrpools_adjust(int tiny, int small, int large)
1643 /* this function doesn't revert the changes if adding new buffers
1644 * failed. It's up to the user space caller to revert the
1647 if (!the_lnet.ln_routing)
1650 return lnet_rtrpools_adjust_helper(tiny, small, large);
1654 lnet_rtrpools_enable(void)
1658 if (the_lnet.ln_routing)
1661 if (the_lnet.ln_rtrpools == NULL)
1662 /* If routing is turned off, and we have never
1663 * initialized the pools before, just call the
1664 * standard buffer pool allocation routine as
1665 * if we are just configuring this for the first
1667 rc = lnet_rtrpools_alloc(1);
1669 rc = lnet_rtrpools_adjust_helper(0, 0, 0);
1673 lnet_net_lock(LNET_LOCK_EX);
1674 the_lnet.ln_routing = 1;
1676 the_lnet.ln_ping_target->pb_info.pi_features &=
1677 ~LNET_PING_FEAT_RTE_DISABLED;
1678 lnet_net_unlock(LNET_LOCK_EX);
1680 if (lnet_peer_discovery_disabled)
1681 CWARN("Consider turning discovery on to enable full "
1682 "Multi-Rail routing functionality\n");
1688 lnet_rtrpools_disable(void)
1690 if (!the_lnet.ln_routing)
1693 lnet_net_lock(LNET_LOCK_EX);
1694 the_lnet.ln_routing = 0;
1695 the_lnet.ln_ping_target->pb_info.pi_features |=
1696 LNET_PING_FEAT_RTE_DISABLED;
1698 tiny_router_buffers = 0;
1699 small_router_buffers = 0;
1700 large_router_buffers = 0;
1701 lnet_net_unlock(LNET_LOCK_EX);
1702 lnet_rtrpools_free(1);
1706 lnet_notify_peer_down(struct lnet_ni *ni, lnet_nid_t nid)
1708 if (ni->ni_net->net_lnd->lnd_notify_peer_down != NULL)
1709 (ni->ni_net->net_lnd->lnd_notify_peer_down)(nid);
1713 * ni: local NI used to communicate with the peer
1715 * alive: true if peer is alive, false otherwise
1716 * reset: reset health value. This is requested by the LND.
1717 * when: notificaiton time.
1720 lnet_notify(struct lnet_ni *ni, lnet_nid_t nid, bool alive, bool reset,
1723 struct lnet_peer_ni *lpni = NULL;
1724 struct lnet_route *route;
1725 struct lnet_peer *lp;
1726 time64_t now = ktime_get_seconds();
1729 LASSERT(!in_interrupt());
1731 CDEBUG(D_NET, "%s notifying %s: %s\n",
1732 (ni == NULL) ? "userspace" : libcfs_nidstr(&ni->ni_nid),
1733 libcfs_nid2str(nid), alive ? "up" : "down");
1736 LNET_NID_NET(&ni->ni_nid) != LNET_NIDNET(nid)) {
1737 CWARN("Ignoring notification of %s %s by %s (different net)\n",
1738 libcfs_nid2str(nid), alive ? "birth" : "death",
1739 libcfs_nidstr(&ni->ni_nid));
1743 /* can't do predictions... */
1745 CWARN("Ignoring prediction from %s of %s %s %lld seconds in the future\n",
1746 ni ? libcfs_nidstr(&ni->ni_nid) : "userspace",
1747 libcfs_nid2str(nid), alive ? "up" : "down", when - now);
1751 if (ni != NULL && !alive && /* LND telling me she's down */
1752 !auto_down) { /* auto-down disabled */
1753 CDEBUG(D_NET, "Auto-down disabled\n");
1757 /* must lock 0 since this is used for synchronization */
1760 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
1765 lpni = lnet_find_peer_ni_locked(nid);
1769 CDEBUG(D_NET, "%s not found\n", libcfs_nid2str(nid));
1775 lpni->lpni_ns_status = LNET_NI_STATUS_UP;
1776 lnet_set_lpni_healthv_locked(lpni,
1777 LNET_MAX_HEALTH_VALUE);
1779 __u32 sensitivity = lpni->lpni_peer_net->
1780 lpn_peer->lp_health_sensitivity;
1782 lnet_inc_lpni_healthv_locked(lpni,
1783 (sensitivity) ? sensitivity :
1784 lnet_health_sensitivity);
1787 lpni->lpni_ns_status = LNET_NI_STATUS_DOWN;
1790 /* recalculate aliveness */
1791 alive = lnet_is_peer_ni_alive(lpni);
1793 lp = lpni->lpni_peer_net->lpn_peer;
1794 /* If this is an LNet router then update route aliveness */
1795 if (lp->lp_rtr_refcount) {
1797 /* reset flag indicates gateway peer went up or down */
1798 lp->lp_alive = alive;
1800 /* If discovery is disabled, locally or on the gateway, then
1801 * any routes using lpni as next-hop need to be updated
1803 * NB: We can get many notifications while a route is down, so
1804 * we try and avoid the expensive net_lock/EX here for the
1805 * common case of receiving duplicate lnet_notify() calls (i.e.
1806 * only grab EX lock when we actually need to update the route
1809 if (lnet_is_discovery_disabled(lp)) {
1810 list_for_each_entry(route, &lp->lp_routes, lr_gwlist) {
1811 if (nid_same(&route->lr_nid, &lpni->lpni_nid))
1812 lnet_set_route_aliveness(route, alive);
1819 if (ni != NULL && !alive)
1820 lnet_notify_peer_down(ni, lnet_nid_to_nid4(&lpni->lpni_nid));
1822 cpt = lpni->lpni_cpt;
1824 lnet_peer_ni_decref_locked(lpni);
1825 lnet_net_unlock(cpt);
1829 EXPORT_SYMBOL(lnet_notify);