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
24 #include <lnet/lib-lnet.h>
26 #define LNET_NRB_TINY_MIN 512 /* min value for each CPT */
27 #define LNET_NRB_TINY (LNET_NRB_TINY_MIN * 4)
28 #define LNET_NRB_SMALL_MIN 4096 /* min value for each CPT */
29 #define LNET_NRB_SMALL (LNET_NRB_SMALL_MIN * 4)
30 #define LNET_NRB_SMALL_PAGES 1
31 #define LNET_NRB_LARGE_MIN 256 /* min value for each CPT */
32 #define LNET_NRB_LARGE (LNET_NRB_LARGE_MIN * 4)
33 #define LNET_NRB_LARGE_PAGES ((LNET_MTU + PAGE_SIZE - 1) >> \
36 static char *forwarding = "";
37 module_param(forwarding, charp, 0444);
38 MODULE_PARM_DESC(forwarding, "Explicitly enable/disable forwarding between networks");
40 static int tiny_router_buffers;
41 module_param(tiny_router_buffers, int, 0444);
42 MODULE_PARM_DESC(tiny_router_buffers, "# of 0 payload messages to buffer in the router");
43 static int small_router_buffers;
44 module_param(small_router_buffers, int, 0444);
45 MODULE_PARM_DESC(small_router_buffers, "# of small (1 page) messages to buffer in the router");
46 static int large_router_buffers;
47 module_param(large_router_buffers, int, 0444);
48 MODULE_PARM_DESC(large_router_buffers, "# of large messages to buffer in the router");
49 static int peer_buffer_credits;
50 module_param(peer_buffer_credits, int, 0444);
51 MODULE_PARM_DESC(peer_buffer_credits, "# router buffer credits per peer");
53 static int auto_down = 1;
54 module_param(auto_down, int, 0444);
55 MODULE_PARM_DESC(auto_down, "Automatically mark peers down on comms error");
58 lnet_peer_buffer_credits(struct lnet_net *net)
60 /* NI option overrides LNet default */
61 if (net->net_tunables.lct_peer_rtr_credits > 0)
62 return net->net_tunables.lct_peer_rtr_credits;
63 if (peer_buffer_credits > 0)
64 return peer_buffer_credits;
66 /* As an approximation, allow this peer the same number of router
67 * buffers as it is allowed outstanding sends */
68 return net->net_tunables.lct_peer_tx_credits;
71 static int check_routers_before_use;
72 module_param(check_routers_before_use, int, 0444);
73 MODULE_PARM_DESC(check_routers_before_use, "Assume routers are down and ping them before use");
75 int avoid_asym_router_failure = 1;
76 module_param(avoid_asym_router_failure, int, 0644);
77 MODULE_PARM_DESC(avoid_asym_router_failure, "Avoid asymmetrical router failures (0 to disable)");
79 static int dead_router_check_interval = 60;
80 module_param(dead_router_check_interval, int, 0644);
81 MODULE_PARM_DESC(dead_router_check_interval, "Seconds between dead router health checks (<= 0 to disable)");
83 static int live_router_check_interval = 60;
84 module_param(live_router_check_interval, int, 0644);
85 MODULE_PARM_DESC(live_router_check_interval, "Seconds between live router health checks (<= 0 to disable)");
87 static int router_ping_timeout = 50;
88 module_param(router_ping_timeout, int, 0644);
89 MODULE_PARM_DESC(router_ping_timeout, "Seconds to wait for the reply to a router health query");
92 lnet_peers_start_down(void)
94 return check_routers_before_use;
98 lnet_notify_locked(struct lnet_peer_ni *lp, int notifylnd, int alive,
101 if (lp->lpni_timestamp > when) { /* out of date information */
102 CDEBUG(D_NET, "Out of date\n");
107 * This function can be called with different cpt locks being
108 * held. lpni_alive_count modification needs to be properly protected.
109 * Significant reads to lpni_alive_count are also protected with
112 spin_lock(&lp->lpni_lock);
114 lp->lpni_timestamp = when; /* update timestamp */
115 lp->lpni_ping_deadline = 0; /* disable ping timeout */
117 if (lp->lpni_alive_count != 0 && /* got old news */
118 (!lp->lpni_alive) == (!alive)) { /* new date for old news */
119 spin_unlock(&lp->lpni_lock);
120 CDEBUG(D_NET, "Old news\n");
124 /* Flag that notification is outstanding */
126 lp->lpni_alive_count++;
127 lp->lpni_alive = (alive) ? 1 : 0;
129 lp->lpni_notifylnd = notifylnd;
131 lp->lpni_ping_feats = LNET_PING_FEAT_INVAL; /* reset */
133 spin_unlock(&lp->lpni_lock);
135 CDEBUG(D_NET, "set %s %d\n", libcfs_nid2str(lp->lpni_nid), alive);
139 * This function will always be called with lp->lpni_cpt lock held.
142 lnet_ni_notify_locked(struct lnet_ni *ni, struct lnet_peer_ni *lp)
147 /* Notify only in 1 thread at any time to ensure ordered notification.
148 * NB individual events can be missed; the only guarantee is that you
149 * always get the most recent news */
151 spin_lock(&lp->lpni_lock);
153 if (lp->lpni_notifying || ni == NULL) {
154 spin_unlock(&lp->lpni_lock);
158 lp->lpni_notifying = 1;
161 * lp->lpni_notify needs to be protected because it can be set in
162 * lnet_notify_locked().
164 while (lp->lpni_notify) {
165 alive = lp->lpni_alive;
166 notifylnd = lp->lpni_notifylnd;
168 lp->lpni_notifylnd = 0;
171 if (notifylnd && ni->ni_net->net_lnd->lnd_notify != NULL) {
172 spin_unlock(&lp->lpni_lock);
173 lnet_net_unlock(lp->lpni_cpt);
175 /* A new notification could happen now; I'll handle it
176 * when control returns to me */
178 (ni->ni_net->net_lnd->lnd_notify)(ni, lp->lpni_nid,
181 lnet_net_lock(lp->lpni_cpt);
182 spin_lock(&lp->lpni_lock);
186 lp->lpni_notifying = 0;
187 spin_unlock(&lp->lpni_lock);
191 lnet_rtr_addref_locked(struct lnet_peer_ni *lp)
193 LASSERT(atomic_read(&lp->lpni_refcount) > 0);
194 LASSERT(lp->lpni_rtr_refcount >= 0);
196 /* lnet_net_lock must be exclusively locked */
197 lp->lpni_rtr_refcount++;
198 if (lp->lpni_rtr_refcount == 1) {
199 struct list_head *pos;
201 /* a simple insertion sort */
202 list_for_each_prev(pos, &the_lnet.ln_routers) {
203 struct lnet_peer_ni *rtr;
205 rtr = list_entry(pos, struct lnet_peer_ni,
207 if (rtr->lpni_nid < lp->lpni_nid)
211 list_add(&lp->lpni_rtr_list, pos);
212 /* addref for the_lnet.ln_routers */
213 lnet_peer_ni_addref_locked(lp);
214 the_lnet.ln_routers_version++;
219 lnet_rtr_decref_locked(struct lnet_peer_ni *lp)
221 LASSERT(atomic_read(&lp->lpni_refcount) > 0);
222 LASSERT(lp->lpni_rtr_refcount > 0);
224 /* lnet_net_lock must be exclusively locked */
225 lp->lpni_rtr_refcount--;
226 if (lp->lpni_rtr_refcount == 0) {
227 LASSERT(list_empty(&lp->lpni_routes));
229 if (lp->lpni_rcd != NULL) {
230 list_add(&lp->lpni_rcd->rcd_list,
231 &the_lnet.ln_rcd_deathrow);
235 list_del(&lp->lpni_rtr_list);
236 /* decref for the_lnet.ln_routers */
237 lnet_peer_ni_decref_locked(lp);
238 the_lnet.ln_routers_version++;
242 struct lnet_remotenet *
243 lnet_find_rnet_locked(__u32 net)
245 struct lnet_remotenet *rnet;
246 struct list_head *tmp;
247 struct list_head *rn_list;
249 LASSERT(the_lnet.ln_state == LNET_STATE_RUNNING);
251 rn_list = lnet_net2rnethash(net);
252 list_for_each(tmp, rn_list) {
253 rnet = list_entry(tmp, struct lnet_remotenet, lrn_list);
255 if (rnet->lrn_net == net)
261 static void lnet_shuffle_seed(void)
266 struct timespec64 ts;
267 struct lnet_ni *ni = NULL;
272 cfs_get_random_bytes(seed, sizeof(seed));
274 /* Nodes with small feet have little entropy
275 * the NID for this node gives the most entropy in the low bits */
276 while ((ni = lnet_get_next_ni_locked(NULL, ni))) {
277 lnd_type = LNET_NETTYP(LNET_NIDNET(ni->ni_nid));
279 if (lnd_type != LOLND)
280 seed[0] ^= (LNET_NIDADDR(ni->ni_nid) | lnd_type);
284 cfs_srand(ts.tv_sec ^ seed[0], ts.tv_nsec ^ seed[1]);
289 /* NB expects LNET_LOCK held */
291 lnet_add_route_to_rnet(struct lnet_remotenet *rnet, struct lnet_route *route)
293 unsigned int len = 0;
294 unsigned int offset = 0;
299 list_for_each(e, &rnet->lrn_routes) {
303 /* len+1 positions to add a new entry, also prevents division by 0 */
304 offset = cfs_rand() % (len + 1);
305 list_for_each(e, &rnet->lrn_routes) {
310 list_add(&route->lr_list, e);
311 list_add(&route->lr_gwlist, &route->lr_gateway->lpni_routes);
313 the_lnet.ln_remote_nets_version++;
314 lnet_rtr_addref_locked(route->lr_gateway);
318 lnet_add_route(__u32 net, __u32 hops, lnet_nid_t gateway,
319 unsigned int priority)
322 struct lnet_remotenet *rnet;
323 struct lnet_remotenet *rnet2;
324 struct lnet_route *route;
326 struct lnet_peer_ni *lpni;
330 CDEBUG(D_NET, "Add route: net %s hops %d priority %u gw %s\n",
331 libcfs_net2str(net), hops, priority, libcfs_nid2str(gateway));
333 if (gateway == LNET_NID_ANY ||
334 LNET_NETTYP(LNET_NIDNET(gateway)) == LOLND ||
335 net == LNET_NIDNET(LNET_NID_ANY) ||
336 LNET_NETTYP(net) == LOLND ||
337 LNET_NIDNET(gateway) == net ||
338 (hops != LNET_UNDEFINED_HOPS && (hops < 1 || hops > 255)))
341 if (lnet_islocalnet(net)) /* it's a local network */
344 /* Assume net, route, all new */
345 LIBCFS_ALLOC(route, sizeof(*route));
346 LIBCFS_ALLOC(rnet, sizeof(*rnet));
347 if (route == NULL || rnet == NULL) {
348 CERROR("Out of memory creating route %s %d %s\n",
349 libcfs_net2str(net), hops, libcfs_nid2str(gateway));
351 LIBCFS_FREE(route, sizeof(*route));
353 LIBCFS_FREE(rnet, sizeof(*rnet));
357 INIT_LIST_HEAD(&rnet->lrn_routes);
359 route->lr_hops = hops;
361 route->lr_priority = priority;
363 lnet_net_lock(LNET_LOCK_EX);
365 lpni = lnet_nid2peerni_ex(gateway, LNET_LOCK_EX);
367 lnet_net_unlock(LNET_LOCK_EX);
369 LIBCFS_FREE(route, sizeof(*route));
370 LIBCFS_FREE(rnet, sizeof(*rnet));
373 if (rc == -EHOSTUNREACH) /* gateway is not on a local net. */
374 return rc; /* ignore the route entry */
375 CERROR("Error %d creating route %s %d %s\n", rc,
376 libcfs_net2str(net), hops,
377 libcfs_nid2str(gateway));
380 route->lr_gateway = lpni;
381 LASSERT(the_lnet.ln_state == LNET_STATE_RUNNING);
383 rnet2 = lnet_find_rnet_locked(net);
386 list_add_tail(&rnet->lrn_list, lnet_net2rnethash(net));
390 /* Search for a duplicate route (it's a NOOP if it is) */
392 list_for_each(e, &rnet2->lrn_routes) {
393 struct lnet_route *route2;
395 route2 = list_entry(e, struct lnet_route, lr_list);
396 if (route2->lr_gateway == route->lr_gateway) {
401 /* our lookups must be true */
402 LASSERT(route2->lr_gateway->lpni_nid != gateway);
406 lnet_peer_ni_addref_locked(route->lr_gateway); /* +1 for notify */
407 lnet_add_route_to_rnet(rnet2, route);
409 ni = lnet_get_next_ni_locked(route->lr_gateway->lpni_net, NULL);
410 lnet_net_unlock(LNET_LOCK_EX);
412 /* XXX Assume alive */
413 if (ni->ni_net->net_lnd->lnd_notify != NULL)
414 (ni->ni_net->net_lnd->lnd_notify)(ni, gateway, 1);
416 lnet_net_lock(LNET_LOCK_EX);
419 /* -1 for notify or !add_route */
420 lnet_peer_ni_decref_locked(route->lr_gateway);
421 lnet_net_unlock(LNET_LOCK_EX);
427 LIBCFS_FREE(route, sizeof(*route));
431 LIBCFS_FREE(rnet, sizeof(*rnet));
433 /* kick start the monitor thread to handle the added route */
434 wake_up(&the_lnet.ln_mt_waitq);
440 lnet_check_routes(void)
442 struct lnet_remotenet *rnet;
443 struct lnet_route *route;
444 struct lnet_route *route2;
445 struct list_head *e1;
446 struct list_head *e2;
448 struct list_head *rn_list;
451 cpt = lnet_net_lock_current();
453 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) {
454 rn_list = &the_lnet.ln_remote_nets_hash[i];
455 list_for_each(e1, rn_list) {
456 rnet = list_entry(e1, struct lnet_remotenet, lrn_list);
459 list_for_each(e2, &rnet->lrn_routes) {
464 route = list_entry(e2, struct lnet_route,
467 if (route2 == NULL) {
472 if (route->lr_gateway->lpni_net ==
473 route2->lr_gateway->lpni_net)
476 nid1 = route->lr_gateway->lpni_nid;
477 nid2 = route2->lr_gateway->lpni_nid;
480 lnet_net_unlock(cpt);
482 CERROR("Routes to %s via %s and %s not "
485 libcfs_nid2str(nid1),
486 libcfs_nid2str(nid2));
492 lnet_net_unlock(cpt);
497 lnet_del_route(__u32 net, lnet_nid_t gw_nid)
499 struct lnet_peer_ni *gateway;
500 struct lnet_remotenet *rnet;
501 struct lnet_route *route;
502 struct list_head *e1;
503 struct list_head *e2;
505 struct list_head *rn_list;
508 CDEBUG(D_NET, "Del route: net %s : gw %s\n",
509 libcfs_net2str(net), libcfs_nid2str(gw_nid));
511 /* NB Caller may specify either all routes via the given gateway
512 * or a specific route entry actual NIDs) */
514 lnet_net_lock(LNET_LOCK_EX);
515 if (net == LNET_NIDNET(LNET_NID_ANY))
516 rn_list = &the_lnet.ln_remote_nets_hash[0];
518 rn_list = lnet_net2rnethash(net);
521 list_for_each(e1, rn_list) {
522 rnet = list_entry(e1, struct lnet_remotenet, lrn_list);
524 if (!(net == LNET_NIDNET(LNET_NID_ANY) ||
525 net == rnet->lrn_net))
528 list_for_each(e2, &rnet->lrn_routes) {
529 route = list_entry(e2, struct lnet_route, lr_list);
531 gateway = route->lr_gateway;
532 if (!(gw_nid == LNET_NID_ANY ||
533 gw_nid == gateway->lpni_nid))
536 list_del(&route->lr_list);
537 list_del(&route->lr_gwlist);
538 the_lnet.ln_remote_nets_version++;
540 if (list_empty(&rnet->lrn_routes))
541 list_del(&rnet->lrn_list);
545 lnet_rtr_decref_locked(gateway);
546 lnet_peer_ni_decref_locked(gateway);
548 lnet_net_unlock(LNET_LOCK_EX);
550 LIBCFS_FREE(route, sizeof(*route));
553 LIBCFS_FREE(rnet, sizeof(*rnet));
556 lnet_net_lock(LNET_LOCK_EX);
561 if (net == LNET_NIDNET(LNET_NID_ANY) &&
562 ++idx < LNET_REMOTE_NETS_HASH_SIZE) {
563 rn_list = &the_lnet.ln_remote_nets_hash[idx];
566 lnet_net_unlock(LNET_LOCK_EX);
572 lnet_destroy_routes (void)
574 lnet_del_route(LNET_NIDNET(LNET_NID_ANY), LNET_NID_ANY);
577 int lnet_get_rtr_pool_cfg(int idx, struct lnet_ioctl_pool_cfg *pool_cfg)
579 int i, rc = -ENOENT, j;
581 if (the_lnet.ln_rtrpools == NULL)
584 for (i = 0; i < LNET_NRBPOOLS; i++) {
585 struct lnet_rtrbufpool *rbp;
587 lnet_net_lock(LNET_LOCK_EX);
588 cfs_percpt_for_each(rbp, j, the_lnet.ln_rtrpools) {
592 pool_cfg->pl_pools[i].pl_npages = rbp[i].rbp_npages;
593 pool_cfg->pl_pools[i].pl_nbuffers = rbp[i].rbp_nbuffers;
594 pool_cfg->pl_pools[i].pl_credits = rbp[i].rbp_credits;
595 pool_cfg->pl_pools[i].pl_mincredits = rbp[i].rbp_mincredits;
599 lnet_net_unlock(LNET_LOCK_EX);
602 lnet_net_lock(LNET_LOCK_EX);
603 pool_cfg->pl_routing = the_lnet.ln_routing;
604 lnet_net_unlock(LNET_LOCK_EX);
610 lnet_get_route(int idx, __u32 *net, __u32 *hops,
611 lnet_nid_t *gateway, __u32 *alive, __u32 *priority)
613 struct list_head *e1;
614 struct list_head *e2;
615 struct lnet_remotenet *rnet;
616 struct lnet_route *route;
619 struct list_head *rn_list;
621 cpt = lnet_net_lock_current();
623 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) {
624 rn_list = &the_lnet.ln_remote_nets_hash[i];
625 list_for_each(e1, rn_list) {
626 rnet = list_entry(e1, struct lnet_remotenet, lrn_list);
628 list_for_each(e2, &rnet->lrn_routes) {
629 route = list_entry(e2, struct lnet_route,
633 *net = rnet->lrn_net;
634 *hops = route->lr_hops;
635 *priority = route->lr_priority;
636 *gateway = route->lr_gateway->lpni_nid;
637 *alive = lnet_is_route_alive(route);
638 lnet_net_unlock(cpt);
645 lnet_net_unlock(cpt);
650 lnet_swap_pinginfo(struct lnet_ping_buffer *pbuf)
652 struct lnet_ni_status *stat;
656 __swab32s(&pbuf->pb_info.pi_magic);
657 __swab32s(&pbuf->pb_info.pi_features);
658 __swab32s(&pbuf->pb_info.pi_pid);
659 __swab32s(&pbuf->pb_info.pi_nnis);
660 nnis = pbuf->pb_info.pi_nnis;
661 if (nnis > pbuf->pb_nnis)
662 nnis = pbuf->pb_nnis;
663 for (i = 0; i < nnis; i++) {
664 stat = &pbuf->pb_info.pi_ni[i];
665 __swab64s(&stat->ns_nid);
666 __swab32s(&stat->ns_status);
672 * parse router-checker pinginfo, record number of down NIs for remote
673 * networks on that router.
676 lnet_parse_rc_info(struct lnet_rc_data *rcd)
678 struct lnet_ping_buffer *pbuf = rcd->rcd_pingbuffer;
679 struct lnet_peer_ni *gw = rcd->rcd_gateway;
680 struct lnet_route *rte;
683 if (!gw->lpni_alive || !pbuf)
687 * Protect gw->lpni_ping_feats. This can be set from
688 * lnet_notify_locked with different locks being held
690 spin_lock(&gw->lpni_lock);
692 if (pbuf->pb_info.pi_magic == __swab32(LNET_PROTO_PING_MAGIC))
693 lnet_swap_pinginfo(pbuf);
695 /* NB always racing with network! */
696 if (pbuf->pb_info.pi_magic != LNET_PROTO_PING_MAGIC) {
697 CDEBUG(D_NET, "%s: Unexpected magic %08x\n",
698 libcfs_nid2str(gw->lpni_nid), pbuf->pb_info.pi_magic);
699 gw->lpni_ping_feats = LNET_PING_FEAT_INVAL;
703 gw->lpni_ping_feats = pbuf->pb_info.pi_features;
705 /* Without NI status info there's nothing more to do. */
706 if ((gw->lpni_ping_feats & LNET_PING_FEAT_NI_STATUS) == 0)
709 /* Determine the number of NIs for which there is data. */
710 nnis = pbuf->pb_info.pi_nnis;
711 if (pbuf->pb_nnis < nnis) {
712 if (rcd->rcd_nnis < nnis)
713 rcd->rcd_nnis = nnis;
714 nnis = pbuf->pb_nnis;
717 list_for_each_entry(rte, &gw->lpni_routes, lr_gwlist) {
722 /* If routing disabled then the route is down. */
723 if ((gw->lpni_ping_feats & LNET_PING_FEAT_RTE_DISABLED) != 0) {
728 for (i = 0; i < nnis; i++) {
729 struct lnet_ni_status *stat = &pbuf->pb_info.pi_ni[i];
730 lnet_nid_t nid = stat->ns_nid;
732 if (nid == LNET_NID_ANY) {
733 CDEBUG(D_NET, "%s: unexpected LNET_NID_ANY\n",
734 libcfs_nid2str(gw->lpni_nid));
735 gw->lpni_ping_feats = LNET_PING_FEAT_INVAL;
739 if (LNET_NETTYP(LNET_NIDNET(nid)) == LOLND)
742 if (stat->ns_status == LNET_NI_STATUS_DOWN) {
747 if (stat->ns_status == LNET_NI_STATUS_UP) {
748 if (LNET_NIDNET(nid) == rte->lr_net) {
755 CDEBUG(D_NET, "%s: Unexpected status 0x%x\n",
756 libcfs_nid2str(gw->lpni_nid), stat->ns_status);
757 gw->lpni_ping_feats = LNET_PING_FEAT_INVAL;
761 if (up) { /* ignore downed NIs if NI for dest network is up */
765 /* if @down is zero and this route is single-hop, it means
766 * we can't find NI for target network */
767 if (down == 0 && rte->lr_hops == 1)
770 rte->lr_downis = down;
773 spin_unlock(&gw->lpni_lock);
777 lnet_router_checker_event(struct lnet_event *event)
779 struct lnet_rc_data *rcd = event->md.user_ptr;
780 struct lnet_peer_ni *lp;
782 LASSERT(rcd != NULL);
784 if (event->unlinked) {
785 LNetInvalidateMDHandle(&rcd->rcd_mdh);
789 LASSERT(event->type == LNET_EVENT_SEND ||
790 event->type == LNET_EVENT_REPLY);
792 lp = rcd->rcd_gateway;
795 /* NB: it's called with holding lnet_res_lock, we have a few
796 * places need to hold both locks at the same time, please take
797 * care of lock ordering */
798 lnet_net_lock(lp->lpni_cpt);
799 if (!lnet_isrouter(lp) || lp->lpni_rcd != rcd) {
800 /* ignore if no longer a router or rcd is replaced */
804 if (event->type == LNET_EVENT_SEND) {
805 lp->lpni_ping_notsent = 0;
806 if (event->status == 0)
810 /* LNET_EVENT_REPLY */
811 /* A successful REPLY means the router is up. If _any_ comms
812 * to the router fail I assume it's down (this will happen if
813 * we ping alive routers to try to detect router death before
814 * apps get burned). */
816 lnet_notify_locked(lp, 1, !event->status, ktime_get_seconds());
817 /* The router checker will wake up very shortly and do the
818 * actual notification.
819 * XXX If 'lp' stops being a router before then, it will still
820 * have the notification pending!!! */
822 if (avoid_asym_router_failure && event->status == 0)
823 lnet_parse_rc_info(rcd);
826 lnet_net_unlock(lp->lpni_cpt);
830 lnet_wait_known_routerstate(void)
832 struct lnet_peer_ni *rtr;
833 struct list_head *entry;
836 LASSERT(the_lnet.ln_mt_state == LNET_MT_STATE_RUNNING);
839 int cpt = lnet_net_lock_current();
842 list_for_each(entry, &the_lnet.ln_routers) {
843 rtr = list_entry(entry, struct lnet_peer_ni,
846 spin_lock(&rtr->lpni_lock);
848 if (rtr->lpni_alive_count == 0) {
850 spin_unlock(&rtr->lpni_lock);
853 spin_unlock(&rtr->lpni_lock);
856 lnet_net_unlock(cpt);
861 set_current_state(TASK_UNINTERRUPTIBLE);
862 schedule_timeout(cfs_time_seconds(1));
867 lnet_router_ni_update_locked(struct lnet_peer_ni *gw, __u32 net)
869 struct lnet_route *rte;
871 if ((gw->lpni_ping_feats & LNET_PING_FEAT_NI_STATUS) != 0) {
872 list_for_each_entry(rte, &gw->lpni_routes, lr_gwlist) {
873 if (rte->lr_net == net) {
882 lnet_update_ni_status_locked(void)
884 struct lnet_ni *ni = NULL;
888 LASSERT(the_lnet.ln_routing);
890 timeout = router_ping_timeout +
891 MAX(live_router_check_interval, dead_router_check_interval);
893 now = ktime_get_real_seconds();
894 while ((ni = lnet_get_next_ni_locked(NULL, ni))) {
895 if (ni->ni_net->net_lnd->lnd_type == LOLND)
898 if (now < ni->ni_last_alive + timeout)
902 /* re-check with lock */
903 if (now < ni->ni_last_alive + timeout) {
908 LASSERT(ni->ni_status != NULL);
910 if (ni->ni_status->ns_status != LNET_NI_STATUS_DOWN) {
911 CDEBUG(D_NET, "NI(%s:%lld) status changed to down\n",
912 libcfs_nid2str(ni->ni_nid), timeout);
913 /* NB: so far, this is the only place to set
914 * NI status to "down" */
915 ni->ni_status->ns_status = LNET_NI_STATUS_DOWN;
922 lnet_destroy_rc_data(struct lnet_rc_data *rcd)
924 LASSERT(list_empty(&rcd->rcd_list));
925 /* detached from network */
926 LASSERT(LNetMDHandleIsInvalid(rcd->rcd_mdh));
928 if (rcd->rcd_gateway != NULL) {
929 int cpt = rcd->rcd_gateway->lpni_cpt;
932 lnet_peer_ni_decref_locked(rcd->rcd_gateway);
933 lnet_net_unlock(cpt);
936 if (rcd->rcd_pingbuffer != NULL)
937 lnet_ping_buffer_decref(rcd->rcd_pingbuffer);
939 LIBCFS_FREE(rcd, sizeof(*rcd));
942 static struct lnet_rc_data *
943 lnet_update_rc_data_locked(struct lnet_peer_ni *gateway)
945 struct lnet_handle_md mdh;
946 struct lnet_rc_data *rcd;
947 struct lnet_ping_buffer *pbuf = NULL;
948 int nnis = LNET_INTERFACES_MIN;
952 rcd = gateway->lpni_rcd;
954 nnis = rcd->rcd_nnis;
956 LNetInvalidateMDHandle(&rcd->rcd_mdh);
957 pbuf = rcd->rcd_pingbuffer;
958 rcd->rcd_pingbuffer = NULL;
960 LNetInvalidateMDHandle(&mdh);
963 lnet_net_unlock(gateway->lpni_cpt);
967 lnet_ping_buffer_decref(pbuf);
969 LIBCFS_ALLOC(rcd, sizeof(*rcd));
973 LNetInvalidateMDHandle(&rcd->rcd_mdh);
974 INIT_LIST_HEAD(&rcd->rcd_list);
975 rcd->rcd_nnis = nnis;
978 pbuf = lnet_ping_buffer_alloc(nnis, GFP_NOFS);
982 for (i = 0; i < nnis; i++) {
983 pbuf->pb_info.pi_ni[i].ns_nid = LNET_NID_ANY;
984 pbuf->pb_info.pi_ni[i].ns_status = LNET_NI_STATUS_INVALID;
986 rcd->rcd_pingbuffer = pbuf;
988 LASSERT(!LNetEQHandleIsInvalid(the_lnet.ln_rc_eqh));
989 rc = LNetMDBind((struct lnet_md){.start = &pbuf->pb_info,
991 .length = LNET_PING_INFO_SIZE(nnis),
992 .threshold = LNET_MD_THRESH_INF,
993 .options = LNET_MD_TRUNCATE,
994 .eq_handle = the_lnet.ln_rc_eqh},
998 CERROR("Can't bind MD: %d\n", rc);
999 goto out_ping_buffer_decref;
1003 lnet_net_lock(gateway->lpni_cpt);
1004 /* Check if this is still a router. */
1005 if (!lnet_isrouter(gateway))
1007 /* Check if someone else installed router data. */
1008 if (gateway->lpni_rcd && gateway->lpni_rcd != rcd)
1011 /* Install and/or update the router data. */
1012 if (!gateway->lpni_rcd) {
1013 lnet_peer_ni_addref_locked(gateway);
1014 rcd->rcd_gateway = gateway;
1015 gateway->lpni_rcd = rcd;
1017 gateway->lpni_ping_notsent = 0;
1022 lnet_net_unlock(gateway->lpni_cpt);
1023 rc = LNetMDUnlink(mdh);
1025 out_ping_buffer_decref:
1026 lnet_ping_buffer_decref(pbuf);
1028 if (rcd && rcd != gateway->lpni_rcd)
1029 lnet_destroy_rc_data(rcd);
1030 lnet_net_lock(gateway->lpni_cpt);
1031 return gateway->lpni_rcd;
1035 lnet_router_check_interval(struct lnet_peer_ni *rtr)
1039 secs = rtr->lpni_alive ? live_router_check_interval :
1040 dead_router_check_interval;
1048 lnet_ping_router_locked(struct lnet_peer_ni *rtr)
1050 struct lnet_rc_data *rcd = NULL;
1051 time64_t now = ktime_get_seconds();
1055 lnet_peer_ni_addref_locked(rtr);
1057 if (rtr->lpni_ping_deadline != 0 && /* ping timed out? */
1058 now > rtr->lpni_ping_deadline)
1059 lnet_notify_locked(rtr, 1, 0, now);
1061 /* Run any outstanding notifications */
1062 ni = lnet_get_next_ni_locked(rtr->lpni_net, NULL);
1063 lnet_ni_notify_locked(ni, rtr);
1065 if (!lnet_isrouter(rtr) ||
1066 the_lnet.ln_mt_state != LNET_MT_STATE_RUNNING) {
1067 /* router table changed or router checker is shutting down */
1068 lnet_peer_ni_decref_locked(rtr);
1072 rcd = rtr->lpni_rcd;
1075 * The response to the router checker ping could've timed out and
1076 * the mdh might've been invalidated, so we need to update it
1079 if (!rcd || rcd->rcd_nnis > rcd->rcd_pingbuffer->pb_nnis ||
1080 LNetMDHandleIsInvalid(rcd->rcd_mdh))
1081 rcd = lnet_update_rc_data_locked(rtr);
1085 secs = lnet_router_check_interval(rtr);
1088 "rtr %s %lld: deadline %lld ping_notsent %d alive %d "
1089 "alive_count %d lpni_ping_timestamp %lld\n",
1090 libcfs_nid2str(rtr->lpni_nid), secs,
1091 rtr->lpni_ping_deadline, rtr->lpni_ping_notsent,
1092 rtr->lpni_alive, rtr->lpni_alive_count, rtr->lpni_ping_timestamp);
1094 if (secs != 0 && !rtr->lpni_ping_notsent &&
1095 now > rtr->lpni_ping_timestamp + secs) {
1097 struct lnet_process_id id;
1098 struct lnet_handle_md mdh;
1100 id.nid = rtr->lpni_nid;
1101 id.pid = LNET_PID_LUSTRE;
1102 CDEBUG(D_NET, "Check: %s\n", libcfs_id2str(id));
1104 rtr->lpni_ping_notsent = 1;
1105 rtr->lpni_ping_timestamp = now;
1109 if (rtr->lpni_ping_deadline == 0) {
1110 rtr->lpni_ping_deadline = ktime_get_seconds() +
1111 router_ping_timeout;
1114 lnet_net_unlock(rtr->lpni_cpt);
1116 rc = LNetGet(LNET_NID_ANY, mdh, id, LNET_RESERVED_PORTAL,
1117 LNET_PROTO_PING_MATCHBITS, 0, false);
1119 lnet_net_lock(rtr->lpni_cpt);
1121 rtr->lpni_ping_notsent = 0; /* no event pending */
1124 lnet_peer_ni_decref_locked(rtr);
1128 int lnet_router_pre_mt_start(void)
1132 if (check_routers_before_use &&
1133 dead_router_check_interval <= 0) {
1134 LCONSOLE_ERROR_MSG(0x10a, "'dead_router_check_interval' must be"
1135 " set if 'check_routers_before_use' is set"
1140 rc = LNetEQAlloc(0, lnet_router_checker_event, &the_lnet.ln_rc_eqh);
1142 CERROR("Can't allocate EQ(0): %d\n", rc);
1149 void lnet_router_post_mt_start(void)
1151 if (check_routers_before_use) {
1152 /* Note that a helpful side-effect of pinging all known routers
1153 * at startup is that it makes them drop stale connections they
1154 * may have to a previous instance of me. */
1155 lnet_wait_known_routerstate();
1160 lnet_router_cleanup(void)
1164 rc = LNetEQFree(the_lnet.ln_rc_eqh);
1170 lnet_prune_rc_data(int wait_unlink)
1172 struct lnet_rc_data *rcd;
1173 struct lnet_rc_data *tmp;
1174 struct lnet_peer_ni *lp;
1175 struct list_head head;
1178 if (likely(the_lnet.ln_mt_state == LNET_MT_STATE_RUNNING &&
1179 list_empty(&the_lnet.ln_rcd_deathrow) &&
1180 list_empty(&the_lnet.ln_rcd_zombie)))
1183 INIT_LIST_HEAD(&head);
1185 lnet_net_lock(LNET_LOCK_EX);
1187 if (the_lnet.ln_mt_state != LNET_MT_STATE_RUNNING) {
1188 /* router checker is stopping, prune all */
1189 list_for_each_entry(lp, &the_lnet.ln_routers,
1191 if (lp->lpni_rcd == NULL)
1194 LASSERT(list_empty(&lp->lpni_rcd->rcd_list));
1195 list_add(&lp->lpni_rcd->rcd_list,
1196 &the_lnet.ln_rcd_deathrow);
1197 lp->lpni_rcd = NULL;
1201 /* unlink all RCDs on deathrow list */
1202 list_splice_init(&the_lnet.ln_rcd_deathrow, &head);
1204 if (!list_empty(&head)) {
1205 lnet_net_unlock(LNET_LOCK_EX);
1207 list_for_each_entry(rcd, &head, rcd_list)
1208 LNetMDUnlink(rcd->rcd_mdh);
1210 lnet_net_lock(LNET_LOCK_EX);
1213 list_splice_init(&head, &the_lnet.ln_rcd_zombie);
1215 /* release all zombie RCDs */
1216 while (!list_empty(&the_lnet.ln_rcd_zombie)) {
1217 list_for_each_entry_safe(rcd, tmp, &the_lnet.ln_rcd_zombie,
1219 if (LNetMDHandleIsInvalid(rcd->rcd_mdh))
1220 list_move(&rcd->rcd_list, &head);
1223 wait_unlink = wait_unlink &&
1224 !list_empty(&the_lnet.ln_rcd_zombie);
1226 lnet_net_unlock(LNET_LOCK_EX);
1228 while (!list_empty(&head)) {
1229 rcd = list_entry(head.next,
1230 struct lnet_rc_data, rcd_list);
1231 list_del_init(&rcd->rcd_list);
1232 lnet_destroy_rc_data(rcd);
1239 CDEBUG(((i & (-i)) == i) ? D_WARNING : D_NET,
1240 "Waiting for rc buffers to unlink\n");
1241 set_current_state(TASK_UNINTERRUPTIBLE);
1242 schedule_timeout(cfs_time_seconds(1) / 4);
1244 lnet_net_lock(LNET_LOCK_EX);
1247 lnet_net_unlock(LNET_LOCK_EX);
1251 * This function is called from the monitor thread to check if there are
1252 * any active routers that need to be checked.
1255 lnet_router_checker_active(void)
1257 if (the_lnet.ln_mt_state != LNET_MT_STATE_RUNNING)
1260 /* Router Checker thread needs to run when routing is enabled in
1261 * order to call lnet_update_ni_status_locked() */
1262 if (the_lnet.ln_routing)
1265 /* if there are routers that need to be cleaned up then do so */
1266 if (!list_empty(&the_lnet.ln_rcd_deathrow) ||
1267 !list_empty(&the_lnet.ln_rcd_zombie))
1270 return !list_empty(&the_lnet.ln_routers) &&
1271 (live_router_check_interval > 0 ||
1272 dead_router_check_interval > 0);
1276 lnet_check_routers(void)
1278 struct lnet_peer_ni *rtr;
1279 struct list_head *entry;
1284 cpt = lnet_net_lock_current();
1286 version = the_lnet.ln_routers_version;
1288 list_for_each(entry, &the_lnet.ln_routers) {
1289 rtr = list_entry(entry, struct lnet_peer_ni,
1292 cpt2 = rtr->lpni_cpt;
1294 lnet_net_unlock(cpt);
1297 /* the routers list has changed */
1298 if (version != the_lnet.ln_routers_version)
1302 lnet_ping_router_locked(rtr);
1304 /* NB dropped lock */
1305 if (version != the_lnet.ln_routers_version) {
1306 /* the routers list has changed */
1311 if (the_lnet.ln_routing)
1312 lnet_update_ni_status_locked();
1314 lnet_net_unlock(cpt);
1316 lnet_prune_rc_data(0); /* don't wait for UNLINK */
1320 lnet_destroy_rtrbuf(struct lnet_rtrbuf *rb, int npages)
1322 int sz = offsetof(struct lnet_rtrbuf, rb_kiov[npages]);
1324 while (--npages >= 0)
1325 __free_page(rb->rb_kiov[npages].kiov_page);
1327 LIBCFS_FREE(rb, sz);
1330 static struct lnet_rtrbuf *
1331 lnet_new_rtrbuf(struct lnet_rtrbufpool *rbp, int cpt)
1333 int npages = rbp->rbp_npages;
1334 int sz = offsetof(struct lnet_rtrbuf, rb_kiov[npages]);
1336 struct lnet_rtrbuf *rb;
1339 LIBCFS_CPT_ALLOC(rb, lnet_cpt_table(), cpt, sz);
1345 for (i = 0; i < npages; i++) {
1346 page = cfs_page_cpt_alloc(lnet_cpt_table(), cpt,
1347 GFP_KERNEL | __GFP_ZERO);
1350 __free_page(rb->rb_kiov[i].kiov_page);
1352 LIBCFS_FREE(rb, sz);
1356 rb->rb_kiov[i].kiov_len = PAGE_SIZE;
1357 rb->rb_kiov[i].kiov_offset = 0;
1358 rb->rb_kiov[i].kiov_page = page;
1365 lnet_rtrpool_free_bufs(struct lnet_rtrbufpool *rbp, int cpt)
1367 int npages = rbp->rbp_npages;
1368 struct lnet_rtrbuf *rb;
1369 struct list_head tmp;
1371 if (rbp->rbp_nbuffers == 0) /* not initialized or already freed */
1374 INIT_LIST_HEAD(&tmp);
1377 list_splice_init(&rbp->rbp_msgs, &tmp);
1378 lnet_drop_routed_msgs_locked(&tmp, cpt);
1379 list_splice_init(&rbp->rbp_bufs, &tmp);
1380 rbp->rbp_req_nbuffers = 0;
1381 rbp->rbp_nbuffers = rbp->rbp_credits = 0;
1382 rbp->rbp_mincredits = 0;
1383 lnet_net_unlock(cpt);
1385 /* Free buffers on the free list. */
1386 while (!list_empty(&tmp)) {
1387 rb = list_entry(tmp.next, struct lnet_rtrbuf, rb_list);
1388 list_del(&rb->rb_list);
1389 lnet_destroy_rtrbuf(rb, npages);
1394 lnet_rtrpool_adjust_bufs(struct lnet_rtrbufpool *rbp, int nbufs, int cpt)
1396 struct list_head rb_list;
1397 struct lnet_rtrbuf *rb;
1399 int num_buffers = 0;
1401 int npages = rbp->rbp_npages;
1404 /* If we are called for less buffers than already in the pool, we
1405 * just lower the req_nbuffers number and excess buffers will be
1406 * thrown away as they are returned to the free list. Credits
1407 * then get adjusted as well.
1408 * If we already have enough buffers allocated to serve the
1409 * increase requested, then we can treat that the same way as we
1410 * do the decrease. */
1411 num_rb = nbufs - rbp->rbp_nbuffers;
1412 if (nbufs <= rbp->rbp_req_nbuffers || num_rb <= 0) {
1413 rbp->rbp_req_nbuffers = nbufs;
1414 lnet_net_unlock(cpt);
1417 /* store the older value of rbp_req_nbuffers and then set it to
1418 * the new request to prevent lnet_return_rx_credits_locked() from
1419 * freeing buffers that we need to keep around */
1420 old_req_nbufs = rbp->rbp_req_nbuffers;
1421 rbp->rbp_req_nbuffers = nbufs;
1422 lnet_net_unlock(cpt);
1424 INIT_LIST_HEAD(&rb_list);
1426 /* allocate the buffers on a local list first. If all buffers are
1427 * allocated successfully then join this list to the rbp buffer
1428 * list. If not then free all allocated buffers. */
1429 while (num_rb-- > 0) {
1430 rb = lnet_new_rtrbuf(rbp, cpt);
1432 CERROR("Failed to allocate %d route bufs of %d pages\n",
1436 rbp->rbp_req_nbuffers = old_req_nbufs;
1437 lnet_net_unlock(cpt);
1442 list_add(&rb->rb_list, &rb_list);
1448 list_splice_tail(&rb_list, &rbp->rbp_bufs);
1449 rbp->rbp_nbuffers += num_buffers;
1450 rbp->rbp_credits += num_buffers;
1451 rbp->rbp_mincredits = rbp->rbp_credits;
1452 /* We need to schedule blocked msg using the newly
1454 while (!list_empty(&rbp->rbp_bufs) &&
1455 !list_empty(&rbp->rbp_msgs))
1456 lnet_schedule_blocked_locked(rbp);
1458 lnet_net_unlock(cpt);
1463 while (!list_empty(&rb_list)) {
1464 rb = list_entry(rb_list.next, struct lnet_rtrbuf, rb_list);
1465 list_del(&rb->rb_list);
1466 lnet_destroy_rtrbuf(rb, npages);
1473 lnet_rtrpool_init(struct lnet_rtrbufpool *rbp, int npages)
1475 INIT_LIST_HEAD(&rbp->rbp_msgs);
1476 INIT_LIST_HEAD(&rbp->rbp_bufs);
1478 rbp->rbp_npages = npages;
1479 rbp->rbp_credits = 0;
1480 rbp->rbp_mincredits = 0;
1484 lnet_rtrpools_free(int keep_pools)
1486 struct lnet_rtrbufpool *rtrp;
1489 if (the_lnet.ln_rtrpools == NULL) /* uninitialized or freed */
1492 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1493 lnet_rtrpool_free_bufs(&rtrp[LNET_TINY_BUF_IDX], i);
1494 lnet_rtrpool_free_bufs(&rtrp[LNET_SMALL_BUF_IDX], i);
1495 lnet_rtrpool_free_bufs(&rtrp[LNET_LARGE_BUF_IDX], i);
1499 cfs_percpt_free(the_lnet.ln_rtrpools);
1500 the_lnet.ln_rtrpools = NULL;
1505 lnet_nrb_tiny_calculate(void)
1507 int nrbs = LNET_NRB_TINY;
1509 if (tiny_router_buffers < 0) {
1510 LCONSOLE_ERROR_MSG(0x10c,
1511 "tiny_router_buffers=%d invalid when "
1512 "routing enabled\n", tiny_router_buffers);
1516 if (tiny_router_buffers > 0)
1517 nrbs = tiny_router_buffers;
1519 nrbs /= LNET_CPT_NUMBER;
1520 return max(nrbs, LNET_NRB_TINY_MIN);
1524 lnet_nrb_small_calculate(void)
1526 int nrbs = LNET_NRB_SMALL;
1528 if (small_router_buffers < 0) {
1529 LCONSOLE_ERROR_MSG(0x10c,
1530 "small_router_buffers=%d invalid when "
1531 "routing enabled\n", small_router_buffers);
1535 if (small_router_buffers > 0)
1536 nrbs = small_router_buffers;
1538 nrbs /= LNET_CPT_NUMBER;
1539 return max(nrbs, LNET_NRB_SMALL_MIN);
1543 lnet_nrb_large_calculate(void)
1545 int nrbs = LNET_NRB_LARGE;
1547 if (large_router_buffers < 0) {
1548 LCONSOLE_ERROR_MSG(0x10c,
1549 "large_router_buffers=%d invalid when "
1550 "routing enabled\n", large_router_buffers);
1554 if (large_router_buffers > 0)
1555 nrbs = large_router_buffers;
1557 nrbs /= LNET_CPT_NUMBER;
1558 return max(nrbs, LNET_NRB_LARGE_MIN);
1562 lnet_rtrpools_alloc(int im_a_router)
1564 struct lnet_rtrbufpool *rtrp;
1571 if (!strcmp(forwarding, "")) {
1572 /* not set either way */
1575 } else if (!strcmp(forwarding, "disabled")) {
1576 /* explicitly disabled */
1578 } else if (!strcmp(forwarding, "enabled")) {
1579 /* explicitly enabled */
1581 LCONSOLE_ERROR_MSG(0x10b, "'forwarding' not set to either "
1582 "'enabled' or 'disabled'\n");
1586 nrb_tiny = lnet_nrb_tiny_calculate();
1590 nrb_small = lnet_nrb_small_calculate();
1594 nrb_large = lnet_nrb_large_calculate();
1598 the_lnet.ln_rtrpools = cfs_percpt_alloc(lnet_cpt_table(),
1600 sizeof(struct lnet_rtrbufpool));
1601 if (the_lnet.ln_rtrpools == NULL) {
1602 LCONSOLE_ERROR_MSG(0x10c,
1603 "Failed to initialize router buffe pool\n");
1607 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1608 lnet_rtrpool_init(&rtrp[LNET_TINY_BUF_IDX], 0);
1609 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_TINY_BUF_IDX],
1614 lnet_rtrpool_init(&rtrp[LNET_SMALL_BUF_IDX],
1615 LNET_NRB_SMALL_PAGES);
1616 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_SMALL_BUF_IDX],
1621 lnet_rtrpool_init(&rtrp[LNET_LARGE_BUF_IDX],
1622 LNET_NRB_LARGE_PAGES);
1623 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_LARGE_BUF_IDX],
1629 lnet_net_lock(LNET_LOCK_EX);
1630 the_lnet.ln_routing = 1;
1631 lnet_net_unlock(LNET_LOCK_EX);
1635 lnet_rtrpools_free(0);
1640 lnet_rtrpools_adjust_helper(int tiny, int small, int large)
1645 struct lnet_rtrbufpool *rtrp;
1647 /* If the provided values for each buffer pool are different than the
1648 * configured values, we need to take action. */
1650 tiny_router_buffers = tiny;
1651 nrb = lnet_nrb_tiny_calculate();
1652 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1653 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_TINY_BUF_IDX],
1660 small_router_buffers = small;
1661 nrb = lnet_nrb_small_calculate();
1662 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1663 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_SMALL_BUF_IDX],
1670 large_router_buffers = large;
1671 nrb = lnet_nrb_large_calculate();
1672 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1673 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_LARGE_BUF_IDX],
1684 lnet_rtrpools_adjust(int tiny, int small, int large)
1686 /* this function doesn't revert the changes if adding new buffers
1687 * failed. It's up to the user space caller to revert the
1690 if (!the_lnet.ln_routing)
1693 return lnet_rtrpools_adjust_helper(tiny, small, large);
1697 lnet_rtrpools_enable(void)
1701 if (the_lnet.ln_routing)
1704 if (the_lnet.ln_rtrpools == NULL)
1705 /* If routing is turned off, and we have never
1706 * initialized the pools before, just call the
1707 * standard buffer pool allocation routine as
1708 * if we are just configuring this for the first
1710 rc = lnet_rtrpools_alloc(1);
1712 rc = lnet_rtrpools_adjust_helper(0, 0, 0);
1716 lnet_net_lock(LNET_LOCK_EX);
1717 the_lnet.ln_routing = 1;
1719 the_lnet.ln_ping_target->pb_info.pi_features &=
1720 ~LNET_PING_FEAT_RTE_DISABLED;
1721 lnet_net_unlock(LNET_LOCK_EX);
1727 lnet_rtrpools_disable(void)
1729 if (!the_lnet.ln_routing)
1732 lnet_net_lock(LNET_LOCK_EX);
1733 the_lnet.ln_routing = 0;
1734 the_lnet.ln_ping_target->pb_info.pi_features |=
1735 LNET_PING_FEAT_RTE_DISABLED;
1737 tiny_router_buffers = 0;
1738 small_router_buffers = 0;
1739 large_router_buffers = 0;
1740 lnet_net_unlock(LNET_LOCK_EX);
1741 lnet_rtrpools_free(1);
1745 lnet_notify(struct lnet_ni *ni, lnet_nid_t nid, int alive, time64_t when)
1747 struct lnet_peer_ni *lp = NULL;
1748 time64_t now = ktime_get_seconds();
1749 int cpt = lnet_cpt_of_nid(nid, ni);
1751 LASSERT (!in_interrupt ());
1753 CDEBUG (D_NET, "%s notifying %s: %s\n",
1754 (ni == NULL) ? "userspace" : libcfs_nid2str(ni->ni_nid),
1755 libcfs_nid2str(nid),
1756 alive ? "up" : "down");
1759 LNET_NIDNET(ni->ni_nid) != LNET_NIDNET(nid)) {
1760 CWARN("Ignoring notification of %s %s by %s (different net)\n",
1761 libcfs_nid2str(nid), alive ? "birth" : "death",
1762 libcfs_nid2str(ni->ni_nid));
1766 /* can't do predictions... */
1768 CWARN("Ignoring prediction from %s of %s %s "
1769 "%lld seconds in the future\n",
1770 (ni == NULL) ? "userspace" : libcfs_nid2str(ni->ni_nid),
1771 libcfs_nid2str(nid), alive ? "up" : "down", when - now);
1775 if (ni != NULL && !alive && /* LND telling me she's down */
1776 !auto_down) { /* auto-down disabled */
1777 CDEBUG(D_NET, "Auto-down disabled\n");
1783 if (the_lnet.ln_state != LNET_STATE_RUNNING) {
1784 lnet_net_unlock(cpt);
1788 lp = lnet_find_peer_ni_locked(nid);
1791 lnet_net_unlock(cpt);
1792 CDEBUG(D_NET, "%s not found\n", libcfs_nid2str(nid));
1797 * It is possible for this function to be called for the same peer
1798 * but with different NIs. We want to synchronize the notification
1799 * between the different calls. So we will use the lpni_cpt to
1800 * grab the net lock.
1802 if (lp->lpni_cpt != cpt) {
1803 lnet_net_unlock(cpt);
1808 /* We can't fully trust LND on reporting exact peer last_alive
1809 * if he notifies us about dead peer. For example ksocklnd can
1810 * call us with when == _time_when_the_node_was_booted_ if
1811 * no connections were successfully established */
1812 if (ni != NULL && !alive && when < lp->lpni_last_alive)
1813 when = lp->lpni_last_alive;
1815 lnet_notify_locked(lp, ni == NULL, alive, when);
1818 lnet_ni_notify_locked(ni, lp);
1820 lnet_peer_ni_decref_locked(lp);
1822 lnet_net_unlock(cpt);
1825 EXPORT_SYMBOL(lnet_notify);