-void
-lnet_swap_pinginfo(struct lnet_ping_info *info)
-{
- int i;
- struct lnet_ni_status *stat;
-
- __swab32s(&info->pi_magic);
- __swab32s(&info->pi_features);
- __swab32s(&info->pi_pid);
- __swab32s(&info->pi_nnis);
- for (i = 0; i < info->pi_nnis && i < LNET_MAX_RTR_NIS; i++) {
- stat = &info->pi_ni[i];
- __swab64s(&stat->ns_nid);
- __swab32s(&stat->ns_status);
- }
- return;
-}
-
-/**
- * parse router-checker pinginfo, record number of down NIs for remote
- * networks on that router.
- */
-static void
-lnet_parse_rc_info(lnet_rc_data_t *rcd)
-{
- struct lnet_ping_info *info = rcd->rcd_pinginfo;
- struct lnet_peer_ni *gw = rcd->rcd_gateway;
- lnet_route_t *rte;
-
- if (!gw->lpni_alive)
- return;
-
- /*
- * Protect gw->lpni_ping_feats. This can be set from
- * lnet_notify_locked with different locks being held
- */
- spin_lock(&gw->lpni_lock);
-
- if (info->pi_magic == __swab32(LNET_PROTO_PING_MAGIC))
- lnet_swap_pinginfo(info);
-
- /* NB always racing with network! */
- if (info->pi_magic != LNET_PROTO_PING_MAGIC) {
- CDEBUG(D_NET, "%s: Unexpected magic %08x\n",
- libcfs_nid2str(gw->lpni_nid), info->pi_magic);
- gw->lpni_ping_feats = LNET_PING_FEAT_INVAL;
- spin_unlock(&gw->lpni_lock);
- return;
- }
-
- gw->lpni_ping_feats = info->pi_features;
- if ((gw->lpni_ping_feats & LNET_PING_FEAT_MASK) == 0) {
- CDEBUG(D_NET, "%s: Unexpected features 0x%x\n",
- libcfs_nid2str(gw->lpni_nid), gw->lpni_ping_feats);
- spin_unlock(&gw->lpni_lock);
- return; /* nothing I can understand */
- }
-
- if ((gw->lpni_ping_feats & LNET_PING_FEAT_NI_STATUS) == 0) {
- spin_unlock(&gw->lpni_lock);
- return; /* can't carry NI status info */
- }
-
- list_for_each_entry(rte, &gw->lpni_routes, lr_gwlist) {
- int down = 0;
- int up = 0;
- int i;
-
- if ((gw->lpni_ping_feats & LNET_PING_FEAT_RTE_DISABLED) != 0) {
- rte->lr_downis = 1;
- continue;
- }
-
- for (i = 0; i < info->pi_nnis && i < LNET_MAX_RTR_NIS; i++) {
- struct lnet_ni_status *stat = &info->pi_ni[i];
- lnet_nid_t nid = stat->ns_nid;
-
- if (nid == LNET_NID_ANY) {
- CDEBUG(D_NET, "%s: unexpected LNET_NID_ANY\n",
- libcfs_nid2str(gw->lpni_nid));
- gw->lpni_ping_feats = LNET_PING_FEAT_INVAL;
- spin_unlock(&gw->lpni_lock);
- return;
- }
-
- if (LNET_NETTYP(LNET_NIDNET(nid)) == LOLND)
- continue;
-
- if (stat->ns_status == LNET_NI_STATUS_DOWN) {
- down++;
- continue;
- }
-
- if (stat->ns_status == LNET_NI_STATUS_UP) {
- if (LNET_NIDNET(nid) == rte->lr_net) {
- up = 1;
- break;
- }
- continue;
- }
-
- CDEBUG(D_NET, "%s: Unexpected status 0x%x\n",
- libcfs_nid2str(gw->lpni_nid), stat->ns_status);
- gw->lpni_ping_feats = LNET_PING_FEAT_INVAL;
- spin_unlock(&gw->lpni_lock);
- return;
- }
-
- if (up) { /* ignore downed NIs if NI for dest network is up */
- rte->lr_downis = 0;
- continue;
- }
- /* if @down is zero and this route is single-hop, it means
- * we can't find NI for target network */
- if (down == 0 && rte->lr_hops == 1)
- down = 1;
-
- rte->lr_downis = down;
- }
-
- spin_unlock(&gw->lpni_lock);
-}
-
-static void
-lnet_router_checker_event(lnet_event_t *event)
-{
- lnet_rc_data_t *rcd = event->md.user_ptr;
- struct lnet_peer_ni *lp;
-
- LASSERT(rcd != NULL);
-
- if (event->unlinked) {
- LNetInvalidateHandle(&rcd->rcd_mdh);
- return;
- }
-
- LASSERT(event->type == LNET_EVENT_SEND ||
- event->type == LNET_EVENT_REPLY);
-
- lp = rcd->rcd_gateway;
- LASSERT(lp != NULL);
-
- /* NB: it's called with holding lnet_res_lock, we have a few
- * places need to hold both locks at the same time, please take
- * care of lock ordering */
- lnet_net_lock(lp->lpni_cpt);
- if (!lnet_isrouter(lp) || lp->lpni_rcd != rcd) {
- /* ignore if no longer a router or rcd is replaced */
- goto out;
- }
-
- if (event->type == LNET_EVENT_SEND) {
- lp->lpni_ping_notsent = 0;
- if (event->status == 0)
- goto out;
- }
-
- /* LNET_EVENT_REPLY */
- /* A successful REPLY means the router is up. If _any_ comms
- * to the router fail I assume it's down (this will happen if
- * we ping alive routers to try to detect router death before
- * apps get burned). */
-
- lnet_notify_locked(lp, 1, (event->status == 0), cfs_time_current());
- /* The router checker will wake up very shortly and do the
- * actual notification.
- * XXX If 'lp' stops being a router before then, it will still
- * have the notification pending!!! */
-
- if (avoid_asym_router_failure && event->status == 0)
- lnet_parse_rc_info(rcd);
-
- out:
- lnet_net_unlock(lp->lpni_cpt);
-}
-