2 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
4 * Copyright (c) 2011, 2015, 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.
20 #define DEBUG_SUBSYSTEM S_LNET
21 #include <linux/completion.h>
22 #include "../../include/linux/lnet/lib-lnet.h"
24 #define LNET_NRB_TINY_MIN 512 /* min value for each CPT */
25 #define LNET_NRB_TINY (LNET_NRB_TINY_MIN * 4)
26 #define LNET_NRB_SMALL_MIN 4096 /* min value for each CPT */
27 #define LNET_NRB_SMALL (LNET_NRB_SMALL_MIN * 4)
28 #define LNET_NRB_SMALL_PAGES 1
29 #define LNET_NRB_LARGE_MIN 256 /* min value for each CPT */
30 #define LNET_NRB_LARGE (LNET_NRB_LARGE_MIN * 4)
31 #define LNET_NRB_LARGE_PAGES ((LNET_MTU + PAGE_SIZE - 1) >> \
34 static char *forwarding = "";
35 module_param(forwarding, charp, 0444);
36 MODULE_PARM_DESC(forwarding, "Explicitly enable/disable forwarding between networks");
38 static int tiny_router_buffers;
39 module_param(tiny_router_buffers, int, 0444);
40 MODULE_PARM_DESC(tiny_router_buffers, "# of 0 payload messages to buffer in the router");
41 static int small_router_buffers;
42 module_param(small_router_buffers, int, 0444);
43 MODULE_PARM_DESC(small_router_buffers, "# of small (1 page) messages to buffer in the router");
44 static int large_router_buffers;
45 module_param(large_router_buffers, int, 0444);
46 MODULE_PARM_DESC(large_router_buffers, "# of large messages to buffer in the router");
47 static int peer_buffer_credits;
48 module_param(peer_buffer_credits, int, 0444);
49 MODULE_PARM_DESC(peer_buffer_credits, "# router buffer credits per peer");
51 static int auto_down = 1;
52 module_param(auto_down, int, 0444);
53 MODULE_PARM_DESC(auto_down, "Automatically mark peers down on comms error");
56 lnet_peer_buffer_credits(lnet_ni_t *ni)
58 /* NI option overrides LNet default */
59 if (ni->ni_peerrtrcredits > 0)
60 return ni->ni_peerrtrcredits;
61 if (peer_buffer_credits > 0)
62 return peer_buffer_credits;
65 * As an approximation, allow this peer the same number of router
66 * buffers as it is allowed outstanding sends
68 return ni->ni_peertxcredits;
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(lnet_peer_t *lp, int notifylnd, int alive,
104 if (time_before(when, lp->lp_timestamp)) { /* out of date information */
105 CDEBUG(D_NET, "Out of date\n");
109 lp->lp_timestamp = when; /* update timestamp */
110 lp->lp_ping_deadline = 0; /* disable ping timeout */
112 if (lp->lp_alive_count && /* got old news */
113 (!lp->lp_alive) == (!alive)) { /* new date for old news */
114 CDEBUG(D_NET, "Old news\n");
118 /* Flag that notification is outstanding */
120 lp->lp_alive_count++;
121 lp->lp_alive = !(!alive); /* 1 bit! */
123 lp->lp_notifylnd |= notifylnd;
125 lp->lp_ping_feats = LNET_PING_FEAT_INVAL; /* reset */
127 CDEBUG(D_NET, "set %s %d\n", libcfs_nid2str(lp->lp_nid), alive);
131 lnet_ni_notify_locked(lnet_ni_t *ni, lnet_peer_t *lp)
137 * Notify only in 1 thread at any time to ensure ordered notification.
138 * NB individual events can be missed; the only guarantee is that you
139 * always get the most recent news
141 if (lp->lp_notifying || !ni)
144 lp->lp_notifying = 1;
146 while (lp->lp_notify) {
147 alive = lp->lp_alive;
148 notifylnd = lp->lp_notifylnd;
150 lp->lp_notifylnd = 0;
153 if (notifylnd && ni->ni_lnd->lnd_notify) {
154 lnet_net_unlock(lp->lp_cpt);
157 * A new notification could happen now; I'll handle it
158 * when control returns to me
160 ni->ni_lnd->lnd_notify(ni, lp->lp_nid, alive);
162 lnet_net_lock(lp->lp_cpt);
166 lp->lp_notifying = 0;
170 lnet_rtr_addref_locked(lnet_peer_t *lp)
172 LASSERT(lp->lp_refcount > 0);
173 LASSERT(lp->lp_rtr_refcount >= 0);
175 /* lnet_net_lock must be exclusively locked */
176 lp->lp_rtr_refcount++;
177 if (lp->lp_rtr_refcount == 1) {
178 struct list_head *pos;
180 /* a simple insertion sort */
181 list_for_each_prev(pos, &the_lnet.ln_routers) {
182 lnet_peer_t *rtr = list_entry(pos, lnet_peer_t,
185 if (rtr->lp_nid < lp->lp_nid)
189 list_add(&lp->lp_rtr_list, pos);
190 /* addref for the_lnet.ln_routers */
191 lnet_peer_addref_locked(lp);
192 the_lnet.ln_routers_version++;
197 lnet_rtr_decref_locked(lnet_peer_t *lp)
199 LASSERT(lp->lp_refcount > 0);
200 LASSERT(lp->lp_rtr_refcount > 0);
202 /* lnet_net_lock must be exclusively locked */
203 lp->lp_rtr_refcount--;
204 if (!lp->lp_rtr_refcount) {
205 LASSERT(list_empty(&lp->lp_routes));
208 list_add(&lp->lp_rcd->rcd_list,
209 &the_lnet.ln_rcd_deathrow);
213 list_del(&lp->lp_rtr_list);
214 /* decref for the_lnet.ln_routers */
215 lnet_peer_decref_locked(lp);
216 the_lnet.ln_routers_version++;
221 lnet_find_net_locked(__u32 net)
223 lnet_remotenet_t *rnet;
224 struct list_head *tmp;
225 struct list_head *rn_list;
227 LASSERT(!the_lnet.ln_shutdown);
229 rn_list = lnet_net2rnethash(net);
230 list_for_each(tmp, rn_list) {
231 rnet = list_entry(tmp, lnet_remotenet_t, lrn_list);
233 if (rnet->lrn_net == net)
239 static void lnet_shuffle_seed(void)
242 __u32 lnd_type, seed[2];
243 struct timespec64 ts;
245 struct list_head *tmp;
250 cfs_get_random_bytes(seed, sizeof(seed));
253 * Nodes with small feet have little entropy
254 * the NID for this node gives the most entropy in the low bits
256 list_for_each(tmp, &the_lnet.ln_nis) {
257 ni = list_entry(tmp, lnet_ni_t, ni_list);
258 lnd_type = LNET_NETTYP(LNET_NIDNET(ni->ni_nid));
260 if (lnd_type != LOLND)
261 seed[0] ^= (LNET_NIDADDR(ni->ni_nid) | lnd_type);
265 cfs_srand(ts.tv_sec ^ seed[0], ts.tv_nsec ^ seed[1]);
269 /* NB expects LNET_LOCK held */
271 lnet_add_route_to_rnet(lnet_remotenet_t *rnet, lnet_route_t *route)
273 unsigned int len = 0;
274 unsigned int offset = 0;
279 list_for_each(e, &rnet->lrn_routes) {
283 /* len+1 positions to add a new entry, also prevents division by 0 */
284 offset = cfs_rand() % (len + 1);
285 list_for_each(e, &rnet->lrn_routes) {
290 list_add(&route->lr_list, e);
291 list_add(&route->lr_gwlist, &route->lr_gateway->lp_routes);
293 the_lnet.ln_remote_nets_version++;
294 lnet_rtr_addref_locked(route->lr_gateway);
298 lnet_add_route(__u32 net, __u32 hops, lnet_nid_t gateway,
299 unsigned int priority)
302 lnet_remotenet_t *rnet;
303 lnet_remotenet_t *rnet2;
309 CDEBUG(D_NET, "Add route: net %s hops %d priority %u gw %s\n",
310 libcfs_net2str(net), hops, priority, libcfs_nid2str(gateway));
312 if (gateway == LNET_NID_ANY ||
313 LNET_NETTYP(LNET_NIDNET(gateway)) == LOLND ||
314 net == LNET_NIDNET(LNET_NID_ANY) ||
315 LNET_NETTYP(net) == LOLND ||
316 LNET_NIDNET(gateway) == net ||
317 (hops != LNET_UNDEFINED_HOPS && (hops < 1 || hops > 255)))
320 if (lnet_islocalnet(net)) /* it's a local network */
323 /* Assume net, route, all new */
324 LIBCFS_ALLOC(route, sizeof(*route));
325 LIBCFS_ALLOC(rnet, sizeof(*rnet));
326 if (!route || !rnet) {
327 CERROR("Out of memory creating route %s %d %s\n",
328 libcfs_net2str(net), hops, libcfs_nid2str(gateway));
330 LIBCFS_FREE(route, sizeof(*route));
332 LIBCFS_FREE(rnet, sizeof(*rnet));
336 INIT_LIST_HEAD(&rnet->lrn_routes);
338 route->lr_hops = hops;
340 route->lr_priority = priority;
342 lnet_net_lock(LNET_LOCK_EX);
344 rc = lnet_nid2peer_locked(&route->lr_gateway, gateway, LNET_LOCK_EX);
346 lnet_net_unlock(LNET_LOCK_EX);
348 LIBCFS_FREE(route, sizeof(*route));
349 LIBCFS_FREE(rnet, sizeof(*rnet));
351 if (rc == -EHOSTUNREACH) /* gateway is not on a local net */
352 return rc; /* ignore the route entry */
353 CERROR("Error %d creating route %s %d %s\n", rc,
354 libcfs_net2str(net), hops,
355 libcfs_nid2str(gateway));
359 LASSERT(!the_lnet.ln_shutdown);
361 rnet2 = lnet_find_net_locked(net);
364 list_add_tail(&rnet->lrn_list, lnet_net2rnethash(net));
368 /* Search for a duplicate route (it's a NOOP if it is) */
370 list_for_each(e, &rnet2->lrn_routes) {
371 lnet_route_t *route2 = list_entry(e, lnet_route_t, lr_list);
373 if (route2->lr_gateway == route->lr_gateway) {
378 /* our lookups must be true */
379 LASSERT(route2->lr_gateway->lp_nid != gateway);
383 lnet_peer_addref_locked(route->lr_gateway); /* +1 for notify */
384 lnet_add_route_to_rnet(rnet2, route);
386 ni = route->lr_gateway->lp_ni;
387 lnet_net_unlock(LNET_LOCK_EX);
389 /* XXX Assume alive */
390 if (ni->ni_lnd->lnd_notify)
391 ni->ni_lnd->lnd_notify(ni, gateway, 1);
393 lnet_net_lock(LNET_LOCK_EX);
396 /* -1 for notify or !add_route */
397 lnet_peer_decref_locked(route->lr_gateway);
398 lnet_net_unlock(LNET_LOCK_EX);
403 LIBCFS_FREE(route, sizeof(*route));
407 LIBCFS_FREE(rnet, sizeof(*rnet));
409 /* indicate to startup the router checker if configured */
410 wake_up(&the_lnet.ln_rc_waitq);
416 lnet_check_routes(void)
418 lnet_remotenet_t *rnet;
420 lnet_route_t *route2;
421 struct list_head *e1;
422 struct list_head *e2;
424 struct list_head *rn_list;
427 cpt = lnet_net_lock_current();
429 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) {
430 rn_list = &the_lnet.ln_remote_nets_hash[i];
431 list_for_each(e1, rn_list) {
432 rnet = list_entry(e1, lnet_remotenet_t, lrn_list);
435 list_for_each(e2, &rnet->lrn_routes) {
440 route = list_entry(e2, lnet_route_t, lr_list);
447 if (route->lr_gateway->lp_ni ==
448 route2->lr_gateway->lp_ni)
451 nid1 = route->lr_gateway->lp_nid;
452 nid2 = route2->lr_gateway->lp_nid;
455 lnet_net_unlock(cpt);
457 CERROR("Routes to %s via %s and %s not supported\n",
459 libcfs_nid2str(nid1),
460 libcfs_nid2str(nid2));
466 lnet_net_unlock(cpt);
471 lnet_del_route(__u32 net, lnet_nid_t gw_nid)
473 struct lnet_peer *gateway;
474 lnet_remotenet_t *rnet;
476 struct list_head *e1;
477 struct list_head *e2;
479 struct list_head *rn_list;
482 CDEBUG(D_NET, "Del route: net %s : gw %s\n",
483 libcfs_net2str(net), libcfs_nid2str(gw_nid));
486 * NB Caller may specify either all routes via the given gateway
487 * or a specific route entry actual NIDs)
489 lnet_net_lock(LNET_LOCK_EX);
490 if (net == LNET_NIDNET(LNET_NID_ANY))
491 rn_list = &the_lnet.ln_remote_nets_hash[0];
493 rn_list = lnet_net2rnethash(net);
496 list_for_each(e1, rn_list) {
497 rnet = list_entry(e1, lnet_remotenet_t, lrn_list);
499 if (!(net == LNET_NIDNET(LNET_NID_ANY) ||
500 net == rnet->lrn_net))
503 list_for_each(e2, &rnet->lrn_routes) {
504 route = list_entry(e2, lnet_route_t, lr_list);
506 gateway = route->lr_gateway;
507 if (!(gw_nid == LNET_NID_ANY ||
508 gw_nid == gateway->lp_nid))
511 list_del(&route->lr_list);
512 list_del(&route->lr_gwlist);
513 the_lnet.ln_remote_nets_version++;
515 if (list_empty(&rnet->lrn_routes))
516 list_del(&rnet->lrn_list);
520 lnet_rtr_decref_locked(gateway);
521 lnet_peer_decref_locked(gateway);
523 lnet_net_unlock(LNET_LOCK_EX);
525 LIBCFS_FREE(route, sizeof(*route));
528 LIBCFS_FREE(rnet, sizeof(*rnet));
531 lnet_net_lock(LNET_LOCK_EX);
536 if (net == LNET_NIDNET(LNET_NID_ANY) &&
537 ++idx < LNET_REMOTE_NETS_HASH_SIZE) {
538 rn_list = &the_lnet.ln_remote_nets_hash[idx];
541 lnet_net_unlock(LNET_LOCK_EX);
547 lnet_destroy_routes(void)
549 lnet_del_route(LNET_NIDNET(LNET_NID_ANY), LNET_NID_ANY);
552 int lnet_get_rtr_pool_cfg(int idx, struct lnet_ioctl_pool_cfg *pool_cfg)
554 int i, rc = -ENOENT, j;
556 if (!the_lnet.ln_rtrpools)
559 for (i = 0; i < LNET_NRBPOOLS; i++) {
560 lnet_rtrbufpool_t *rbp;
562 lnet_net_lock(LNET_LOCK_EX);
563 cfs_percpt_for_each(rbp, j, the_lnet.ln_rtrpools) {
567 pool_cfg->pl_pools[i].pl_npages = rbp[i].rbp_npages;
568 pool_cfg->pl_pools[i].pl_nbuffers = rbp[i].rbp_nbuffers;
569 pool_cfg->pl_pools[i].pl_credits = rbp[i].rbp_credits;
570 pool_cfg->pl_pools[i].pl_mincredits = rbp[i].rbp_mincredits;
574 lnet_net_unlock(LNET_LOCK_EX);
577 lnet_net_lock(LNET_LOCK_EX);
578 pool_cfg->pl_routing = the_lnet.ln_routing;
579 lnet_net_unlock(LNET_LOCK_EX);
585 lnet_get_route(int idx, __u32 *net, __u32 *hops,
586 lnet_nid_t *gateway, __u32 *alive, __u32 *priority)
588 struct list_head *e1;
589 struct list_head *e2;
590 lnet_remotenet_t *rnet;
594 struct list_head *rn_list;
596 cpt = lnet_net_lock_current();
598 for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) {
599 rn_list = &the_lnet.ln_remote_nets_hash[i];
600 list_for_each(e1, rn_list) {
601 rnet = list_entry(e1, lnet_remotenet_t, lrn_list);
603 list_for_each(e2, &rnet->lrn_routes) {
604 route = list_entry(e2, lnet_route_t, lr_list);
607 *net = rnet->lrn_net;
608 *hops = route->lr_hops;
609 *priority = route->lr_priority;
610 *gateway = route->lr_gateway->lp_nid;
611 *alive = lnet_is_route_alive(route);
612 lnet_net_unlock(cpt);
619 lnet_net_unlock(cpt);
624 lnet_swap_pinginfo(lnet_ping_info_t *info)
627 lnet_ni_status_t *stat;
629 __swab32s(&info->pi_magic);
630 __swab32s(&info->pi_features);
631 __swab32s(&info->pi_pid);
632 __swab32s(&info->pi_nnis);
633 for (i = 0; i < info->pi_nnis && i < LNET_MAX_RTR_NIS; i++) {
634 stat = &info->pi_ni[i];
635 __swab64s(&stat->ns_nid);
636 __swab32s(&stat->ns_status);
641 * parse router-checker pinginfo, record number of down NIs for remote
642 * networks on that router.
645 lnet_parse_rc_info(lnet_rc_data_t *rcd)
647 lnet_ping_info_t *info = rcd->rcd_pinginfo;
648 struct lnet_peer *gw = rcd->rcd_gateway;
654 if (info->pi_magic == __swab32(LNET_PROTO_PING_MAGIC))
655 lnet_swap_pinginfo(info);
657 /* NB always racing with network! */
658 if (info->pi_magic != LNET_PROTO_PING_MAGIC) {
659 CDEBUG(D_NET, "%s: Unexpected magic %08x\n",
660 libcfs_nid2str(gw->lp_nid), info->pi_magic);
661 gw->lp_ping_feats = LNET_PING_FEAT_INVAL;
665 gw->lp_ping_feats = info->pi_features;
666 if (!(gw->lp_ping_feats & LNET_PING_FEAT_MASK)) {
667 CDEBUG(D_NET, "%s: Unexpected features 0x%x\n",
668 libcfs_nid2str(gw->lp_nid), gw->lp_ping_feats);
669 return; /* nothing I can understand */
672 if (!(gw->lp_ping_feats & LNET_PING_FEAT_NI_STATUS))
673 return; /* can't carry NI status info */
675 list_for_each_entry(rte, &gw->lp_routes, lr_gwlist) {
680 if (gw->lp_ping_feats & LNET_PING_FEAT_RTE_DISABLED) {
685 for (i = 0; i < info->pi_nnis && i < LNET_MAX_RTR_NIS; i++) {
686 lnet_ni_status_t *stat = &info->pi_ni[i];
687 lnet_nid_t nid = stat->ns_nid;
689 if (nid == LNET_NID_ANY) {
690 CDEBUG(D_NET, "%s: unexpected LNET_NID_ANY\n",
691 libcfs_nid2str(gw->lp_nid));
692 gw->lp_ping_feats = LNET_PING_FEAT_INVAL;
696 if (LNET_NETTYP(LNET_NIDNET(nid)) == LOLND)
699 if (stat->ns_status == LNET_NI_STATUS_DOWN) {
704 if (stat->ns_status == LNET_NI_STATUS_UP) {
705 if (LNET_NIDNET(nid) == rte->lr_net) {
712 CDEBUG(D_NET, "%s: Unexpected status 0x%x\n",
713 libcfs_nid2str(gw->lp_nid), stat->ns_status);
714 gw->lp_ping_feats = LNET_PING_FEAT_INVAL;
718 if (up) { /* ignore downed NIs if NI for dest network is up */
723 * if @down is zero and this route is single-hop, it means
724 * we can't find NI for target network
726 if (!down && rte->lr_hops == 1)
729 rte->lr_downis = down;
734 lnet_router_checker_event(lnet_event_t *event)
736 lnet_rc_data_t *rcd = event->md.user_ptr;
737 struct lnet_peer *lp;
741 if (event->unlinked) {
742 LNetInvalidateHandle(&rcd->rcd_mdh);
746 LASSERT(event->type == LNET_EVENT_SEND ||
747 event->type == LNET_EVENT_REPLY);
749 lp = rcd->rcd_gateway;
753 * NB: it's called with holding lnet_res_lock, we have a few
754 * places need to hold both locks at the same time, please take
755 * care of lock ordering
757 lnet_net_lock(lp->lp_cpt);
758 if (!lnet_isrouter(lp) || lp->lp_rcd != rcd) {
759 /* ignore if no longer a router or rcd is replaced */
763 if (event->type == LNET_EVENT_SEND) {
764 lp->lp_ping_notsent = 0;
769 /* LNET_EVENT_REPLY */
771 * A successful REPLY means the router is up. If _any_ comms
772 * to the router fail I assume it's down (this will happen if
773 * we ping alive routers to try to detect router death before
776 lnet_notify_locked(lp, 1, !event->status, cfs_time_current());
779 * The router checker will wake up very shortly and do the
780 * actual notification.
781 * XXX If 'lp' stops being a router before then, it will still
782 * have the notification pending!!!
784 if (avoid_asym_router_failure && !event->status)
785 lnet_parse_rc_info(rcd);
788 lnet_net_unlock(lp->lp_cpt);
792 lnet_wait_known_routerstate(void)
795 struct list_head *entry;
798 LASSERT(the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING);
801 int cpt = lnet_net_lock_current();
804 list_for_each(entry, &the_lnet.ln_routers) {
805 rtr = list_entry(entry, lnet_peer_t, lp_rtr_list);
807 if (!rtr->lp_alive_count) {
813 lnet_net_unlock(cpt);
818 set_current_state(TASK_UNINTERRUPTIBLE);
819 schedule_timeout(cfs_time_seconds(1));
824 lnet_router_ni_update_locked(lnet_peer_t *gw, __u32 net)
828 if ((gw->lp_ping_feats & LNET_PING_FEAT_NI_STATUS)) {
829 list_for_each_entry(rte, &gw->lp_routes, lr_gwlist) {
830 if (rte->lr_net == net) {
839 lnet_update_ni_status_locked(void)
845 LASSERT(the_lnet.ln_routing);
847 timeout = router_ping_timeout +
848 max(live_router_check_interval, dead_router_check_interval);
850 now = ktime_get_real_seconds();
851 list_for_each_entry(ni, &the_lnet.ln_nis, ni_list) {
852 if (ni->ni_lnd->lnd_type == LOLND)
855 if (now < ni->ni_last_alive + timeout)
859 /* re-check with lock */
860 if (now < ni->ni_last_alive + timeout) {
865 LASSERT(ni->ni_status);
867 if (ni->ni_status->ns_status != LNET_NI_STATUS_DOWN) {
868 CDEBUG(D_NET, "NI(%s:%d) status changed to down\n",
869 libcfs_nid2str(ni->ni_nid), timeout);
871 * NB: so far, this is the only place to set
872 * NI status to "down"
874 ni->ni_status->ns_status = LNET_NI_STATUS_DOWN;
881 lnet_destroy_rc_data(lnet_rc_data_t *rcd)
883 LASSERT(list_empty(&rcd->rcd_list));
884 /* detached from network */
885 LASSERT(LNetHandleIsInvalid(rcd->rcd_mdh));
887 if (rcd->rcd_gateway) {
888 int cpt = rcd->rcd_gateway->lp_cpt;
891 lnet_peer_decref_locked(rcd->rcd_gateway);
892 lnet_net_unlock(cpt);
895 if (rcd->rcd_pinginfo)
896 LIBCFS_FREE(rcd->rcd_pinginfo, LNET_PINGINFO_SIZE);
898 LIBCFS_FREE(rcd, sizeof(*rcd));
901 static lnet_rc_data_t *
902 lnet_create_rc_data_locked(lnet_peer_t *gateway)
904 lnet_rc_data_t *rcd = NULL;
905 lnet_ping_info_t *pi;
909 lnet_net_unlock(gateway->lp_cpt);
911 LIBCFS_ALLOC(rcd, sizeof(*rcd));
915 LNetInvalidateHandle(&rcd->rcd_mdh);
916 INIT_LIST_HEAD(&rcd->rcd_list);
918 LIBCFS_ALLOC(pi, LNET_PINGINFO_SIZE);
922 for (i = 0; i < LNET_MAX_RTR_NIS; i++) {
923 pi->pi_ni[i].ns_nid = LNET_NID_ANY;
924 pi->pi_ni[i].ns_status = LNET_NI_STATUS_INVALID;
926 rcd->rcd_pinginfo = pi;
928 LASSERT(!LNetHandleIsInvalid(the_lnet.ln_rc_eqh));
929 rc = LNetMDBind((lnet_md_t){.start = pi,
931 .length = LNET_PINGINFO_SIZE,
932 .threshold = LNET_MD_THRESH_INF,
933 .options = LNET_MD_TRUNCATE,
934 .eq_handle = the_lnet.ln_rc_eqh},
938 CERROR("Can't bind MD: %d\n", rc);
943 lnet_net_lock(gateway->lp_cpt);
944 /* router table changed or someone has created rcd for this gateway */
945 if (!lnet_isrouter(gateway) || gateway->lp_rcd) {
946 lnet_net_unlock(gateway->lp_cpt);
950 lnet_peer_addref_locked(gateway);
951 rcd->rcd_gateway = gateway;
952 gateway->lp_rcd = rcd;
953 gateway->lp_ping_notsent = 0;
959 if (!LNetHandleIsInvalid(rcd->rcd_mdh)) {
960 rc = LNetMDUnlink(rcd->rcd_mdh);
963 lnet_destroy_rc_data(rcd);
966 lnet_net_lock(gateway->lp_cpt);
967 return gateway->lp_rcd;
971 lnet_router_check_interval(lnet_peer_t *rtr)
975 secs = rtr->lp_alive ? live_router_check_interval :
976 dead_router_check_interval;
984 lnet_ping_router_locked(lnet_peer_t *rtr)
986 lnet_rc_data_t *rcd = NULL;
987 unsigned long now = cfs_time_current();
990 lnet_peer_addref_locked(rtr);
992 if (rtr->lp_ping_deadline && /* ping timed out? */
993 cfs_time_after(now, rtr->lp_ping_deadline))
994 lnet_notify_locked(rtr, 1, 0, now);
996 /* Run any outstanding notifications */
997 lnet_ni_notify_locked(rtr->lp_ni, rtr);
999 if (!lnet_isrouter(rtr) ||
1000 the_lnet.ln_rc_state != LNET_RC_STATE_RUNNING) {
1001 /* router table changed or router checker is shutting down */
1002 lnet_peer_decref_locked(rtr);
1007 rtr->lp_rcd : lnet_create_rc_data_locked(rtr);
1012 secs = lnet_router_check_interval(rtr);
1015 "rtr %s %d: deadline %lu ping_notsent %d alive %d alive_count %d lp_ping_timestamp %lu\n",
1016 libcfs_nid2str(rtr->lp_nid), secs,
1017 rtr->lp_ping_deadline, rtr->lp_ping_notsent,
1018 rtr->lp_alive, rtr->lp_alive_count, rtr->lp_ping_timestamp);
1020 if (secs && !rtr->lp_ping_notsent &&
1021 cfs_time_after(now, cfs_time_add(rtr->lp_ping_timestamp,
1022 cfs_time_seconds(secs)))) {
1024 lnet_process_id_t id;
1025 lnet_handle_md_t mdh;
1027 id.nid = rtr->lp_nid;
1028 id.pid = LNET_PID_LUSTRE;
1029 CDEBUG(D_NET, "Check: %s\n", libcfs_id2str(id));
1031 rtr->lp_ping_notsent = 1;
1032 rtr->lp_ping_timestamp = now;
1036 if (!rtr->lp_ping_deadline) {
1037 rtr->lp_ping_deadline =
1038 cfs_time_shift(router_ping_timeout);
1041 lnet_net_unlock(rtr->lp_cpt);
1043 rc = LNetGet(LNET_NID_ANY, mdh, id, LNET_RESERVED_PORTAL,
1044 LNET_PROTO_PING_MATCHBITS, 0);
1046 lnet_net_lock(rtr->lp_cpt);
1048 rtr->lp_ping_notsent = 0; /* no event pending */
1051 lnet_peer_decref_locked(rtr);
1055 lnet_router_checker_start(void)
1057 struct task_struct *task;
1061 LASSERT(the_lnet.ln_rc_state == LNET_RC_STATE_SHUTDOWN);
1063 if (check_routers_before_use &&
1064 dead_router_check_interval <= 0) {
1065 LCONSOLE_ERROR_MSG(0x10a, "'dead_router_check_interval' must be set if 'check_routers_before_use' is set\n");
1069 init_completion(&the_lnet.ln_rc_signal);
1071 rc = LNetEQAlloc(0, lnet_router_checker_event, &the_lnet.ln_rc_eqh);
1073 CERROR("Can't allocate EQ(%d): %d\n", eqsz, rc);
1077 the_lnet.ln_rc_state = LNET_RC_STATE_RUNNING;
1078 task = kthread_run(lnet_router_checker, NULL, "router_checker");
1081 CERROR("Can't start router checker thread: %d\n", rc);
1082 /* block until event callback signals exit */
1083 wait_for_completion(&the_lnet.ln_rc_signal);
1084 rc = LNetEQFree(the_lnet.ln_rc_eqh);
1086 the_lnet.ln_rc_state = LNET_RC_STATE_SHUTDOWN;
1090 if (check_routers_before_use) {
1092 * Note that a helpful side-effect of pinging all known routers
1093 * at startup is that it makes them drop stale connections they
1094 * may have to a previous instance of me.
1096 lnet_wait_known_routerstate();
1103 lnet_router_checker_stop(void)
1107 if (the_lnet.ln_rc_state == LNET_RC_STATE_SHUTDOWN)
1110 LASSERT(the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING);
1111 the_lnet.ln_rc_state = LNET_RC_STATE_STOPPING;
1112 /* wakeup the RC thread if it's sleeping */
1113 wake_up(&the_lnet.ln_rc_waitq);
1115 /* block until event callback signals exit */
1116 wait_for_completion(&the_lnet.ln_rc_signal);
1117 LASSERT(the_lnet.ln_rc_state == LNET_RC_STATE_SHUTDOWN);
1119 rc = LNetEQFree(the_lnet.ln_rc_eqh);
1124 lnet_prune_rc_data(int wait_unlink)
1126 lnet_rc_data_t *rcd;
1127 lnet_rc_data_t *tmp;
1129 struct list_head head;
1132 if (likely(the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING &&
1133 list_empty(&the_lnet.ln_rcd_deathrow) &&
1134 list_empty(&the_lnet.ln_rcd_zombie)))
1137 INIT_LIST_HEAD(&head);
1139 lnet_net_lock(LNET_LOCK_EX);
1141 if (the_lnet.ln_rc_state != LNET_RC_STATE_RUNNING) {
1142 /* router checker is stopping, prune all */
1143 list_for_each_entry(lp, &the_lnet.ln_routers,
1148 LASSERT(list_empty(&lp->lp_rcd->rcd_list));
1149 list_add(&lp->lp_rcd->rcd_list,
1150 &the_lnet.ln_rcd_deathrow);
1155 /* unlink all RCDs on deathrow list */
1156 list_splice_init(&the_lnet.ln_rcd_deathrow, &head);
1158 if (!list_empty(&head)) {
1159 lnet_net_unlock(LNET_LOCK_EX);
1161 list_for_each_entry(rcd, &head, rcd_list)
1162 LNetMDUnlink(rcd->rcd_mdh);
1164 lnet_net_lock(LNET_LOCK_EX);
1167 list_splice_init(&head, &the_lnet.ln_rcd_zombie);
1169 /* release all zombie RCDs */
1170 while (!list_empty(&the_lnet.ln_rcd_zombie)) {
1171 list_for_each_entry_safe(rcd, tmp, &the_lnet.ln_rcd_zombie,
1173 if (LNetHandleIsInvalid(rcd->rcd_mdh))
1174 list_move(&rcd->rcd_list, &head);
1177 wait_unlink = wait_unlink &&
1178 !list_empty(&the_lnet.ln_rcd_zombie);
1180 lnet_net_unlock(LNET_LOCK_EX);
1182 while (!list_empty(&head)) {
1183 rcd = list_entry(head.next,
1184 lnet_rc_data_t, rcd_list);
1185 list_del_init(&rcd->rcd_list);
1186 lnet_destroy_rc_data(rcd);
1193 CDEBUG(((i & (-i)) == i) ? D_WARNING : D_NET,
1194 "Waiting for rc buffers to unlink\n");
1195 set_current_state(TASK_UNINTERRUPTIBLE);
1196 schedule_timeout(cfs_time_seconds(1) / 4);
1198 lnet_net_lock(LNET_LOCK_EX);
1201 lnet_net_unlock(LNET_LOCK_EX);
1205 * This function is called to check if the RC should block indefinitely.
1206 * It's called from lnet_router_checker() as well as being passed to
1207 * wait_event_interruptible() to avoid the lost wake_up problem.
1209 * When it's called from wait_event_interruptible() it is necessary to
1210 * also not sleep if the rc state is not running to avoid a deadlock
1211 * when the system is shutting down
1214 lnet_router_checker_active(void)
1216 if (the_lnet.ln_rc_state != LNET_RC_STATE_RUNNING)
1220 * Router Checker thread needs to run when routing is enabled in
1221 * order to call lnet_update_ni_status_locked()
1223 if (the_lnet.ln_routing)
1226 return !list_empty(&the_lnet.ln_routers) &&
1227 (live_router_check_interval > 0 ||
1228 dead_router_check_interval > 0);
1232 lnet_router_checker(void *arg)
1235 struct list_head *entry;
1237 cfs_block_allsigs();
1239 while (the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING) {
1244 cpt = lnet_net_lock_current();
1246 version = the_lnet.ln_routers_version;
1248 list_for_each(entry, &the_lnet.ln_routers) {
1249 rtr = list_entry(entry, lnet_peer_t, lp_rtr_list);
1251 cpt2 = lnet_cpt_of_nid_locked(rtr->lp_nid);
1253 lnet_net_unlock(cpt);
1256 /* the routers list has changed */
1257 if (version != the_lnet.ln_routers_version)
1261 lnet_ping_router_locked(rtr);
1263 /* NB dropped lock */
1264 if (version != the_lnet.ln_routers_version) {
1265 /* the routers list has changed */
1270 if (the_lnet.ln_routing)
1271 lnet_update_ni_status_locked();
1273 lnet_net_unlock(cpt);
1275 lnet_prune_rc_data(0); /* don't wait for UNLINK */
1278 * Call schedule_timeout() here always adds 1 to load average
1279 * because kernel counts # active tasks as nr_running
1280 * + nr_uninterruptible.
1283 * if there are any routes then wakeup every second. If
1284 * there are no routes then sleep indefinitely until woken
1285 * up by a user adding a route
1287 if (!lnet_router_checker_active())
1288 wait_event_interruptible(the_lnet.ln_rc_waitq,
1289 lnet_router_checker_active());
1291 wait_event_interruptible_timeout(the_lnet.ln_rc_waitq,
1293 cfs_time_seconds(1));
1296 lnet_prune_rc_data(1); /* wait for UNLINK */
1298 the_lnet.ln_rc_state = LNET_RC_STATE_SHUTDOWN;
1299 complete(&the_lnet.ln_rc_signal);
1300 /* The unlink event callback will signal final completion */
1305 lnet_destroy_rtrbuf(lnet_rtrbuf_t *rb, int npages)
1307 int sz = offsetof(lnet_rtrbuf_t, rb_kiov[npages]);
1309 while (--npages >= 0)
1310 __free_page(rb->rb_kiov[npages].bv_page);
1312 LIBCFS_FREE(rb, sz);
1315 static lnet_rtrbuf_t *
1316 lnet_new_rtrbuf(lnet_rtrbufpool_t *rbp, int cpt)
1318 int npages = rbp->rbp_npages;
1319 int sz = offsetof(lnet_rtrbuf_t, rb_kiov[npages]);
1324 LIBCFS_CPT_ALLOC(rb, lnet_cpt_table(), cpt, sz);
1330 for (i = 0; i < npages; i++) {
1331 page = alloc_pages_node(
1332 cfs_cpt_spread_node(lnet_cpt_table(), cpt),
1333 GFP_KERNEL | __GFP_ZERO, 0);
1336 __free_page(rb->rb_kiov[i].bv_page);
1338 LIBCFS_FREE(rb, sz);
1342 rb->rb_kiov[i].bv_len = PAGE_SIZE;
1343 rb->rb_kiov[i].bv_offset = 0;
1344 rb->rb_kiov[i].bv_page = page;
1351 lnet_rtrpool_free_bufs(lnet_rtrbufpool_t *rbp, int cpt)
1353 int npages = rbp->rbp_npages;
1354 struct list_head tmp;
1356 lnet_rtrbuf_t *temp;
1358 if (!rbp->rbp_nbuffers) /* not initialized or already freed */
1361 INIT_LIST_HEAD(&tmp);
1364 lnet_drop_routed_msgs_locked(&rbp->rbp_msgs, cpt);
1365 list_splice_init(&rbp->rbp_bufs, &tmp);
1366 rbp->rbp_req_nbuffers = 0;
1367 rbp->rbp_nbuffers = 0;
1368 rbp->rbp_credits = 0;
1369 rbp->rbp_mincredits = 0;
1370 lnet_net_unlock(cpt);
1372 /* Free buffers on the free list. */
1373 list_for_each_entry_safe(rb, temp, &tmp, rb_list) {
1374 list_del(&rb->rb_list);
1375 lnet_destroy_rtrbuf(rb, npages);
1380 lnet_rtrpool_adjust_bufs(lnet_rtrbufpool_t *rbp, int nbufs, int cpt)
1382 struct list_head rb_list;
1385 int num_buffers = 0;
1387 int npages = rbp->rbp_npages;
1391 * If we are called for less buffers than already in the pool, we
1392 * just lower the req_nbuffers number and excess buffers will be
1393 * thrown away as they are returned to the free list. Credits
1394 * then get adjusted as well.
1395 * If we already have enough buffers allocated to serve the
1396 * increase requested, then we can treat that the same way as we
1399 num_rb = nbufs - rbp->rbp_nbuffers;
1400 if (nbufs <= rbp->rbp_req_nbuffers || num_rb <= 0) {
1401 rbp->rbp_req_nbuffers = nbufs;
1402 lnet_net_unlock(cpt);
1406 * store the older value of rbp_req_nbuffers and then set it to
1407 * the new request to prevent lnet_return_rx_credits_locked() from
1408 * freeing buffers that we need to keep around
1410 old_req_nbufs = rbp->rbp_req_nbuffers;
1411 rbp->rbp_req_nbuffers = nbufs;
1412 lnet_net_unlock(cpt);
1414 INIT_LIST_HEAD(&rb_list);
1417 * allocate the buffers on a local list first. If all buffers are
1418 * allocated successfully then join this list to the rbp buffer
1419 * list. If not then free all allocated buffers.
1421 while (num_rb-- > 0) {
1422 rb = lnet_new_rtrbuf(rbp, cpt);
1424 CERROR("Failed to allocate %d route bufs of %d pages\n",
1428 rbp->rbp_req_nbuffers = old_req_nbufs;
1429 lnet_net_unlock(cpt);
1434 list_add(&rb->rb_list, &rb_list);
1440 list_splice_tail(&rb_list, &rbp->rbp_bufs);
1441 rbp->rbp_nbuffers += num_buffers;
1442 rbp->rbp_credits += num_buffers;
1443 rbp->rbp_mincredits = rbp->rbp_credits;
1445 * We need to schedule blocked msg using the newly
1448 while (!list_empty(&rbp->rbp_bufs) &&
1449 !list_empty(&rbp->rbp_msgs))
1450 lnet_schedule_blocked_locked(rbp);
1452 lnet_net_unlock(cpt);
1457 while (!list_empty(&rb_list)) {
1458 rb = list_entry(rb_list.next, lnet_rtrbuf_t, rb_list);
1459 list_del(&rb->rb_list);
1460 lnet_destroy_rtrbuf(rb, npages);
1467 lnet_rtrpool_init(lnet_rtrbufpool_t *rbp, int npages)
1469 INIT_LIST_HEAD(&rbp->rbp_msgs);
1470 INIT_LIST_HEAD(&rbp->rbp_bufs);
1472 rbp->rbp_npages = npages;
1473 rbp->rbp_credits = 0;
1474 rbp->rbp_mincredits = 0;
1478 lnet_rtrpools_free(int keep_pools)
1480 lnet_rtrbufpool_t *rtrp;
1483 if (!the_lnet.ln_rtrpools) /* uninitialized or freed */
1486 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1487 lnet_rtrpool_free_bufs(&rtrp[LNET_TINY_BUF_IDX], i);
1488 lnet_rtrpool_free_bufs(&rtrp[LNET_SMALL_BUF_IDX], i);
1489 lnet_rtrpool_free_bufs(&rtrp[LNET_LARGE_BUF_IDX], i);
1493 cfs_percpt_free(the_lnet.ln_rtrpools);
1494 the_lnet.ln_rtrpools = NULL;
1499 lnet_nrb_tiny_calculate(void)
1501 int nrbs = LNET_NRB_TINY;
1503 if (tiny_router_buffers < 0) {
1504 LCONSOLE_ERROR_MSG(0x10c,
1505 "tiny_router_buffers=%d invalid when routing enabled\n",
1506 tiny_router_buffers);
1510 if (tiny_router_buffers > 0)
1511 nrbs = tiny_router_buffers;
1513 nrbs /= LNET_CPT_NUMBER;
1514 return max(nrbs, LNET_NRB_TINY_MIN);
1518 lnet_nrb_small_calculate(void)
1520 int nrbs = LNET_NRB_SMALL;
1522 if (small_router_buffers < 0) {
1523 LCONSOLE_ERROR_MSG(0x10c,
1524 "small_router_buffers=%d invalid when routing enabled\n",
1525 small_router_buffers);
1529 if (small_router_buffers > 0)
1530 nrbs = small_router_buffers;
1532 nrbs /= LNET_CPT_NUMBER;
1533 return max(nrbs, LNET_NRB_SMALL_MIN);
1537 lnet_nrb_large_calculate(void)
1539 int nrbs = LNET_NRB_LARGE;
1541 if (large_router_buffers < 0) {
1542 LCONSOLE_ERROR_MSG(0x10c,
1543 "large_router_buffers=%d invalid when routing enabled\n",
1544 large_router_buffers);
1548 if (large_router_buffers > 0)
1549 nrbs = large_router_buffers;
1551 nrbs /= LNET_CPT_NUMBER;
1552 return max(nrbs, LNET_NRB_LARGE_MIN);
1556 lnet_rtrpools_alloc(int im_a_router)
1558 lnet_rtrbufpool_t *rtrp;
1565 if (!strcmp(forwarding, "")) {
1566 /* not set either way */
1569 } else if (!strcmp(forwarding, "disabled")) {
1570 /* explicitly disabled */
1572 } else if (!strcmp(forwarding, "enabled")) {
1573 /* explicitly enabled */
1575 LCONSOLE_ERROR_MSG(0x10b, "'forwarding' not set to either 'enabled' or 'disabled'\n");
1579 nrb_tiny = lnet_nrb_tiny_calculate();
1583 nrb_small = lnet_nrb_small_calculate();
1587 nrb_large = lnet_nrb_large_calculate();
1591 the_lnet.ln_rtrpools = cfs_percpt_alloc(lnet_cpt_table(),
1593 sizeof(lnet_rtrbufpool_t));
1594 if (!the_lnet.ln_rtrpools) {
1595 LCONSOLE_ERROR_MSG(0x10c,
1596 "Failed to initialize router buffe pool\n");
1600 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1601 lnet_rtrpool_init(&rtrp[LNET_TINY_BUF_IDX], 0);
1602 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_TINY_BUF_IDX],
1607 lnet_rtrpool_init(&rtrp[LNET_SMALL_BUF_IDX],
1608 LNET_NRB_SMALL_PAGES);
1609 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_SMALL_BUF_IDX],
1614 lnet_rtrpool_init(&rtrp[LNET_LARGE_BUF_IDX],
1615 LNET_NRB_LARGE_PAGES);
1616 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_LARGE_BUF_IDX],
1622 lnet_net_lock(LNET_LOCK_EX);
1623 the_lnet.ln_routing = 1;
1624 lnet_net_unlock(LNET_LOCK_EX);
1629 lnet_rtrpools_free(0);
1634 lnet_rtrpools_adjust_helper(int tiny, int small, int large)
1639 lnet_rtrbufpool_t *rtrp;
1642 * If the provided values for each buffer pool are different than the
1643 * configured values, we need to take action.
1646 tiny_router_buffers = tiny;
1647 nrb = lnet_nrb_tiny_calculate();
1648 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1649 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_TINY_BUF_IDX],
1656 small_router_buffers = small;
1657 nrb = lnet_nrb_small_calculate();
1658 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1659 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_SMALL_BUF_IDX],
1666 large_router_buffers = large;
1667 nrb = lnet_nrb_large_calculate();
1668 cfs_percpt_for_each(rtrp, i, the_lnet.ln_rtrpools) {
1669 rc = lnet_rtrpool_adjust_bufs(&rtrp[LNET_LARGE_BUF_IDX],
1680 lnet_rtrpools_adjust(int tiny, int small, int large)
1683 * this function doesn't revert the changes if adding new buffers
1684 * failed. It's up to the user space caller to revert the
1687 if (!the_lnet.ln_routing)
1690 return lnet_rtrpools_adjust_helper(tiny, small, large);
1694 lnet_rtrpools_enable(void)
1698 if (the_lnet.ln_routing)
1701 if (!the_lnet.ln_rtrpools)
1703 * If routing is turned off, and we have never
1704 * initialized the pools before, just call the
1705 * standard buffer pool allocation routine as
1706 * if we are just configuring this for the first
1709 rc = lnet_rtrpools_alloc(1);
1711 rc = lnet_rtrpools_adjust_helper(0, 0, 0);
1715 lnet_net_lock(LNET_LOCK_EX);
1716 the_lnet.ln_routing = 1;
1718 the_lnet.ln_ping_info->pi_features &= ~LNET_PING_FEAT_RTE_DISABLED;
1719 lnet_net_unlock(LNET_LOCK_EX);
1725 lnet_rtrpools_disable(void)
1727 if (!the_lnet.ln_routing)
1730 lnet_net_lock(LNET_LOCK_EX);
1731 the_lnet.ln_routing = 0;
1732 the_lnet.ln_ping_info->pi_features |= LNET_PING_FEAT_RTE_DISABLED;
1734 tiny_router_buffers = 0;
1735 small_router_buffers = 0;
1736 large_router_buffers = 0;
1737 lnet_net_unlock(LNET_LOCK_EX);
1738 lnet_rtrpools_free(1);
1742 lnet_notify(lnet_ni_t *ni, lnet_nid_t nid, int alive, unsigned long when)
1744 struct lnet_peer *lp = NULL;
1745 unsigned long now = cfs_time_current();
1746 int cpt = lnet_cpt_of_nid(nid);
1748 LASSERT(!in_interrupt());
1750 CDEBUG(D_NET, "%s notifying %s: %s\n",
1751 !ni ? "userspace" : libcfs_nid2str(ni->ni_nid),
1752 libcfs_nid2str(nid),
1753 alive ? "up" : "down");
1756 LNET_NIDNET(ni->ni_nid) != LNET_NIDNET(nid)) {
1757 CWARN("Ignoring notification of %s %s by %s (different net)\n",
1758 libcfs_nid2str(nid), alive ? "birth" : "death",
1759 libcfs_nid2str(ni->ni_nid));
1763 /* can't do predictions... */
1764 if (cfs_time_after(when, now)) {
1765 CWARN("Ignoring prediction from %s of %s %s %ld seconds in the future\n",
1766 !ni ? "userspace" : libcfs_nid2str(ni->ni_nid),
1767 libcfs_nid2str(nid), alive ? "up" : "down",
1768 cfs_duration_sec(cfs_time_sub(when, now)));
1772 if (ni && !alive && /* LND telling me she's down */
1773 !auto_down) { /* auto-down disabled */
1774 CDEBUG(D_NET, "Auto-down disabled\n");
1780 if (the_lnet.ln_shutdown) {
1781 lnet_net_unlock(cpt);
1785 lp = lnet_find_peer_locked(the_lnet.ln_peer_tables[cpt], nid);
1788 lnet_net_unlock(cpt);
1789 CDEBUG(D_NET, "%s not found\n", libcfs_nid2str(nid));
1794 * We can't fully trust LND on reporting exact peer last_alive
1795 * if he notifies us about dead peer. For example ksocklnd can
1796 * call us with when == _time_when_the_node_was_booted_ if
1797 * no connections were successfully established
1799 if (ni && !alive && when < lp->lp_last_alive)
1800 when = lp->lp_last_alive;
1802 lnet_notify_locked(lp, !ni, alive, when);
1805 lnet_ni_notify_locked(ni, lp);
1807 lnet_peer_decref_locked(lp);
1809 lnet_net_unlock(cpt);
1812 EXPORT_SYMBOL(lnet_notify);