- LASSERT(ni->ni_status != NULL);
-
- if (ni->ni_status->ns_status != LNET_NI_STATUS_DOWN) {
- CDEBUG(D_NET, "NI(%s:%d) status changed to down\n",
- libcfs_nid2str(ni->ni_nid), timeout);
- /* NB: so far, this is the only place to set
- * NI status to "down" */
- ni->ni_status->ns_status = LNET_NI_STATUS_DOWN;
- }
- lnet_ni_unlock(ni);
- }
-}
-
-static void
-lnet_destroy_rc_data(struct lnet_rc_data *rcd)
-{
- LASSERT(list_empty(&rcd->rcd_list));
- /* detached from network */
- LASSERT(LNetMDHandleIsInvalid(rcd->rcd_mdh));
-
- if (rcd->rcd_gateway != NULL) {
- int cpt = rcd->rcd_gateway->lpni_cpt;
-
- lnet_net_lock(cpt);
- lnet_peer_ni_decref_locked(rcd->rcd_gateway);
- lnet_net_unlock(cpt);
- }
-
- if (rcd->rcd_pinginfo != NULL)
- LIBCFS_FREE(rcd->rcd_pinginfo, LNET_PINGINFO_SIZE);
-
- LIBCFS_FREE(rcd, sizeof(*rcd));
-}
-
-static struct lnet_rc_data *
-lnet_create_rc_data_locked(struct lnet_peer_ni *gateway)
-{
- struct lnet_rc_data *rcd = NULL;
- struct lnet_ping_info *pi;
- int rc;
- int i;
-
- lnet_net_unlock(gateway->lpni_cpt);
-
- LIBCFS_ALLOC(rcd, sizeof(*rcd));
- if (rcd == NULL)
- goto out;
-
- LNetInvalidateMDHandle(&rcd->rcd_mdh);
- INIT_LIST_HEAD(&rcd->rcd_list);
-
- LIBCFS_ALLOC(pi, LNET_PINGINFO_SIZE);
- if (pi == NULL)
- goto out;
-
- for (i = 0; i < LNET_MAX_RTR_NIS; i++) {
- pi->pi_ni[i].ns_nid = LNET_NID_ANY;
- pi->pi_ni[i].ns_status = LNET_NI_STATUS_INVALID;
- }
- rcd->rcd_pinginfo = pi;
-
- LASSERT(!LNetEQHandleIsInvalid(the_lnet.ln_rc_eqh));
- rc = LNetMDBind((struct lnet_md){.start = pi,
- .user_ptr = rcd,
- .length = LNET_PINGINFO_SIZE,
- .threshold = LNET_MD_THRESH_INF,
- .options = LNET_MD_TRUNCATE,
- .eq_handle = the_lnet.ln_rc_eqh},
- LNET_UNLINK,
- &rcd->rcd_mdh);
- if (rc < 0) {
- CERROR("Can't bind MD: %d\n", rc);
- goto out;
- }
- LASSERT(rc == 0);
-
- lnet_net_lock(gateway->lpni_cpt);
- /* router table changed or someone has created rcd for this gateway */
- if (!lnet_isrouter(gateway) || gateway->lpni_rcd != NULL) {
- lnet_net_unlock(gateway->lpni_cpt);
- goto out;
- }
-
- lnet_peer_ni_addref_locked(gateway);
- rcd->rcd_gateway = gateway;
- gateway->lpni_rcd = rcd;
- gateway->lpni_ping_notsent = 0;
-
- return rcd;
-
-out:
- if (rcd != NULL) {
- if (!LNetMDHandleIsInvalid(rcd->rcd_mdh)) {
- rc = LNetMDUnlink(rcd->rcd_mdh);
- LASSERT(rc == 0);
- }
- lnet_destroy_rc_data(rcd);
- }
-
- lnet_net_lock(gateway->lpni_cpt);
- return gateway->lpni_rcd;
-}
-
-static int
-lnet_router_check_interval(struct lnet_peer_ni *rtr)
-{
- int secs;
-
- secs = rtr->lpni_alive ? live_router_check_interval :
- dead_router_check_interval;
- if (secs < 0)
- secs = 0;
-
- return secs;
-}
-
-static void
-lnet_ping_router_locked(struct lnet_peer_ni *rtr)
-{
- struct lnet_rc_data *rcd = NULL;
- cfs_time_t now = cfs_time_current();
- int secs;
- struct lnet_ni *ni;
-
- lnet_peer_ni_addref_locked(rtr);
-
- if (rtr->lpni_ping_deadline != 0 && /* ping timed out? */
- cfs_time_after(now, rtr->lpni_ping_deadline))
- lnet_notify_locked(rtr, 1, 0, now);
-
- /* Run any outstanding notifications */
- ni = lnet_get_next_ni_locked(rtr->lpni_net, NULL);
- lnet_ni_notify_locked(ni, rtr);
-
- if (!lnet_isrouter(rtr) ||
- the_lnet.ln_rc_state != LNET_RC_STATE_RUNNING) {
- /* router table changed or router checker is shutting down */
- lnet_peer_ni_decref_locked(rtr);
- return;
- }
-
- rcd = rtr->lpni_rcd != NULL ?
- rtr->lpni_rcd : lnet_create_rc_data_locked(rtr);
-
- if (rcd == NULL)
- return;
-
- secs = lnet_router_check_interval(rtr);
-
- CDEBUG(D_NET,
- "rtr %s %d: deadline %lu ping_notsent %d alive %d "
- "alive_count %d lpni_ping_timestamp %lu\n",
- libcfs_nid2str(rtr->lpni_nid), secs,
- rtr->lpni_ping_deadline, rtr->lpni_ping_notsent,
- rtr->lpni_alive, rtr->lpni_alive_count, rtr->lpni_ping_timestamp);
-
- if (secs != 0 && !rtr->lpni_ping_notsent &&
- cfs_time_after(now, cfs_time_add(rtr->lpni_ping_timestamp,
- cfs_time_seconds(secs)))) {
- int rc;
- struct lnet_process_id id;
- struct lnet_handle_md mdh;
-
- id.nid = rtr->lpni_nid;
- id.pid = LNET_PID_LUSTRE;
- CDEBUG(D_NET, "Check: %s\n", libcfs_id2str(id));
-
- rtr->lpni_ping_notsent = 1;
- rtr->lpni_ping_timestamp = now;
-
- mdh = rcd->rcd_mdh;
-
- if (rtr->lpni_ping_deadline == 0) {
- rtr->lpni_ping_deadline =
- cfs_time_shift(router_ping_timeout);
- }
-
- lnet_net_unlock(rtr->lpni_cpt);
-
- rc = LNetGet(LNET_NID_ANY, mdh, id, LNET_RESERVED_PORTAL,
- LNET_PROTO_PING_MATCHBITS, 0);
-
- lnet_net_lock(rtr->lpni_cpt);
- if (rc != 0)
- rtr->lpni_ping_notsent = 0; /* no event pending */