2 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
4 * Copyright (c) 2011, 2016, Intel Corporation.
6 * This file is part of Lustre, https://wiki.hpdd.intel.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;
72 static int lnet_router_checker(void *);
74 static int check_routers_before_use;
75 module_param(check_routers_before_use, int, 0444);
76 MODULE_PARM_DESC(check_routers_before_use, "Assume routers are down and ping them before use");
78 int avoid_asym_router_failure = 1;
79 module_param(avoid_asym_router_failure, int, 0644);
80 MODULE_PARM_DESC(avoid_asym_router_failure, "Avoid asymmetrical router failures (0 to disable)");
82 static int dead_router_check_interval = 60;
83 module_param(dead_router_check_interval, int, 0644);
84 MODULE_PARM_DESC(dead_router_check_interval, "Seconds between dead router health checks (<= 0 to disable)");
86 static int live_router_check_interval = 60;
87 module_param(live_router_check_interval, int, 0644);
88 MODULE_PARM_DESC(live_router_check_interval, "Seconds between live router health checks (<= 0 to disable)");
90 static int router_ping_timeout = 50;
91 module_param(router_ping_timeout, int, 0644);
92 MODULE_PARM_DESC(router_ping_timeout, "Seconds to wait for the reply to a router health query");
95 lnet_peers_start_down(void)
97 return check_routers_before_use;
101 lnet_notify_locked(struct lnet_peer_ni *lp, int notifylnd, int alive,
104 if (cfs_time_before(when, lp->lpni_timestamp)) { /* out of date information */
105 CDEBUG(D_NET, "Out of date\n");
110 * This function can be called with different cpt locks being
111 * held. lpni_alive_count modification needs to be properly protected.
112 * Significant reads to lpni_alive_count are also protected with
115 spin_lock(&lp->lpni_lock);
117 lp->lpni_timestamp = when; /* update timestamp */
118 lp->lpni_ping_deadline = 0; /* disable ping timeout */
120 if (lp->lpni_alive_count != 0 && /* got old news */
121 (!lp->lpni_alive) == (!alive)) { /* new date for old news */
122 spin_unlock(&lp->lpni_lock);
123 CDEBUG(D_NET, "Old news\n");
127 /* Flag that notification is outstanding */
129 lp->lpni_alive_count++;
130 lp->lpni_alive = (alive) ? 1 : 0;
132 lp->lpni_notifylnd = notifylnd;
134 lp->lpni_ping_feats = LNET_PING_FEAT_INVAL; /* reset */
136 spin_unlock(&lp->lpni_lock);
138 CDEBUG(D_NET, "set %s %d\n", libcfs_nid2str(lp->lpni_nid), alive);
142 * This function will always be called with lp->lpni_cpt lock held.
145 lnet_ni_notify_locked(struct lnet_ni *ni, struct lnet_peer_ni *lp)
150 /* Notify only in 1 thread at any time to ensure ordered notification.
151 * NB individual events can be missed; the only guarantee is that you
152 * always get the most recent news */
154 spin_lock(&lp->lpni_lock);
156 if (lp->lpni_notifying || ni == NULL) {
157 spin_unlock(&lp->lpni_lock);
161 lp->lpni_notifying = 1;
164 * lp->lpni_notify needs to be protected because it can be set in
165 * lnet_notify_locked().
167 while (lp->lpni_notify) {
168 alive = lp->lpni_alive;
169 notifylnd = lp->lpni_notifylnd;
171 lp->lpni_notifylnd = 0;
174 if (notifylnd && ni->ni_net->net_lnd->lnd_notify != NULL) {
175 spin_unlock(&lp->lpni_lock);
176 lnet_net_unlock(lp->lpni_cpt);
178 /* A new notification could happen now; I'll handle it
179 * when control returns to me */
181 (ni->ni_net->net_lnd->lnd_notify)(ni, lp->lpni_nid,
184 lnet_net_lock(lp->lpni_cpt);
185 spin_lock(&lp->lpni_lock);
189 lp->lpni_notifying = 0;
190 spin_unlock(&lp->lpni_lock);
194 lnet_rtr_addref_locked(struct lnet_peer_ni *lp)
196 LASSERT(atomic_read(&lp->lpni_refcount) > 0);
197 LASSERT(lp->lpni_rtr_refcount >= 0);
199 /* lnet_net_lock must be exclusively locked */
200 lp->lpni_rtr_refcount++;
201 if (lp->lpni_rtr_refcount == 1) {
202 struct list_head *pos;
204 /* a simple insertion sort */
205 list_for_each_prev(pos, &the_lnet.ln_routers) {
206 struct lnet_peer_ni *rtr;
208 rtr = list_entry(pos, struct lnet_peer_ni,
210 if (rtr->lpni_nid < lp->lpni_nid)
214 list_add(&lp->lpni_rtr_list, pos);
215 /* addref for the_lnet.ln_routers */
216 lnet_peer_ni_addref_locked(lp);
217 the_lnet.ln_routers_version++;
222 lnet_rtr_decref_locked(struct lnet_peer_ni *lp)
224 LASSERT(atomic_read(&lp->lpni_refcount) > 0);
225 LASSERT(lp->lpni_rtr_refcount > 0);
227 /* lnet_net_lock must be exclusively locked */
228 lp->lpni_rtr_refcount--;
229 if (lp->lpni_rtr_refcount == 0) {
230 LASSERT(list_empty(&lp->lpni_routes));
232 if (lp->lpni_rcd != NULL) {
233 list_add(&lp->lpni_rcd->rcd_list,
234 &the_lnet.ln_rcd_deathrow);
238 list_del(&lp->lpni_rtr_list);
239 /* decref for the_lnet.ln_routers */
240 lnet_peer_ni_decref_locked(lp);
241 the_lnet.ln_routers_version++;
245 struct lnet_remotenet *
246 lnet_find_rnet_locked(__u32 net)
248 struct lnet_remotenet *rnet;
249 struct list_head *tmp;
250 struct list_head *rn_list;
252 LASSERT(!the_lnet.ln_shutdown);
254 rn_list = lnet_net2rnethash(net);
255 list_for_each(tmp, rn_list) {
256 rnet = list_entry(tmp, struct lnet_remotenet, lrn_list);
258 if (rnet->lrn_net == net)
264 static void lnet_shuffle_seed(void)
269 struct timespec64 ts;
270 struct lnet_ni *ni = NULL;
275 cfs_get_random_bytes(seed, sizeof(seed));
277 /* Nodes with small feet have little entropy
278 * the NID for this node gives the most entropy in the low bits */
279 while ((ni = lnet_get_next_ni_locked(NULL, ni))) {
280 lnd_type = LNET_NETTYP(LNET_NIDNET(ni->ni_nid));
282 if (lnd_type != LOLND)
283 seed[0] ^= (LNET_NIDADDR(ni->ni_nid) | lnd_type);
287 cfs_srand(ts.tv_sec ^ seed[0], ts.tv_nsec ^ seed[1]);
292 /* NB expects LNET_LOCK held */
294 lnet_add_route_to_rnet(struct lnet_remotenet *rnet, struct lnet_route *route)
296 unsigned int len = 0;
297 unsigned int offset = 0;
302 list_for_each(e, &rnet->lrn_routes) {
306 /* len+1 positions to add a new entry, also prevents division by 0 */
307 offset = cfs_rand() % (len + 1);
308 list_for_each(e, &rnet->lrn_routes) {
313 list_add(&route->lr_list, e);
314 list_add(&route->lr_gwlist, &route->lr_gateway->lpni_routes);
316 the_lnet.ln_remote_nets_version++;
317 lnet_rtr_addref_locked(route->lr_gateway);
321 lnet_add_route(__u32 net, __u32 hops, lnet_nid_t gateway,
322 unsigned int priority)
325 struct lnet_remotenet *rnet;
326 struct lnet_remotenet *rnet2;
327 struct lnet_route *route;
329 struct lnet_peer_ni *lpni;
333 CDEBUG(D_NET, "Add route: net %s hops %d priority %u gw %s\n",
334 libcfs_net2str(net), hops, priority, libcfs_nid2str(gateway));
336 if (gateway == LNET_NID_ANY ||
337 LNET_NETTYP(LNET_NIDNET(gateway)) == LOLND ||
338 net == LNET_NIDNET(LNET_NID_ANY) ||
339 LNET_NETTYP(net) == LOLND ||
340 LNET_NIDNET(gateway) == net ||
341 (hops != LNET_UNDEFINED_HOPS && (hops < 1 || hops > 255)))
344 if (lnet_islocalnet(net)) /* it's a local network */
347 /* Assume net, route, all new */
348 LIBCFS_ALLOC(route, sizeof(*route));
349 LIBCFS_ALLOC(rnet, sizeof(*rnet));
350 if (route == NULL || rnet == NULL) {
351 CERROR("Out of memory creating route %s %d %s\n",
352 libcfs_net2str(net), hops, libcfs_nid2str(gateway));
354 LIBCFS_FREE(route, sizeof(*route));
356 LIBCFS_FREE(rnet, sizeof(*rnet));
360 INIT_LIST_HEAD(&rnet->lrn_routes);
362 route->lr_hops = hops;
364 route->lr_priority = priority;
366 lnet_net_lock(LNET_LOCK_EX);
368 lpni = lnet_nid2peerni_ex(gateway, LNET_LOCK_EX);
370 lnet_net_unlock(LNET_LOCK_EX);
372 LIBCFS_FREE(route, sizeof(*route));
373 LIBCFS_FREE(rnet, sizeof(*rnet));
376 if (rc == -EHOSTUNREACH) /* gateway is not on a local net. */
377 return rc; /* ignore the route entry */
378 CERROR("Error %d creating route %s %d %s\n", rc,
379 libcfs_net2str(net), hops,
380 libcfs_nid2str(gateway));
383 route->lr_gateway = lpni;
384 LASSERT(!the_lnet.ln_shutdown);
386 rnet2 = lnet_find_rnet_locked(net);
389 list_add_tail(&rnet->lrn_list, lnet_net2rnethash(net));
393 /* Search for a duplicate route (it's a NOOP if it is) */
395 list_for_each(e, &rnet2->lrn_routes) {
396 struct lnet_route *route2;
398 route2 = list_entry(e, struct lnet_route, lr_list);
399 if (route2->lr_gateway == route->lr_gateway) {
404 /* our lookups must be true */
405 LASSERT(route2->lr_gateway->lpni_nid != gateway);
409 lnet_peer_ni_addref_locked(route->lr_gateway); /* +1 for notify */
410 lnet_add_route_to_rnet(rnet2, route);
412 ni = lnet_get_next_ni_locked(route->lr_gateway->lpni_net, NULL);
413 lnet_net_unlock(LNET_LOCK_EX);
415 /* XXX Assume alive */
416 if (ni->ni_net->net_lnd->lnd_notify != NULL)
417 (ni->ni_net->net_lnd->lnd_notify)(ni, gateway, 1);
419 lnet_net_lock(LNET_LOCK_EX);
422 /* -1 for notify or !add_route */
423 lnet_peer_ni_decref_locked(route->lr_gateway);
424 lnet_net_unlock(LNET_LOCK_EX);
430 LIBCFS_FREE(route, sizeof(*route));
434 LIBCFS_FREE(rnet, sizeof(*rnet));
436 /* indicate to startup the router checker if configured */
437 wake_up(&the_lnet.ln_rc_waitq);
443 lnet_check_routes(void)
445 struct lnet_remotenet *rnet;
446 struct lnet_route *route;
447 struct lnet_route *route2;
448 struct list_head *e1;
449 struct list_head *e2;
451 struct list_head *rn_list;
454 cpt = lnet_net_lock_current();
456 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) {
457 rn_list = &the_lnet.ln_remote_nets_hash[i];
458 list_for_each(e1, rn_list) {
459 rnet = list_entry(e1, struct lnet_remotenet, lrn_list);
462 list_for_each(e2, &rnet->lrn_routes) {
467 route = list_entry(e2, struct lnet_route,
470 if (route2 == NULL) {
475 if (route->lr_gateway->lpni_net ==
476 route2->lr_gateway->lpni_net)
479 nid1 = route->lr_gateway->lpni_nid;
480 nid2 = route2->lr_gateway->lpni_nid;
483 lnet_net_unlock(cpt);
485 CERROR("Routes to %s via %s and %s not "
488 libcfs_nid2str(nid1),
489 libcfs_nid2str(nid2));
495 lnet_net_unlock(cpt);
500 lnet_del_route(__u32 net, lnet_nid_t gw_nid)
502 struct lnet_peer_ni *gateway;
503 struct lnet_remotenet *rnet;
504 struct lnet_route *route;
505 struct list_head *e1;
506 struct list_head *e2;
508 struct list_head *rn_list;
511 CDEBUG(D_NET, "Del route: net %s : gw %s\n",
512 libcfs_net2str(net), libcfs_nid2str(gw_nid));
514 /* NB Caller may specify either all routes via the given gateway
515 * or a specific route entry actual NIDs) */
517 lnet_net_lock(LNET_LOCK_EX);
518 if (net == LNET_NIDNET(LNET_NID_ANY))
519 rn_list = &the_lnet.ln_remote_nets_hash[0];
521 rn_list = lnet_net2rnethash(net);
524 list_for_each(e1, rn_list) {
525 rnet = list_entry(e1, struct lnet_remotenet, lrn_list);
527 if (!(net == LNET_NIDNET(LNET_NID_ANY) ||
528 net == rnet->lrn_net))
531 list_for_each(e2, &rnet->lrn_routes) {
532 route = list_entry(e2, struct lnet_route, lr_list);
534 gateway = route->lr_gateway;
535 if (!(gw_nid == LNET_NID_ANY ||
536 gw_nid == gateway->lpni_nid))
539 list_del(&route->lr_list);
540 list_del(&route->lr_gwlist);
541 the_lnet.ln_remote_nets_version++;
543 if (list_empty(&rnet->lrn_routes))
544 list_del(&rnet->lrn_list);
548 lnet_rtr_decref_locked(gateway);
549 lnet_peer_ni_decref_locked(gateway);
551 lnet_net_unlock(LNET_LOCK_EX);
553 LIBCFS_FREE(route, sizeof(*route));
556 LIBCFS_FREE(rnet, sizeof(*rnet));
559 lnet_net_lock(LNET_LOCK_EX);
564 if (net == LNET_NIDNET(LNET_NID_ANY) &&
565 ++idx < LNET_REMOTE_NETS_HASH_SIZE) {
566 rn_list = &the_lnet.ln_remote_nets_hash[idx];
569 lnet_net_unlock(LNET_LOCK_EX);
575 lnet_destroy_routes (void)
577 lnet_del_route(LNET_NIDNET(LNET_NID_ANY), LNET_NID_ANY);
580 int lnet_get_rtr_pool_cfg(int idx, struct lnet_ioctl_pool_cfg *pool_cfg)
582 int i, rc = -ENOENT, j;
584 if (the_lnet.ln_rtrpools == NULL)
587 for (i = 0; i < LNET_NRBPOOLS; i++) {
588 struct lnet_rtrbufpool *rbp;
590 lnet_net_lock(LNET_LOCK_EX);
591 cfs_percpt_for_each(rbp, j, the_lnet.ln_rtrpools) {
595 pool_cfg->pl_pools[i].pl_npages = rbp[i].rbp_npages;
596 pool_cfg->pl_pools[i].pl_nbuffers = rbp[i].rbp_nbuffers;
597 pool_cfg->pl_pools[i].pl_credits = rbp[i].rbp_credits;
598 pool_cfg->pl_pools[i].pl_mincredits = rbp[i].rbp_mincredits;
602 lnet_net_unlock(LNET_LOCK_EX);
605 lnet_net_lock(LNET_LOCK_EX);
606 pool_cfg->pl_routing = the_lnet.ln_routing;
607 lnet_net_unlock(LNET_LOCK_EX);
613 lnet_get_route(int idx, __u32 *net, __u32 *hops,
614 lnet_nid_t *gateway, __u32 *alive, __u32 *priority)
616 struct list_head *e1;
617 struct list_head *e2;
618 struct lnet_remotenet *rnet;
619 struct lnet_route *route;
622 struct list_head *rn_list;
624 cpt = lnet_net_lock_current();
626 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) {
627 rn_list = &the_lnet.ln_remote_nets_hash[i];
628 list_for_each(e1, rn_list) {
629 rnet = list_entry(e1, struct lnet_remotenet, lrn_list);
631 list_for_each(e2, &rnet->lrn_routes) {
632 route = list_entry(e2, struct lnet_route,
636 *net = rnet->lrn_net;
637 *hops = route->lr_hops;
638 *priority = route->lr_priority;
639 *gateway = route->lr_gateway->lpni_nid;
640 *alive = lnet_is_route_alive(route);
641 lnet_net_unlock(cpt);
648 lnet_net_unlock(cpt);
653 lnet_swap_pinginfo(struct lnet_ping_info *info)
656 struct lnet_ni_status *stat;
658 __swab32s(&info->pi_magic);
659 __swab32s(&info->pi_features);
660 __swab32s(&info->pi_pid);
661 __swab32s(&info->pi_nnis);
662 for (i = 0; i < info->pi_nnis && i < LNET_MAX_RTR_NIS; i++) {
663 stat = &info->pi_ni[i];
664 __swab64s(&stat->ns_nid);
665 __swab32s(&stat->ns_status);
671 * parse router-checker pinginfo, record number of down NIs for remote
672 * networks on that router.
675 lnet_parse_rc_info(struct lnet_rc_data *rcd)
677 struct lnet_ping_info *info = rcd->rcd_pinginfo;
678 struct lnet_peer_ni *gw = rcd->rcd_gateway;
679 struct lnet_route *rte;
685 * Protect gw->lpni_ping_feats. This can be set from
686 * lnet_notify_locked with different locks being held
688 spin_lock(&gw->lpni_lock);
690 if (info->pi_magic == __swab32(LNET_PROTO_PING_MAGIC))
691 lnet_swap_pinginfo(info);
693 /* NB always racing with network! */
694 if (info->pi_magic != LNET_PROTO_PING_MAGIC) {
695 CDEBUG(D_NET, "%s: Unexpected magic %08x\n",
696 libcfs_nid2str(gw->lpni_nid), info->pi_magic);
697 gw->lpni_ping_feats = LNET_PING_FEAT_INVAL;
698 spin_unlock(&gw->lpni_lock);
702 gw->lpni_ping_feats = info->pi_features;
703 if ((gw->lpni_ping_feats & LNET_PING_FEAT_MASK) == 0) {
704 CDEBUG(D_NET, "%s: Unexpected features 0x%x\n",
705 libcfs_nid2str(gw->lpni_nid), gw->lpni_ping_feats);
706 spin_unlock(&gw->lpni_lock);
707 return; /* nothing I can understand */
710 if ((gw->lpni_ping_feats & LNET_PING_FEAT_NI_STATUS) == 0) {
711 spin_unlock(&gw->lpni_lock);
712 return; /* can't carry NI status info */
715 list_for_each_entry(rte, &gw->lpni_routes, lr_gwlist) {
720 if ((gw->lpni_ping_feats & LNET_PING_FEAT_RTE_DISABLED) != 0) {
725 for (i = 0; i < info->pi_nnis && i < LNET_MAX_RTR_NIS; i++) {
726 struct lnet_ni_status *stat = &info->pi_ni[i];
727 lnet_nid_t nid = stat->ns_nid;
729 if (nid == LNET_NID_ANY) {
730 CDEBUG(D_NET, "%s: unexpected LNET_NID_ANY\n",
731 libcfs_nid2str(gw->lpni_nid));
732 gw->lpni_ping_feats = LNET_PING_FEAT_INVAL;
733 spin_unlock(&gw->lpni_lock);
737 if (LNET_NETTYP(LNET_NIDNET(nid)) == LOLND)
740 if (stat->ns_status == LNET_NI_STATUS_DOWN) {
745 if (stat->ns_status == LNET_NI_STATUS_UP) {
746 if (LNET_NIDNET(nid) == rte->lr_net) {
753 CDEBUG(D_NET, "%s: Unexpected status 0x%x\n",
754 libcfs_nid2str(gw->lpni_nid), stat->ns_status);
755 gw->lpni_ping_feats = LNET_PING_FEAT_INVAL;
756 spin_unlock(&gw->lpni_lock);
760 if (up) { /* ignore downed NIs if NI for dest network is up */
764 /* if @down is zero and this route is single-hop, it means
765 * we can't find NI for target network */
766 if (down == 0 && rte->lr_hops == 1)
769 rte->lr_downis = down;
772 spin_unlock(&gw->lpni_lock);
776 lnet_router_checker_event(struct lnet_event *event)
778 struct lnet_rc_data *rcd = event->md.user_ptr;
779 struct lnet_peer_ni *lp;
781 LASSERT(rcd != NULL);
783 if (event->unlinked) {
784 LNetInvalidateMDHandle(&rcd->rcd_mdh);
788 LASSERT(event->type == LNET_EVENT_SEND ||
789 event->type == LNET_EVENT_REPLY);
791 lp = rcd->rcd_gateway;
794 /* NB: it's called with holding lnet_res_lock, we have a few
795 * places need to hold both locks at the same time, please take
796 * care of lock ordering */
797 lnet_net_lock(lp->lpni_cpt);
798 if (!lnet_isrouter(lp) || lp->lpni_rcd != rcd) {
799 /* ignore if no longer a router or rcd is replaced */
803 if (event->type == LNET_EVENT_SEND) {
804 lp->lpni_ping_notsent = 0;
805 if (event->status == 0)
809 /* LNET_EVENT_REPLY */
810 /* A successful REPLY means the router is up. If _any_ comms
811 * to the router fail I assume it's down (this will happen if
812 * we ping alive routers to try to detect router death before
813 * apps get burned). */
815 lnet_notify_locked(lp, 1, (event->status == 0), cfs_time_current());
816 /* The router checker will wake up very shortly and do the
817 * actual notification.
818 * XXX If 'lp' stops being a router before then, it will still
819 * have the notification pending!!! */
821 if (avoid_asym_router_failure && event->status == 0)
822 lnet_parse_rc_info(rcd);
825 lnet_net_unlock(lp->lpni_cpt);
829 lnet_wait_known_routerstate(void)
831 struct lnet_peer_ni *rtr;
832 struct list_head *entry;
835 LASSERT(the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING);
838 int cpt = lnet_net_lock_current();
841 list_for_each(entry, &the_lnet.ln_routers) {
842 rtr = list_entry(entry, struct lnet_peer_ni,
845 spin_lock(&rtr->lpni_lock);
847 if (rtr->lpni_alive_count == 0) {
849 spin_unlock(&rtr->lpni_lock);
852 spin_unlock(&rtr->lpni_lock);
855 lnet_net_unlock(cpt);
860 set_current_state(TASK_UNINTERRUPTIBLE);
861 schedule_timeout(cfs_time_seconds(1));
866 lnet_router_ni_update_locked(struct lnet_peer_ni *gw, __u32 net)
868 struct lnet_route *rte;
870 if ((gw->lpni_ping_feats & LNET_PING_FEAT_NI_STATUS) != 0) {
871 list_for_each_entry(rte, &gw->lpni_routes, lr_gwlist) {
872 if (rte->lr_net == net) {
881 lnet_update_ni_status_locked(void)
883 struct lnet_ni *ni = NULL;
887 LASSERT(the_lnet.ln_routing);
889 timeout = router_ping_timeout +
890 MAX(live_router_check_interval, dead_router_check_interval);
892 now = ktime_get_real_seconds();
893 while ((ni = lnet_get_next_ni_locked(NULL, ni))) {
894 if (ni->ni_net->net_lnd->lnd_type == LOLND)
897 if (now < ni->ni_last_alive + timeout)
901 /* re-check with lock */
902 if (now < ni->ni_last_alive + timeout) {
907 LASSERT(ni->ni_status != NULL);
909 if (ni->ni_status->ns_status != LNET_NI_STATUS_DOWN) {
910 CDEBUG(D_NET, "NI(%s:%d) status changed to down\n",
911 libcfs_nid2str(ni->ni_nid), timeout);
912 /* NB: so far, this is the only place to set
913 * NI status to "down" */
914 ni->ni_status->ns_status = LNET_NI_STATUS_DOWN;
921 lnet_destroy_rc_data(struct lnet_rc_data *rcd)
923 LASSERT(list_empty(&rcd->rcd_list));
924 /* detached from network */
925 LASSERT(LNetMDHandleIsInvalid(rcd->rcd_mdh));
927 if (rcd->rcd_gateway != NULL) {
928 int cpt = rcd->rcd_gateway->lpni_cpt;
931 lnet_peer_ni_decref_locked(rcd->rcd_gateway);
932 lnet_net_unlock(cpt);
935 if (rcd->rcd_pinginfo != NULL)
936 LIBCFS_FREE(rcd->rcd_pinginfo, LNET_PINGINFO_SIZE);
938 LIBCFS_FREE(rcd, sizeof(*rcd));
941 static struct lnet_rc_data *
942 lnet_create_rc_data_locked(struct lnet_peer_ni *gateway)
944 struct lnet_rc_data *rcd = NULL;
945 struct lnet_ping_info *pi;
949 lnet_net_unlock(gateway->lpni_cpt);
951 LIBCFS_ALLOC(rcd, sizeof(*rcd));
955 LNetInvalidateMDHandle(&rcd->rcd_mdh);
956 INIT_LIST_HEAD(&rcd->rcd_list);
958 LIBCFS_ALLOC(pi, LNET_PINGINFO_SIZE);
962 for (i = 0; i < LNET_MAX_RTR_NIS; i++) {
963 pi->pi_ni[i].ns_nid = LNET_NID_ANY;
964 pi->pi_ni[i].ns_status = LNET_NI_STATUS_INVALID;
966 rcd->rcd_pinginfo = pi;
968 LASSERT(!LNetEQHandleIsInvalid(the_lnet.ln_rc_eqh));
969 rc = LNetMDBind((struct lnet_md){.start = pi,
971 .length = LNET_PINGINFO_SIZE,
972 .threshold = LNET_MD_THRESH_INF,
973 .options = LNET_MD_TRUNCATE,
974 .eq_handle = the_lnet.ln_rc_eqh},
978 CERROR("Can't bind MD: %d\n", rc);
983 lnet_net_lock(gateway->lpni_cpt);
984 /* router table changed or someone has created rcd for this gateway */
985 if (!lnet_isrouter(gateway) || gateway->lpni_rcd != NULL) {
986 lnet_net_unlock(gateway->lpni_cpt);
990 lnet_peer_ni_addref_locked(gateway);
991 rcd->rcd_gateway = gateway;
992 gateway->lpni_rcd = rcd;
993 gateway->lpni_ping_notsent = 0;
999 if (!LNetMDHandleIsInvalid(rcd->rcd_mdh)) {
1000 rc = LNetMDUnlink(rcd->rcd_mdh);
1003 lnet_destroy_rc_data(rcd);
1006 lnet_net_lock(gateway->lpni_cpt);
1007 return gateway->lpni_rcd;
1011 lnet_router_check_interval(struct lnet_peer_ni *rtr)
1015 secs = rtr->lpni_alive ? live_router_check_interval :
1016 dead_router_check_interval;
1024 lnet_ping_router_locked(struct lnet_peer_ni *rtr)
1026 struct lnet_rc_data *rcd = NULL;
1027 cfs_time_t now = cfs_time_current();
1031 lnet_peer_ni_addref_locked(rtr);
1033 if (rtr->lpni_ping_deadline != 0 && /* ping timed out? */
1034 cfs_time_after(now, rtr->lpni_ping_deadline))
1035 lnet_notify_locked(rtr, 1, 0, now);
1037 /* Run any outstanding notifications */
1038 ni = lnet_get_next_ni_locked(rtr->lpni_net, NULL);
1039 lnet_ni_notify_locked(ni, rtr);
1041 if (!lnet_isrouter(rtr) ||
1042 the_lnet.ln_rc_state != LNET_RC_STATE_RUNNING) {
1043 /* router table changed or router checker is shutting down */
1044 lnet_peer_ni_decref_locked(rtr);
1048 rcd = rtr->lpni_rcd != NULL ?
1049 rtr->lpni_rcd : lnet_create_rc_data_locked(rtr);
1054 secs = lnet_router_check_interval(rtr);
1057 "rtr %s %d: deadline %lu ping_notsent %d alive %d "
1058 "alive_count %d lpni_ping_timestamp %lu\n",
1059 libcfs_nid2str(rtr->lpni_nid), secs,
1060 rtr->lpni_ping_deadline, rtr->lpni_ping_notsent,
1061 rtr->lpni_alive, rtr->lpni_alive_count, rtr->lpni_ping_timestamp);
1063 if (secs != 0 && !rtr->lpni_ping_notsent &&
1064 cfs_time_after(now, cfs_time_add(rtr->lpni_ping_timestamp,
1065 cfs_time_seconds(secs)))) {
1067 struct lnet_process_id id;
1068 struct lnet_handle_md mdh;
1070 id.nid = rtr->lpni_nid;
1071 id.pid = LNET_PID_LUSTRE;
1072 CDEBUG(D_NET, "Check: %s\n", libcfs_id2str(id));
1074 rtr->lpni_ping_notsent = 1;
1075 rtr->lpni_ping_timestamp = now;
1079 if (rtr->lpni_ping_deadline == 0) {
1080 rtr->lpni_ping_deadline =
1081 cfs_time_shift(router_ping_timeout);
1084 lnet_net_unlock(rtr->lpni_cpt);
1086 rc = LNetGet(LNET_NID_ANY, mdh, id, LNET_RESERVED_PORTAL,
1087 LNET_PROTO_PING_MATCHBITS, 0);
1089 lnet_net_lock(rtr->lpni_cpt);
1091 rtr->lpni_ping_notsent = 0; /* no event pending */
1094 lnet_peer_ni_decref_locked(rtr);
1099 lnet_router_checker_start(void)
1103 struct task_struct *task;
1105 LASSERT(the_lnet.ln_rc_state == LNET_RC_STATE_SHUTDOWN);
1107 if (check_routers_before_use &&
1108 dead_router_check_interval <= 0) {
1109 LCONSOLE_ERROR_MSG(0x10a, "'dead_router_check_interval' must be"
1110 " set if 'check_routers_before_use' is set"
1115 sema_init(&the_lnet.ln_rc_signal, 0);
1117 rc = LNetEQAlloc(0, lnet_router_checker_event, &the_lnet.ln_rc_eqh);
1119 CERROR("Can't allocate EQ(%d): %d\n", eqsz, rc);
1123 the_lnet.ln_rc_state = LNET_RC_STATE_RUNNING;
1124 task = kthread_run(lnet_router_checker, NULL, "router_checker");
1127 CERROR("Can't start router checker thread: %d\n", rc);
1128 /* block until event callback signals exit */
1129 down(&the_lnet.ln_rc_signal);
1130 rc = LNetEQFree(the_lnet.ln_rc_eqh);
1132 the_lnet.ln_rc_state = LNET_RC_STATE_SHUTDOWN;
1136 if (check_routers_before_use) {
1137 /* Note that a helpful side-effect of pinging all known routers
1138 * at startup is that it makes them drop stale connections they
1139 * may have to a previous instance of me. */
1140 lnet_wait_known_routerstate();
1147 lnet_router_checker_stop (void)
1151 if (the_lnet.ln_rc_state == LNET_RC_STATE_SHUTDOWN)
1154 LASSERT (the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING);
1155 the_lnet.ln_rc_state = LNET_RC_STATE_STOPPING;
1156 /* wakeup the RC thread if it's sleeping */
1157 wake_up(&the_lnet.ln_rc_waitq);
1159 /* block until event callback signals exit */
1160 down(&the_lnet.ln_rc_signal);
1161 LASSERT(the_lnet.ln_rc_state == LNET_RC_STATE_SHUTDOWN);
1163 rc = LNetEQFree(the_lnet.ln_rc_eqh);
1169 lnet_prune_rc_data(int wait_unlink)
1171 struct lnet_rc_data *rcd;
1172 struct lnet_rc_data *tmp;
1173 struct lnet_peer_ni *lp;
1174 struct list_head head;
1177 if (likely(the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING &&
1178 list_empty(&the_lnet.ln_rcd_deathrow) &&
1179 list_empty(&the_lnet.ln_rcd_zombie)))
1182 INIT_LIST_HEAD(&head);
1184 lnet_net_lock(LNET_LOCK_EX);
1186 if (the_lnet.ln_rc_state != LNET_RC_STATE_RUNNING) {
1187 /* router checker is stopping, prune all */
1188 list_for_each_entry(lp, &the_lnet.ln_routers,
1190 if (lp->lpni_rcd == NULL)
1193 LASSERT(list_empty(&lp->lpni_rcd->rcd_list));
1194 list_add(&lp->lpni_rcd->rcd_list,
1195 &the_lnet.ln_rcd_deathrow);
1196 lp->lpni_rcd = NULL;
1200 /* unlink all RCDs on deathrow list */
1201 list_splice_init(&the_lnet.ln_rcd_deathrow, &head);
1203 if (!list_empty(&head)) {
1204 lnet_net_unlock(LNET_LOCK_EX);
1206 list_for_each_entry(rcd, &head, rcd_list)
1207 LNetMDUnlink(rcd->rcd_mdh);
1209 lnet_net_lock(LNET_LOCK_EX);
1212 list_splice_init(&head, &the_lnet.ln_rcd_zombie);
1214 /* release all zombie RCDs */
1215 while (!list_empty(&the_lnet.ln_rcd_zombie)) {
1216 list_for_each_entry_safe(rcd, tmp, &the_lnet.ln_rcd_zombie,
1218 if (LNetMDHandleIsInvalid(rcd->rcd_mdh))
1219 list_move(&rcd->rcd_list, &head);
1222 wait_unlink = wait_unlink &&
1223 !list_empty(&the_lnet.ln_rcd_zombie);
1225 lnet_net_unlock(LNET_LOCK_EX);
1227 while (!list_empty(&head)) {
1228 rcd = list_entry(head.next,
1229 struct lnet_rc_data, rcd_list);
1230 list_del_init(&rcd->rcd_list);
1231 lnet_destroy_rc_data(rcd);
1238 CDEBUG(((i & (-i)) == i) ? D_WARNING : D_NET,
1239 "Waiting for rc buffers to unlink\n");
1240 set_current_state(TASK_UNINTERRUPTIBLE);
1241 schedule_timeout(cfs_time_seconds(1) / 4);
1243 lnet_net_lock(LNET_LOCK_EX);
1246 lnet_net_unlock(LNET_LOCK_EX);
1250 * This function is called to check if the RC should block indefinitely.
1251 * It's called from lnet_router_checker() as well as being passed to
1252 * wait_event_interruptible() to avoid the lost wake_up problem.
1254 * When it's called from wait_event_interruptible() it is necessary to
1255 * also not sleep if the rc state is not running to avoid a deadlock
1256 * when the system is shutting down
1259 lnet_router_checker_active(void)
1261 if (the_lnet.ln_rc_state != LNET_RC_STATE_RUNNING)
1264 /* Router Checker thread needs to run when routing is enabled in
1265 * order to call lnet_update_ni_status_locked() */
1266 if (the_lnet.ln_routing)
1269 return !list_empty(&the_lnet.ln_routers) &&
1270 (live_router_check_interval > 0 ||
1271 dead_router_check_interval > 0);
1275 lnet_router_checker(void *arg)
1277 struct lnet_peer_ni *rtr;
1278 struct list_head *entry;
1280 cfs_block_allsigs();
1282 while (the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING) {
1287 cpt = lnet_net_lock_current();
1289 version = the_lnet.ln_routers_version;
1291 list_for_each(entry, &the_lnet.ln_routers) {
1292 rtr = list_entry(entry, struct lnet_peer_ni,
1295 cpt2 = rtr->lpni_cpt;
1297 lnet_net_unlock(cpt);
1300 /* the routers list has changed */
1301 if (version != the_lnet.ln_routers_version)
1305 lnet_ping_router_locked(rtr);
1307 /* NB dropped lock */
1308 if (version != the_lnet.ln_routers_version) {
1309 /* the routers list has changed */
1314 if (the_lnet.ln_routing)
1315 lnet_update_ni_status_locked();
1317 lnet_net_unlock(cpt);
1319 lnet_prune_rc_data(0); /* don't wait for UNLINK */
1321 /* Call schedule_timeout() here always adds 1 to load average
1322 * because kernel counts # active tasks as nr_running
1323 * + nr_uninterruptible. */
1324 /* if there are any routes then wakeup every second. If
1325 * there are no routes then sleep indefinitely until woken
1326 * up by a user adding a route */
1327 if (!lnet_router_checker_active())
1328 wait_event_interruptible(the_lnet.ln_rc_waitq,
1329 lnet_router_checker_active());
1331 wait_event_interruptible_timeout(the_lnet.ln_rc_waitq,
1333 cfs_time_seconds(1));
1336 lnet_prune_rc_data(1); /* wait for UNLINK */
1338 the_lnet.ln_rc_state = LNET_RC_STATE_SHUTDOWN;
1339 up(&the_lnet.ln_rc_signal);
1340 /* The unlink event callback will signal final completion */
1345 lnet_destroy_rtrbuf(struct lnet_rtrbuf *rb, int npages)
1347 int sz = offsetof(struct lnet_rtrbuf, rb_kiov[npages]);
1349 while (--npages >= 0)
1350 __free_page(rb->rb_kiov[npages].kiov_page);
1352 LIBCFS_FREE(rb, sz);
1355 static struct lnet_rtrbuf *
1356 lnet_new_rtrbuf(struct lnet_rtrbufpool *rbp, int cpt)
1358 int npages = rbp->rbp_npages;
1359 int sz = offsetof(struct lnet_rtrbuf, rb_kiov[npages]);
1361 struct lnet_rtrbuf *rb;
1364 LIBCFS_CPT_ALLOC(rb, lnet_cpt_table(), cpt, sz);
1370 for (i = 0; i < npages; i++) {
1371 page = cfs_page_cpt_alloc(lnet_cpt_table(), cpt,
1372 GFP_KERNEL | __GFP_ZERO);
1375 __free_page(rb->rb_kiov[i].kiov_page);
1377 LIBCFS_FREE(rb, sz);
1381 rb->rb_kiov[i].kiov_len = PAGE_SIZE;
1382 rb->rb_kiov[i].kiov_offset = 0;
1383 rb->rb_kiov[i].kiov_page = page;
1390 lnet_rtrpool_free_bufs(struct lnet_rtrbufpool *rbp, int cpt)
1392 int npages = rbp->rbp_npages;
1393 struct lnet_rtrbuf *rb;
1394 struct list_head tmp;
1396 if (rbp->rbp_nbuffers == 0) /* not initialized or already freed */
1399 INIT_LIST_HEAD(&tmp);
1402 list_splice_init(&rbp->rbp_msgs, &tmp);
1403 lnet_drop_routed_msgs_locked(&tmp, cpt);
1404 list_splice_init(&rbp->rbp_bufs, &tmp);
1405 rbp->rbp_req_nbuffers = 0;
1406 rbp->rbp_nbuffers = rbp->rbp_credits = 0;
1407 rbp->rbp_mincredits = 0;
1408 lnet_net_unlock(cpt);
1410 /* Free buffers on the free list. */
1411 while (!list_empty(&tmp)) {
1412 rb = list_entry(tmp.next, struct lnet_rtrbuf, rb_list);
1413 list_del(&rb->rb_list);
1414 lnet_destroy_rtrbuf(rb, npages);
1419 lnet_rtrpool_adjust_bufs(struct lnet_rtrbufpool *rbp, int nbufs, int cpt)
1421 struct list_head rb_list;
1422 struct lnet_rtrbuf *rb;
1424 int num_buffers = 0;
1426 int npages = rbp->rbp_npages;
1429 /* If we are called for less buffers than already in the pool, we
1430 * just lower the req_nbuffers number and excess buffers will be
1431 * thrown away as they are returned to the free list. Credits
1432 * then get adjusted as well.
1433 * If we already have enough buffers allocated to serve the
1434 * increase requested, then we can treat that the same way as we
1435 * do the decrease. */
1436 num_rb = nbufs - rbp->rbp_nbuffers;
1437 if (nbufs <= rbp->rbp_req_nbuffers || num_rb <= 0) {
1438 rbp->rbp_req_nbuffers = nbufs;
1439 lnet_net_unlock(cpt);
1442 /* store the older value of rbp_req_nbuffers and then set it to
1443 * the new request to prevent lnet_return_rx_credits_locked() from
1444 * freeing buffers that we need to keep around */
1445 old_req_nbufs = rbp->rbp_req_nbuffers;
1446 rbp->rbp_req_nbuffers = nbufs;
1447 lnet_net_unlock(cpt);
1449 INIT_LIST_HEAD(&rb_list);
1451 /* allocate the buffers on a local list first. If all buffers are
1452 * allocated successfully then join this list to the rbp buffer
1453 * list. If not then free all allocated buffers. */
1454 while (num_rb-- > 0) {
1455 rb = lnet_new_rtrbuf(rbp, cpt);
1457 CERROR("Failed to allocate %d route bufs of %d pages\n",
1461 rbp->rbp_req_nbuffers = old_req_nbufs;
1462 lnet_net_unlock(cpt);
1467 list_add(&rb->rb_list, &rb_list);
1473 list_splice_tail(&rb_list, &rbp->rbp_bufs);
1474 rbp->rbp_nbuffers += num_buffers;
1475 rbp->rbp_credits += num_buffers;
1476 rbp->rbp_mincredits = rbp->rbp_credits;
1477 /* We need to schedule blocked msg using the newly
1479 while (!list_empty(&rbp->rbp_bufs) &&
1480 !list_empty(&rbp->rbp_msgs))
1481 lnet_schedule_blocked_locked(rbp);
1483 lnet_net_unlock(cpt);
1488 while (!list_empty(&rb_list)) {
1489 rb = list_entry(rb_list.next, struct lnet_rtrbuf, rb_list);
1490 list_del(&rb->rb_list);
1491 lnet_destroy_rtrbuf(rb, npages);
1498 lnet_rtrpool_init(struct lnet_rtrbufpool *rbp, int npages)
1500 INIT_LIST_HEAD(&rbp->rbp_msgs);
1501 INIT_LIST_HEAD(&rbp->rbp_bufs);
1503 rbp->rbp_npages = npages;
1504 rbp->rbp_credits = 0;
1505 rbp->rbp_mincredits = 0;
1509 lnet_rtrpools_free(int keep_pools)
1511 struct lnet_rtrbufpool *rtrp;
1514 if (the_lnet.ln_rtrpools == NULL) /* uninitialized or freed */
1517 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1518 lnet_rtrpool_free_bufs(&rtrp[LNET_TINY_BUF_IDX], i);
1519 lnet_rtrpool_free_bufs(&rtrp[LNET_SMALL_BUF_IDX], i);
1520 lnet_rtrpool_free_bufs(&rtrp[LNET_LARGE_BUF_IDX], i);
1524 cfs_percpt_free(the_lnet.ln_rtrpools);
1525 the_lnet.ln_rtrpools = NULL;
1530 lnet_nrb_tiny_calculate(void)
1532 int nrbs = LNET_NRB_TINY;
1534 if (tiny_router_buffers < 0) {
1535 LCONSOLE_ERROR_MSG(0x10c,
1536 "tiny_router_buffers=%d invalid when "
1537 "routing enabled\n", tiny_router_buffers);
1541 if (tiny_router_buffers > 0)
1542 nrbs = tiny_router_buffers;
1544 nrbs /= LNET_CPT_NUMBER;
1545 return max(nrbs, LNET_NRB_TINY_MIN);
1549 lnet_nrb_small_calculate(void)
1551 int nrbs = LNET_NRB_SMALL;
1553 if (small_router_buffers < 0) {
1554 LCONSOLE_ERROR_MSG(0x10c,
1555 "small_router_buffers=%d invalid when "
1556 "routing enabled\n", small_router_buffers);
1560 if (small_router_buffers > 0)
1561 nrbs = small_router_buffers;
1563 nrbs /= LNET_CPT_NUMBER;
1564 return max(nrbs, LNET_NRB_SMALL_MIN);
1568 lnet_nrb_large_calculate(void)
1570 int nrbs = LNET_NRB_LARGE;
1572 if (large_router_buffers < 0) {
1573 LCONSOLE_ERROR_MSG(0x10c,
1574 "large_router_buffers=%d invalid when "
1575 "routing enabled\n", large_router_buffers);
1579 if (large_router_buffers > 0)
1580 nrbs = large_router_buffers;
1582 nrbs /= LNET_CPT_NUMBER;
1583 return max(nrbs, LNET_NRB_LARGE_MIN);
1587 lnet_rtrpools_alloc(int im_a_router)
1589 struct lnet_rtrbufpool *rtrp;
1596 if (!strcmp(forwarding, "")) {
1597 /* not set either way */
1600 } else if (!strcmp(forwarding, "disabled")) {
1601 /* explicitly disabled */
1603 } else if (!strcmp(forwarding, "enabled")) {
1604 /* explicitly enabled */
1606 LCONSOLE_ERROR_MSG(0x10b, "'forwarding' not set to either "
1607 "'enabled' or 'disabled'\n");
1611 nrb_tiny = lnet_nrb_tiny_calculate();
1615 nrb_small = lnet_nrb_small_calculate();
1619 nrb_large = lnet_nrb_large_calculate();
1623 the_lnet.ln_rtrpools = cfs_percpt_alloc(lnet_cpt_table(),
1625 sizeof(struct lnet_rtrbufpool));
1626 if (the_lnet.ln_rtrpools == NULL) {
1627 LCONSOLE_ERROR_MSG(0x10c,
1628 "Failed to initialize router buffe pool\n");
1632 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1633 lnet_rtrpool_init(&rtrp[LNET_TINY_BUF_IDX], 0);
1634 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_TINY_BUF_IDX],
1639 lnet_rtrpool_init(&rtrp[LNET_SMALL_BUF_IDX],
1640 LNET_NRB_SMALL_PAGES);
1641 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_SMALL_BUF_IDX],
1646 lnet_rtrpool_init(&rtrp[LNET_LARGE_BUF_IDX],
1647 LNET_NRB_LARGE_PAGES);
1648 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_LARGE_BUF_IDX],
1654 lnet_net_lock(LNET_LOCK_EX);
1655 the_lnet.ln_routing = 1;
1656 lnet_net_unlock(LNET_LOCK_EX);
1660 lnet_rtrpools_free(0);
1665 lnet_rtrpools_adjust_helper(int tiny, int small, int large)
1670 struct lnet_rtrbufpool *rtrp;
1672 /* If the provided values for each buffer pool are different than the
1673 * configured values, we need to take action. */
1675 tiny_router_buffers = tiny;
1676 nrb = lnet_nrb_tiny_calculate();
1677 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1678 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_TINY_BUF_IDX],
1685 small_router_buffers = small;
1686 nrb = lnet_nrb_small_calculate();
1687 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1688 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_SMALL_BUF_IDX],
1695 large_router_buffers = large;
1696 nrb = lnet_nrb_large_calculate();
1697 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1698 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_LARGE_BUF_IDX],
1709 lnet_rtrpools_adjust(int tiny, int small, int large)
1711 /* this function doesn't revert the changes if adding new buffers
1712 * failed. It's up to the user space caller to revert the
1715 if (!the_lnet.ln_routing)
1718 return lnet_rtrpools_adjust_helper(tiny, small, large);
1722 lnet_rtrpools_enable(void)
1726 if (the_lnet.ln_routing)
1729 if (the_lnet.ln_rtrpools == NULL)
1730 /* If routing is turned off, and we have never
1731 * initialized the pools before, just call the
1732 * standard buffer pool allocation routine as
1733 * if we are just configuring this for the first
1735 rc = lnet_rtrpools_alloc(1);
1737 rc = lnet_rtrpools_adjust_helper(0, 0, 0);
1741 lnet_net_lock(LNET_LOCK_EX);
1742 the_lnet.ln_routing = 1;
1744 the_lnet.ln_ping_info->pi_features &= ~LNET_PING_FEAT_RTE_DISABLED;
1745 lnet_net_unlock(LNET_LOCK_EX);
1751 lnet_rtrpools_disable(void)
1753 if (!the_lnet.ln_routing)
1756 lnet_net_lock(LNET_LOCK_EX);
1757 the_lnet.ln_routing = 0;
1758 the_lnet.ln_ping_info->pi_features |= LNET_PING_FEAT_RTE_DISABLED;
1760 tiny_router_buffers = 0;
1761 small_router_buffers = 0;
1762 large_router_buffers = 0;
1763 lnet_net_unlock(LNET_LOCK_EX);
1764 lnet_rtrpools_free(1);
1768 lnet_notify(struct lnet_ni *ni, lnet_nid_t nid, int alive, cfs_time_t when)
1770 struct lnet_peer_ni *lp = NULL;
1771 cfs_time_t now = cfs_time_current();
1772 int cpt = lnet_cpt_of_nid(nid, ni);
1774 LASSERT (!in_interrupt ());
1776 CDEBUG (D_NET, "%s notifying %s: %s\n",
1777 (ni == NULL) ? "userspace" : libcfs_nid2str(ni->ni_nid),
1778 libcfs_nid2str(nid),
1779 alive ? "up" : "down");
1782 LNET_NIDNET(ni->ni_nid) != LNET_NIDNET(nid)) {
1783 CWARN("Ignoring notification of %s %s by %s (different net)\n",
1784 libcfs_nid2str(nid), alive ? "birth" : "death",
1785 libcfs_nid2str(ni->ni_nid));
1789 /* can't do predictions... */
1790 if (cfs_time_after(when, now)) {
1791 CWARN("Ignoring prediction from %s of %s %s "
1792 "%ld seconds in the future\n",
1793 (ni == NULL) ? "userspace" : libcfs_nid2str(ni->ni_nid),
1794 libcfs_nid2str(nid), alive ? "up" : "down",
1795 cfs_duration_sec(cfs_time_sub(when, now)));
1799 if (ni != NULL && !alive && /* LND telling me she's down */
1800 !auto_down) { /* auto-down disabled */
1801 CDEBUG(D_NET, "Auto-down disabled\n");
1807 if (the_lnet.ln_shutdown) {
1808 lnet_net_unlock(cpt);
1812 lp = lnet_find_peer_ni_locked(nid);
1815 lnet_net_unlock(cpt);
1816 CDEBUG(D_NET, "%s not found\n", libcfs_nid2str(nid));
1821 * It is possible for this function to be called for the same peer
1822 * but with different NIs. We want to synchronize the notification
1823 * between the different calls. So we will use the lpni_cpt to
1824 * grab the net lock.
1826 if (lp->lpni_cpt != cpt) {
1827 lnet_net_unlock(cpt);
1832 /* We can't fully trust LND on reporting exact peer last_alive
1833 * if he notifies us about dead peer. For example ksocklnd can
1834 * call us with when == _time_when_the_node_was_booted_ if
1835 * no connections were successfully established */
1836 if (ni != NULL && !alive && when < lp->lpni_last_alive)
1837 when = lp->lpni_last_alive;
1839 lnet_notify_locked(lp, ni == NULL, alive, when);
1842 lnet_ni_notify_locked(ni, lp);
1844 lnet_peer_ni_decref_locked(lp);
1846 lnet_net_unlock(cpt);
1849 EXPORT_SYMBOL(lnet_notify);