1 // SPDX-License-Identifier: GPL-2.0
3 /* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
5 * Copyright (c) 2011, 2017, Intel Corporation.
8 /* This file is part of Lustre, http://www.lustre.org/ */
10 #define DEBUG_SUBSYSTEM S_LNET
12 #include <linux/random.h>
13 #include <lnet/lib-lnet.h>
15 #define LNET_NRB_TINY_MIN 512 /* min value for each CPT */
16 #define LNET_NRB_TINY (LNET_NRB_TINY_MIN * 4)
17 #define LNET_NRB_SMALL_MIN 4096 /* min value for each CPT */
18 #define LNET_NRB_SMALL (LNET_NRB_SMALL_MIN * 4)
19 #define LNET_NRB_SMALL_PAGES 1
20 #define LNET_NRB_LARGE_MIN 256 /* min value for each CPT */
21 #define LNET_NRB_LARGE (LNET_NRB_LARGE_MIN * 4)
22 #define LNET_NRB_LARGE_PAGES ((LNET_MTU + PAGE_SIZE - 1) >> \
25 static char *forwarding = "";
26 module_param(forwarding, charp, 0444);
27 MODULE_PARM_DESC(forwarding, "Explicitly enable/disable forwarding between networks");
29 static int tiny_router_buffers;
30 module_param(tiny_router_buffers, int, 0444);
31 MODULE_PARM_DESC(tiny_router_buffers, "# of 0 payload messages to buffer in the router");
32 static int small_router_buffers;
33 module_param(small_router_buffers, int, 0444);
34 MODULE_PARM_DESC(small_router_buffers, "# of small (1 page) messages to buffer in the router");
35 static int large_router_buffers;
36 module_param(large_router_buffers, int, 0444);
37 MODULE_PARM_DESC(large_router_buffers, "# of large messages to buffer in the router");
38 static int peer_buffer_credits;
39 module_param(peer_buffer_credits, int, 0444);
40 MODULE_PARM_DESC(peer_buffer_credits, "# router buffer credits per peer");
42 static int auto_down = 1;
43 module_param(auto_down, int, 0444);
44 MODULE_PARM_DESC(auto_down, "Automatically mark peers down on comms error");
47 lnet_peer_buffer_credits(struct lnet_net *net)
49 /* NI option overrides LNet default */
50 if (net->net_tunables.lct_peer_rtr_credits > 0)
51 return net->net_tunables.lct_peer_rtr_credits;
52 if (peer_buffer_credits > 0)
53 return peer_buffer_credits;
55 /* As an approximation, allow this peer the same number of router
56 * buffers as it is allowed outstanding sends */
57 return net->net_tunables.lct_peer_tx_credits;
60 static int check_routers_before_use;
61 module_param(check_routers_before_use, int, 0444);
62 MODULE_PARM_DESC(check_routers_before_use, "Assume routers are down and ping them before use");
64 int avoid_asym_router_failure = 1;
65 module_param(avoid_asym_router_failure, int, 0644);
66 MODULE_PARM_DESC(avoid_asym_router_failure, "Avoid asymmetrical router failures (0 to disable)");
68 int dead_router_check_interval = INT_MIN;
69 module_param(dead_router_check_interval, int, 0444);
70 MODULE_PARM_DESC(dead_router_check_interval, "(DEPRECATED - Use alive_router_check_interval)");
72 int live_router_check_interval = INT_MIN;
73 module_param(live_router_check_interval, int, 0444);
74 MODULE_PARM_DESC(live_router_check_interval, "(DEPRECATED - Use alive_router_check_interval)");
76 int alive_router_check_interval = 60;
77 module_param(alive_router_check_interval, int, 0644);
78 MODULE_PARM_DESC(alive_router_check_interval, "Seconds between live router health checks (<= 0 to disable)");
80 static int router_ping_timeout = 50;
81 module_param(router_ping_timeout, int, 0644);
82 MODULE_PARM_DESC(router_ping_timeout, "Seconds to wait for the reply to a router health query");
85 * A value between 0 and 100. 0 meaning that even if router's interfaces
86 * have the worse health still consider the gateway usable.
87 * 100 means that at least one interface on the route's remote net is 100%
88 * healthy to consider the route alive.
89 * The default is set to 100 to ensure we maintain the original behavior.
91 unsigned int router_sensitivity_percentage = 100;
92 static int rtr_sensitivity_set(const char *val, cfs_kernel_param_arg_t *kp);
93 static struct kernel_param_ops param_ops_rtr_sensitivity = {
94 .set = rtr_sensitivity_set,
97 #define param_check_rtr_sensitivity(name, p) \
98 __param_check(name, p, int)
99 #ifdef HAVE_KERNEL_PARAM_OPS
100 module_param(router_sensitivity_percentage, rtr_sensitivity, S_IRUGO|S_IWUSR);
102 module_param_call(router_sensitivity_percentage, rtr_sensitivity_set, param_get_int,
103 &router_sensitivity_percentage, S_IRUGO|S_IWUSR);
105 MODULE_PARM_DESC(router_sensitivity_percentage,
106 "How healthy a gateway should be to be used in percent");
108 static void lnet_add_route_to_rnet(struct lnet_remotenet *rnet,
109 struct lnet_route *route);
110 static void lnet_del_route_from_rnet(struct lnet_nid *gw_nid,
111 struct list_head *route_list,
112 struct list_head *zombies);
115 rtr_sensitivity_set(const char *val, cfs_kernel_param_arg_t *kp)
118 unsigned *sen = (unsigned *)kp->arg;
121 rc = kstrtoul(val, 0, &value);
123 CERROR("Invalid module parameter value for 'router_sensitivity_percentage'\n");
127 if (value < 0 || value > 100) {
128 CERROR("Invalid value: %lu for 'router_sensitivity_percentage'\n", value);
133 * The purpose of locking the api_mutex here is to ensure that
134 * the correct value ends up stored properly.
136 mutex_lock(&the_lnet.ln_api_mutex);
140 mutex_unlock(&the_lnet.ln_api_mutex);
146 lnet_move_route(struct lnet_route *route, struct lnet_peer *lp,
147 struct list_head *rt_list)
148 __must_hold(&the_lnet.ln_api_mutex)
150 struct lnet_remotenet *rnet;
151 struct list_head zombies;
154 INIT_LIST_HEAD(&zombies);
161 rnet = lnet_find_rnet_locked(route->lr_net);
164 CDEBUG(D_NET, "deleting route %s->%s\n",
165 libcfs_net2str(route->lr_net),
166 libcfs_nidstr(&route->lr_nid));
169 * use the gateway's lp_primary_nid to delete the route as the
170 * lr_nid can be a constituent NID of the peer
172 lnet_del_route_from_rnet(
173 &route->lr_gateway->lp_primary_nid,
174 &rnet->lrn_routes, l);
177 route = list_first_entry(l, struct lnet_route,
179 route->lr_gateway = lp;
180 lnet_add_route_to_rnet(rnet, route);
182 while (!list_empty(l) && !rt_list) {
183 route = list_first_entry(l, struct lnet_route,
185 list_del(&route->lr_list);
186 LIBCFS_FREE(route, sizeof(*route));
192 lnet_rtr_transfer_to_peer(struct lnet_peer *src, struct lnet_peer *target)
194 struct lnet_route *route;
195 struct lnet_route *tmp, *tmp2;
197 lnet_net_lock(LNET_LOCK_EX);
198 CDEBUG(D_NET, "transfering routes from %s -> %s\n",
199 libcfs_nidstr(&src->lp_primary_nid),
200 libcfs_nidstr(&target->lp_primary_nid));
201 list_for_each_entry(route, &src->lp_routes, lr_gwlist) {
202 CDEBUG(D_NET, "%s: %s->%s\n",
203 libcfs_nidstr(&src->lp_primary_nid),
204 libcfs_net2str(route->lr_net),
205 libcfs_nidstr(&route->lr_nid));
207 list_splice_init(&src->lp_rtrq, &target->lp_rtrq);
208 list_for_each_entry_safe(route, tmp, &src->lp_routes, lr_gwlist) {
209 struct lnet_route *r2;
210 bool present = false;
211 list_for_each_entry_safe(r2, tmp2, &target->lp_routes, lr_gwlist) {
212 if (route->lr_net == r2->lr_net) {
213 if (route->lr_priority >= r2->lr_priority)
215 else if (route->lr_hops >= r2->lr_hops)
218 lnet_move_route(r2, NULL, NULL);
222 lnet_move_route(route, NULL, NULL);
224 lnet_move_route(route, target, NULL);
227 if (list_empty(&target->lp_rtr_list)) {
228 lnet_peer_addref_locked(target);
229 list_add_tail(&target->lp_rtr_list, &the_lnet.ln_routers);
232 the_lnet.ln_routers_version++;
233 lnet_net_unlock(LNET_LOCK_EX);
237 lnet_peers_start_down(void)
239 return check_routers_before_use;
243 * The peer_net of a gateway is alive if at least one of the peer_ni's on
244 * that peer_net is alive.
247 lnet_is_gateway_net_alive(struct lnet_peer_net *lpn)
249 struct lnet_peer_ni *lpni;
251 list_for_each_entry(lpni, &lpn->lpn_peer_nis, lpni_peer_nis) {
252 if (lnet_is_peer_ni_alive(lpni))
260 * a gateway is alive only if all its nets are alive
261 * called with cpt lock held
263 bool lnet_is_gateway_alive(struct lnet_peer *gw)
265 struct lnet_peer_net *lpn;
270 list_for_each_entry(lpn, &gw->lp_peer_nets, lpn_peer_nets) {
271 if (!lnet_is_gateway_net_alive(lpn))
279 * lnet_is_route_alive() needs to be called with cpt lock held
280 * A route is alive if the gateway can route between the local network and
281 * the remote network of the route.
282 * This means at least one NI is alive on each of the local and remote
283 * networks of the gateway.
285 bool lnet_is_route_alive(struct lnet_route *route)
287 struct lnet_peer *gw = route->lr_gateway;
288 struct lnet_peer_net *llpn;
289 struct lnet_peer_net *rlpn;
291 /* If the gateway is down then all routes are considered down */
296 * if discovery is disabled then rely on the cached aliveness
297 * information. This is handicapped information which we log when
298 * we receive the discovery ping response. The most uptodate
299 * aliveness information can only be obtained when discovery is
302 if (lnet_is_discovery_disabled(gw))
303 return atomic_read(&route->lr_alive) == 1;
306 * check the gateway's interfaces on the local network
308 llpn = lnet_peer_get_net_locked(gw, route->lr_lnet);
312 if (!lnet_is_gateway_net_alive(llpn))
316 * For single hop routes avoid_asym_router_failure dictates
317 * that the remote net must exist on the gateway. For multi-hop
318 * routes the next-hop will not have the remote net.
320 if (avoid_asym_router_failure &&
321 (route->lr_hops == 1 || route->lr_single_hop)) {
322 rlpn = lnet_peer_get_net_locked(gw, route->lr_net);
325 if (!lnet_is_gateway_net_alive(rlpn))
329 spin_lock(&gw->lp_lock);
330 if (!(gw->lp_state & LNET_PEER_ROUTER_ENABLED)) {
331 spin_unlock(&gw->lp_lock);
332 if (gw->lp_rtr_refcount > 0)
333 CERROR("peer %s is being used as a gateway but routing feature is not turned on\n",
334 libcfs_nidstr(&gw->lp_primary_nid));
337 spin_unlock(&gw->lp_lock);
343 lnet_consolidate_routes_locked(struct lnet_peer *orig_lp,
344 struct lnet_peer *new_lp)
346 struct lnet_peer_ni *lpni;
347 struct lnet_route *route;
350 * Although a route is correlated with a peer, but when it's added
351 * a specific NID is used. That NID refers to a peer_ni within
352 * a peer. There could be other peer_nis on the same net, which
353 * can be used to send to that gateway. However when we are
354 * consolidating gateways because of discovery, the nid used to
355 * add the route might've moved between gateway peers. In this
356 * case we want to move the route to the new gateway as well. The
357 * intent here is not to confuse the user who added the route.
359 list_for_each_entry(route, &orig_lp->lp_routes, lr_gwlist) {
360 lpni = lnet_peer_ni_get_locked(orig_lp, &route->lr_nid);
362 lnet_net_lock(LNET_LOCK_EX);
363 list_move(&route->lr_gwlist, &new_lp->lp_routes);
364 lnet_net_unlock(LNET_LOCK_EX);
370 lnet_check_route_inconsistency(struct lnet_route *route)
372 if (!route->lr_single_hop && route->lr_hops == 1 &&
373 avoid_asym_router_failure) {
374 CWARN("route %s->%s is detected to be multi-hop but hop count is set to %d\n",
375 libcfs_net2str(route->lr_net),
376 libcfs_nidstr(&route->lr_gateway->lp_primary_nid),
377 (int) route->lr_hops);
381 /* Routes are added and removed under both ln_api_mutex and net_lock/EX
382 * Since we are not modifying anything we simply require the ln_api_mutex be
383 * held so that things are not modified underneath us
386 lnet_router_discovery_ping_reply(struct lnet_peer *lp,
387 struct lnet_ping_buffer *pbuf)
388 __must_hold(&the_lnet.ln_api_mutex)
390 struct lnet_ping_iter piter;
391 struct lnet_peer_net *llpn;
392 struct lnet_route *route;
394 bool single_hop = false;
398 if (pbuf->pb_info.pi_features & LNET_PING_FEAT_RTE_DISABLED) {
399 CERROR("Peer %s is being used as a gateway but routing feature is not turned on\n",
400 libcfs_nidstr(&lp->lp_primary_nid));
401 list_for_each_entry(route, &lp->lp_routes, lr_gwlist)
402 lnet_set_route_aliveness(route, false);
406 CDEBUG(D_NET, "Processing reply for gw: %s nnis %d\n",
407 libcfs_nidstr(&lp->lp_primary_nid), pbuf->pb_info.pi_nnis);
409 /* examine the ping response to determine if the routes on that
410 * gateway should be declared alive.
411 * The route is alive if:
412 * 1. local network to reach the route is alive and
413 * 2. route is single hop, avoid_async_router_failure is set and
414 * there exists at least one NI on the route's remote net
416 list_for_each_entry(route, &lp->lp_routes, lr_gwlist) {
417 llpn = lnet_peer_get_net_locked(lp, route->lr_lnet);
419 lnet_set_route_aliveness(route, false);
423 if (!lnet_is_gateway_net_alive(llpn)) {
424 lnet_set_route_aliveness(route, false);
428 single_hop = net_up = false;
429 for (stp = ping_iter_first(&piter, pbuf, &nid);
431 stp = ping_iter_next(&piter, &nid)) {
432 if (route->lr_net == LNET_NID_NET(&nid)) {
434 if (*stp == LNET_NI_STATUS_UP) {
441 route->lr_single_hop = single_hop;
442 if (avoid_asym_router_failure &&
443 (route->lr_hops == 1 || route->lr_single_hop))
444 lnet_set_route_aliveness(route, net_up);
446 lnet_set_route_aliveness(route, true);
449 * warn that the route is configured as single-hop but it
450 * really is multi-hop as far as we can tell.
452 lnet_check_route_inconsistency(route);
457 lnet_router_discovery_complete(struct lnet_peer *lp)
459 struct lnet_peer_ni *lpni = NULL;
460 struct lnet_route *route;
462 spin_lock(&lp->lp_lock);
463 lp->lp_state &= ~LNET_PEER_RTR_DISCOVERY;
464 lp->lp_state |= LNET_PEER_RTR_DISCOVERED;
465 lp->lp_alive = lp->lp_dc_error == 0;
466 spin_unlock(&lp->lp_lock);
468 if (!lp->lp_dc_error)
472 * We do not send messages directly to the remote interfaces
473 * of an LNet router. As such, we rely on the PING response
474 * to determine the up/down status of these interfaces. If
475 * a PING response is not receieved, or some other problem with
476 * discovery occurs that prevents us from getting this status,
477 * we assume all interfaces are down until we're able to
478 * determine otherwise.
480 CDEBUG(D_NET, "%s: Router discovery failed %d\n",
481 libcfs_nidstr(&lp->lp_primary_nid), lp->lp_dc_error);
482 while ((lpni = lnet_get_next_peer_ni_locked(lp, NULL, lpni)) != NULL)
483 lpni->lpni_ns_status = LNET_NI_STATUS_DOWN;
485 list_for_each_entry(route, &lp->lp_routes, lr_gwlist)
486 lnet_set_route_aliveness(route, false);
490 lnet_rtr_addref_locked(struct lnet_peer *lp)
492 LASSERT(lp->lp_rtr_refcount >= 0);
494 /* lnet_net_lock must be exclusively locked */
495 lp->lp_rtr_refcount++;
496 if (lp->lp_rtr_refcount == 1) {
497 list_add_tail(&lp->lp_rtr_list, &the_lnet.ln_routers);
498 /* addref for the_lnet.ln_routers */
499 lnet_peer_addref_locked(lp);
500 the_lnet.ln_routers_version++;
505 lnet_rtr_decref_locked(struct lnet_peer *lp)
507 LASSERT(atomic_read(&lp->lp_refcount) > 0);
508 LASSERT(lp->lp_rtr_refcount > 0);
510 /* lnet_net_lock must be exclusively locked */
511 lp->lp_rtr_refcount--;
512 if (lp->lp_rtr_refcount == 0) {
513 LASSERT(list_empty(&lp->lp_routes));
515 list_del(&lp->lp_rtr_list);
516 /* decref for the_lnet.ln_routers */
517 lnet_peer_decref_locked(lp);
518 the_lnet.ln_routers_version++;
522 struct lnet_remotenet *
523 lnet_find_rnet_locked(__u32 net)
525 struct lnet_remotenet *rnet;
526 struct list_head *rn_list;
528 LASSERT(the_lnet.ln_state == LNET_STATE_RUNNING);
530 rn_list = lnet_net2rnethash(net);
531 list_for_each_entry(rnet, rn_list, lrn_list) {
532 if (rnet->lrn_net == net)
538 static void lnet_shuffle_seed(void)
541 struct lnet_ni *ni = NULL;
546 /* Nodes with small feet have little entropy
547 * the NID for this node gives the most entropy in the low bits */
548 while ((ni = lnet_get_next_ni_locked(NULL, ni)))
549 add_device_randomness(&ni->ni_nid, sizeof(ni->ni_nid));
554 /* NB expects LNET_LOCK held */
556 lnet_add_route_to_rnet(struct lnet_remotenet *rnet, struct lnet_route *route)
558 struct lnet_peer_net *lpn;
559 unsigned int offset = 0;
560 unsigned int len = 0;
566 list_for_each(e, &rnet->lrn_routes)
570 * Randomly adding routes to the list is done to ensure that when
571 * different nodes are using the same list of routers, they end up
572 * preferring different routers.
574 offset = get_random_u32_below(len + 1);
575 list_for_each(e, &rnet->lrn_routes) {
580 list_add(&route->lr_list, e);
582 * force a router check on the gateway to make sure the route is
585 now = ktime_get_real_seconds();
586 list_for_each_entry(lpn, &route->lr_gateway->lp_peer_nets,
588 lpn->lpn_next_ping = now;
591 the_lnet.ln_remote_nets_version++;
593 /* add the route on the gateway list */
594 list_add(&route->lr_gwlist, &route->lr_gateway->lp_routes);
596 /* take a router reference count on the gateway */
597 lnet_rtr_addref_locked(route->lr_gateway);
601 lnet_add_route(__u32 net, __u32 hops, struct lnet_nid *gateway,
602 __u32 priority, __u32 sensitivity)
603 __must_hold(&the_lnet.ln_api_mutex)
605 struct list_head *route_entry;
606 struct lnet_remotenet *rnet;
607 struct lnet_remotenet *rnet2;
608 struct lnet_route *route;
609 struct lnet_peer_ni *lpni;
610 struct lnet_peer *gw;
614 CDEBUG(D_NET, "Add route: remote net %s hops %d priority %u gw %s\n",
615 libcfs_net2str(net), hops, priority, libcfs_nidstr(gateway));
617 if (LNET_NID_IS_ANY(gateway) ||
618 nid_is_lo0(gateway) ||
619 net == LNET_NET_ANY ||
620 LNET_NETTYP(net) == LOLND ||
621 LNET_NID_NET(gateway) == net ||
622 (hops != LNET_UNDEFINED_HOPS && (hops < 1 || hops > 255)))
625 /* it's a local network */
626 if (lnet_islocalnet(net))
629 if (!lnet_islocalnet(LNET_NID_NET(gateway))) {
630 CERROR("Cannot add route with gateway %s. There is no local interface configured on LNet %s\n",
631 libcfs_nidstr(gateway),
632 libcfs_net2str(LNET_NID_NET(gateway)));
633 return -EHOSTUNREACH;
636 /* Assume net, route, all new */
637 LIBCFS_ALLOC(route, sizeof(*route));
638 LIBCFS_ALLOC(rnet, sizeof(*rnet));
639 if (route == NULL || rnet == NULL) {
640 CERROR("Out of memory creating route %s %d %s\n",
641 libcfs_net2str(net), hops, libcfs_nidstr(gateway));
643 LIBCFS_FREE(route, sizeof(*route));
645 LIBCFS_FREE(rnet, sizeof(*rnet));
649 INIT_LIST_HEAD(&rnet->lrn_routes);
651 /* store the local and remote net that the route represents */
652 route->lr_lnet = LNET_NID_NET(gateway);
654 route->lr_nid = *gateway;
655 route->lr_priority = priority;
656 route->lr_hops = hops;
657 if (lnet_peers_start_down())
658 atomic_set(&route->lr_alive, 0);
660 atomic_set(&route->lr_alive, 1);
662 lnet_net_lock(LNET_LOCK_EX);
665 * lnet_nid2peerni_ex() grabs a ref on the lpni. We will need to
666 * lose that once we're done
668 lpni = lnet_nid2peerni_ex(gateway);
670 lnet_net_unlock(LNET_LOCK_EX);
672 LIBCFS_FREE(route, sizeof(*route));
673 LIBCFS_FREE(rnet, sizeof(*rnet));
676 CERROR("Error %d creating route %s %d %s\n", rc,
677 libcfs_net2str(net), hops,
678 libcfs_nidstr(gateway));
683 LASSERT(lpni->lpni_peer_net);
684 LASSERT(lpni->lpni_peer_net->lpn_peer);
685 gw = lpni->lpni_peer_net->lpn_peer;
687 route->lr_gateway = gw;
689 rnet2 = lnet_find_rnet_locked(net);
692 list_add_tail(&rnet->lrn_list, lnet_net2rnethash(net));
696 /* Search for a duplicate route (it's a NOOP if it is) */
698 list_for_each(route_entry, &rnet2->lrn_routes) {
699 struct lnet_route *route2;
701 route2 = list_entry(route_entry, struct lnet_route, lr_list);
702 if (route2->lr_gateway == route->lr_gateway) {
707 /* our lookups must be true */
708 LASSERT(!nid_same(&route2->lr_gateway->lp_primary_nid,
713 * It is possible to add multiple routes through the same peer,
714 * but it'll be using a different NID of that peer. When the
715 * gateway is discovered, discovery will consolidate the different
716 * peers into one peer. In this case the discovery code will have
717 * to move the routes from the peer that's being deleted to the
718 * consolidated peer lp_routes list
721 gw->lp_health_sensitivity = sensitivity;
722 lnet_add_route_to_rnet(rnet2, route);
723 if (lnet_peer_discovery_disabled)
724 CWARN("Consider turning discovery on to enable full Multi-Rail routing functionality\n");
728 * get rid of the reference on the lpni.
730 lnet_peer_ni_decref_locked(lpni);
731 lnet_net_unlock(LNET_LOCK_EX);
733 /* If avoid_asym_router_failure is enabled and hop count is not
734 * set to 1 for a route that is actually single-hop, then the
735 * feature will fail to prevent the router from being selected
736 * if it is missing a NI on the remote network due to misconfiguration.
738 if (avoid_asym_router_failure && hops == LNET_UNDEFINED_HOPS)
739 CWARN("Use hops = 1 for a single-hop route when avoid_asym_router_failure feature is enabled\n");
745 LIBCFS_FREE(route, sizeof(*route));
749 LIBCFS_FREE(rnet, sizeof(*rnet));
751 /* kick start the monitor thread to handle the added route */
752 complete(&the_lnet.ln_mt_wait_complete);
758 lnet_del_route_from_rnet(struct lnet_nid *gw_nid,
759 struct list_head *route_list,
760 struct list_head *zombies)
762 struct lnet_peer *gateway;
763 struct lnet_route *route;
764 struct lnet_route *tmp;
766 list_for_each_entry_safe(route, tmp, route_list, lr_list) {
767 gateway = route->lr_gateway;
768 if (gw_nid && !nid_same(gw_nid, &gateway->lp_primary_nid))
772 * move to zombie to delete outside the lock
773 * Note that this function is called with the
774 * ln_api_mutex held as well as the exclusive net
775 * lock. Adding to the remote net list happens
776 * under the same conditions. Same goes for the
777 * gateway router list
779 list_move(&route->lr_list, zombies);
780 the_lnet.ln_remote_nets_version++;
782 list_del(&route->lr_gwlist);
783 lnet_rtr_decref_locked(gateway);
788 lnet_del_route(__u32 net, struct lnet_nid *gw)
789 __must_hold(&the_lnet.ln_api_mutex)
791 LIST_HEAD(rnet_zombies);
792 struct lnet_remotenet *rnet;
793 struct lnet_remotenet *tmp;
794 struct list_head *rn_list;
795 struct lnet_peer_ni *lpni;
796 struct lnet_route *route;
797 struct lnet_nid gw_nid;
799 struct lnet_peer *lp = NULL;
802 CDEBUG(D_NET, "Del route: net %s : gw %s\n",
803 libcfs_net2str(net), libcfs_nidstr(gw));
805 /* NB Caller may specify either all routes via the given gateway
806 * or a specific route entry actual NIDs) */
808 lnet_net_lock(LNET_LOCK_EX);
811 lpni = lnet_peer_ni_find_locked(gw);
815 lp = lpni->lpni_peer_net->lpn_peer;
817 gw_nid = lp->lp_primary_nid;
821 if (net != LNET_NET_ANY) {
822 rnet = lnet_find_rnet_locked(net);
825 lnet_peer_ni_decref_locked(lpni);
826 lnet_net_unlock(LNET_LOCK_EX);
829 lnet_del_route_from_rnet(gw, &rnet->lrn_routes,
831 if (list_empty(&rnet->lrn_routes))
832 list_move(&rnet->lrn_list, &rnet_zombies);
836 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) {
837 rn_list = &the_lnet.ln_remote_nets_hash[i];
839 list_for_each_entry_safe(rnet, tmp, rn_list, lrn_list) {
840 lnet_del_route_from_rnet(gw, &rnet->lrn_routes,
842 if (list_empty(&rnet->lrn_routes))
843 list_move(&rnet->lrn_list, &rnet_zombies);
849 * check if there are any routes remaining on the gateway
850 * If there are no more routes make sure to set the peer's
851 * lp_disc_net_id to 0 (invalid), in case we add more routes in
852 * the future on that gateway, then we start our discovery process
856 if (list_empty(&lp->lp_routes))
857 lp->lp_disc_net_id = 0;
858 lnet_peer_ni_decref_locked(lpni);
861 lnet_net_unlock(LNET_LOCK_EX);
863 while (!list_empty(&zombies)) {
864 route = list_first_entry(&zombies, struct lnet_route, lr_list);
865 list_del(&route->lr_list);
866 LIBCFS_FREE(route, sizeof(*route));
869 while (!list_empty(&rnet_zombies)) {
870 rnet = list_first_entry(&rnet_zombies, struct lnet_remotenet,
872 list_del(&rnet->lrn_list);
873 LIBCFS_FREE(rnet, sizeof(*rnet));
880 lnet_destroy_routes(void)
882 lnet_del_route(LNET_NET_ANY, NULL);
885 int lnet_get_rtr_pool_cfg(int cpt, struct lnet_ioctl_pool_cfg *pool_cfg)
887 struct lnet_rtrbufpool *rbp;
888 int i, rc = -ENOENT, j;
890 if (the_lnet.ln_rtrpools == NULL)
894 cfs_percpt_for_each(rbp, i, the_lnet.ln_rtrpools) {
899 for (j = 0; j < LNET_NRBPOOLS; j++) {
900 pool_cfg->pl_pools[j].pl_npages = rbp[j].rbp_npages;
901 pool_cfg->pl_pools[j].pl_nbuffers = rbp[j].rbp_nbuffers;
902 pool_cfg->pl_pools[j].pl_credits = rbp[j].rbp_credits;
903 pool_cfg->pl_pools[j].pl_mincredits = rbp[j].rbp_mincredits;
910 lnet_net_lock(LNET_LOCK_EX);
911 pool_cfg->pl_routing = the_lnet.ln_routing;
912 lnet_net_unlock(LNET_LOCK_EX);
918 lnet_get_route(int idx, __u32 *net, __u32 *hops, lnet_nid_t *gateway,
919 __u32 *flags, __u32 *priority, __u32 *sensitivity)
921 struct lnet_remotenet *rnet;
922 struct list_head *rn_list;
923 struct lnet_route *route;
927 cpt = lnet_net_lock_current();
929 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) {
930 rn_list = &the_lnet.ln_remote_nets_hash[i];
931 list_for_each_entry(rnet, rn_list, lrn_list) {
932 list_for_each_entry(route, &rnet->lrn_routes, lr_list) {
934 *net = rnet->lrn_net;
935 *gateway = lnet_nid_to_nid4(&route->lr_nid);
936 *hops = route->lr_hops;
937 *priority = route->lr_priority;
938 *sensitivity = route->lr_gateway->
939 lp_health_sensitivity;
940 if (lnet_is_route_alive(route))
941 *flags |= LNET_RT_ALIVE;
943 *flags &= ~LNET_RT_ALIVE;
944 if (route->lr_single_hop)
945 *flags &= ~LNET_RT_MULTI_HOP;
947 *flags |= LNET_RT_MULTI_HOP;
948 lnet_net_unlock(cpt);
955 lnet_net_unlock(cpt);
960 lnet_wait_known_routerstate(void)
962 struct lnet_peer *rtr;
965 LASSERT(the_lnet.ln_mt_state == LNET_MT_STATE_RUNNING);
968 int cpt = lnet_net_lock_current();
971 list_for_each_entry(rtr, &the_lnet.ln_routers, lp_rtr_list) {
972 spin_lock(&rtr->lp_lock);
974 if ((rtr->lp_state & LNET_PEER_RTR_DISCOVERED) == 0) {
976 spin_unlock(&rtr->lp_lock);
979 spin_unlock(&rtr->lp_lock);
982 lnet_net_unlock(cpt);
987 schedule_timeout_uninterruptible(cfs_time_seconds(1));
992 lnet_net_set_status_locked(struct lnet_net *net, __u32 status)
997 list_for_each_entry(ni, &net->net_ni_list, ni_netlist)
998 if (lnet_ni_set_status(ni, status))
1005 lnet_update_ni_status_locked(void)
1007 struct lnet_net *net;
1013 LASSERT(the_lnet.ln_routing);
1015 timeout = router_ping_timeout + alive_router_check_interval;
1017 now = ktime_get_seconds();
1018 list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
1019 if (net->net_lnd->lnd_type == LOLND)
1022 if (now < net->net_last_alive + timeout)
1023 goto check_ni_fatal;
1025 spin_lock(&net->net_lock);
1026 /* re-check with lock */
1027 if (now < net->net_last_alive + timeout) {
1028 spin_unlock(&net->net_lock);
1029 goto check_ni_fatal;
1031 spin_unlock(&net->net_lock);
1034 * if the net didn't receive any traffic for past the
1035 * timeout on any of its constituent NIs, then mark all
1038 if (lnet_net_set_status_locked(net, LNET_NI_STATUS_DOWN)) {
1044 list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
1045 /* lnet_ni_set_status() will perform the same check of
1046 * ni_status while holding the ni lock. We can safely
1047 * check ni_status without that lock because it is only
1048 * written to under net_lock/EX and our caller is
1049 * holding a net lock.
1051 if (atomic_read(&ni->ni_fatal_error_on) &&
1053 *ni->ni_status != LNET_NI_STATUS_DOWN &&
1054 lnet_ni_set_status(ni, LNET_NI_STATUS_DOWN))
1062 void lnet_wait_router_start(void)
1064 if (check_routers_before_use) {
1065 /* Note that a helpful side-effect of pinging all known routers
1066 * at startup is that it makes them drop stale connections they
1067 * may have to a previous instance of me. */
1068 lnet_wait_known_routerstate();
1073 * This function is called from the monitor thread to check if there are
1074 * any active routers that need to be checked.
1076 bool lnet_router_checker_active(void)
1078 /* Router Checker thread needs to run when routing is enabled in
1079 * order to call lnet_update_ni_status_locked() */
1080 if (the_lnet.ln_routing)
1083 return !list_empty(&the_lnet.ln_routers) &&
1084 alive_router_check_interval > 0;
1088 lnet_check_routers(void)
1090 struct lnet_peer_net *first_lpn;
1091 struct lnet_peer_net *lpn;
1092 struct lnet_peer_ni *lpni;
1093 struct lnet_peer *rtr;
1103 cpt = lnet_net_lock_current();
1105 version = the_lnet.ln_routers_version;
1107 list_for_each_entry(rtr, &the_lnet.ln_routers, lp_rtr_list) {
1108 /* If we're currently discovering the peer then don't
1109 * issue another discovery
1111 if (rtr->lp_state & LNET_PEER_RTR_DISCOVERY)
1114 now = ktime_get_real_seconds();
1116 /* find the next local peer net which needs to be ping'd */
1120 net_id = rtr->lp_disc_net_id;
1122 lpn = lnet_get_next_peer_net_locked(rtr, net_id);
1124 CERROR("gateway %s has no networks\n",
1125 libcfs_nidstr(&rtr->lp_primary_nid));
1129 /* We looped back to the first peer net */
1130 if (first_lpn == lpn)
1135 net_id = lpn->lpn_net_id;
1136 if (!lnet_islocalnet_locked(net_id))
1141 CDEBUG(D_NET, "rtr %s(%p) %s(%p) next ping %lld\n",
1142 libcfs_nidstr(&rtr->lp_primary_nid), rtr,
1143 libcfs_net2str(net_id), lpn,
1144 lpn->lpn_next_ping);
1146 needs_ping = now >= lpn->lpn_next_ping;
1148 } while (!needs_ping);
1150 if (!found_lpn || !lpn) {
1151 CERROR("no local network found for gateway %s\n",
1152 libcfs_nidstr(&rtr->lp_primary_nid));
1159 spin_lock(&rtr->lp_lock);
1160 /* make sure we fully discover the router */
1161 rtr->lp_state &= ~LNET_PEER_NIDS_UPTODATE;
1162 rtr->lp_state |= LNET_PEER_FORCE_PING | LNET_PEER_FORCE_PUSH |
1163 LNET_PEER_RTR_DISCOVERY;
1164 spin_unlock(&rtr->lp_lock);
1166 /* find the peer_ni associated with the primary NID */
1167 lpni = lnet_peer_ni_get_locked(rtr, &rtr->lp_primary_nid);
1169 CDEBUG(D_NET, "Expected to find an lpni for %s, but non found\n",
1170 libcfs_nidstr(&rtr->lp_primary_nid));
1173 lnet_peer_ni_addref_locked(lpni);
1175 /* specify the net to use */
1176 rtr->lp_disc_net_id = lpn->lpn_net_id;
1178 /* discover the router */
1179 CDEBUG(D_NET, "discover %s, cpt = %d\n",
1180 libcfs_nidstr(&lpni->lpni_nid), cpt);
1181 rc = lnet_discover_peer_locked(lpni, cpt, false);
1183 /* drop ref taken above */
1184 lnet_peer_ni_decref_locked(lpni);
1187 lpn->lpn_next_ping = now + alive_router_check_interval;
1189 CERROR("Failed to discover router %s\n",
1190 libcfs_nidstr(&rtr->lp_primary_nid));
1192 /* NB cpt lock was dropped in lnet_discover_peer_locked() */
1193 if (version != the_lnet.ln_routers_version) {
1194 /* the routers list has changed */
1199 if (the_lnet.ln_routing)
1200 push = lnet_update_ni_status_locked();
1202 lnet_net_unlock(cpt);
1204 /* if the status of the ni changed update the peers */
1206 lnet_push_update_to_peers(1);
1210 lnet_destroy_rtrbuf(struct lnet_rtrbuf *rb, int npages)
1212 int sz = offsetof(struct lnet_rtrbuf, rb_kiov[npages]);
1214 while (--npages >= 0)
1215 __free_page(rb->rb_kiov[npages].bv_page);
1217 LIBCFS_FREE(rb, sz);
1220 static struct lnet_rtrbuf *
1221 lnet_new_rtrbuf(struct lnet_rtrbufpool *rbp, int cpt)
1223 int npages = rbp->rbp_npages;
1224 int sz = offsetof(struct lnet_rtrbuf, rb_kiov[npages]);
1226 struct lnet_rtrbuf *rb;
1229 LIBCFS_CPT_ALLOC(rb, lnet_cpt_table(), cpt, sz);
1235 for (i = 0; i < npages; i++) {
1236 page = cfs_page_cpt_alloc(lnet_cpt_table(), cpt, GFP_KERNEL |
1237 __GFP_ZERO | __GFP_NORETRY);
1240 __free_page(rb->rb_kiov[i].bv_page);
1242 LIBCFS_FREE(rb, sz);
1246 rb->rb_kiov[i].bv_len = PAGE_SIZE;
1247 rb->rb_kiov[i].bv_offset = 0;
1248 rb->rb_kiov[i].bv_page = page;
1255 lnet_rtrpool_free_bufs(struct lnet_rtrbufpool *rbp, int cpt)
1257 int npages = rbp->rbp_npages;
1258 struct lnet_rtrbuf *rb;
1261 if (rbp->rbp_nbuffers == 0) /* not initialized or already freed */
1265 list_splice_init(&rbp->rbp_msgs, &tmp);
1266 lnet_drop_routed_msgs_locked(&tmp, cpt);
1267 list_splice_init(&rbp->rbp_bufs, &tmp);
1268 rbp->rbp_req_nbuffers = 0;
1269 rbp->rbp_nbuffers = rbp->rbp_credits = 0;
1270 rbp->rbp_mincredits = 0;
1271 lnet_net_unlock(cpt);
1273 /* Free buffers on the free list. */
1274 while (!list_empty(&tmp)) {
1275 rb = list_first_entry(&tmp, struct lnet_rtrbuf, rb_list);
1276 list_del(&rb->rb_list);
1277 lnet_destroy_rtrbuf(rb, npages);
1282 lnet_rtrpool_adjust_bufs(struct lnet_rtrbufpool *rbp, int nbufs, int cpt)
1285 struct lnet_rtrbuf *rb;
1287 int num_buffers = 0;
1289 int npages = rbp->rbp_npages;
1292 /* If we are called for less buffers than already in the pool, we
1293 * just lower the req_nbuffers number and excess buffers will be
1294 * thrown away as they are returned to the free list. Credits
1295 * then get adjusted as well.
1296 * If we already have enough buffers allocated to serve the
1297 * increase requested, then we can treat that the same way as we
1298 * do the decrease. */
1299 num_rb = nbufs - rbp->rbp_nbuffers;
1300 if (nbufs <= rbp->rbp_req_nbuffers || num_rb <= 0) {
1301 rbp->rbp_req_nbuffers = nbufs;
1302 lnet_net_unlock(cpt);
1305 /* store the older value of rbp_req_nbuffers and then set it to
1306 * the new request to prevent lnet_return_rx_credits_locked() from
1307 * freeing buffers that we need to keep around */
1308 old_req_nbufs = rbp->rbp_req_nbuffers;
1309 rbp->rbp_req_nbuffers = nbufs;
1310 lnet_net_unlock(cpt);
1312 /* allocate the buffers on a local list first. If all buffers are
1313 * allocated successfully then join this list to the rbp buffer
1314 * list. If not then free all allocated buffers. */
1315 while (num_rb-- > 0) {
1316 rb = lnet_new_rtrbuf(rbp, cpt);
1318 CERROR("lnet: error allocating %ux%u page router buffers on CPT %u: rc = %d\n",
1319 nbufs, npages, cpt, -ENOMEM);
1322 rbp->rbp_req_nbuffers = old_req_nbufs;
1323 lnet_net_unlock(cpt);
1328 list_add(&rb->rb_list, &rb_list);
1334 list_splice_tail(&rb_list, &rbp->rbp_bufs);
1335 rbp->rbp_nbuffers += num_buffers;
1336 rbp->rbp_credits += num_buffers;
1337 rbp->rbp_mincredits = rbp->rbp_credits;
1338 /* We need to schedule blocked msg using the newly
1340 while (!list_empty(&rbp->rbp_bufs) &&
1341 !list_empty(&rbp->rbp_msgs))
1342 lnet_schedule_blocked_locked(rbp);
1344 lnet_net_unlock(cpt);
1349 while ((rb = list_first_entry_or_null(&rb_list,
1351 rb_list)) != NULL) {
1352 list_del(&rb->rb_list);
1353 lnet_destroy_rtrbuf(rb, npages);
1360 lnet_rtrpool_init(struct lnet_rtrbufpool *rbp, int npages)
1362 INIT_LIST_HEAD(&rbp->rbp_msgs);
1363 INIT_LIST_HEAD(&rbp->rbp_bufs);
1365 rbp->rbp_npages = npages;
1366 rbp->rbp_credits = 0;
1367 rbp->rbp_mincredits = 0;
1371 lnet_rtrpools_free(int keep_pools)
1373 struct lnet_rtrbufpool *rtrp;
1376 if (the_lnet.ln_rtrpools == NULL) /* uninitialized or freed */
1379 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1380 lnet_rtrpool_free_bufs(&rtrp[LNET_TINY_BUF_IDX], i);
1381 lnet_rtrpool_free_bufs(&rtrp[LNET_SMALL_BUF_IDX], i);
1382 lnet_rtrpool_free_bufs(&rtrp[LNET_LARGE_BUF_IDX], i);
1386 cfs_percpt_free(the_lnet.ln_rtrpools);
1387 the_lnet.ln_rtrpools = NULL;
1392 lnet_nrb_tiny_calculate(void)
1394 int nrbs = LNET_NRB_TINY;
1396 if (tiny_router_buffers < 0) {
1397 LCONSOLE_ERROR_MSG(0x10c,
1398 "tiny_router_buffers=%d invalid when "
1399 "routing enabled\n", tiny_router_buffers);
1403 if (tiny_router_buffers > 0) {
1404 if (tiny_router_buffers < LNET_NRB_TINY_MIN)
1405 CWARN("tiny_router_buffers=%d less than recommended minimum %d\n",
1406 tiny_router_buffers, LNET_NRB_TINY_MIN);
1407 nrbs = tiny_router_buffers;
1410 nrbs /= LNET_CPT_NUMBER;
1411 return max(nrbs, 1);
1415 lnet_nrb_small_calculate(void)
1417 int nrbs = LNET_NRB_SMALL;
1419 if (small_router_buffers < 0) {
1420 LCONSOLE_ERROR_MSG(0x10c,
1421 "small_router_buffers=%d invalid when "
1422 "routing enabled\n", small_router_buffers);
1426 if (small_router_buffers > 0) {
1427 if (small_router_buffers < LNET_NRB_SMALL_MIN)
1428 CWARN("small_router_buffers=%d less than recommended minimum %d\n",
1429 small_router_buffers, LNET_NRB_SMALL_MIN);
1430 nrbs = small_router_buffers;
1433 nrbs /= LNET_CPT_NUMBER;
1434 return max(nrbs, 1);
1438 lnet_nrb_large_calculate(void)
1440 int nrbs = LNET_NRB_LARGE;
1442 if (large_router_buffers < 0) {
1443 LCONSOLE_ERROR_MSG(0x10c,
1444 "large_router_buffers=%d invalid when "
1445 "routing enabled\n", large_router_buffers);
1449 if (large_router_buffers > 0) {
1450 if (large_router_buffers < LNET_NRB_LARGE_MIN)
1451 CWARN("large_router_buffers=%d less than recommended minimum %d\n",
1452 large_router_buffers, LNET_NRB_LARGE_MIN);
1453 nrbs = large_router_buffers;
1456 nrbs /= LNET_CPT_NUMBER;
1457 return max(nrbs, 1);
1461 lnet_rtrpools_alloc(int im_a_router)
1463 struct lnet_rtrbufpool *rtrp;
1470 if (!strcmp(forwarding, "")) {
1471 /* not set either way */
1474 } else if (!strcmp(forwarding, "disabled")) {
1475 /* explicitly disabled */
1477 } else if (!strcmp(forwarding, "enabled")) {
1478 /* explicitly enabled */
1481 LCONSOLE_ERROR_MSG(0x10b,
1482 "lnet: forwarding='%s' not set to either 'enabled' or 'disabled': rc = %d\n",
1487 nrb_tiny = lnet_nrb_tiny_calculate();
1491 nrb_small = lnet_nrb_small_calculate();
1495 nrb_large = lnet_nrb_large_calculate();
1499 the_lnet.ln_rtrpools = cfs_percpt_alloc(lnet_cpt_table(),
1501 sizeof(struct lnet_rtrbufpool));
1502 if (the_lnet.ln_rtrpools == NULL) {
1504 LCONSOLE_ERROR_MSG(0x10c,
1505 "lnet: error allocating router buffer pool: rc = %d\n",
1510 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1511 lnet_rtrpool_init(&rtrp[LNET_TINY_BUF_IDX], 0);
1512 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_TINY_BUF_IDX],
1517 lnet_rtrpool_init(&rtrp[LNET_SMALL_BUF_IDX],
1518 LNET_NRB_SMALL_PAGES);
1519 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_SMALL_BUF_IDX],
1524 lnet_rtrpool_init(&rtrp[LNET_LARGE_BUF_IDX],
1525 LNET_NRB_LARGE_PAGES);
1526 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_LARGE_BUF_IDX],
1532 lnet_net_lock(LNET_LOCK_EX);
1533 the_lnet.ln_routing = 1;
1534 lnet_net_unlock(LNET_LOCK_EX);
1535 complete(&the_lnet.ln_mt_wait_complete);
1539 lnet_rtrpools_free(0);
1544 lnet_rtrpools_adjust_helper(int tiny, int small, int large)
1549 struct lnet_rtrbufpool *rtrp;
1551 /* If the provided values for each buffer pool are different than the
1552 * configured values, we need to take action. */
1554 tiny_router_buffers = tiny;
1555 nrb = lnet_nrb_tiny_calculate();
1556 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1557 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_TINY_BUF_IDX],
1564 small_router_buffers = small;
1565 nrb = lnet_nrb_small_calculate();
1566 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1567 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_SMALL_BUF_IDX],
1574 large_router_buffers = large;
1575 nrb = lnet_nrb_large_calculate();
1576 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1577 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_LARGE_BUF_IDX],
1588 lnet_rtrpools_adjust(int tiny, int small, int large)
1590 /* this function doesn't revert the changes if adding new buffers
1591 * failed. It's up to the user space caller to revert the
1594 if (!the_lnet.ln_routing)
1597 return lnet_rtrpools_adjust_helper(tiny, small, large);
1601 lnet_rtrpools_enable(void)
1605 if (the_lnet.ln_routing)
1608 if (the_lnet.ln_rtrpools == NULL)
1609 /* If routing is turned off, and we have never
1610 * initialized the pools before, just call the
1611 * standard buffer pool allocation routine as
1612 * if we are just configuring this for the first
1614 rc = lnet_rtrpools_alloc(1);
1616 rc = lnet_rtrpools_adjust_helper(0, 0, 0);
1620 lnet_net_lock(LNET_LOCK_EX);
1621 the_lnet.ln_routing = 1;
1623 the_lnet.ln_ping_target->pb_info.pi_features &=
1624 ~LNET_PING_FEAT_RTE_DISABLED;
1625 lnet_net_unlock(LNET_LOCK_EX);
1627 if (lnet_peer_discovery_disabled)
1628 CWARN("Consider turning discovery on to enable full "
1629 "Multi-Rail routing functionality\n");
1635 lnet_rtrpools_disable(void)
1637 if (!the_lnet.ln_routing)
1640 lnet_net_lock(LNET_LOCK_EX);
1641 the_lnet.ln_routing = 0;
1642 the_lnet.ln_ping_target->pb_info.pi_features |=
1643 LNET_PING_FEAT_RTE_DISABLED;
1645 tiny_router_buffers = 0;
1646 small_router_buffers = 0;
1647 large_router_buffers = 0;
1648 lnet_net_unlock(LNET_LOCK_EX);
1649 lnet_rtrpools_free(1);
1653 lnet_notify_peer_down(struct lnet_ni *ni, struct lnet_nid *nid)
1655 if (ni->ni_net->net_lnd->lnd_notify_peer_down != NULL)
1656 (ni->ni_net->net_lnd->lnd_notify_peer_down)(nid);
1660 * ni: local NI used to communicate with the peer
1662 * alive: true if peer is alive, false otherwise
1663 * reset: reset health value. This is requested by the LND.
1664 * when: notificaiton time.
1667 lnet_notify(struct lnet_ni *ni, struct lnet_nid *nid, bool alive, bool reset,
1670 struct lnet_peer_ni *lpni = NULL;
1671 struct lnet_route *route;
1672 struct lnet_peer *lp;
1673 time64_t now = ktime_get_seconds();
1676 LASSERT(!in_interrupt());
1678 CDEBUG(D_NET, "%s notifying %s: %s\n",
1679 (ni == NULL) ? "userspace" : libcfs_nidstr(&ni->ni_nid),
1680 libcfs_nidstr(nid), alive ? "up" : "down");
1683 LNET_NID_NET(&ni->ni_nid) != LNET_NID_NET(nid)) {
1684 CWARN("Ignoring notification of %s %s by %s (different net)\n",
1685 libcfs_nidstr(nid), alive ? "birth" : "death",
1686 libcfs_nidstr(&ni->ni_nid));
1690 /* can't do predictions... */
1692 CWARN("Ignoring prediction from %s of %s %s %lld seconds in the future\n",
1693 ni ? libcfs_nidstr(&ni->ni_nid) : "userspace",
1694 libcfs_nidstr(nid), alive ? "up" : "down", when - now);
1698 if (ni != NULL && !alive && /* LND telling me she's down */
1699 !auto_down) { /* auto-down disabled */
1700 CDEBUG(D_NET, "Auto-down disabled\n");
1704 /* must lock 0 since this is used for synchronization */
1707 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
1712 lpni = lnet_peer_ni_find_locked(nid);
1716 CDEBUG(D_NET, "%s not found\n", libcfs_nidstr(nid));
1722 lpni->lpni_ns_status = LNET_NI_STATUS_UP;
1723 lnet_set_lpni_healthv_locked(lpni,
1724 LNET_MAX_HEALTH_VALUE);
1726 lnet_inc_lpni_healthv_locked(lpni);
1729 lpni->lpni_ns_status = LNET_NI_STATUS_DOWN;
1732 /* recalculate aliveness */
1733 alive = lnet_is_peer_ni_alive(lpni);
1735 lp = lpni->lpni_peer_net->lpn_peer;
1736 /* If this is an LNet router then update route aliveness */
1737 if (lp->lp_rtr_refcount) {
1739 /* reset flag indicates gateway peer went up or down */
1740 lp->lp_alive = alive;
1742 /* If discovery is disabled, locally or on the gateway, then
1743 * any routes using lpni as next-hop need to be updated
1745 * NB: We can get many notifications while a route is down, so
1746 * we try and avoid the expensive net_lock/EX here for the
1747 * common case of receiving duplicate lnet_notify() calls (i.e.
1748 * only grab EX lock when we actually need to update the route
1751 if (lnet_is_discovery_disabled(lp)) {
1752 list_for_each_entry(route, &lp->lp_routes, lr_gwlist) {
1753 if (nid_same(&route->lr_nid, &lpni->lpni_nid))
1754 lnet_set_route_aliveness(route, alive);
1761 if (ni != NULL && !alive)
1762 lnet_notify_peer_down(ni, &lpni->lpni_nid);
1764 cpt = lpni->lpni_cpt;
1766 lnet_peer_ni_decref_locked(lpni);
1767 lnet_net_unlock(cpt);
1771 EXPORT_SYMBOL(lnet_notify);