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));
423 lnet_check_routes(void)
425 lnet_remotenet_t *rnet;
427 lnet_route_t *route2;
428 struct list_head *e1;
429 struct list_head *e2;
431 struct list_head *rn_list;
434 cpt = lnet_net_lock_current();
436 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) {
437 rn_list = &the_lnet.ln_remote_nets_hash[i];
438 list_for_each(e1, rn_list) {
439 rnet = list_entry(e1, lnet_remotenet_t, lrn_list);
442 list_for_each(e2, &rnet->lrn_routes) {
447 route = list_entry(e2, lnet_route_t,
450 if (route2 == NULL) {
455 if (route->lr_gateway->lp_ni ==
456 route2->lr_gateway->lp_ni)
459 nid1 = route->lr_gateway->lp_nid;
460 nid2 = route2->lr_gateway->lp_nid;
463 lnet_net_unlock(cpt);
465 CERROR("Routes to %s via %s and %s not "
468 libcfs_nid2str(nid1),
469 libcfs_nid2str(nid2));
475 lnet_net_unlock(cpt);
480 lnet_del_route(__u32 net, lnet_nid_t gw_nid)
482 struct lnet_peer *gateway;
483 lnet_remotenet_t *rnet;
485 struct list_head *e1;
486 struct list_head *e2;
488 struct list_head *rn_list;
491 CDEBUG(D_NET, "Del route: net %s : gw %s\n",
492 libcfs_net2str(net), libcfs_nid2str(gw_nid));
494 /* NB Caller may specify either all routes via the given gateway
495 * or a specific route entry actual NIDs) */
497 lnet_net_lock(LNET_LOCK_EX);
498 if (net == LNET_NIDNET(LNET_NID_ANY))
499 rn_list = &the_lnet.ln_remote_nets_hash[0];
501 rn_list = lnet_net2rnethash(net);
504 list_for_each(e1, rn_list) {
505 rnet = list_entry(e1, lnet_remotenet_t, lrn_list);
507 if (!(net == LNET_NIDNET(LNET_NID_ANY) ||
508 net == rnet->lrn_net))
511 list_for_each(e2, &rnet->lrn_routes) {
512 route = list_entry(e2, lnet_route_t, lr_list);
514 gateway = route->lr_gateway;
515 if (!(gw_nid == LNET_NID_ANY ||
516 gw_nid == gateway->lp_nid))
519 list_del(&route->lr_list);
520 list_del(&route->lr_gwlist);
521 the_lnet.ln_remote_nets_version++;
523 if (list_empty(&rnet->lrn_routes))
524 list_del(&rnet->lrn_list);
528 lnet_rtr_decref_locked(gateway);
529 lnet_peer_decref_locked(gateway);
531 lnet_net_unlock(LNET_LOCK_EX);
533 LIBCFS_FREE(route, sizeof(*route));
536 LIBCFS_FREE(rnet, sizeof(*rnet));
539 lnet_net_lock(LNET_LOCK_EX);
544 if (net == LNET_NIDNET(LNET_NID_ANY) &&
545 ++idx < LNET_REMOTE_NETS_HASH_SIZE) {
546 rn_list = &the_lnet.ln_remote_nets_hash[idx];
549 lnet_net_unlock(LNET_LOCK_EX);
555 lnet_destroy_routes (void)
557 lnet_del_route(LNET_NIDNET(LNET_NID_ANY), LNET_NID_ANY);
560 int lnet_get_rtr_pool_cfg(int idx, struct lnet_ioctl_pool_cfg *pool_cfg)
562 int i, rc = -ENOENT, lidx, j;
564 if (the_lnet.ln_rtrpools == NULL)
567 for (i = 0; i < LNET_NRBPOOLS; i++) {
568 lnet_rtrbufpool_t *rbp;
570 lnet_net_lock(LNET_LOCK_EX);
572 cfs_percpt_for_each(rbp, j, the_lnet.ln_rtrpools) {
575 pool_cfg->pl_pools[i].pl_npages =
577 pool_cfg->pl_pools[i].pl_nbuffers =
579 pool_cfg->pl_pools[i].pl_credits =
581 pool_cfg->pl_pools[i].pl_mincredits =
582 rbp[i].rbp_mincredits;
586 lnet_net_unlock(LNET_LOCK_EX);
589 lnet_net_lock(LNET_LOCK_EX);
590 pool_cfg->pl_routing = the_lnet.ln_routing;
591 lnet_net_unlock(LNET_LOCK_EX);
597 lnet_get_route(int idx, __u32 *net, __u32 *hops,
598 lnet_nid_t *gateway, __u32 *alive, __u32 *priority)
600 struct list_head *e1;
601 struct list_head *e2;
602 lnet_remotenet_t *rnet;
606 struct list_head *rn_list;
608 cpt = lnet_net_lock_current();
610 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) {
611 rn_list = &the_lnet.ln_remote_nets_hash[i];
612 list_for_each(e1, rn_list) {
613 rnet = list_entry(e1, lnet_remotenet_t, lrn_list);
615 list_for_each(e2, &rnet->lrn_routes) {
616 route = list_entry(e2, lnet_route_t,
620 *net = rnet->lrn_net;
621 *hops = route->lr_hops;
622 *priority = route->lr_priority;
623 *gateway = route->lr_gateway->lp_nid;
625 route->lr_gateway->lp_alive &&
627 lnet_net_unlock(cpt);
634 lnet_net_unlock(cpt);
639 lnet_swap_pinginfo(lnet_ping_info_t *info)
642 lnet_ni_status_t *stat;
644 __swab32s(&info->pi_magic);
645 __swab32s(&info->pi_features);
646 __swab32s(&info->pi_pid);
647 __swab32s(&info->pi_nnis);
648 for (i = 0; i < info->pi_nnis && i < LNET_MAX_RTR_NIS; i++) {
649 stat = &info->pi_ni[i];
650 __swab64s(&stat->ns_nid);
651 __swab32s(&stat->ns_status);
657 * parse router-checker pinginfo, record number of down NIs for remote
658 * networks on that router.
661 lnet_parse_rc_info(lnet_rc_data_t *rcd)
663 lnet_ping_info_t *info = rcd->rcd_pinginfo;
664 struct lnet_peer *gw = rcd->rcd_gateway;
670 if (info->pi_magic == __swab32(LNET_PROTO_PING_MAGIC))
671 lnet_swap_pinginfo(info);
673 /* NB always racing with network! */
674 if (info->pi_magic != LNET_PROTO_PING_MAGIC) {
675 CDEBUG(D_NET, "%s: Unexpected magic %08x\n",
676 libcfs_nid2str(gw->lp_nid), info->pi_magic);
677 gw->lp_ping_feats = LNET_PING_FEAT_INVAL;
681 gw->lp_ping_feats = info->pi_features;
682 if ((gw->lp_ping_feats & LNET_PING_FEAT_MASK) == 0) {
683 CDEBUG(D_NET, "%s: Unexpected features 0x%x\n",
684 libcfs_nid2str(gw->lp_nid), gw->lp_ping_feats);
685 return; /* nothing I can understand */
688 if ((gw->lp_ping_feats & LNET_PING_FEAT_NI_STATUS) == 0)
689 return; /* can't carry NI status info */
691 list_for_each_entry(rte, &gw->lp_routes, lr_gwlist) {
696 if ((gw->lp_ping_feats & LNET_PING_FEAT_RTE_DISABLED) != 0) {
701 for (i = 0; i < info->pi_nnis && i < LNET_MAX_RTR_NIS; i++) {
702 lnet_ni_status_t *stat = &info->pi_ni[i];
703 lnet_nid_t nid = stat->ns_nid;
705 if (nid == LNET_NID_ANY) {
706 CDEBUG(D_NET, "%s: unexpected LNET_NID_ANY\n",
707 libcfs_nid2str(gw->lp_nid));
708 gw->lp_ping_feats = LNET_PING_FEAT_INVAL;
712 if (LNET_NETTYP(LNET_NIDNET(nid)) == LOLND)
715 if (stat->ns_status == LNET_NI_STATUS_DOWN) {
720 if (stat->ns_status == LNET_NI_STATUS_UP) {
721 if (LNET_NIDNET(nid) == rte->lr_net) {
728 CDEBUG(D_NET, "%s: Unexpected status 0x%x\n",
729 libcfs_nid2str(gw->lp_nid), stat->ns_status);
730 gw->lp_ping_feats = LNET_PING_FEAT_INVAL;
734 if (up) { /* ignore downed NIs if NI for dest network is up */
738 rte->lr_downis = down;
743 lnet_router_checker_event(lnet_event_t *event)
745 lnet_rc_data_t *rcd = event->md.user_ptr;
746 struct lnet_peer *lp;
748 LASSERT(rcd != NULL);
750 if (event->unlinked) {
751 LNetInvalidateHandle(&rcd->rcd_mdh);
755 LASSERT(event->type == LNET_EVENT_SEND ||
756 event->type == LNET_EVENT_REPLY);
758 lp = rcd->rcd_gateway;
761 /* NB: it's called with holding lnet_res_lock, we have a few
762 * places need to hold both locks at the same time, please take
763 * care of lock ordering */
764 lnet_net_lock(lp->lp_cpt);
765 if (!lnet_isrouter(lp) || lp->lp_rcd != rcd) {
766 /* ignore if no longer a router or rcd is replaced */
770 if (event->type == LNET_EVENT_SEND) {
771 lp->lp_ping_notsent = 0;
772 if (event->status == 0)
776 /* LNET_EVENT_REPLY */
777 /* A successful REPLY means the router is up. If _any_ comms
778 * to the router fail I assume it's down (this will happen if
779 * we ping alive routers to try to detect router death before
780 * apps get burned). */
782 lnet_notify_locked(lp, 1, (event->status == 0), cfs_time_current());
783 /* The router checker will wake up very shortly and do the
784 * actual notification.
785 * XXX If 'lp' stops being a router before then, it will still
786 * have the notification pending!!! */
788 if (avoid_asym_router_failure && event->status == 0)
789 lnet_parse_rc_info(rcd);
792 lnet_net_unlock(lp->lp_cpt);
796 lnet_wait_known_routerstate(void)
799 struct list_head *entry;
802 LASSERT(the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING);
805 int cpt = lnet_net_lock_current();
808 list_for_each(entry, &the_lnet.ln_routers) {
809 rtr = list_entry(entry, lnet_peer_t, lp_rtr_list);
811 if (rtr->lp_alive_count == 0) {
817 lnet_net_unlock(cpt);
823 lnet_router_checker();
825 cfs_pause(cfs_time_seconds(1));
830 lnet_router_ni_update_locked(lnet_peer_t *gw, __u32 net)
834 if ((gw->lp_ping_feats & LNET_PING_FEAT_NI_STATUS) != 0) {
835 list_for_each_entry(rte, &gw->lp_routes, lr_gwlist) {
836 if (rte->lr_net == net) {
845 lnet_update_ni_status_locked(void)
851 LASSERT(the_lnet.ln_routing);
853 timeout = router_ping_timeout +
854 MAX(live_router_check_interval, dead_router_check_interval);
856 now = cfs_time_current_sec();
857 list_for_each_entry(ni, &the_lnet.ln_nis, ni_list) {
858 if (ni->ni_lnd->lnd_type == LOLND)
861 if (now < ni->ni_last_alive + timeout)
865 /* re-check with lock */
866 if (now < ni->ni_last_alive + timeout) {
871 LASSERT(ni->ni_status != NULL);
873 if (ni->ni_status->ns_status != LNET_NI_STATUS_DOWN) {
874 CDEBUG(D_NET, "NI(%s:%d) status changed to down\n",
875 libcfs_nid2str(ni->ni_nid), timeout);
876 /* NB: so far, this is the only place to set
877 * NI status to "down" */
878 ni->ni_status->ns_status = LNET_NI_STATUS_DOWN;
885 lnet_destroy_rc_data(lnet_rc_data_t *rcd)
887 LASSERT(list_empty(&rcd->rcd_list));
888 /* detached from network */
889 LASSERT(LNetHandleIsInvalid(rcd->rcd_mdh));
891 if (rcd->rcd_gateway != NULL) {
892 int cpt = rcd->rcd_gateway->lp_cpt;
895 lnet_peer_decref_locked(rcd->rcd_gateway);
896 lnet_net_unlock(cpt);
899 if (rcd->rcd_pinginfo != NULL)
900 LIBCFS_FREE(rcd->rcd_pinginfo, LNET_PINGINFO_SIZE);
902 LIBCFS_FREE(rcd, sizeof(*rcd));
905 static lnet_rc_data_t *
906 lnet_create_rc_data_locked(lnet_peer_t *gateway)
908 lnet_rc_data_t *rcd = NULL;
909 lnet_ping_info_t *pi;
913 lnet_net_unlock(gateway->lp_cpt);
915 LIBCFS_ALLOC(rcd, sizeof(*rcd));
919 LNetInvalidateHandle(&rcd->rcd_mdh);
920 INIT_LIST_HEAD(&rcd->rcd_list);
922 LIBCFS_ALLOC(pi, LNET_PINGINFO_SIZE);
926 for (i = 0; i < LNET_MAX_RTR_NIS; i++) {
927 pi->pi_ni[i].ns_nid = LNET_NID_ANY;
928 pi->pi_ni[i].ns_status = LNET_NI_STATUS_INVALID;
930 rcd->rcd_pinginfo = pi;
932 LASSERT (!LNetHandleIsInvalid(the_lnet.ln_rc_eqh));
933 rc = LNetMDBind((lnet_md_t){.start = pi,
935 .length = LNET_PINGINFO_SIZE,
936 .threshold = LNET_MD_THRESH_INF,
937 .options = LNET_MD_TRUNCATE,
938 .eq_handle = the_lnet.ln_rc_eqh},
942 CERROR("Can't bind MD: %d\n", rc);
947 lnet_net_lock(gateway->lp_cpt);
948 /* router table changed or someone has created rcd for this gateway */
949 if (!lnet_isrouter(gateway) || gateway->lp_rcd != NULL) {
950 lnet_net_unlock(gateway->lp_cpt);
954 lnet_peer_addref_locked(gateway);
955 rcd->rcd_gateway = gateway;
956 gateway->lp_rcd = rcd;
957 gateway->lp_ping_notsent = 0;
963 if (!LNetHandleIsInvalid(rcd->rcd_mdh)) {
964 rc = LNetMDUnlink(rcd->rcd_mdh);
967 lnet_destroy_rc_data(rcd);
970 lnet_net_lock(gateway->lp_cpt);
971 return gateway->lp_rcd;
975 lnet_router_check_interval (lnet_peer_t *rtr)
979 secs = rtr->lp_alive ? live_router_check_interval :
980 dead_router_check_interval;
988 lnet_ping_router_locked (lnet_peer_t *rtr)
990 lnet_rc_data_t *rcd = NULL;
991 cfs_time_t now = cfs_time_current();
994 lnet_peer_addref_locked(rtr);
996 if (rtr->lp_ping_deadline != 0 && /* ping timed out? */
997 cfs_time_after(now, rtr->lp_ping_deadline))
998 lnet_notify_locked(rtr, 1, 0, now);
1000 /* Run any outstanding notifications */
1001 lnet_ni_notify_locked(rtr->lp_ni, rtr);
1003 if (!lnet_isrouter(rtr) ||
1004 the_lnet.ln_rc_state != LNET_RC_STATE_RUNNING) {
1005 /* router table changed or router checker is shutting down */
1006 lnet_peer_decref_locked(rtr);
1010 rcd = rtr->lp_rcd != NULL ?
1011 rtr->lp_rcd : lnet_create_rc_data_locked(rtr);
1016 secs = lnet_router_check_interval(rtr);
1019 "rtr %s %d: deadline %lu ping_notsent %d alive %d "
1020 "alive_count %d lp_ping_timestamp %lu\n",
1021 libcfs_nid2str(rtr->lp_nid), secs,
1022 rtr->lp_ping_deadline, rtr->lp_ping_notsent,
1023 rtr->lp_alive, rtr->lp_alive_count, rtr->lp_ping_timestamp);
1025 if (secs != 0 && !rtr->lp_ping_notsent &&
1026 cfs_time_after(now, cfs_time_add(rtr->lp_ping_timestamp,
1027 cfs_time_seconds(secs)))) {
1029 lnet_process_id_t id;
1030 lnet_handle_md_t mdh;
1032 id.nid = rtr->lp_nid;
1033 id.pid = LNET_PID_LUSTRE;
1034 CDEBUG(D_NET, "Check: %s\n", libcfs_id2str(id));
1036 rtr->lp_ping_notsent = 1;
1037 rtr->lp_ping_timestamp = now;
1041 if (rtr->lp_ping_deadline == 0) {
1042 rtr->lp_ping_deadline =
1043 cfs_time_shift(router_ping_timeout);
1046 lnet_net_unlock(rtr->lp_cpt);
1048 rc = LNetGet(LNET_NID_ANY, mdh, id, LNET_RESERVED_PORTAL,
1049 LNET_PROTO_PING_MATCHBITS, 0);
1051 lnet_net_lock(rtr->lp_cpt);
1053 rtr->lp_ping_notsent = 0; /* no event pending */
1056 lnet_peer_decref_locked(rtr);
1061 lnet_router_checker_start(void)
1066 struct task_struct *task;
1067 #else /* __KERNEL__ */
1071 int router_checker_max_eqsize = 10240;
1073 LASSERT (check_routers_before_use);
1074 LASSERT (dead_router_check_interval > 0);
1078 /* As an approximation, allow each router the same number of
1079 * outstanding events as it is allowed outstanding sends */
1081 version = the_lnet.ln_routers_version;
1082 list_for_each_entry(rtr, &the_lnet.ln_routers, lp_rtr_list) {
1083 lnet_ni_t *ni = rtr->lp_ni;
1084 lnet_process_id_t id;
1087 eqsz += ni->ni_peertxcredits;
1089 /* one async ping reply per router */
1090 id.nid = rtr->lp_nid;
1091 id.pid = LNET_PID_LUSTRE;
1095 rc = LNetSetAsync(id, 1);
1097 CWARN("LNetSetAsync %s failed: %d\n",
1098 libcfs_id2str(id), rc);
1103 /* NB router list doesn't change in userspace */
1104 LASSERT(version == the_lnet.ln_routers_version);
1111 "No router found, not starting router checker\n");
1115 /* at least allow a SENT and a REPLY per router */
1116 if (router_checker_max_eqsize < 2 * nrtr)
1117 router_checker_max_eqsize = 2 * nrtr;
1120 if (eqsz > router_checker_max_eqsize)
1121 eqsz = router_checker_max_eqsize;
1124 LASSERT (the_lnet.ln_rc_state == LNET_RC_STATE_SHUTDOWN);
1126 if (check_routers_before_use &&
1127 dead_router_check_interval <= 0) {
1128 LCONSOLE_ERROR_MSG(0x10a, "'dead_router_check_interval' must be"
1129 " set if 'check_routers_before_use' is set"
1134 if (!the_lnet.ln_routing &&
1135 live_router_check_interval <= 0 &&
1136 dead_router_check_interval <= 0)
1140 sema_init(&the_lnet.ln_rc_signal, 0);
1141 /* EQ size doesn't matter; the callback is guaranteed to get every
1144 rc = LNetEQAlloc(eqsz, lnet_router_checker_event,
1145 &the_lnet.ln_rc_eqh);
1147 rc = LNetEQAlloc(eqsz, LNET_EQ_HANDLER_NONE,
1148 &the_lnet.ln_rc_eqh);
1151 CERROR("Can't allocate EQ(%d): %d\n", eqsz, rc);
1155 the_lnet.ln_rc_state = LNET_RC_STATE_RUNNING;
1157 task = kthread_run(lnet_router_checker, NULL, "router_checker");
1160 CERROR("Can't start router checker thread: %d\n", rc);
1161 /* block until event callback signals exit */
1162 down(&the_lnet.ln_rc_signal);
1163 rc = LNetEQFree(the_lnet.ln_rc_eqh);
1165 the_lnet.ln_rc_state = LNET_RC_STATE_SHUTDOWN;
1170 if (check_routers_before_use) {
1171 /* Note that a helpful side-effect of pinging all known routers
1172 * at startup is that it makes them drop stale connections they
1173 * may have to a previous instance of me. */
1174 lnet_wait_known_routerstate();
1181 lnet_router_checker_stop (void)
1185 if (the_lnet.ln_rc_state == LNET_RC_STATE_SHUTDOWN)
1188 LASSERT (the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING);
1189 the_lnet.ln_rc_state = LNET_RC_STATE_STOPPING;
1192 /* block until event callback signals exit */
1193 down(&the_lnet.ln_rc_signal);
1195 lnet_router_checker();
1197 LASSERT(the_lnet.ln_rc_state == LNET_RC_STATE_SHUTDOWN);
1199 rc = LNetEQFree(the_lnet.ln_rc_eqh);
1205 lnet_prune_rc_data(int wait_unlink)
1207 lnet_rc_data_t *rcd;
1208 lnet_rc_data_t *tmp;
1210 struct list_head head;
1213 if (likely(the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING &&
1214 list_empty(&the_lnet.ln_rcd_deathrow) &&
1215 list_empty(&the_lnet.ln_rcd_zombie)))
1218 INIT_LIST_HEAD(&head);
1220 lnet_net_lock(LNET_LOCK_EX);
1222 if (the_lnet.ln_rc_state != LNET_RC_STATE_RUNNING) {
1223 /* router checker is stopping, prune all */
1224 list_for_each_entry(lp, &the_lnet.ln_routers,
1226 if (lp->lp_rcd == NULL)
1229 LASSERT(list_empty(&lp->lp_rcd->rcd_list));
1230 list_add(&lp->lp_rcd->rcd_list,
1231 &the_lnet.ln_rcd_deathrow);
1236 /* unlink all RCDs on deathrow list */
1237 list_splice_init(&the_lnet.ln_rcd_deathrow, &head);
1239 if (!list_empty(&head)) {
1240 lnet_net_unlock(LNET_LOCK_EX);
1242 list_for_each_entry(rcd, &head, rcd_list)
1243 LNetMDUnlink(rcd->rcd_mdh);
1245 lnet_net_lock(LNET_LOCK_EX);
1248 list_splice_init(&head, &the_lnet.ln_rcd_zombie);
1250 /* release all zombie RCDs */
1251 while (!list_empty(&the_lnet.ln_rcd_zombie)) {
1252 list_for_each_entry_safe(rcd, tmp, &the_lnet.ln_rcd_zombie,
1254 if (LNetHandleIsInvalid(rcd->rcd_mdh))
1255 list_move(&rcd->rcd_list, &head);
1258 wait_unlink = wait_unlink &&
1259 !list_empty(&the_lnet.ln_rcd_zombie);
1261 lnet_net_unlock(LNET_LOCK_EX);
1263 while (!list_empty(&head)) {
1264 rcd = list_entry(head.next,
1265 lnet_rc_data_t, rcd_list);
1266 list_del_init(&rcd->rcd_list);
1267 lnet_destroy_rc_data(rcd);
1274 CDEBUG(((i & (-i)) == i) ? D_WARNING : D_NET,
1275 "Waiting for rc buffers to unlink\n");
1276 cfs_pause(cfs_time_seconds(1) / 4);
1278 lnet_net_lock(LNET_LOCK_EX);
1281 lnet_net_unlock(LNET_LOCK_EX);
1285 #if defined(__KERNEL__) && defined(LNET_ROUTER)
1288 lnet_router_checker(void *arg)
1291 struct list_head *entry;
1293 cfs_block_allsigs();
1295 LASSERT (the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING);
1297 while (the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING) {
1302 cpt = lnet_net_lock_current();
1304 version = the_lnet.ln_routers_version;
1306 list_for_each(entry, &the_lnet.ln_routers) {
1307 rtr = list_entry(entry, lnet_peer_t, lp_rtr_list);
1309 cpt2 = lnet_cpt_of_nid_locked(rtr->lp_nid);
1311 lnet_net_unlock(cpt);
1314 /* the routers list has changed */
1315 if (version != the_lnet.ln_routers_version)
1319 lnet_ping_router_locked(rtr);
1321 /* NB dropped lock */
1322 if (version != the_lnet.ln_routers_version) {
1323 /* the routers list has changed */
1328 if (the_lnet.ln_routing)
1329 lnet_update_ni_status_locked();
1331 lnet_net_unlock(cpt);
1333 lnet_prune_rc_data(0); /* don't wait for UNLINK */
1335 /* Call cfs_pause() here always adds 1 to load average
1336 * because kernel counts # active tasks as nr_running
1337 * + nr_uninterruptible. */
1338 schedule_timeout_and_set_state(TASK_INTERRUPTIBLE,
1339 cfs_time_seconds(1));
1342 LASSERT(the_lnet.ln_rc_state == LNET_RC_STATE_STOPPING);
1344 lnet_prune_rc_data(1); /* wait for UNLINK */
1346 the_lnet.ln_rc_state = LNET_RC_STATE_SHUTDOWN;
1347 up(&the_lnet.ln_rc_signal);
1348 /* The unlink event callback will signal final completion */
1353 lnet_destroy_rtrbuf(lnet_rtrbuf_t *rb, int npages)
1355 int sz = offsetof(lnet_rtrbuf_t, rb_kiov[npages]);
1357 while (--npages >= 0)
1358 __free_page(rb->rb_kiov[npages].kiov_page);
1360 LIBCFS_FREE(rb, sz);
1363 static lnet_rtrbuf_t *
1364 lnet_new_rtrbuf(lnet_rtrbufpool_t *rbp, int cpt)
1366 int npages = rbp->rbp_npages;
1367 int sz = offsetof(lnet_rtrbuf_t, rb_kiov[npages]);
1372 LIBCFS_CPT_ALLOC(rb, lnet_cpt_table(), cpt, sz);
1378 for (i = 0; i < npages; i++) {
1379 page = cfs_page_cpt_alloc(lnet_cpt_table(), cpt,
1380 __GFP_ZERO | GFP_IOFS);
1383 __free_page(rb->rb_kiov[i].kiov_page);
1385 LIBCFS_FREE(rb, sz);
1389 rb->rb_kiov[i].kiov_len = PAGE_CACHE_SIZE;
1390 rb->rb_kiov[i].kiov_offset = 0;
1391 rb->rb_kiov[i].kiov_page = page;
1398 lnet_rtrpool_free_bufs(lnet_rtrbufpool_t *rbp, int cpt)
1400 int npages = rbp->rbp_npages;
1402 struct list_head tmp;
1404 if (rbp->rbp_nbuffers == 0) /* not initialized or already freed */
1407 INIT_LIST_HEAD(&tmp);
1410 lnet_drop_routed_msgs_locked(&rbp->rbp_msgs, cpt);
1411 list_splice_init(&rbp->rbp_bufs, &tmp);
1412 rbp->rbp_nbuffers = rbp->rbp_credits = 0;
1413 rbp->rbp_mincredits = 0;
1414 lnet_net_unlock(cpt);
1416 /* Free buffers on the free list. */
1417 while (!list_empty(&tmp)) {
1418 rb = list_entry(tmp.next, lnet_rtrbuf_t, rb_list);
1419 list_del(&rb->rb_list);
1420 lnet_destroy_rtrbuf(rb, npages);
1425 lnet_rtrpool_adjust_bufs(lnet_rtrbufpool_t *rbp, int nbufs, int cpt)
1427 struct list_head rb_list;
1430 int num_buffers = 0;
1431 int npages = rbp->rbp_npages;
1433 /* If we are called for less buffers than already in the pool, we
1434 * just lower the nbuffers number and excess buffers will be
1435 * thrown away as they are returned to the free list. Credits
1436 * then get adjusted as well. */
1437 if (nbufs <= rbp->rbp_nbuffers) {
1439 rbp->rbp_nbuffers = nbufs;
1440 lnet_net_unlock(cpt);
1444 INIT_LIST_HEAD(&rb_list);
1446 /* allocate the buffers on a local list first. If all buffers are
1447 * allocated successfully then join this list to the rbp buffer
1448 * list. If not then free all allocated buffers. */
1449 num_rb = rbp->rbp_nbuffers;
1451 while (num_rb < nbufs) {
1452 rb = lnet_new_rtrbuf(rbp, cpt);
1454 CERROR("Failed to allocate %d route bufs of %d pages\n",
1459 list_add(&rb->rb_list, &rb_list);
1466 list_splice_tail(&rb_list, &rbp->rbp_bufs);
1467 rbp->rbp_nbuffers += num_buffers;
1468 rbp->rbp_credits += num_buffers;
1469 rbp->rbp_mincredits = rbp->rbp_credits;
1470 /* We need to schedule blocked msg using the newly
1472 while (!list_empty(&rbp->rbp_bufs) &&
1473 !list_empty(&rbp->rbp_msgs))
1474 lnet_schedule_blocked_locked(rbp);
1476 lnet_net_unlock(cpt);
1481 while (!list_empty(&rb_list)) {
1482 rb = list_entry(rb_list.next, lnet_rtrbuf_t, rb_list);
1483 list_del(&rb->rb_list);
1484 lnet_destroy_rtrbuf(rb, npages);
1491 lnet_rtrpool_init(lnet_rtrbufpool_t *rbp, int npages)
1493 INIT_LIST_HEAD(&rbp->rbp_msgs);
1494 INIT_LIST_HEAD(&rbp->rbp_bufs);
1496 rbp->rbp_npages = npages;
1497 rbp->rbp_credits = 0;
1498 rbp->rbp_mincredits = 0;
1502 lnet_rtrpools_free(int keep_pools)
1504 lnet_rtrbufpool_t *rtrp;
1507 if (the_lnet.ln_rtrpools == NULL) /* uninitialized or freed */
1510 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1511 lnet_rtrpool_free_bufs(&rtrp[LNET_TINY_BUF_IDX], i);
1512 lnet_rtrpool_free_bufs(&rtrp[LNET_SMALL_BUF_IDX], i);
1513 lnet_rtrpool_free_bufs(&rtrp[LNET_LARGE_BUF_IDX], i);
1517 cfs_percpt_free(the_lnet.ln_rtrpools);
1518 the_lnet.ln_rtrpools = NULL;
1523 lnet_nrb_tiny_calculate(void)
1525 int nrbs = LNET_NRB_TINY;
1527 if (tiny_router_buffers < 0) {
1528 LCONSOLE_ERROR_MSG(0x10c,
1529 "tiny_router_buffers=%d invalid when "
1530 "routing enabled\n", tiny_router_buffers);
1534 if (tiny_router_buffers > 0)
1535 nrbs = tiny_router_buffers;
1537 nrbs /= LNET_CPT_NUMBER;
1538 return max(nrbs, LNET_NRB_TINY_MIN);
1542 lnet_nrb_small_calculate(void)
1544 int nrbs = LNET_NRB_SMALL;
1546 if (small_router_buffers < 0) {
1547 LCONSOLE_ERROR_MSG(0x10c,
1548 "small_router_buffers=%d invalid when "
1549 "routing enabled\n", small_router_buffers);
1553 if (small_router_buffers > 0)
1554 nrbs = small_router_buffers;
1556 nrbs /= LNET_CPT_NUMBER;
1557 return max(nrbs, LNET_NRB_SMALL_MIN);
1561 lnet_nrb_large_calculate(void)
1563 int nrbs = LNET_NRB_LARGE;
1565 if (large_router_buffers < 0) {
1566 LCONSOLE_ERROR_MSG(0x10c,
1567 "large_router_buffers=%d invalid when "
1568 "routing enabled\n", large_router_buffers);
1572 if (large_router_buffers > 0)
1573 nrbs = large_router_buffers;
1575 nrbs /= LNET_CPT_NUMBER;
1576 return max(nrbs, LNET_NRB_LARGE_MIN);
1580 lnet_rtrpools_alloc(int im_a_router)
1582 lnet_rtrbufpool_t *rtrp;
1589 if (!strcmp(forwarding, "")) {
1590 /* not set either way */
1593 } else if (!strcmp(forwarding, "disabled")) {
1594 /* explicitly disabled */
1596 } else if (!strcmp(forwarding, "enabled")) {
1597 /* explicitly enabled */
1599 LCONSOLE_ERROR_MSG(0x10b, "'forwarding' not set to either "
1600 "'enabled' or 'disabled'\n");
1604 nrb_tiny = lnet_nrb_tiny_calculate();
1608 nrb_small = lnet_nrb_small_calculate();
1612 nrb_large = lnet_nrb_large_calculate();
1616 the_lnet.ln_rtrpools = cfs_percpt_alloc(lnet_cpt_table(),
1618 sizeof(lnet_rtrbufpool_t));
1619 if (the_lnet.ln_rtrpools == NULL) {
1620 LCONSOLE_ERROR_MSG(0x10c,
1621 "Failed to initialize router buffe pool\n");
1625 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1626 lnet_rtrpool_init(&rtrp[LNET_TINY_BUF_IDX], 0);
1627 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_TINY_BUF_IDX],
1632 lnet_rtrpool_init(&rtrp[LNET_SMALL_BUF_IDX],
1633 LNET_NRB_SMALL_PAGES);
1634 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_SMALL_BUF_IDX],
1639 lnet_rtrpool_init(&rtrp[LNET_LARGE_BUF_IDX],
1640 LNET_NRB_LARGE_PAGES);
1641 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_LARGE_BUF_IDX],
1647 lnet_net_lock(LNET_LOCK_EX);
1648 the_lnet.ln_routing = 1;
1649 lnet_net_unlock(LNET_LOCK_EX);
1653 lnet_rtrpools_free(0);
1658 lnet_rtrpools_adjust_helper(int tiny, int small, int large)
1663 lnet_rtrbufpool_t *rtrp;
1665 /* If the provided values for each buffer pool are different than the
1666 * configured values, we need to take action. */
1668 tiny_router_buffers = tiny;
1669 nrb = lnet_nrb_tiny_calculate();
1670 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1671 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_TINY_BUF_IDX],
1678 small_router_buffers = small;
1679 nrb = lnet_nrb_small_calculate();
1680 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1681 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_SMALL_BUF_IDX],
1688 large_router_buffers = large;
1689 nrb = lnet_nrb_large_calculate();
1690 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1691 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_LARGE_BUF_IDX],
1702 lnet_rtrpools_adjust(int tiny, int small, int large)
1704 /* this function doesn't revert the changes if adding new buffers
1705 * failed. It's up to the user space caller to revert the
1708 if (!the_lnet.ln_routing)
1711 return lnet_rtrpools_adjust_helper(tiny, small, large);
1715 lnet_rtrpools_enable(void)
1719 if (the_lnet.ln_routing)
1722 if (the_lnet.ln_rtrpools == NULL)
1723 /* If routing is turned off, and we have never
1724 * initialized the pools before, just call the
1725 * standard buffer pool allocation routine as
1726 * if we are just configuring this for the first
1728 return lnet_rtrpools_alloc(1);
1730 rc = lnet_rtrpools_adjust_helper(0, 0, 0);
1734 lnet_net_lock(LNET_LOCK_EX);
1735 the_lnet.ln_routing = 1;
1737 the_lnet.ln_ping_info->pi_features &= ~LNET_PING_FEAT_RTE_DISABLED;
1738 lnet_net_unlock(LNET_LOCK_EX);
1744 lnet_rtrpools_disable(void)
1746 if (!the_lnet.ln_routing)
1749 lnet_net_lock(LNET_LOCK_EX);
1750 the_lnet.ln_routing = 0;
1751 the_lnet.ln_ping_info->pi_features |= LNET_PING_FEAT_RTE_DISABLED;
1753 tiny_router_buffers = 0;
1754 small_router_buffers = 0;
1755 large_router_buffers = 0;
1756 lnet_net_unlock(LNET_LOCK_EX);
1757 lnet_rtrpools_free(1);
1761 lnet_notify(lnet_ni_t *ni, lnet_nid_t nid, int alive, cfs_time_t when)
1763 struct lnet_peer *lp = NULL;
1764 cfs_time_t now = cfs_time_current();
1765 int cpt = lnet_cpt_of_nid(nid);
1767 LASSERT (!in_interrupt ());
1769 CDEBUG (D_NET, "%s notifying %s: %s\n",
1770 (ni == NULL) ? "userspace" : libcfs_nid2str(ni->ni_nid),
1771 libcfs_nid2str(nid),
1772 alive ? "up" : "down");
1775 LNET_NIDNET(ni->ni_nid) != LNET_NIDNET(nid)) {
1776 CWARN ("Ignoring notification of %s %s by %s (different net)\n",
1777 libcfs_nid2str(nid), alive ? "birth" : "death",
1778 libcfs_nid2str(ni->ni_nid));
1782 /* can't do predictions... */
1783 if (cfs_time_after(when, now)) {
1784 CWARN ("Ignoring prediction from %s of %s %s "
1785 "%ld seconds in the future\n",
1786 (ni == NULL) ? "userspace" : libcfs_nid2str(ni->ni_nid),
1787 libcfs_nid2str(nid), alive ? "up" : "down",
1788 cfs_duration_sec(cfs_time_sub(when, now)));
1792 if (ni != NULL && !alive && /* LND telling me she's down */
1793 !auto_down) { /* auto-down disabled */
1794 CDEBUG(D_NET, "Auto-down disabled\n");
1800 if (the_lnet.ln_shutdown) {
1801 lnet_net_unlock(cpt);
1805 lp = lnet_find_peer_locked(the_lnet.ln_peer_tables[cpt], nid);
1808 lnet_net_unlock(cpt);
1809 CDEBUG(D_NET, "%s not found\n", libcfs_nid2str(nid));
1813 /* We can't fully trust LND on reporting exact peer last_alive
1814 * if he notifies us about dead peer. For example ksocklnd can
1815 * call us with when == _time_when_the_node_was_booted_ if
1816 * no connections were successfully established */
1817 if (ni != NULL && !alive && when < lp->lp_last_alive)
1818 when = lp->lp_last_alive;
1820 lnet_notify_locked(lp, ni == NULL, alive, when);
1823 lnet_ni_notify_locked(ni, lp);
1825 lnet_peer_decref_locked(lp);
1827 lnet_net_unlock(cpt);
1830 EXPORT_SYMBOL(lnet_notify);
1833 lnet_get_tunables (void)
1841 lnet_notify (lnet_ni_t *ni, lnet_nid_t nid, int alive, cfs_time_t when)
1847 lnet_router_checker (void)
1849 static time_t last = 0;
1850 static int running = 0;
1852 time_t now = cfs_time_current_sec();
1853 int interval = now - last;
1858 /* It's no use to call me again within a sec - all intervals and
1859 * timeouts are measured in seconds */
1860 if (last != 0 && interval < 2)
1864 interval > MAX(live_router_check_interval,
1865 dead_router_check_interval))
1866 CNETERR("Checker(%d/%d) not called for %d seconds\n",
1867 live_router_check_interval, dead_router_check_interval,
1870 LASSERT(LNET_CPT_NUMBER == 1);
1873 LASSERT(!running); /* recursion check */
1879 if (the_lnet.ln_rc_state == LNET_RC_STATE_STOPPING)
1880 lnet_prune_rc_data(0); /* unlink all rcd and nowait */
1882 /* consume all pending events */
1887 /* NB ln_rc_eqh must be the 1st in 'eventqs' otherwise the
1888 * recursion breaker in LNetEQPoll would fail */
1889 rc = LNetEQPoll(&the_lnet.ln_rc_eqh, 1, 0, &ev, &i);
1890 if (rc == 0) /* no event pending */
1893 /* NB a lost SENT prevents me from pinging a router again */
1894 if (rc == -EOVERFLOW) {
1895 CERROR("Dropped an event!!!\n");
1901 lnet_router_checker_event(&ev);
1904 if (the_lnet.ln_rc_state == LNET_RC_STATE_STOPPING) {
1905 lnet_prune_rc_data(1); /* release rcd */
1906 the_lnet.ln_rc_state = LNET_RC_STATE_SHUTDOWN;
1911 LASSERT (the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING);
1915 version = the_lnet.ln_routers_version;
1916 list_for_each_entry(rtr, &the_lnet.ln_routers, lp_rtr_list) {
1917 lnet_ping_router_locked(rtr);
1918 LASSERT(version == the_lnet.ln_routers_version);
1923 running = 0; /* lock only needed for the recursion check */
1927 /* NB lnet_peers_start_down depends on me,
1928 * so must be called before any peer creation */
1930 lnet_get_tunables (void)
1934 s = getenv("LNET_ROUTER_PING_TIMEOUT");
1935 if (s != NULL) router_ping_timeout = atoi(s);
1937 s = getenv("LNET_LIVE_ROUTER_CHECK_INTERVAL");
1938 if (s != NULL) live_router_check_interval = atoi(s);
1940 s = getenv("LNET_DEAD_ROUTER_CHECK_INTERVAL");
1941 if (s != NULL) dead_router_check_interval = atoi(s);
1943 /* This replaces old lnd_notify mechanism */
1944 check_routers_before_use = 1;
1945 if (dead_router_check_interval <= 0)
1946 dead_router_check_interval = 30;
1950 lnet_rtrpools_free(int keep_pools)
1955 lnet_rtrpools_alloc(int im_a_arouter)