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(struct lnet_nid *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,
160 struct list_head *rt_list)
162 struct lnet_remotenet *rnet;
163 struct list_head zombies;
166 INIT_LIST_HEAD(&zombies);
173 rnet = lnet_find_rnet_locked(route->lr_net);
176 CDEBUG(D_NET, "deleting route %s->%s\n",
177 libcfs_net2str(route->lr_net),
178 libcfs_nidstr(&route->lr_nid));
181 * use the gateway's lp_primary_nid to delete the route as the
182 * lr_nid can be a constituent NID of the peer
184 lnet_del_route_from_rnet(
185 &route->lr_gateway->lp_primary_nid,
186 &rnet->lrn_routes, l);
189 route = list_first_entry(l, struct lnet_route,
191 route->lr_gateway = lp;
192 lnet_add_route_to_rnet(rnet, route);
194 while (!list_empty(l) && !rt_list) {
195 route = list_first_entry(l, struct lnet_route,
197 list_del(&route->lr_list);
198 LIBCFS_FREE(route, sizeof(*route));
204 lnet_rtr_transfer_to_peer(struct lnet_peer *src, struct lnet_peer *target)
206 struct lnet_route *route;
207 struct lnet_route *tmp, *tmp2;
209 lnet_net_lock(LNET_LOCK_EX);
210 CDEBUG(D_NET, "transfering routes from %s -> %s\n",
211 libcfs_nidstr(&src->lp_primary_nid),
212 libcfs_nidstr(&target->lp_primary_nid));
213 list_for_each_entry(route, &src->lp_routes, lr_gwlist) {
214 CDEBUG(D_NET, "%s: %s->%s\n",
215 libcfs_nidstr(&src->lp_primary_nid),
216 libcfs_net2str(route->lr_net),
217 libcfs_nidstr(&route->lr_nid));
219 list_splice_init(&src->lp_rtrq, &target->lp_rtrq);
220 list_for_each_entry_safe(route, tmp, &src->lp_routes, lr_gwlist) {
221 struct lnet_route *r2;
222 bool present = false;
223 list_for_each_entry_safe(r2, tmp2, &target->lp_routes, lr_gwlist) {
224 if (route->lr_net == r2->lr_net) {
225 if (route->lr_priority >= r2->lr_priority)
227 else if (route->lr_hops >= r2->lr_hops)
230 lnet_move_route(r2, NULL, NULL);
234 lnet_move_route(route, NULL, NULL);
236 lnet_move_route(route, target, NULL);
239 if (list_empty(&target->lp_rtr_list)) {
240 lnet_peer_addref_locked(target);
241 list_add_tail(&target->lp_rtr_list, &the_lnet.ln_routers);
244 the_lnet.ln_routers_version++;
245 lnet_net_unlock(LNET_LOCK_EX);
249 lnet_peers_start_down(void)
251 return check_routers_before_use;
255 * The peer_net of a gateway is alive if at least one of the peer_ni's on
256 * that peer_net is alive.
259 lnet_is_gateway_net_alive(struct lnet_peer_net *lpn)
261 struct lnet_peer_ni *lpni;
263 list_for_each_entry(lpni, &lpn->lpn_peer_nis, lpni_peer_nis) {
264 if (lnet_is_peer_ni_alive(lpni))
272 * a gateway is alive only if all its nets are alive
273 * called with cpt lock held
275 bool lnet_is_gateway_alive(struct lnet_peer *gw)
277 struct lnet_peer_net *lpn;
282 list_for_each_entry(lpn, &gw->lp_peer_nets, lpn_peer_nets) {
283 if (!lnet_is_gateway_net_alive(lpn))
291 * lnet_is_route_alive() needs to be called with cpt lock held
292 * A route is alive if the gateway can route between the local network and
293 * the remote network of the route.
294 * This means at least one NI is alive on each of the local and remote
295 * networks of the gateway.
297 bool lnet_is_route_alive(struct lnet_route *route)
299 struct lnet_peer *gw = route->lr_gateway;
300 struct lnet_peer_net *llpn;
301 struct lnet_peer_net *rlpn;
303 /* If the gateway is down then all routes are considered down */
308 * if discovery is disabled then rely on the cached aliveness
309 * information. This is handicapped information which we log when
310 * we receive the discovery ping response. The most uptodate
311 * aliveness information can only be obtained when discovery is
314 if (lnet_is_discovery_disabled(gw))
315 return atomic_read(&route->lr_alive) == 1;
318 * check the gateway's interfaces on the local network
320 llpn = lnet_peer_get_net_locked(gw, route->lr_lnet);
324 if (!lnet_is_gateway_net_alive(llpn))
328 * For single hop routes avoid_asym_router_failure dictates
329 * that the remote net must exist on the gateway. For multi-hop
330 * routes the next-hop will not have the remote net.
332 if (avoid_asym_router_failure &&
333 (route->lr_hops == 1 || route->lr_single_hop)) {
334 rlpn = lnet_peer_get_net_locked(gw, route->lr_net);
337 if (!lnet_is_gateway_net_alive(rlpn))
341 spin_lock(&gw->lp_lock);
342 if (!(gw->lp_state & LNET_PEER_ROUTER_ENABLED)) {
343 spin_unlock(&gw->lp_lock);
344 if (gw->lp_rtr_refcount > 0)
345 CERROR("peer %s is being used as a gateway but routing feature is not turned on\n",
346 libcfs_nidstr(&gw->lp_primary_nid));
349 spin_unlock(&gw->lp_lock);
355 lnet_consolidate_routes_locked(struct lnet_peer *orig_lp,
356 struct lnet_peer *new_lp)
358 struct lnet_peer_ni *lpni;
359 struct lnet_route *route;
362 * Although a route is correlated with a peer, but when it's added
363 * a specific NID is used. That NID refers to a peer_ni within
364 * a peer. There could be other peer_nis on the same net, which
365 * can be used to send to that gateway. However when we are
366 * consolidating gateways because of discovery, the nid used to
367 * add the route might've moved between gateway peers. In this
368 * case we want to move the route to the new gateway as well. The
369 * intent here is not to confuse the user who added the route.
371 list_for_each_entry(route, &orig_lp->lp_routes, lr_gwlist) {
372 lpni = lnet_peer_ni_get_locked(orig_lp, &route->lr_nid);
374 lnet_net_lock(LNET_LOCK_EX);
375 list_move(&route->lr_gwlist, &new_lp->lp_routes);
376 lnet_net_unlock(LNET_LOCK_EX);
382 lnet_check_route_inconsistency(struct lnet_route *route)
384 if (!route->lr_single_hop &&
385 (route->lr_hops == 1 || route->lr_hops == LNET_UNDEFINED_HOPS)) {
386 CWARN("route %s->%s is detected to be multi-hop but hop count is set to %d\n",
387 libcfs_net2str(route->lr_net),
388 libcfs_nidstr(&route->lr_gateway->lp_primary_nid),
389 (int) route->lr_hops);
394 lnet_set_route_hop_type(struct lnet_peer *gw, struct lnet_route *route)
396 struct lnet_peer_net *lpn;
397 bool single_hop = false;
399 list_for_each_entry(lpn, &gw->lp_peer_nets, lpn_peer_nets) {
400 if (route->lr_net == lpn->lpn_net_id) {
405 route->lr_single_hop = single_hop;
406 lnet_check_route_inconsistency(route);
409 /* Must hold net_lock/EX */
411 lnet_router_discovery_ping_reply(struct lnet_peer *lp)
413 struct lnet_ping_buffer *pbuf = lp->lp_data;
414 struct lnet_peer_net *llpn;
415 struct lnet_route *route;
416 bool single_hop = false;
423 spin_lock(&lp->lp_lock);
424 lp_state = lp->lp_state;
426 /* only handle replies if discovery is disabled. */
427 if (!lnet_is_discovery_disabled_locked(lp)) {
428 spin_unlock(&lp->lp_lock);
432 spin_unlock(&lp->lp_lock);
434 if (lp_state & LNET_PEER_PING_FAILED ||
435 pbuf->pb_info.pi_features & LNET_PING_FEAT_RTE_DISABLED) {
436 CDEBUG(D_NET, "Set routes down for gw %s because %s %d\n",
437 libcfs_nidstr(&lp->lp_primary_nid),
438 lp_state & LNET_PEER_PING_FAILED ? "ping failed" :
439 "route feature is disabled", lp->lp_ping_error);
440 /* If the ping failed or the peer has routing disabled then
441 * mark the routes served by this peer down
443 list_for_each_entry(route, &lp->lp_routes, lr_gwlist)
444 lnet_set_route_aliveness(route, false);
448 CDEBUG(D_NET, "Discovery is disabled. Processing reply for gw: %s:%d\n",
449 libcfs_nidstr(&lp->lp_primary_nid), pbuf->pb_info.pi_nnis);
452 * examine the ping response to determine if the routes on that
453 * gateway should be declared alive.
454 * The route is alive if:
455 * 1. local network to reach the route is alive and
456 * 2. route is single hop, avoid_async_router_failure is set and
457 * there exists at least one NI on the route's remote net
459 list_for_each_entry(route, &lp->lp_routes, lr_gwlist) {
460 llpn = lnet_peer_get_net_locked(lp, route->lr_lnet);
462 lnet_set_route_aliveness(route, false);
466 if (!lnet_is_gateway_net_alive(llpn)) {
467 lnet_set_route_aliveness(route, false);
471 single_hop = net_up = false;
472 for (i = 1; i < pbuf->pb_info.pi_nnis; i++) {
473 net = LNET_NIDNET(pbuf->pb_info.pi_ni[i].ns_nid);
475 if (route->lr_net == net) {
477 if (pbuf->pb_info.pi_ni[i].ns_status ==
485 route->lr_single_hop = single_hop;
486 if (avoid_asym_router_failure &&
487 (route->lr_hops == 1 || route->lr_single_hop))
488 lnet_set_route_aliveness(route, net_up);
490 lnet_set_route_aliveness(route, true);
493 * warn that the route is configured as single-hop but it
494 * really is multi-hop as far as we can tell.
496 lnet_check_route_inconsistency(route);
501 lnet_router_discovery_complete(struct lnet_peer *lp)
503 struct lnet_peer_ni *lpni = NULL;
504 struct lnet_route *route;
506 spin_lock(&lp->lp_lock);
507 lp->lp_state &= ~LNET_PEER_RTR_DISCOVERY;
508 lp->lp_state |= LNET_PEER_RTR_DISCOVERED;
509 lp->lp_alive = lp->lp_dc_error == 0;
510 spin_unlock(&lp->lp_lock);
512 if (!lp->lp_dc_error) {
513 /* ping replies are being handled when discovery is disabled */
514 if (lnet_is_discovery_disabled_locked(lp))
518 * mark single-hop routes. If the remote net is not configured on
519 * the gateway we assume this is intentional and we mark the
520 * gateway as multi-hop
522 list_for_each_entry(route, &lp->lp_routes, lr_gwlist) {
523 lnet_set_route_aliveness(route, true);
524 lnet_set_route_hop_type(lp, route);
531 * We do not send messages directly to the remote interfaces
532 * of an LNet router. As such, we rely on the PING response
533 * to determine the up/down status of these interfaces. If
534 * a PING response is not receieved, or some other problem with
535 * discovery occurs that prevents us from getting this status,
536 * we assume all interfaces are down until we're able to
537 * determine otherwise.
539 CDEBUG(D_NET, "%s: Router discovery failed %d\n",
540 libcfs_nidstr(&lp->lp_primary_nid), lp->lp_dc_error);
541 while ((lpni = lnet_get_next_peer_ni_locked(lp, NULL, lpni)) != NULL)
542 lpni->lpni_ns_status = LNET_NI_STATUS_DOWN;
544 list_for_each_entry(route, &lp->lp_routes, lr_gwlist)
545 lnet_set_route_aliveness(route, false);
549 lnet_rtr_addref_locked(struct lnet_peer *lp)
551 LASSERT(lp->lp_rtr_refcount >= 0);
553 /* lnet_net_lock must be exclusively locked */
554 lp->lp_rtr_refcount++;
555 if (lp->lp_rtr_refcount == 1) {
556 list_add_tail(&lp->lp_rtr_list, &the_lnet.ln_routers);
557 /* addref for the_lnet.ln_routers */
558 lnet_peer_addref_locked(lp);
559 the_lnet.ln_routers_version++;
564 lnet_rtr_decref_locked(struct lnet_peer *lp)
566 LASSERT(atomic_read(&lp->lp_refcount) > 0);
567 LASSERT(lp->lp_rtr_refcount > 0);
569 /* lnet_net_lock must be exclusively locked */
570 lp->lp_rtr_refcount--;
571 if (lp->lp_rtr_refcount == 0) {
572 LASSERT(list_empty(&lp->lp_routes));
574 list_del(&lp->lp_rtr_list);
575 /* decref for the_lnet.ln_routers */
576 lnet_peer_decref_locked(lp);
577 the_lnet.ln_routers_version++;
581 struct lnet_remotenet *
582 lnet_find_rnet_locked(__u32 net)
584 struct lnet_remotenet *rnet;
585 struct list_head *tmp;
586 struct list_head *rn_list;
588 LASSERT(the_lnet.ln_state == LNET_STATE_RUNNING);
590 rn_list = lnet_net2rnethash(net);
591 list_for_each(tmp, rn_list) {
592 rnet = list_entry(tmp, struct lnet_remotenet, lrn_list);
594 if (rnet->lrn_net == net)
600 static void lnet_shuffle_seed(void)
603 struct lnet_ni *ni = NULL;
608 /* Nodes with small feet have little entropy
609 * the NID for this node gives the most entropy in the low bits */
610 while ((ni = lnet_get_next_ni_locked(NULL, ni)))
611 add_device_randomness(&ni->ni_nid, sizeof(ni->ni_nid));
616 /* NB expects LNET_LOCK held */
618 lnet_add_route_to_rnet(struct lnet_remotenet *rnet, struct lnet_route *route)
620 struct lnet_peer_net *lpn;
621 unsigned int offset = 0;
622 unsigned int len = 0;
628 list_for_each(e, &rnet->lrn_routes)
632 * Randomly adding routes to the list is done to ensure that when
633 * different nodes are using the same list of routers, they end up
634 * preferring different routers.
636 offset = prandom_u32_max(len + 1);
637 list_for_each(e, &rnet->lrn_routes) {
642 list_add(&route->lr_list, e);
644 * force a router check on the gateway to make sure the route is
647 now = ktime_get_real_seconds();
648 list_for_each_entry(lpn, &route->lr_gateway->lp_peer_nets,
650 lpn->lpn_next_ping = now;
653 the_lnet.ln_remote_nets_version++;
655 /* add the route on the gateway list */
656 list_add(&route->lr_gwlist, &route->lr_gateway->lp_routes);
658 /* take a router reference count on the gateway */
659 lnet_rtr_addref_locked(route->lr_gateway);
663 lnet_add_route(__u32 net, __u32 hops, struct lnet_nid *gateway,
664 __u32 priority, __u32 sensitivity)
666 struct list_head *route_entry;
667 struct lnet_remotenet *rnet;
668 struct lnet_remotenet *rnet2;
669 struct lnet_route *route;
670 struct lnet_peer_ni *lpni;
671 struct lnet_peer *gw;
675 CDEBUG(D_NET, "Add route: remote net %s hops %d priority %u gw %s\n",
676 libcfs_net2str(net), hops, priority, libcfs_nidstr(gateway));
678 if (LNET_NID_IS_ANY(gateway) ||
679 nid_is_lo0(gateway) ||
680 net == LNET_NET_ANY ||
681 LNET_NETTYP(net) == LOLND ||
682 LNET_NID_NET(gateway) == net ||
683 (hops != LNET_UNDEFINED_HOPS && (hops < 1 || hops > 255)))
686 /* it's a local network */
687 if (lnet_islocalnet(net))
690 if (!lnet_islocalnet(LNET_NID_NET(gateway))) {
691 CERROR("Cannot add route with gateway %s. There is no local interface configured on LNet %s\n",
692 libcfs_nidstr(gateway),
693 libcfs_net2str(LNET_NID_NET(gateway)));
694 return -EHOSTUNREACH;
697 /* Assume net, route, all new */
698 LIBCFS_ALLOC(route, sizeof(*route));
699 LIBCFS_ALLOC(rnet, sizeof(*rnet));
700 if (route == NULL || rnet == NULL) {
701 CERROR("Out of memory creating route %s %d %s\n",
702 libcfs_net2str(net), hops, libcfs_nidstr(gateway));
704 LIBCFS_FREE(route, sizeof(*route));
706 LIBCFS_FREE(rnet, sizeof(*rnet));
710 INIT_LIST_HEAD(&rnet->lrn_routes);
712 /* store the local and remote net that the route represents */
713 route->lr_lnet = LNET_NID_NET(gateway);
715 route->lr_nid = *gateway;
716 route->lr_priority = priority;
717 route->lr_hops = hops;
718 if (lnet_peers_start_down())
719 atomic_set(&route->lr_alive, 0);
721 atomic_set(&route->lr_alive, 1);
723 lnet_net_lock(LNET_LOCK_EX);
726 * lnet_nid2peerni_ex() grabs a ref on the lpni. We will need to
727 * lose that once we're done
729 lpni = lnet_nid2peerni_ex(gateway, LNET_LOCK_EX);
731 lnet_net_unlock(LNET_LOCK_EX);
733 LIBCFS_FREE(route, sizeof(*route));
734 LIBCFS_FREE(rnet, sizeof(*rnet));
737 CERROR("Error %d creating route %s %d %s\n", rc,
738 libcfs_net2str(net), hops,
739 libcfs_nidstr(gateway));
743 LASSERT(lpni->lpni_peer_net && lpni->lpni_peer_net->lpn_peer);
744 gw = lpni->lpni_peer_net->lpn_peer;
746 route->lr_gateway = gw;
748 rnet2 = lnet_find_rnet_locked(net);
751 list_add_tail(&rnet->lrn_list, lnet_net2rnethash(net));
755 /* Search for a duplicate route (it's a NOOP if it is) */
757 list_for_each(route_entry, &rnet2->lrn_routes) {
758 struct lnet_route *route2;
760 route2 = list_entry(route_entry, struct lnet_route, lr_list);
761 if (route2->lr_gateway == route->lr_gateway) {
766 /* our lookups must be true */
767 LASSERT(!nid_same(&route2->lr_gateway->lp_primary_nid,
772 * It is possible to add multiple routes through the same peer,
773 * but it'll be using a different NID of that peer. When the
774 * gateway is discovered, discovery will consolidate the different
775 * peers into one peer. In this case the discovery code will have
776 * to move the routes from the peer that's being deleted to the
777 * consolidated peer lp_routes list
780 gw->lp_health_sensitivity = sensitivity;
781 lnet_add_route_to_rnet(rnet2, route);
782 if (lnet_peer_discovery_disabled)
783 CWARN("Consider turning discovery on to enable full Multi-Rail routing functionality\n");
787 * get rid of the reference on the lpni.
789 lnet_peer_ni_decref_locked(lpni);
790 lnet_net_unlock(LNET_LOCK_EX);
792 /* If avoid_asym_router_failure is enabled and hop count is not
793 * set to 1 for a route that is actually single-hop, then the
794 * feature will fail to prevent the router from being selected
795 * if it is missing a NI on the remote network due to misconfiguration.
797 if (avoid_asym_router_failure && hops == LNET_UNDEFINED_HOPS)
798 CWARN("Use hops = 1 for a single-hop route when avoid_asym_router_failure feature is enabled\n");
804 LIBCFS_FREE(route, sizeof(*route));
808 LIBCFS_FREE(rnet, sizeof(*rnet));
810 /* kick start the monitor thread to handle the added route */
811 complete(&the_lnet.ln_mt_wait_complete);
817 lnet_del_route_from_rnet(struct lnet_nid *gw_nid,
818 struct list_head *route_list,
819 struct list_head *zombies)
821 struct lnet_peer *gateway;
822 struct lnet_route *route;
823 struct lnet_route *tmp;
825 list_for_each_entry_safe(route, tmp, route_list, lr_list) {
826 gateway = route->lr_gateway;
827 if (gw_nid && !nid_same(gw_nid, &gateway->lp_primary_nid))
831 * move to zombie to delete outside the lock
832 * Note that this function is called with the
833 * ln_api_mutex held as well as the exclusive net
834 * lock. Adding to the remote net list happens
835 * under the same conditions. Same goes for the
836 * gateway router list
838 list_move(&route->lr_list, zombies);
839 the_lnet.ln_remote_nets_version++;
841 list_del(&route->lr_gwlist);
842 lnet_rtr_decref_locked(gateway);
847 lnet_del_route(__u32 net, struct lnet_nid *gw)
849 LIST_HEAD(rnet_zombies);
850 struct lnet_remotenet *rnet;
851 struct lnet_remotenet *tmp;
852 struct list_head *rn_list;
853 struct lnet_peer_ni *lpni;
854 struct lnet_route *route;
855 struct lnet_nid gw_nid;
857 struct lnet_peer *lp = NULL;
860 CDEBUG(D_NET, "Del route: net %s : gw %s\n",
861 libcfs_net2str(net), libcfs_nidstr(gw));
863 /* NB Caller may specify either all routes via the given gateway
864 * or a specific route entry actual NIDs) */
866 lnet_net_lock(LNET_LOCK_EX);
869 lpni = lnet_peer_ni_find_locked(gw);
873 lp = lpni->lpni_peer_net->lpn_peer;
875 gw_nid = lp->lp_primary_nid;
877 lnet_peer_ni_decref_locked(lpni);
880 if (net != LNET_NET_ANY) {
881 rnet = lnet_find_rnet_locked(net);
883 lnet_net_unlock(LNET_LOCK_EX);
886 lnet_del_route_from_rnet(gw, &rnet->lrn_routes,
888 if (list_empty(&rnet->lrn_routes))
889 list_move(&rnet->lrn_list, &rnet_zombies);
893 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) {
894 rn_list = &the_lnet.ln_remote_nets_hash[i];
896 list_for_each_entry_safe(rnet, tmp, rn_list, lrn_list) {
897 lnet_del_route_from_rnet(gw, &rnet->lrn_routes,
899 if (list_empty(&rnet->lrn_routes))
900 list_move(&rnet->lrn_list, &rnet_zombies);
906 * check if there are any routes remaining on the gateway
907 * If there are no more routes make sure to set the peer's
908 * lp_disc_net_id to 0 (invalid), in case we add more routes in
909 * the future on that gateway, then we start our discovery process
913 if (list_empty(&lp->lp_routes))
914 lp->lp_disc_net_id = 0;
917 lnet_net_unlock(LNET_LOCK_EX);
919 while (!list_empty(&zombies)) {
920 route = list_first_entry(&zombies, struct lnet_route, lr_list);
921 list_del(&route->lr_list);
922 LIBCFS_FREE(route, sizeof(*route));
925 while (!list_empty(&rnet_zombies)) {
926 rnet = list_first_entry(&rnet_zombies, struct lnet_remotenet,
928 list_del(&rnet->lrn_list);
929 LIBCFS_FREE(rnet, sizeof(*rnet));
936 lnet_destroy_routes(void)
938 lnet_del_route(LNET_NET_ANY, NULL);
941 int lnet_get_rtr_pool_cfg(int cpt, struct lnet_ioctl_pool_cfg *pool_cfg)
943 struct lnet_rtrbufpool *rbp;
944 int i, rc = -ENOENT, j;
946 if (the_lnet.ln_rtrpools == NULL)
950 cfs_percpt_for_each(rbp, i, the_lnet.ln_rtrpools) {
955 for (j = 0; j < LNET_NRBPOOLS; j++) {
956 pool_cfg->pl_pools[j].pl_npages = rbp[j].rbp_npages;
957 pool_cfg->pl_pools[j].pl_nbuffers = rbp[j].rbp_nbuffers;
958 pool_cfg->pl_pools[j].pl_credits = rbp[j].rbp_credits;
959 pool_cfg->pl_pools[j].pl_mincredits = rbp[j].rbp_mincredits;
966 lnet_net_lock(LNET_LOCK_EX);
967 pool_cfg->pl_routing = the_lnet.ln_routing;
968 lnet_net_unlock(LNET_LOCK_EX);
974 lnet_get_route(int idx, __u32 *net, __u32 *hops, lnet_nid_t *gateway,
975 __u32 *flags, __u32 *priority, __u32 *sensitivity)
977 struct lnet_remotenet *rnet;
978 struct list_head *rn_list;
979 struct lnet_route *route;
980 struct list_head *e1;
981 struct list_head *e2;
985 cpt = lnet_net_lock_current();
987 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) {
988 rn_list = &the_lnet.ln_remote_nets_hash[i];
989 list_for_each(e1, rn_list) {
990 rnet = list_entry(e1, struct lnet_remotenet, lrn_list);
992 list_for_each(e2, &rnet->lrn_routes) {
993 route = list_entry(e2, struct lnet_route,
997 *net = rnet->lrn_net;
998 *gateway = lnet_nid_to_nid4(&route->lr_nid);
999 *hops = route->lr_hops;
1000 *priority = route->lr_priority;
1001 *sensitivity = route->lr_gateway->
1002 lp_health_sensitivity;
1003 if (lnet_is_route_alive(route))
1004 *flags |= LNET_RT_ALIVE;
1006 *flags &= ~LNET_RT_ALIVE;
1007 if (route->lr_single_hop)
1008 *flags &= ~LNET_RT_MULTI_HOP;
1010 *flags |= LNET_RT_MULTI_HOP;
1011 lnet_net_unlock(cpt);
1018 lnet_net_unlock(cpt);
1023 lnet_wait_known_routerstate(void)
1025 struct lnet_peer *rtr;
1026 struct list_head *entry;
1029 LASSERT(the_lnet.ln_mt_state == LNET_MT_STATE_RUNNING);
1032 int cpt = lnet_net_lock_current();
1035 list_for_each(entry, &the_lnet.ln_routers) {
1036 rtr = list_entry(entry, struct lnet_peer,
1039 spin_lock(&rtr->lp_lock);
1041 if ((rtr->lp_state & LNET_PEER_RTR_DISCOVERED) == 0) {
1043 spin_unlock(&rtr->lp_lock);
1046 spin_unlock(&rtr->lp_lock);
1049 lnet_net_unlock(cpt);
1054 schedule_timeout_uninterruptible(cfs_time_seconds(1));
1059 lnet_net_set_status_locked(struct lnet_net *net, __u32 status)
1062 bool update = false;
1064 list_for_each_entry(ni, &net->net_ni_list, ni_netlist)
1065 if (lnet_ni_set_status(ni, status))
1072 lnet_update_ni_status_locked(void)
1074 struct lnet_net *net;
1080 LASSERT(the_lnet.ln_routing);
1082 timeout = router_ping_timeout + alive_router_check_interval;
1084 now = ktime_get_seconds();
1085 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1086 if (net->net_lnd->lnd_type == LOLND)
1089 if (now < net->net_last_alive + timeout)
1090 goto check_ni_fatal;
1092 spin_lock(&net->net_lock);
1093 /* re-check with lock */
1094 if (now < net->net_last_alive + timeout) {
1095 spin_unlock(&net->net_lock);
1096 goto check_ni_fatal;
1098 spin_unlock(&net->net_lock);
1101 * if the net didn't receive any traffic for past the
1102 * timeout on any of its constituent NIs, then mark all
1105 if (lnet_net_set_status_locked(net, LNET_NI_STATUS_DOWN)) {
1111 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
1112 /* lnet_ni_set_status() will perform the same check of
1113 * ni_status while holding the ni lock. We can safely
1114 * check ni_status without that lock because it is only
1115 * written to under net_lock/EX and our caller is
1116 * holding a net lock.
1118 if (atomic_read(&ni->ni_fatal_error_on) &&
1120 ni->ni_status->ns_status != LNET_NI_STATUS_DOWN &&
1121 lnet_ni_set_status(ni, LNET_NI_STATUS_DOWN))
1129 void lnet_wait_router_start(void)
1131 if (check_routers_before_use) {
1132 /* Note that a helpful side-effect of pinging all known routers
1133 * at startup is that it makes them drop stale connections they
1134 * may have to a previous instance of me. */
1135 lnet_wait_known_routerstate();
1140 * This function is called from the monitor thread to check if there are
1141 * any active routers that need to be checked.
1143 bool lnet_router_checker_active(void)
1145 /* Router Checker thread needs to run when routing is enabled in
1146 * order to call lnet_update_ni_status_locked() */
1147 if (the_lnet.ln_routing)
1150 return !list_empty(&the_lnet.ln_routers) &&
1151 alive_router_check_interval > 0;
1155 lnet_check_routers(void)
1157 struct lnet_peer_net *first_lpn;
1158 struct lnet_peer_net *lpn;
1159 struct lnet_peer_ni *lpni;
1160 struct list_head *entry;
1161 struct lnet_peer *rtr;
1171 cpt = lnet_net_lock_current();
1173 version = the_lnet.ln_routers_version;
1175 list_for_each(entry, &the_lnet.ln_routers) {
1176 rtr = list_entry(entry, struct lnet_peer,
1179 /* If we're currently discovering the peer then don't
1180 * issue another discovery
1182 if (rtr->lp_state & LNET_PEER_RTR_DISCOVERY)
1185 now = ktime_get_real_seconds();
1187 /* find the next local peer net which needs to be ping'd */
1191 net_id = rtr->lp_disc_net_id;
1193 lpn = lnet_get_next_peer_net_locked(rtr, net_id);
1195 CERROR("gateway %s has no networks\n",
1196 libcfs_nidstr(&rtr->lp_primary_nid));
1200 /* We looped back to the first peer net */
1201 if (first_lpn == lpn)
1206 net_id = lpn->lpn_net_id;
1207 if (!lnet_islocalnet_locked(net_id))
1212 CDEBUG(D_NET, "rtr %s(%p) %s(%p) next ping %lld\n",
1213 libcfs_nidstr(&rtr->lp_primary_nid), rtr,
1214 libcfs_net2str(net_id), lpn,
1215 lpn->lpn_next_ping);
1217 needs_ping = now >= lpn->lpn_next_ping;
1219 } while (!needs_ping);
1221 if (!found_lpn || !lpn) {
1222 CERROR("no local network found for gateway %s\n",
1223 libcfs_nidstr(&rtr->lp_primary_nid));
1230 spin_lock(&rtr->lp_lock);
1231 /* make sure we fully discover the router */
1232 rtr->lp_state &= ~LNET_PEER_NIDS_UPTODATE;
1233 rtr->lp_state |= LNET_PEER_FORCE_PING | LNET_PEER_FORCE_PUSH |
1234 LNET_PEER_RTR_DISCOVERY;
1235 spin_unlock(&rtr->lp_lock);
1237 /* find the peer_ni associated with the primary NID */
1238 lpni = lnet_peer_get_ni_locked(
1239 rtr, lnet_nid_to_nid4(&rtr->lp_primary_nid));
1241 CDEBUG(D_NET, "Expected to find an lpni for %s, but non found\n",
1242 libcfs_nidstr(&rtr->lp_primary_nid));
1245 lnet_peer_ni_addref_locked(lpni);
1247 /* specify the net to use */
1248 rtr->lp_disc_net_id = lpn->lpn_net_id;
1250 /* discover the router */
1251 CDEBUG(D_NET, "discover %s, cpt = %d\n",
1252 libcfs_nidstr(&lpni->lpni_nid), cpt);
1253 rc = lnet_discover_peer_locked(lpni, cpt, false);
1255 /* drop ref taken above */
1256 lnet_peer_ni_decref_locked(lpni);
1259 lpn->lpn_next_ping = now + alive_router_check_interval;
1261 CERROR("Failed to discover router %s\n",
1262 libcfs_nidstr(&rtr->lp_primary_nid));
1264 /* NB cpt lock was dropped in lnet_discover_peer_locked() */
1265 if (version != the_lnet.ln_routers_version) {
1266 /* the routers list has changed */
1271 if (the_lnet.ln_routing)
1272 push = lnet_update_ni_status_locked();
1274 lnet_net_unlock(cpt);
1276 /* if the status of the ni changed update the peers */
1278 lnet_push_update_to_peers(1);
1282 lnet_destroy_rtrbuf(struct lnet_rtrbuf *rb, int npages)
1284 int sz = offsetof(struct lnet_rtrbuf, rb_kiov[npages]);
1286 while (--npages >= 0)
1287 __free_page(rb->rb_kiov[npages].bv_page);
1289 LIBCFS_FREE(rb, sz);
1292 static struct lnet_rtrbuf *
1293 lnet_new_rtrbuf(struct lnet_rtrbufpool *rbp, int cpt)
1295 int npages = rbp->rbp_npages;
1296 int sz = offsetof(struct lnet_rtrbuf, rb_kiov[npages]);
1298 struct lnet_rtrbuf *rb;
1301 LIBCFS_CPT_ALLOC(rb, lnet_cpt_table(), cpt, sz);
1307 for (i = 0; i < npages; i++) {
1308 page = cfs_page_cpt_alloc(lnet_cpt_table(), cpt, GFP_KERNEL |
1309 __GFP_ZERO | __GFP_NORETRY);
1312 __free_page(rb->rb_kiov[i].bv_page);
1314 LIBCFS_FREE(rb, sz);
1318 rb->rb_kiov[i].bv_len = PAGE_SIZE;
1319 rb->rb_kiov[i].bv_offset = 0;
1320 rb->rb_kiov[i].bv_page = page;
1327 lnet_rtrpool_free_bufs(struct lnet_rtrbufpool *rbp, int cpt)
1329 int npages = rbp->rbp_npages;
1330 struct lnet_rtrbuf *rb;
1333 if (rbp->rbp_nbuffers == 0) /* not initialized or already freed */
1337 list_splice_init(&rbp->rbp_msgs, &tmp);
1338 lnet_drop_routed_msgs_locked(&tmp, cpt);
1339 list_splice_init(&rbp->rbp_bufs, &tmp);
1340 rbp->rbp_req_nbuffers = 0;
1341 rbp->rbp_nbuffers = rbp->rbp_credits = 0;
1342 rbp->rbp_mincredits = 0;
1343 lnet_net_unlock(cpt);
1345 /* Free buffers on the free list. */
1346 while (!list_empty(&tmp)) {
1347 rb = list_entry(tmp.next, struct lnet_rtrbuf, rb_list);
1348 list_del(&rb->rb_list);
1349 lnet_destroy_rtrbuf(rb, npages);
1354 lnet_rtrpool_adjust_bufs(struct lnet_rtrbufpool *rbp, int nbufs, int cpt)
1357 struct lnet_rtrbuf *rb;
1359 int num_buffers = 0;
1361 int npages = rbp->rbp_npages;
1364 /* If we are called for less buffers than already in the pool, we
1365 * just lower the req_nbuffers number and excess buffers will be
1366 * thrown away as they are returned to the free list. Credits
1367 * then get adjusted as well.
1368 * If we already have enough buffers allocated to serve the
1369 * increase requested, then we can treat that the same way as we
1370 * do the decrease. */
1371 num_rb = nbufs - rbp->rbp_nbuffers;
1372 if (nbufs <= rbp->rbp_req_nbuffers || num_rb <= 0) {
1373 rbp->rbp_req_nbuffers = nbufs;
1374 lnet_net_unlock(cpt);
1377 /* store the older value of rbp_req_nbuffers and then set it to
1378 * the new request to prevent lnet_return_rx_credits_locked() from
1379 * freeing buffers that we need to keep around */
1380 old_req_nbufs = rbp->rbp_req_nbuffers;
1381 rbp->rbp_req_nbuffers = nbufs;
1382 lnet_net_unlock(cpt);
1384 /* allocate the buffers on a local list first. If all buffers are
1385 * allocated successfully then join this list to the rbp buffer
1386 * list. If not then free all allocated buffers. */
1387 while (num_rb-- > 0) {
1388 rb = lnet_new_rtrbuf(rbp, cpt);
1390 CERROR("lnet: error allocating %ux%u page router buffers on CPT %u: rc = %d\n",
1391 nbufs, npages, cpt, -ENOMEM);
1394 rbp->rbp_req_nbuffers = old_req_nbufs;
1395 lnet_net_unlock(cpt);
1400 list_add(&rb->rb_list, &rb_list);
1406 list_splice_tail(&rb_list, &rbp->rbp_bufs);
1407 rbp->rbp_nbuffers += num_buffers;
1408 rbp->rbp_credits += num_buffers;
1409 rbp->rbp_mincredits = rbp->rbp_credits;
1410 /* We need to schedule blocked msg using the newly
1412 while (!list_empty(&rbp->rbp_bufs) &&
1413 !list_empty(&rbp->rbp_msgs))
1414 lnet_schedule_blocked_locked(rbp);
1416 lnet_net_unlock(cpt);
1421 while (!list_empty(&rb_list)) {
1422 rb = list_entry(rb_list.next, struct lnet_rtrbuf, rb_list);
1423 list_del(&rb->rb_list);
1424 lnet_destroy_rtrbuf(rb, npages);
1431 lnet_rtrpool_init(struct lnet_rtrbufpool *rbp, int npages)
1433 INIT_LIST_HEAD(&rbp->rbp_msgs);
1434 INIT_LIST_HEAD(&rbp->rbp_bufs);
1436 rbp->rbp_npages = npages;
1437 rbp->rbp_credits = 0;
1438 rbp->rbp_mincredits = 0;
1442 lnet_rtrpools_free(int keep_pools)
1444 struct lnet_rtrbufpool *rtrp;
1447 if (the_lnet.ln_rtrpools == NULL) /* uninitialized or freed */
1450 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1451 lnet_rtrpool_free_bufs(&rtrp[LNET_TINY_BUF_IDX], i);
1452 lnet_rtrpool_free_bufs(&rtrp[LNET_SMALL_BUF_IDX], i);
1453 lnet_rtrpool_free_bufs(&rtrp[LNET_LARGE_BUF_IDX], i);
1457 cfs_percpt_free(the_lnet.ln_rtrpools);
1458 the_lnet.ln_rtrpools = NULL;
1463 lnet_nrb_tiny_calculate(void)
1465 int nrbs = LNET_NRB_TINY;
1467 if (tiny_router_buffers < 0) {
1468 LCONSOLE_ERROR_MSG(0x10c,
1469 "tiny_router_buffers=%d invalid when "
1470 "routing enabled\n", tiny_router_buffers);
1474 if (tiny_router_buffers > 0)
1475 nrbs = tiny_router_buffers;
1477 nrbs /= LNET_CPT_NUMBER;
1478 return max(nrbs, LNET_NRB_TINY_MIN);
1482 lnet_nrb_small_calculate(void)
1484 int nrbs = LNET_NRB_SMALL;
1486 if (small_router_buffers < 0) {
1487 LCONSOLE_ERROR_MSG(0x10c,
1488 "small_router_buffers=%d invalid when "
1489 "routing enabled\n", small_router_buffers);
1493 if (small_router_buffers > 0)
1494 nrbs = small_router_buffers;
1496 nrbs /= LNET_CPT_NUMBER;
1497 return max(nrbs, LNET_NRB_SMALL_MIN);
1501 lnet_nrb_large_calculate(void)
1503 int nrbs = LNET_NRB_LARGE;
1505 if (large_router_buffers < 0) {
1506 LCONSOLE_ERROR_MSG(0x10c,
1507 "large_router_buffers=%d invalid when "
1508 "routing enabled\n", large_router_buffers);
1512 if (large_router_buffers > 0)
1513 nrbs = large_router_buffers;
1515 nrbs /= LNET_CPT_NUMBER;
1516 return max(nrbs, LNET_NRB_LARGE_MIN);
1520 lnet_rtrpools_alloc(int im_a_router)
1522 struct lnet_rtrbufpool *rtrp;
1529 if (!strcmp(forwarding, "")) {
1530 /* not set either way */
1533 } else if (!strcmp(forwarding, "disabled")) {
1534 /* explicitly disabled */
1536 } else if (!strcmp(forwarding, "enabled")) {
1537 /* explicitly enabled */
1540 LCONSOLE_ERROR_MSG(0x10b,
1541 "lnet: forwarding='%s' not set to either 'enabled' or 'disabled': rc = %d\n",
1546 nrb_tiny = lnet_nrb_tiny_calculate();
1550 nrb_small = lnet_nrb_small_calculate();
1554 nrb_large = lnet_nrb_large_calculate();
1558 the_lnet.ln_rtrpools = cfs_percpt_alloc(lnet_cpt_table(),
1560 sizeof(struct lnet_rtrbufpool));
1561 if (the_lnet.ln_rtrpools == NULL) {
1563 LCONSOLE_ERROR_MSG(0x10c,
1564 "lnet: error allocating router buffer pool: rc = %d\n",
1569 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1570 lnet_rtrpool_init(&rtrp[LNET_TINY_BUF_IDX], 0);
1571 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_TINY_BUF_IDX],
1576 lnet_rtrpool_init(&rtrp[LNET_SMALL_BUF_IDX],
1577 LNET_NRB_SMALL_PAGES);
1578 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_SMALL_BUF_IDX],
1583 lnet_rtrpool_init(&rtrp[LNET_LARGE_BUF_IDX],
1584 LNET_NRB_LARGE_PAGES);
1585 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_LARGE_BUF_IDX],
1591 lnet_net_lock(LNET_LOCK_EX);
1592 the_lnet.ln_routing = 1;
1593 lnet_net_unlock(LNET_LOCK_EX);
1594 complete(&the_lnet.ln_mt_wait_complete);
1598 lnet_rtrpools_free(0);
1603 lnet_rtrpools_adjust_helper(int tiny, int small, int large)
1608 struct lnet_rtrbufpool *rtrp;
1610 /* If the provided values for each buffer pool are different than the
1611 * configured values, we need to take action. */
1613 tiny_router_buffers = tiny;
1614 nrb = lnet_nrb_tiny_calculate();
1615 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1616 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_TINY_BUF_IDX],
1623 small_router_buffers = small;
1624 nrb = lnet_nrb_small_calculate();
1625 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1626 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_SMALL_BUF_IDX],
1633 large_router_buffers = large;
1634 nrb = lnet_nrb_large_calculate();
1635 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1636 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_LARGE_BUF_IDX],
1647 lnet_rtrpools_adjust(int tiny, int small, int large)
1649 /* this function doesn't revert the changes if adding new buffers
1650 * failed. It's up to the user space caller to revert the
1653 if (!the_lnet.ln_routing)
1656 return lnet_rtrpools_adjust_helper(tiny, small, large);
1660 lnet_rtrpools_enable(void)
1664 if (the_lnet.ln_routing)
1667 if (the_lnet.ln_rtrpools == NULL)
1668 /* If routing is turned off, and we have never
1669 * initialized the pools before, just call the
1670 * standard buffer pool allocation routine as
1671 * if we are just configuring this for the first
1673 rc = lnet_rtrpools_alloc(1);
1675 rc = lnet_rtrpools_adjust_helper(0, 0, 0);
1679 lnet_net_lock(LNET_LOCK_EX);
1680 the_lnet.ln_routing = 1;
1682 the_lnet.ln_ping_target->pb_info.pi_features &=
1683 ~LNET_PING_FEAT_RTE_DISABLED;
1684 lnet_net_unlock(LNET_LOCK_EX);
1686 if (lnet_peer_discovery_disabled)
1687 CWARN("Consider turning discovery on to enable full "
1688 "Multi-Rail routing functionality\n");
1694 lnet_rtrpools_disable(void)
1696 if (!the_lnet.ln_routing)
1699 lnet_net_lock(LNET_LOCK_EX);
1700 the_lnet.ln_routing = 0;
1701 the_lnet.ln_ping_target->pb_info.pi_features |=
1702 LNET_PING_FEAT_RTE_DISABLED;
1704 tiny_router_buffers = 0;
1705 small_router_buffers = 0;
1706 large_router_buffers = 0;
1707 lnet_net_unlock(LNET_LOCK_EX);
1708 lnet_rtrpools_free(1);
1712 lnet_notify_peer_down(struct lnet_ni *ni, struct lnet_nid *nid)
1714 if (ni->ni_net->net_lnd->lnd_notify_peer_down != NULL)
1715 (ni->ni_net->net_lnd->lnd_notify_peer_down)(nid);
1719 * ni: local NI used to communicate with the peer
1721 * alive: true if peer is alive, false otherwise
1722 * reset: reset health value. This is requested by the LND.
1723 * when: notificaiton time.
1726 lnet_notify(struct lnet_ni *ni, lnet_nid_t nid, bool alive, bool reset,
1729 struct lnet_peer_ni *lpni = NULL;
1730 struct lnet_route *route;
1731 struct lnet_peer *lp;
1732 time64_t now = ktime_get_seconds();
1735 LASSERT(!in_interrupt());
1737 CDEBUG(D_NET, "%s notifying %s: %s\n",
1738 (ni == NULL) ? "userspace" : libcfs_nidstr(&ni->ni_nid),
1739 libcfs_nid2str(nid), alive ? "up" : "down");
1742 LNET_NID_NET(&ni->ni_nid) != LNET_NIDNET(nid)) {
1743 CWARN("Ignoring notification of %s %s by %s (different net)\n",
1744 libcfs_nid2str(nid), alive ? "birth" : "death",
1745 libcfs_nidstr(&ni->ni_nid));
1749 /* can't do predictions... */
1751 CWARN("Ignoring prediction from %s of %s %s %lld seconds in the future\n",
1752 ni ? libcfs_nidstr(&ni->ni_nid) : "userspace",
1753 libcfs_nid2str(nid), alive ? "up" : "down", when - now);
1757 if (ni != NULL && !alive && /* LND telling me she's down */
1758 !auto_down) { /* auto-down disabled */
1759 CDEBUG(D_NET, "Auto-down disabled\n");
1763 /* must lock 0 since this is used for synchronization */
1766 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
1771 lpni = lnet_find_peer_ni_locked(nid);
1775 CDEBUG(D_NET, "%s not found\n", libcfs_nid2str(nid));
1781 lpni->lpni_ns_status = LNET_NI_STATUS_UP;
1782 lnet_set_lpni_healthv_locked(lpni,
1783 LNET_MAX_HEALTH_VALUE);
1785 __u32 sensitivity = lpni->lpni_peer_net->
1786 lpn_peer->lp_health_sensitivity;
1788 lnet_inc_lpni_healthv_locked(lpni,
1789 (sensitivity) ? sensitivity :
1790 lnet_health_sensitivity);
1793 lpni->lpni_ns_status = LNET_NI_STATUS_DOWN;
1796 /* recalculate aliveness */
1797 alive = lnet_is_peer_ni_alive(lpni);
1799 lp = lpni->lpni_peer_net->lpn_peer;
1800 /* If this is an LNet router then update route aliveness */
1801 if (lp->lp_rtr_refcount) {
1803 /* reset flag indicates gateway peer went up or down */
1804 lp->lp_alive = alive;
1806 /* If discovery is disabled, locally or on the gateway, then
1807 * any routes using lpni as next-hop need to be updated
1809 * NB: We can get many notifications while a route is down, so
1810 * we try and avoid the expensive net_lock/EX here for the
1811 * common case of receiving duplicate lnet_notify() calls (i.e.
1812 * only grab EX lock when we actually need to update the route
1815 if (lnet_is_discovery_disabled(lp)) {
1816 list_for_each_entry(route, &lp->lp_routes, lr_gwlist) {
1817 if (nid_same(&route->lr_nid, &lpni->lpni_nid))
1818 lnet_set_route_aliveness(route, alive);
1825 if (ni != NULL && !alive)
1826 lnet_notify_peer_down(ni, &lpni->lpni_nid);
1828 cpt = lpni->lpni_cpt;
1830 lnet_peer_ni_decref_locked(lpni);
1831 lnet_net_unlock(cpt);
1835 EXPORT_SYMBOL(lnet_notify);