2 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
4 * Copyright (c) 2011, 2014, Intel Corporation.
6 * This file is part of Portals
7 * http://sourceforge.net/projects/sandiaportals/
9 * Portals is free software; you can redistribute it and/or
10 * modify it under the terms of version 2 of the GNU General Public
11 * License as published by the Free Software Foundation.
13 * Portals is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Portals; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #define DEBUG_SUBSYSTEM S_LNET
25 #include <lnet/lib-lnet.h>
27 #if defined(__KERNEL__) && defined(LNET_ROUTER)
29 #define LNET_NRB_TINY_MIN 512 /* min value for each CPT */
30 #define LNET_NRB_TINY (LNET_NRB_TINY_MIN * 4)
31 #define LNET_NRB_SMALL_MIN 4096 /* min value for each CPT */
32 #define LNET_NRB_SMALL (LNET_NRB_SMALL_MIN * 4)
33 #define LNET_NRB_SMALL_PAGES 1
34 #define LNET_NRB_LARGE_MIN 256 /* min value for each CPT */
35 #define LNET_NRB_LARGE (LNET_NRB_LARGE_MIN * 4)
36 #define LNET_NRB_LARGE_PAGES ((LNET_MTU + PAGE_CACHE_SIZE - 1) >> \
39 static char *forwarding = "";
40 CFS_MODULE_PARM(forwarding, "s", charp, 0444,
41 "Explicitly enable/disable forwarding between networks");
43 static int tiny_router_buffers;
44 CFS_MODULE_PARM(tiny_router_buffers, "i", int, 0444,
45 "# of 0 payload messages to buffer in the router");
46 static int small_router_buffers;
47 CFS_MODULE_PARM(small_router_buffers, "i", int, 0444,
48 "# of small (1 page) messages to buffer in the router");
49 static int large_router_buffers;
50 CFS_MODULE_PARM(large_router_buffers, "i", int, 0444,
51 "# of large messages to buffer in the router");
52 static int peer_buffer_credits = 0;
53 CFS_MODULE_PARM(peer_buffer_credits, "i", int, 0444,
54 "# router buffer credits per peer");
56 static int auto_down = 1;
57 CFS_MODULE_PARM(auto_down, "i", int, 0444,
58 "Automatically mark peers down on comms error");
61 lnet_peer_buffer_credits(lnet_ni_t *ni)
63 /* NI option overrides LNet default */
64 if (ni->ni_peerrtrcredits > 0)
65 return ni->ni_peerrtrcredits;
66 if (peer_buffer_credits > 0)
67 return peer_buffer_credits;
69 /* As an approximation, allow this peer the same number of router
70 * buffers as it is allowed outstanding sends */
71 return ni->ni_peertxcredits;
75 static int lnet_router_checker(void *);
79 lnet_peer_buffer_credits(lnet_ni_t *ni)
86 static int check_routers_before_use = 0;
87 CFS_MODULE_PARM(check_routers_before_use, "i", int, 0444,
88 "Assume routers are down and ping them before use");
90 int avoid_asym_router_failure = 1;
91 CFS_MODULE_PARM(avoid_asym_router_failure, "i", int, 0644,
92 "Avoid asymmetrical router failures (0 to disable)");
94 static int dead_router_check_interval = 60;
95 CFS_MODULE_PARM(dead_router_check_interval, "i", int, 0644,
96 "Seconds between dead router health checks (<= 0 to disable)");
98 static int live_router_check_interval = 60;
99 CFS_MODULE_PARM(live_router_check_interval, "i", int, 0644,
100 "Seconds between live router health checks (<= 0 to disable)");
102 static int router_ping_timeout = 50;
103 CFS_MODULE_PARM(router_ping_timeout, "i", int, 0644,
104 "Seconds to wait for the reply to a router health query");
107 lnet_peers_start_down(void)
109 return check_routers_before_use;
113 lnet_notify_locked(lnet_peer_t *lp, int notifylnd, int alive, cfs_time_t when)
115 if (cfs_time_before(when, lp->lp_timestamp)) { /* out of date information */
116 CDEBUG(D_NET, "Out of date\n");
120 lp->lp_timestamp = when; /* update timestamp */
121 lp->lp_ping_deadline = 0; /* disable ping timeout */
123 if (lp->lp_alive_count != 0 && /* got old news */
124 (!lp->lp_alive) == (!alive)) { /* new date for old news */
125 CDEBUG(D_NET, "Old news\n");
129 /* Flag that notification is outstanding */
131 lp->lp_alive_count++;
132 lp->lp_alive = !(!alive); /* 1 bit! */
134 lp->lp_notifylnd |= notifylnd;
136 lp->lp_ping_feats = LNET_PING_FEAT_INVAL; /* reset */
138 CDEBUG(D_NET, "set %s %d\n", libcfs_nid2str(lp->lp_nid), alive);
142 lnet_ni_notify_locked(lnet_ni_t *ni, lnet_peer_t *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 if (lp->lp_notifying)
154 lp->lp_notifying = 1;
156 while (lp->lp_notify) {
157 alive = lp->lp_alive;
158 notifylnd = lp->lp_notifylnd;
160 lp->lp_notifylnd = 0;
163 if (notifylnd && ni->ni_lnd->lnd_notify != NULL) {
164 lnet_net_unlock(lp->lp_cpt);
166 /* A new notification could happen now; I'll handle it
167 * when control returns to me */
169 (ni->ni_lnd->lnd_notify)(ni, lp->lp_nid, alive);
171 lnet_net_lock(lp->lp_cpt);
175 lp->lp_notifying = 0;
180 lnet_rtr_addref_locked(lnet_peer_t *lp)
182 LASSERT(lp->lp_refcount > 0);
183 LASSERT(lp->lp_rtr_refcount >= 0);
185 /* lnet_net_lock must be exclusively locked */
186 lp->lp_rtr_refcount++;
187 if (lp->lp_rtr_refcount == 1) {
188 struct list_head *pos;
190 /* a simple insertion sort */
191 list_for_each_prev(pos, &the_lnet.ln_routers) {
192 lnet_peer_t *rtr = list_entry(pos, lnet_peer_t,
195 if (rtr->lp_nid < lp->lp_nid)
199 list_add(&lp->lp_rtr_list, pos);
200 /* addref for the_lnet.ln_routers */
201 lnet_peer_addref_locked(lp);
202 the_lnet.ln_routers_version++;
207 lnet_rtr_decref_locked(lnet_peer_t *lp)
209 LASSERT(lp->lp_refcount > 0);
210 LASSERT(lp->lp_rtr_refcount > 0);
212 /* lnet_net_lock must be exclusively locked */
213 lp->lp_rtr_refcount--;
214 if (lp->lp_rtr_refcount == 0) {
215 LASSERT(list_empty(&lp->lp_routes));
217 if (lp->lp_rcd != NULL) {
218 list_add(&lp->lp_rcd->rcd_list,
219 &the_lnet.ln_rcd_deathrow);
223 list_del(&lp->lp_rtr_list);
224 /* decref for the_lnet.ln_routers */
225 lnet_peer_decref_locked(lp);
226 the_lnet.ln_routers_version++;
231 lnet_find_net_locked (__u32 net)
233 lnet_remotenet_t *rnet;
234 struct list_head *tmp;
235 struct list_head *rn_list;
237 LASSERT(!the_lnet.ln_shutdown);
239 rn_list = lnet_net2rnethash(net);
240 list_for_each(tmp, rn_list) {
241 rnet = list_entry(tmp, lnet_remotenet_t, lrn_list);
243 if (rnet->lrn_net == net)
249 static void lnet_shuffle_seed(void)
251 static int seeded = 0;
252 int lnd_type, seed[2];
255 struct list_head *tmp;
260 cfs_get_random_bytes(seed, sizeof(seed));
262 /* Nodes with small feet have little entropy
263 * the NID for this node gives the most entropy in the low bits */
264 list_for_each(tmp, &the_lnet.ln_nis) {
265 ni = list_entry(tmp, lnet_ni_t, ni_list);
266 lnd_type = LNET_NETTYP(LNET_NIDNET(ni->ni_nid));
268 if (lnd_type != LOLND)
269 seed[0] ^= (LNET_NIDADDR(ni->ni_nid) | lnd_type);
272 do_gettimeofday(&tv);
273 cfs_srand(tv.tv_sec ^ seed[0], tv.tv_usec ^ seed[1]);
278 /* NB expects LNET_LOCK held */
280 lnet_add_route_to_rnet(lnet_remotenet_t *rnet, lnet_route_t *route)
282 unsigned int len = 0;
283 unsigned int offset = 0;
288 list_for_each(e, &rnet->lrn_routes) {
292 /* len+1 positions to add a new entry, also prevents division by 0 */
293 offset = cfs_rand() % (len + 1);
294 list_for_each(e, &rnet->lrn_routes) {
299 list_add(&route->lr_list, e);
300 list_add(&route->lr_gwlist, &route->lr_gateway->lp_routes);
302 the_lnet.ln_remote_nets_version++;
303 lnet_rtr_addref_locked(route->lr_gateway);
307 lnet_add_route(__u32 net, unsigned int hops, lnet_nid_t gateway,
308 unsigned int priority)
311 lnet_remotenet_t *rnet;
312 lnet_remotenet_t *rnet2;
318 CDEBUG(D_NET, "Add route: net %s hops %u priority %u gw %s\n",
319 libcfs_net2str(net), hops, priority, libcfs_nid2str(gateway));
321 if (gateway == LNET_NID_ANY ||
322 LNET_NETTYP(LNET_NIDNET(gateway)) == LOLND ||
323 net == LNET_NIDNET(LNET_NID_ANY) ||
324 LNET_NETTYP(net) == LOLND ||
325 LNET_NIDNET(gateway) == net ||
326 hops < 1 || hops > 255)
329 if (lnet_islocalnet(net)) /* it's a local network */
332 /* Assume net, route, all new */
333 LIBCFS_ALLOC(route, sizeof(*route));
334 LIBCFS_ALLOC(rnet, sizeof(*rnet));
335 if (route == NULL || rnet == NULL) {
336 CERROR("Out of memory creating route %s %d %s\n",
337 libcfs_net2str(net), hops, libcfs_nid2str(gateway));
339 LIBCFS_FREE(route, sizeof(*route));
341 LIBCFS_FREE(rnet, sizeof(*rnet));
345 INIT_LIST_HEAD(&rnet->lrn_routes);
347 route->lr_hops = hops;
349 route->lr_priority = priority;
351 lnet_net_lock(LNET_LOCK_EX);
353 rc = lnet_nid2peer_locked(&route->lr_gateway, gateway, LNET_LOCK_EX);
355 lnet_net_unlock(LNET_LOCK_EX);
357 LIBCFS_FREE(route, sizeof(*route));
358 LIBCFS_FREE(rnet, sizeof(*rnet));
360 if (rc == -EHOSTUNREACH) /* gateway is not on a local net. */
361 return rc; /* ignore the route entry */
362 CERROR("Error %d creating route %s %d %s\n", rc,
363 libcfs_net2str(net), hops,
364 libcfs_nid2str(gateway));
368 LASSERT(!the_lnet.ln_shutdown);
370 rnet2 = lnet_find_net_locked(net);
373 list_add_tail(&rnet->lrn_list, lnet_net2rnethash(net));
377 /* Search for a duplicate route (it's a NOOP if it is) */
379 list_for_each(e, &rnet2->lrn_routes) {
380 lnet_route_t *route2 = list_entry(e, lnet_route_t, lr_list);
382 if (route2->lr_gateway == route->lr_gateway) {
387 /* our lookups must be true */
388 LASSERT(route2->lr_gateway->lp_nid != gateway);
392 lnet_peer_addref_locked(route->lr_gateway); /* +1 for notify */
393 lnet_add_route_to_rnet(rnet2, route);
395 ni = route->lr_gateway->lp_ni;
396 lnet_net_unlock(LNET_LOCK_EX);
398 /* XXX Assume alive */
399 if (ni->ni_lnd->lnd_notify != NULL)
400 (ni->ni_lnd->lnd_notify)(ni, gateway, 1);
402 lnet_net_lock(LNET_LOCK_EX);
405 /* -1 for notify or !add_route */
406 lnet_peer_decref_locked(route->lr_gateway);
407 lnet_net_unlock(LNET_LOCK_EX);
413 LIBCFS_FREE(route, sizeof(*route));
417 LIBCFS_FREE(rnet, sizeof(*rnet));
419 /* indicate to startup the router checker if configured */
420 wake_up(&the_lnet.ln_rc_waitq);
426 lnet_check_routes(void)
428 lnet_remotenet_t *rnet;
430 lnet_route_t *route2;
431 struct list_head *e1;
432 struct list_head *e2;
434 struct list_head *rn_list;
437 cpt = lnet_net_lock_current();
439 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) {
440 rn_list = &the_lnet.ln_remote_nets_hash[i];
441 list_for_each(e1, rn_list) {
442 rnet = list_entry(e1, lnet_remotenet_t, lrn_list);
445 list_for_each(e2, &rnet->lrn_routes) {
450 route = list_entry(e2, lnet_route_t,
453 if (route2 == NULL) {
458 if (route->lr_gateway->lp_ni ==
459 route2->lr_gateway->lp_ni)
462 nid1 = route->lr_gateway->lp_nid;
463 nid2 = route2->lr_gateway->lp_nid;
466 lnet_net_unlock(cpt);
468 CERROR("Routes to %s via %s and %s not "
471 libcfs_nid2str(nid1),
472 libcfs_nid2str(nid2));
478 lnet_net_unlock(cpt);
483 lnet_del_route(__u32 net, lnet_nid_t gw_nid)
485 struct lnet_peer *gateway;
486 lnet_remotenet_t *rnet;
488 struct list_head *e1;
489 struct list_head *e2;
491 struct list_head *rn_list;
494 CDEBUG(D_NET, "Del route: net %s : gw %s\n",
495 libcfs_net2str(net), libcfs_nid2str(gw_nid));
497 /* NB Caller may specify either all routes via the given gateway
498 * or a specific route entry actual NIDs) */
500 lnet_net_lock(LNET_LOCK_EX);
501 if (net == LNET_NIDNET(LNET_NID_ANY))
502 rn_list = &the_lnet.ln_remote_nets_hash[0];
504 rn_list = lnet_net2rnethash(net);
507 list_for_each(e1, rn_list) {
508 rnet = list_entry(e1, lnet_remotenet_t, lrn_list);
510 if (!(net == LNET_NIDNET(LNET_NID_ANY) ||
511 net == rnet->lrn_net))
514 list_for_each(e2, &rnet->lrn_routes) {
515 route = list_entry(e2, lnet_route_t, lr_list);
517 gateway = route->lr_gateway;
518 if (!(gw_nid == LNET_NID_ANY ||
519 gw_nid == gateway->lp_nid))
522 list_del(&route->lr_list);
523 list_del(&route->lr_gwlist);
524 the_lnet.ln_remote_nets_version++;
526 if (list_empty(&rnet->lrn_routes))
527 list_del(&rnet->lrn_list);
531 lnet_rtr_decref_locked(gateway);
532 lnet_peer_decref_locked(gateway);
534 lnet_net_unlock(LNET_LOCK_EX);
536 LIBCFS_FREE(route, sizeof(*route));
539 LIBCFS_FREE(rnet, sizeof(*rnet));
542 lnet_net_lock(LNET_LOCK_EX);
547 if (net == LNET_NIDNET(LNET_NID_ANY) &&
548 ++idx < LNET_REMOTE_NETS_HASH_SIZE) {
549 rn_list = &the_lnet.ln_remote_nets_hash[idx];
552 lnet_net_unlock(LNET_LOCK_EX);
558 lnet_destroy_routes (void)
560 lnet_del_route(LNET_NIDNET(LNET_NID_ANY), LNET_NID_ANY);
563 int lnet_get_rtr_pool_cfg(int idx, struct lnet_ioctl_pool_cfg *pool_cfg)
565 int i, rc = -ENOENT, lidx, j;
567 if (the_lnet.ln_rtrpools == NULL)
570 for (i = 0; i < LNET_NRBPOOLS; i++) {
571 lnet_rtrbufpool_t *rbp;
573 lnet_net_lock(LNET_LOCK_EX);
575 cfs_percpt_for_each(rbp, j, the_lnet.ln_rtrpools) {
578 pool_cfg->pl_pools[i].pl_npages =
580 pool_cfg->pl_pools[i].pl_nbuffers =
582 pool_cfg->pl_pools[i].pl_credits =
584 pool_cfg->pl_pools[i].pl_mincredits =
585 rbp[i].rbp_mincredits;
589 lnet_net_unlock(LNET_LOCK_EX);
592 lnet_net_lock(LNET_LOCK_EX);
593 pool_cfg->pl_routing = the_lnet.ln_routing;
594 lnet_net_unlock(LNET_LOCK_EX);
600 lnet_get_route(int idx, __u32 *net, __u32 *hops,
601 lnet_nid_t *gateway, __u32 *alive, __u32 *priority)
603 struct list_head *e1;
604 struct list_head *e2;
605 lnet_remotenet_t *rnet;
609 struct list_head *rn_list;
611 cpt = lnet_net_lock_current();
613 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) {
614 rn_list = &the_lnet.ln_remote_nets_hash[i];
615 list_for_each(e1, rn_list) {
616 rnet = list_entry(e1, lnet_remotenet_t, lrn_list);
618 list_for_each(e2, &rnet->lrn_routes) {
619 route = list_entry(e2, lnet_route_t,
623 *net = rnet->lrn_net;
624 *hops = route->lr_hops;
625 *priority = route->lr_priority;
626 *gateway = route->lr_gateway->lp_nid;
628 route->lr_gateway->lp_alive &&
630 lnet_net_unlock(cpt);
637 lnet_net_unlock(cpt);
642 lnet_swap_pinginfo(lnet_ping_info_t *info)
645 lnet_ni_status_t *stat;
647 __swab32s(&info->pi_magic);
648 __swab32s(&info->pi_features);
649 __swab32s(&info->pi_pid);
650 __swab32s(&info->pi_nnis);
651 for (i = 0; i < info->pi_nnis && i < LNET_MAX_RTR_NIS; i++) {
652 stat = &info->pi_ni[i];
653 __swab64s(&stat->ns_nid);
654 __swab32s(&stat->ns_status);
660 * parse router-checker pinginfo, record number of down NIs for remote
661 * networks on that router.
664 lnet_parse_rc_info(lnet_rc_data_t *rcd)
666 lnet_ping_info_t *info = rcd->rcd_pinginfo;
667 struct lnet_peer *gw = rcd->rcd_gateway;
673 if (info->pi_magic == __swab32(LNET_PROTO_PING_MAGIC))
674 lnet_swap_pinginfo(info);
676 /* NB always racing with network! */
677 if (info->pi_magic != LNET_PROTO_PING_MAGIC) {
678 CDEBUG(D_NET, "%s: Unexpected magic %08x\n",
679 libcfs_nid2str(gw->lp_nid), info->pi_magic);
680 gw->lp_ping_feats = LNET_PING_FEAT_INVAL;
684 gw->lp_ping_feats = info->pi_features;
685 if ((gw->lp_ping_feats & LNET_PING_FEAT_MASK) == 0) {
686 CDEBUG(D_NET, "%s: Unexpected features 0x%x\n",
687 libcfs_nid2str(gw->lp_nid), gw->lp_ping_feats);
688 return; /* nothing I can understand */
691 if ((gw->lp_ping_feats & LNET_PING_FEAT_NI_STATUS) == 0)
692 return; /* can't carry NI status info */
694 list_for_each_entry(rte, &gw->lp_routes, lr_gwlist) {
699 if ((gw->lp_ping_feats & LNET_PING_FEAT_RTE_DISABLED) != 0) {
704 for (i = 0; i < info->pi_nnis && i < LNET_MAX_RTR_NIS; i++) {
705 lnet_ni_status_t *stat = &info->pi_ni[i];
706 lnet_nid_t nid = stat->ns_nid;
708 if (nid == LNET_NID_ANY) {
709 CDEBUG(D_NET, "%s: unexpected LNET_NID_ANY\n",
710 libcfs_nid2str(gw->lp_nid));
711 gw->lp_ping_feats = LNET_PING_FEAT_INVAL;
715 if (LNET_NETTYP(LNET_NIDNET(nid)) == LOLND)
718 if (stat->ns_status == LNET_NI_STATUS_DOWN) {
723 if (stat->ns_status == LNET_NI_STATUS_UP) {
724 if (LNET_NIDNET(nid) == rte->lr_net) {
731 CDEBUG(D_NET, "%s: Unexpected status 0x%x\n",
732 libcfs_nid2str(gw->lp_nid), stat->ns_status);
733 gw->lp_ping_feats = LNET_PING_FEAT_INVAL;
737 if (up) { /* ignore downed NIs if NI for dest network is up */
741 /* if @down is zero and this route is single-hop, it means
742 * we can't find NI for target network */
743 if (down == 0 && rte->lr_hops == 1)
746 rte->lr_downis = down;
751 lnet_router_checker_event(lnet_event_t *event)
753 lnet_rc_data_t *rcd = event->md.user_ptr;
754 struct lnet_peer *lp;
756 LASSERT(rcd != NULL);
758 if (event->unlinked) {
759 LNetInvalidateHandle(&rcd->rcd_mdh);
763 LASSERT(event->type == LNET_EVENT_SEND ||
764 event->type == LNET_EVENT_REPLY);
766 lp = rcd->rcd_gateway;
769 /* NB: it's called with holding lnet_res_lock, we have a few
770 * places need to hold both locks at the same time, please take
771 * care of lock ordering */
772 lnet_net_lock(lp->lp_cpt);
773 if (!lnet_isrouter(lp) || lp->lp_rcd != rcd) {
774 /* ignore if no longer a router or rcd is replaced */
778 if (event->type == LNET_EVENT_SEND) {
779 lp->lp_ping_notsent = 0;
780 if (event->status == 0)
784 /* LNET_EVENT_REPLY */
785 /* A successful REPLY means the router is up. If _any_ comms
786 * to the router fail I assume it's down (this will happen if
787 * we ping alive routers to try to detect router death before
788 * apps get burned). */
790 lnet_notify_locked(lp, 1, (event->status == 0), cfs_time_current());
791 /* The router checker will wake up very shortly and do the
792 * actual notification.
793 * XXX If 'lp' stops being a router before then, it will still
794 * have the notification pending!!! */
796 if (avoid_asym_router_failure && event->status == 0)
797 lnet_parse_rc_info(rcd);
800 lnet_net_unlock(lp->lp_cpt);
804 lnet_wait_known_routerstate(void)
807 struct list_head *entry;
810 LASSERT(the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING);
813 int cpt = lnet_net_lock_current();
816 list_for_each(entry, &the_lnet.ln_routers) {
817 rtr = list_entry(entry, lnet_peer_t, lp_rtr_list);
819 if (rtr->lp_alive_count == 0) {
825 lnet_net_unlock(cpt);
831 lnet_router_checker();
833 cfs_pause(cfs_time_seconds(1));
838 lnet_router_ni_update_locked(lnet_peer_t *gw, __u32 net)
842 if ((gw->lp_ping_feats & LNET_PING_FEAT_NI_STATUS) != 0) {
843 list_for_each_entry(rte, &gw->lp_routes, lr_gwlist) {
844 if (rte->lr_net == net) {
853 lnet_update_ni_status_locked(void)
859 LASSERT(the_lnet.ln_routing);
861 timeout = router_ping_timeout +
862 MAX(live_router_check_interval, dead_router_check_interval);
864 now = cfs_time_current_sec();
865 list_for_each_entry(ni, &the_lnet.ln_nis, ni_list) {
866 if (ni->ni_lnd->lnd_type == LOLND)
869 if (now < ni->ni_last_alive + timeout)
873 /* re-check with lock */
874 if (now < ni->ni_last_alive + timeout) {
879 LASSERT(ni->ni_status != NULL);
881 if (ni->ni_status->ns_status != LNET_NI_STATUS_DOWN) {
882 CDEBUG(D_NET, "NI(%s:%d) status changed to down\n",
883 libcfs_nid2str(ni->ni_nid), timeout);
884 /* NB: so far, this is the only place to set
885 * NI status to "down" */
886 ni->ni_status->ns_status = LNET_NI_STATUS_DOWN;
893 lnet_destroy_rc_data(lnet_rc_data_t *rcd)
895 LASSERT(list_empty(&rcd->rcd_list));
896 /* detached from network */
897 LASSERT(LNetHandleIsInvalid(rcd->rcd_mdh));
899 if (rcd->rcd_gateway != NULL) {
900 int cpt = rcd->rcd_gateway->lp_cpt;
903 lnet_peer_decref_locked(rcd->rcd_gateway);
904 lnet_net_unlock(cpt);
907 if (rcd->rcd_pinginfo != NULL)
908 LIBCFS_FREE(rcd->rcd_pinginfo, LNET_PINGINFO_SIZE);
910 LIBCFS_FREE(rcd, sizeof(*rcd));
913 static lnet_rc_data_t *
914 lnet_create_rc_data_locked(lnet_peer_t *gateway)
916 lnet_rc_data_t *rcd = NULL;
917 lnet_ping_info_t *pi;
921 lnet_net_unlock(gateway->lp_cpt);
923 LIBCFS_ALLOC(rcd, sizeof(*rcd));
927 LNetInvalidateHandle(&rcd->rcd_mdh);
928 INIT_LIST_HEAD(&rcd->rcd_list);
930 LIBCFS_ALLOC(pi, LNET_PINGINFO_SIZE);
934 for (i = 0; i < LNET_MAX_RTR_NIS; i++) {
935 pi->pi_ni[i].ns_nid = LNET_NID_ANY;
936 pi->pi_ni[i].ns_status = LNET_NI_STATUS_INVALID;
938 rcd->rcd_pinginfo = pi;
940 LASSERT (!LNetHandleIsInvalid(the_lnet.ln_rc_eqh));
941 rc = LNetMDBind((lnet_md_t){.start = pi,
943 .length = LNET_PINGINFO_SIZE,
944 .threshold = LNET_MD_THRESH_INF,
945 .options = LNET_MD_TRUNCATE,
946 .eq_handle = the_lnet.ln_rc_eqh},
950 CERROR("Can't bind MD: %d\n", rc);
955 lnet_net_lock(gateway->lp_cpt);
956 /* router table changed or someone has created rcd for this gateway */
957 if (!lnet_isrouter(gateway) || gateway->lp_rcd != NULL) {
958 lnet_net_unlock(gateway->lp_cpt);
962 lnet_peer_addref_locked(gateway);
963 rcd->rcd_gateway = gateway;
964 gateway->lp_rcd = rcd;
965 gateway->lp_ping_notsent = 0;
971 if (!LNetHandleIsInvalid(rcd->rcd_mdh)) {
972 rc = LNetMDUnlink(rcd->rcd_mdh);
975 lnet_destroy_rc_data(rcd);
978 lnet_net_lock(gateway->lp_cpt);
979 return gateway->lp_rcd;
983 lnet_router_check_interval (lnet_peer_t *rtr)
987 secs = rtr->lp_alive ? live_router_check_interval :
988 dead_router_check_interval;
996 lnet_ping_router_locked (lnet_peer_t *rtr)
998 lnet_rc_data_t *rcd = NULL;
999 cfs_time_t now = cfs_time_current();
1002 lnet_peer_addref_locked(rtr);
1004 if (rtr->lp_ping_deadline != 0 && /* ping timed out? */
1005 cfs_time_after(now, rtr->lp_ping_deadline))
1006 lnet_notify_locked(rtr, 1, 0, now);
1008 /* Run any outstanding notifications */
1009 lnet_ni_notify_locked(rtr->lp_ni, rtr);
1011 if (!lnet_isrouter(rtr) ||
1012 the_lnet.ln_rc_state != LNET_RC_STATE_RUNNING) {
1013 /* router table changed or router checker is shutting down */
1014 lnet_peer_decref_locked(rtr);
1018 rcd = rtr->lp_rcd != NULL ?
1019 rtr->lp_rcd : lnet_create_rc_data_locked(rtr);
1024 secs = lnet_router_check_interval(rtr);
1027 "rtr %s %d: deadline %lu ping_notsent %d alive %d "
1028 "alive_count %d lp_ping_timestamp %lu\n",
1029 libcfs_nid2str(rtr->lp_nid), secs,
1030 rtr->lp_ping_deadline, rtr->lp_ping_notsent,
1031 rtr->lp_alive, rtr->lp_alive_count, rtr->lp_ping_timestamp);
1033 if (secs != 0 && !rtr->lp_ping_notsent &&
1034 cfs_time_after(now, cfs_time_add(rtr->lp_ping_timestamp,
1035 cfs_time_seconds(secs)))) {
1037 lnet_process_id_t id;
1038 lnet_handle_md_t mdh;
1040 id.nid = rtr->lp_nid;
1041 id.pid = LNET_PID_LUSTRE;
1042 CDEBUG(D_NET, "Check: %s\n", libcfs_id2str(id));
1044 rtr->lp_ping_notsent = 1;
1045 rtr->lp_ping_timestamp = now;
1049 if (rtr->lp_ping_deadline == 0) {
1050 rtr->lp_ping_deadline =
1051 cfs_time_shift(router_ping_timeout);
1054 lnet_net_unlock(rtr->lp_cpt);
1056 rc = LNetGet(LNET_NID_ANY, mdh, id, LNET_RESERVED_PORTAL,
1057 LNET_PROTO_PING_MATCHBITS, 0);
1059 lnet_net_lock(rtr->lp_cpt);
1061 rtr->lp_ping_notsent = 0; /* no event pending */
1064 lnet_peer_decref_locked(rtr);
1069 lnet_router_checker_start(void)
1074 struct task_struct *task;
1075 #else /* __KERNEL__ */
1079 int router_checker_max_eqsize = 10240;
1081 LASSERT (check_routers_before_use);
1082 LASSERT (dead_router_check_interval > 0);
1086 /* As an approximation, allow each router the same number of
1087 * outstanding events as it is allowed outstanding sends */
1089 version = the_lnet.ln_routers_version;
1090 list_for_each_entry(rtr, &the_lnet.ln_routers, lp_rtr_list) {
1091 lnet_ni_t *ni = rtr->lp_ni;
1092 lnet_process_id_t id;
1095 eqsz += ni->ni_peertxcredits;
1097 /* one async ping reply per router */
1098 id.nid = rtr->lp_nid;
1099 id.pid = LNET_PID_LUSTRE;
1103 rc = LNetSetAsync(id, 1);
1105 CWARN("LNetSetAsync %s failed: %d\n",
1106 libcfs_id2str(id), rc);
1111 /* NB router list doesn't change in userspace */
1112 LASSERT(version == the_lnet.ln_routers_version);
1119 "No router found, not starting router checker\n");
1123 /* at least allow a SENT and a REPLY per router */
1124 if (router_checker_max_eqsize < 2 * nrtr)
1125 router_checker_max_eqsize = 2 * nrtr;
1128 if (eqsz > router_checker_max_eqsize)
1129 eqsz = router_checker_max_eqsize;
1132 LASSERT (the_lnet.ln_rc_state == LNET_RC_STATE_SHUTDOWN);
1134 if (check_routers_before_use &&
1135 dead_router_check_interval <= 0) {
1136 LCONSOLE_ERROR_MSG(0x10a, "'dead_router_check_interval' must be"
1137 " set if 'check_routers_before_use' is set"
1143 sema_init(&the_lnet.ln_rc_signal, 0);
1144 /* EQ size doesn't matter; the callback is guaranteed to get every
1147 rc = LNetEQAlloc(eqsz, lnet_router_checker_event,
1148 &the_lnet.ln_rc_eqh);
1150 rc = LNetEQAlloc(eqsz, LNET_EQ_HANDLER_NONE,
1151 &the_lnet.ln_rc_eqh);
1154 CERROR("Can't allocate EQ(%d): %d\n", eqsz, rc);
1158 the_lnet.ln_rc_state = LNET_RC_STATE_RUNNING;
1160 task = kthread_run(lnet_router_checker, NULL, "router_checker");
1163 CERROR("Can't start router checker thread: %d\n", rc);
1164 /* block until event callback signals exit */
1165 down(&the_lnet.ln_rc_signal);
1166 rc = LNetEQFree(the_lnet.ln_rc_eqh);
1168 the_lnet.ln_rc_state = LNET_RC_STATE_SHUTDOWN;
1173 if (check_routers_before_use) {
1174 /* Note that a helpful side-effect of pinging all known routers
1175 * at startup is that it makes them drop stale connections they
1176 * may have to a previous instance of me. */
1177 lnet_wait_known_routerstate();
1184 lnet_router_checker_stop (void)
1188 if (the_lnet.ln_rc_state == LNET_RC_STATE_SHUTDOWN)
1191 LASSERT (the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING);
1192 the_lnet.ln_rc_state = LNET_RC_STATE_STOPPING;
1193 /* wakeup the RC thread if it's sleeping */
1194 wake_up(&the_lnet.ln_rc_waitq);
1197 /* block until event callback signals exit */
1198 down(&the_lnet.ln_rc_signal);
1200 lnet_router_checker();
1202 LASSERT(the_lnet.ln_rc_state == LNET_RC_STATE_SHUTDOWN);
1204 rc = LNetEQFree(the_lnet.ln_rc_eqh);
1210 lnet_prune_rc_data(int wait_unlink)
1212 lnet_rc_data_t *rcd;
1213 lnet_rc_data_t *tmp;
1215 struct list_head head;
1218 if (likely(the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING &&
1219 list_empty(&the_lnet.ln_rcd_deathrow) &&
1220 list_empty(&the_lnet.ln_rcd_zombie)))
1223 INIT_LIST_HEAD(&head);
1225 lnet_net_lock(LNET_LOCK_EX);
1227 if (the_lnet.ln_rc_state != LNET_RC_STATE_RUNNING) {
1228 /* router checker is stopping, prune all */
1229 list_for_each_entry(lp, &the_lnet.ln_routers,
1231 if (lp->lp_rcd == NULL)
1234 LASSERT(list_empty(&lp->lp_rcd->rcd_list));
1235 list_add(&lp->lp_rcd->rcd_list,
1236 &the_lnet.ln_rcd_deathrow);
1241 /* unlink all RCDs on deathrow list */
1242 list_splice_init(&the_lnet.ln_rcd_deathrow, &head);
1244 if (!list_empty(&head)) {
1245 lnet_net_unlock(LNET_LOCK_EX);
1247 list_for_each_entry(rcd, &head, rcd_list)
1248 LNetMDUnlink(rcd->rcd_mdh);
1250 lnet_net_lock(LNET_LOCK_EX);
1253 list_splice_init(&head, &the_lnet.ln_rcd_zombie);
1255 /* release all zombie RCDs */
1256 while (!list_empty(&the_lnet.ln_rcd_zombie)) {
1257 list_for_each_entry_safe(rcd, tmp, &the_lnet.ln_rcd_zombie,
1259 if (LNetHandleIsInvalid(rcd->rcd_mdh))
1260 list_move(&rcd->rcd_list, &head);
1263 wait_unlink = wait_unlink &&
1264 !list_empty(&the_lnet.ln_rcd_zombie);
1266 lnet_net_unlock(LNET_LOCK_EX);
1268 while (!list_empty(&head)) {
1269 rcd = list_entry(head.next,
1270 lnet_rc_data_t, rcd_list);
1271 list_del_init(&rcd->rcd_list);
1272 lnet_destroy_rc_data(rcd);
1279 CDEBUG(((i & (-i)) == i) ? D_WARNING : D_NET,
1280 "Waiting for rc buffers to unlink\n");
1281 cfs_pause(cfs_time_seconds(1) / 4);
1283 lnet_net_lock(LNET_LOCK_EX);
1286 lnet_net_unlock(LNET_LOCK_EX);
1290 #if defined(__KERNEL__) && defined(LNET_ROUTER)
1293 * This function is called to check if the RC should block indefinitely.
1294 * It's called from lnet_router_checker() as well as being passed to
1295 * wait_event_interruptible() to avoid the lost wake_up problem.
1297 * When it's called from wait_event_interruptible() it is necessary to
1298 * also not sleep if the rc state is not running to avoid a deadlock
1299 * when the system is shutting down
1302 lnet_router_checker_active(void)
1304 if (the_lnet.ln_rc_state != LNET_RC_STATE_RUNNING)
1307 /* Router Checker thread needs to run when routing is enabled in
1308 * order to call lnet_update_ni_status_locked() */
1309 if (the_lnet.ln_routing)
1312 return !list_empty(&the_lnet.ln_routers) &&
1313 (live_router_check_interval > 0 ||
1314 dead_router_check_interval > 0);
1318 lnet_router_checker(void *arg)
1321 struct list_head *entry;
1323 cfs_block_allsigs();
1325 LASSERT (the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING);
1327 while (the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING) {
1332 cpt = lnet_net_lock_current();
1334 version = the_lnet.ln_routers_version;
1336 list_for_each(entry, &the_lnet.ln_routers) {
1337 rtr = list_entry(entry, lnet_peer_t, lp_rtr_list);
1339 cpt2 = lnet_cpt_of_nid_locked(rtr->lp_nid);
1341 lnet_net_unlock(cpt);
1344 /* the routers list has changed */
1345 if (version != the_lnet.ln_routers_version)
1349 lnet_ping_router_locked(rtr);
1351 /* NB dropped lock */
1352 if (version != the_lnet.ln_routers_version) {
1353 /* the routers list has changed */
1358 if (the_lnet.ln_routing)
1359 lnet_update_ni_status_locked();
1361 lnet_net_unlock(cpt);
1363 lnet_prune_rc_data(0); /* don't wait for UNLINK */
1365 /* Call cfs_pause() here always adds 1 to load average
1366 * because kernel counts # active tasks as nr_running
1367 * + nr_uninterruptible. */
1368 /* if there are any routes then wakeup every second. If
1369 * there are no routes then sleep indefinitely until woken
1370 * up by a user adding a route */
1371 if (!lnet_router_checker_active())
1372 wait_event_interruptible(the_lnet.ln_rc_waitq,
1373 lnet_router_checker_active());
1375 wait_event_interruptible_timeout(the_lnet.ln_rc_waitq,
1377 cfs_time_seconds(1));
1380 LASSERT(the_lnet.ln_rc_state == LNET_RC_STATE_STOPPING);
1382 lnet_prune_rc_data(1); /* wait for UNLINK */
1384 the_lnet.ln_rc_state = LNET_RC_STATE_SHUTDOWN;
1385 up(&the_lnet.ln_rc_signal);
1386 /* The unlink event callback will signal final completion */
1391 lnet_destroy_rtrbuf(lnet_rtrbuf_t *rb, int npages)
1393 int sz = offsetof(lnet_rtrbuf_t, rb_kiov[npages]);
1395 while (--npages >= 0)
1396 __free_page(rb->rb_kiov[npages].kiov_page);
1398 LIBCFS_FREE(rb, sz);
1401 static lnet_rtrbuf_t *
1402 lnet_new_rtrbuf(lnet_rtrbufpool_t *rbp, int cpt)
1404 int npages = rbp->rbp_npages;
1405 int sz = offsetof(lnet_rtrbuf_t, rb_kiov[npages]);
1410 LIBCFS_CPT_ALLOC(rb, lnet_cpt_table(), cpt, sz);
1416 for (i = 0; i < npages; i++) {
1417 page = cfs_page_cpt_alloc(lnet_cpt_table(), cpt,
1418 __GFP_ZERO | GFP_IOFS);
1421 __free_page(rb->rb_kiov[i].kiov_page);
1423 LIBCFS_FREE(rb, sz);
1427 rb->rb_kiov[i].kiov_len = PAGE_CACHE_SIZE;
1428 rb->rb_kiov[i].kiov_offset = 0;
1429 rb->rb_kiov[i].kiov_page = page;
1436 lnet_rtrpool_free_bufs(lnet_rtrbufpool_t *rbp, int cpt)
1438 int npages = rbp->rbp_npages;
1440 struct list_head tmp;
1442 if (rbp->rbp_nbuffers == 0) /* not initialized or already freed */
1445 INIT_LIST_HEAD(&tmp);
1448 lnet_drop_routed_msgs_locked(&rbp->rbp_msgs, cpt);
1449 list_splice_init(&rbp->rbp_bufs, &tmp);
1450 rbp->rbp_nbuffers = rbp->rbp_credits = 0;
1451 rbp->rbp_mincredits = 0;
1452 lnet_net_unlock(cpt);
1454 /* Free buffers on the free list. */
1455 while (!list_empty(&tmp)) {
1456 rb = list_entry(tmp.next, lnet_rtrbuf_t, rb_list);
1457 list_del(&rb->rb_list);
1458 lnet_destroy_rtrbuf(rb, npages);
1463 lnet_rtrpool_adjust_bufs(lnet_rtrbufpool_t *rbp, int nbufs, int cpt)
1465 struct list_head rb_list;
1468 int num_buffers = 0;
1469 int npages = rbp->rbp_npages;
1471 /* If we are called for less buffers than already in the pool, we
1472 * just lower the nbuffers number and excess buffers will be
1473 * thrown away as they are returned to the free list. Credits
1474 * then get adjusted as well. */
1475 if (nbufs <= rbp->rbp_nbuffers) {
1477 rbp->rbp_nbuffers = nbufs;
1478 lnet_net_unlock(cpt);
1482 INIT_LIST_HEAD(&rb_list);
1484 /* allocate the buffers on a local list first. If all buffers are
1485 * allocated successfully then join this list to the rbp buffer
1486 * list. If not then free all allocated buffers. */
1487 num_rb = rbp->rbp_nbuffers;
1489 while (num_rb < nbufs) {
1490 rb = lnet_new_rtrbuf(rbp, cpt);
1492 CERROR("Failed to allocate %d route bufs of %d pages\n",
1497 list_add(&rb->rb_list, &rb_list);
1504 list_splice_tail(&rb_list, &rbp->rbp_bufs);
1505 rbp->rbp_nbuffers += num_buffers;
1506 rbp->rbp_credits += num_buffers;
1507 rbp->rbp_mincredits = rbp->rbp_credits;
1508 /* We need to schedule blocked msg using the newly
1510 while (!list_empty(&rbp->rbp_bufs) &&
1511 !list_empty(&rbp->rbp_msgs))
1512 lnet_schedule_blocked_locked(rbp);
1514 lnet_net_unlock(cpt);
1519 while (!list_empty(&rb_list)) {
1520 rb = list_entry(rb_list.next, lnet_rtrbuf_t, rb_list);
1521 list_del(&rb->rb_list);
1522 lnet_destroy_rtrbuf(rb, npages);
1529 lnet_rtrpool_init(lnet_rtrbufpool_t *rbp, int npages)
1531 INIT_LIST_HEAD(&rbp->rbp_msgs);
1532 INIT_LIST_HEAD(&rbp->rbp_bufs);
1534 rbp->rbp_npages = npages;
1535 rbp->rbp_credits = 0;
1536 rbp->rbp_mincredits = 0;
1540 lnet_rtrpools_free(int keep_pools)
1542 lnet_rtrbufpool_t *rtrp;
1545 if (the_lnet.ln_rtrpools == NULL) /* uninitialized or freed */
1548 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1549 lnet_rtrpool_free_bufs(&rtrp[LNET_TINY_BUF_IDX], i);
1550 lnet_rtrpool_free_bufs(&rtrp[LNET_SMALL_BUF_IDX], i);
1551 lnet_rtrpool_free_bufs(&rtrp[LNET_LARGE_BUF_IDX], i);
1555 cfs_percpt_free(the_lnet.ln_rtrpools);
1556 the_lnet.ln_rtrpools = NULL;
1561 lnet_nrb_tiny_calculate(void)
1563 int nrbs = LNET_NRB_TINY;
1565 if (tiny_router_buffers < 0) {
1566 LCONSOLE_ERROR_MSG(0x10c,
1567 "tiny_router_buffers=%d invalid when "
1568 "routing enabled\n", tiny_router_buffers);
1572 if (tiny_router_buffers > 0)
1573 nrbs = tiny_router_buffers;
1575 nrbs /= LNET_CPT_NUMBER;
1576 return max(nrbs, LNET_NRB_TINY_MIN);
1580 lnet_nrb_small_calculate(void)
1582 int nrbs = LNET_NRB_SMALL;
1584 if (small_router_buffers < 0) {
1585 LCONSOLE_ERROR_MSG(0x10c,
1586 "small_router_buffers=%d invalid when "
1587 "routing enabled\n", small_router_buffers);
1591 if (small_router_buffers > 0)
1592 nrbs = small_router_buffers;
1594 nrbs /= LNET_CPT_NUMBER;
1595 return max(nrbs, LNET_NRB_SMALL_MIN);
1599 lnet_nrb_large_calculate(void)
1601 int nrbs = LNET_NRB_LARGE;
1603 if (large_router_buffers < 0) {
1604 LCONSOLE_ERROR_MSG(0x10c,
1605 "large_router_buffers=%d invalid when "
1606 "routing enabled\n", large_router_buffers);
1610 if (large_router_buffers > 0)
1611 nrbs = large_router_buffers;
1613 nrbs /= LNET_CPT_NUMBER;
1614 return max(nrbs, LNET_NRB_LARGE_MIN);
1618 lnet_rtrpools_alloc(int im_a_router)
1620 lnet_rtrbufpool_t *rtrp;
1627 if (!strcmp(forwarding, "")) {
1628 /* not set either way */
1631 } else if (!strcmp(forwarding, "disabled")) {
1632 /* explicitly disabled */
1634 } else if (!strcmp(forwarding, "enabled")) {
1635 /* explicitly enabled */
1637 LCONSOLE_ERROR_MSG(0x10b, "'forwarding' not set to either "
1638 "'enabled' or 'disabled'\n");
1642 nrb_tiny = lnet_nrb_tiny_calculate();
1646 nrb_small = lnet_nrb_small_calculate();
1650 nrb_large = lnet_nrb_large_calculate();
1654 the_lnet.ln_rtrpools = cfs_percpt_alloc(lnet_cpt_table(),
1656 sizeof(lnet_rtrbufpool_t));
1657 if (the_lnet.ln_rtrpools == NULL) {
1658 LCONSOLE_ERROR_MSG(0x10c,
1659 "Failed to initialize router buffe pool\n");
1663 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1664 lnet_rtrpool_init(&rtrp[LNET_TINY_BUF_IDX], 0);
1665 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_TINY_BUF_IDX],
1670 lnet_rtrpool_init(&rtrp[LNET_SMALL_BUF_IDX],
1671 LNET_NRB_SMALL_PAGES);
1672 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_SMALL_BUF_IDX],
1677 lnet_rtrpool_init(&rtrp[LNET_LARGE_BUF_IDX],
1678 LNET_NRB_LARGE_PAGES);
1679 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_LARGE_BUF_IDX],
1685 lnet_net_lock(LNET_LOCK_EX);
1686 the_lnet.ln_routing = 1;
1687 lnet_net_unlock(LNET_LOCK_EX);
1691 lnet_rtrpools_free(0);
1696 lnet_rtrpools_adjust_helper(int tiny, int small, int large)
1701 lnet_rtrbufpool_t *rtrp;
1703 /* If the provided values for each buffer pool are different than the
1704 * configured values, we need to take action. */
1706 tiny_router_buffers = tiny;
1707 nrb = lnet_nrb_tiny_calculate();
1708 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1709 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_TINY_BUF_IDX],
1716 small_router_buffers = small;
1717 nrb = lnet_nrb_small_calculate();
1718 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1719 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_SMALL_BUF_IDX],
1726 large_router_buffers = large;
1727 nrb = lnet_nrb_large_calculate();
1728 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1729 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_LARGE_BUF_IDX],
1740 lnet_rtrpools_adjust(int tiny, int small, int large)
1742 /* this function doesn't revert the changes if adding new buffers
1743 * failed. It's up to the user space caller to revert the
1746 if (!the_lnet.ln_routing)
1749 return lnet_rtrpools_adjust_helper(tiny, small, large);
1753 lnet_rtrpools_enable(void)
1757 if (the_lnet.ln_routing)
1760 if (the_lnet.ln_rtrpools == NULL)
1761 /* If routing is turned off, and we have never
1762 * initialized the pools before, just call the
1763 * standard buffer pool allocation routine as
1764 * if we are just configuring this for the first
1766 return lnet_rtrpools_alloc(1);
1768 rc = lnet_rtrpools_adjust_helper(0, 0, 0);
1772 lnet_net_lock(LNET_LOCK_EX);
1773 the_lnet.ln_routing = 1;
1775 the_lnet.ln_ping_info->pi_features &= ~LNET_PING_FEAT_RTE_DISABLED;
1776 lnet_net_unlock(LNET_LOCK_EX);
1782 lnet_rtrpools_disable(void)
1784 if (!the_lnet.ln_routing)
1787 lnet_net_lock(LNET_LOCK_EX);
1788 the_lnet.ln_routing = 0;
1789 the_lnet.ln_ping_info->pi_features |= LNET_PING_FEAT_RTE_DISABLED;
1791 tiny_router_buffers = 0;
1792 small_router_buffers = 0;
1793 large_router_buffers = 0;
1794 lnet_net_unlock(LNET_LOCK_EX);
1795 lnet_rtrpools_free(1);
1799 lnet_notify(lnet_ni_t *ni, lnet_nid_t nid, int alive, cfs_time_t when)
1801 struct lnet_peer *lp = NULL;
1802 cfs_time_t now = cfs_time_current();
1803 int cpt = lnet_cpt_of_nid(nid);
1805 LASSERT (!in_interrupt ());
1807 CDEBUG (D_NET, "%s notifying %s: %s\n",
1808 (ni == NULL) ? "userspace" : libcfs_nid2str(ni->ni_nid),
1809 libcfs_nid2str(nid),
1810 alive ? "up" : "down");
1813 LNET_NIDNET(ni->ni_nid) != LNET_NIDNET(nid)) {
1814 CWARN ("Ignoring notification of %s %s by %s (different net)\n",
1815 libcfs_nid2str(nid), alive ? "birth" : "death",
1816 libcfs_nid2str(ni->ni_nid));
1820 /* can't do predictions... */
1821 if (cfs_time_after(when, now)) {
1822 CWARN ("Ignoring prediction from %s of %s %s "
1823 "%ld seconds in the future\n",
1824 (ni == NULL) ? "userspace" : libcfs_nid2str(ni->ni_nid),
1825 libcfs_nid2str(nid), alive ? "up" : "down",
1826 cfs_duration_sec(cfs_time_sub(when, now)));
1830 if (ni != NULL && !alive && /* LND telling me she's down */
1831 !auto_down) { /* auto-down disabled */
1832 CDEBUG(D_NET, "Auto-down disabled\n");
1838 if (the_lnet.ln_shutdown) {
1839 lnet_net_unlock(cpt);
1843 lp = lnet_find_peer_locked(the_lnet.ln_peer_tables[cpt], nid);
1846 lnet_net_unlock(cpt);
1847 CDEBUG(D_NET, "%s not found\n", libcfs_nid2str(nid));
1851 /* We can't fully trust LND on reporting exact peer last_alive
1852 * if he notifies us about dead peer. For example ksocklnd can
1853 * call us with when == _time_when_the_node_was_booted_ if
1854 * no connections were successfully established */
1855 if (ni != NULL && !alive && when < lp->lp_last_alive)
1856 when = lp->lp_last_alive;
1858 lnet_notify_locked(lp, ni == NULL, alive, when);
1861 lnet_ni_notify_locked(ni, lp);
1863 lnet_peer_decref_locked(lp);
1865 lnet_net_unlock(cpt);
1868 EXPORT_SYMBOL(lnet_notify);
1871 lnet_get_tunables (void)
1879 lnet_notify (lnet_ni_t *ni, lnet_nid_t nid, int alive, cfs_time_t when)
1885 lnet_router_checker (void)
1887 static time_t last = 0;
1888 static int running = 0;
1890 time_t now = cfs_time_current_sec();
1891 int interval = now - last;
1896 /* It's no use to call me again within a sec - all intervals and
1897 * timeouts are measured in seconds */
1898 if (last != 0 && interval < 2)
1902 interval > MAX(live_router_check_interval,
1903 dead_router_check_interval))
1904 CNETERR("Checker(%d/%d) not called for %d seconds\n",
1905 live_router_check_interval, dead_router_check_interval,
1908 LASSERT(LNET_CPT_NUMBER == 1);
1911 LASSERT(!running); /* recursion check */
1917 if (the_lnet.ln_rc_state == LNET_RC_STATE_STOPPING)
1918 lnet_prune_rc_data(0); /* unlink all rcd and nowait */
1920 /* consume all pending events */
1925 /* NB ln_rc_eqh must be the 1st in 'eventqs' otherwise the
1926 * recursion breaker in LNetEQPoll would fail */
1927 rc = LNetEQPoll(&the_lnet.ln_rc_eqh, 1, 0, &ev, &i);
1928 if (rc == 0) /* no event pending */
1931 /* NB a lost SENT prevents me from pinging a router again */
1932 if (rc == -EOVERFLOW) {
1933 CERROR("Dropped an event!!!\n");
1939 lnet_router_checker_event(&ev);
1942 if (the_lnet.ln_rc_state == LNET_RC_STATE_STOPPING) {
1943 lnet_prune_rc_data(1); /* release rcd */
1944 the_lnet.ln_rc_state = LNET_RC_STATE_SHUTDOWN;
1949 LASSERT (the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING);
1953 version = the_lnet.ln_routers_version;
1954 list_for_each_entry(rtr, &the_lnet.ln_routers, lp_rtr_list) {
1955 lnet_ping_router_locked(rtr);
1956 LASSERT(version == the_lnet.ln_routers_version);
1961 running = 0; /* lock only needed for the recursion check */
1965 /* NB lnet_peers_start_down depends on me,
1966 * so must be called before any peer creation */
1968 lnet_get_tunables (void)
1972 s = getenv("LNET_ROUTER_PING_TIMEOUT");
1973 if (s != NULL) router_ping_timeout = atoi(s);
1975 s = getenv("LNET_LIVE_ROUTER_CHECK_INTERVAL");
1976 if (s != NULL) live_router_check_interval = atoi(s);
1978 s = getenv("LNET_DEAD_ROUTER_CHECK_INTERVAL");
1979 if (s != NULL) dead_router_check_interval = atoi(s);
1981 /* This replaces old lnd_notify mechanism */
1982 check_routers_before_use = 1;
1983 if (dead_router_check_interval <= 0)
1984 dead_router_check_interval = 30;
1988 lnet_rtrpools_free(int keep_pools)
1993 lnet_rtrpools_alloc(int im_a_arouter)